no more template shifting

This commit is contained in:
Boblet 2022-05-10 16:24:04 +02:00
parent 416e2e6278
commit 4628858d64
4 changed files with 263 additions and 231 deletions

View File

@ -95,6 +95,14 @@ public class AssemblerRecipes {
if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) { if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) {
ComparableStack comp = ItemAssemblyTemplate.readType(stack);
//NEW
if(comp != null) {
return comp.toStack();
}
//LEGACY
int i = stack.getItemDamage(); int i = stack.getItemDamage();
if(i >= 0 && i < recipeList.size()) { if(i >= 0 && i < recipeList.size()) {
return recipeList.get(i).toStack(); return recipeList.get(i).toStack();
@ -108,8 +116,15 @@ public class AssemblerRecipes {
if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) { if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) {
int i = stack.getItemDamage(); //NEW
ComparableStack compStack = ItemAssemblyTemplate.readType(stack);
if(compStack != null) {
AStack[] ret = recipes.get(compStack);
return Arrays.asList(ret);
}
//LEGACY
int i = stack.getItemDamage();
if(i >= 0 && i < recipeList.size()) { if(i >= 0 && i < recipeList.size()) {
ItemStack out = recipeList.get(i).toStack(); ItemStack out = recipeList.get(i).toStack();

View File

@ -8,7 +8,6 @@ import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.RecipesCommon.OreDictStack; import com.hbm.inventory.RecipesCommon.OreDictStack;
import com.hbm.inventory.recipes.AssemblerRecipes; import com.hbm.inventory.recipes.AssemblerRecipes;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.lib.RefStrings;
import com.hbm.util.I18nUtil; import com.hbm.util.I18nUtil;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -18,6 +17,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
@ -28,8 +28,7 @@ public class ItemAssemblyTemplate extends Item {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
protected IIcon hiddenIcon; protected IIcon hiddenIcon;
public ItemAssemblyTemplate() public ItemAssemblyTemplate() {
{
this.setHasSubtypes(true); this.setHasSubtypes(true);
this.setMaxDamage(0); this.setMaxDamage(0);
} }
@ -51,14 +50,35 @@ public class ItemAssemblyTemplate extends Item {
this.hiddenIcon = reg.registerIcon(this.iconString + "_secret"); this.hiddenIcon = reg.registerIcon(this.iconString + "_secret");
} }
public String getItemStackDisplayName(ItemStack stack) public static void writeType(ItemStack stack, ComparableStack comp) {
{ if(!stack.hasTagCompound())
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setInteger("id", Item.getIdFromItem(comp.item));
stack.stackTagCompound.setByte("count", (byte)comp.stacksize);
stack.stackTagCompound.setShort("meta", (short)comp.meta);
}
public static ComparableStack readType(ItemStack stack) {
if(!stack.hasTagCompound())
return null;
if(!stack.stackTagCompound.hasKey("id"))
return null;
int id = stack.stackTagCompound.getInteger("id");
int count = stack.stackTagCompound.getByte("count");
int meta = stack.stackTagCompound.getShort("meta");
return new ComparableStack(Item.getItemById(id), count, meta);
}
public String getItemStackDisplayName(ItemStack stack) {
String s = ("" + StatCollector.translateToLocal(this.getUnlocalizedName() + ".name")).trim(); String s = ("" + StatCollector.translateToLocal(this.getUnlocalizedName() + ".name")).trim();
ItemStack out = stack.getItemDamage() < AssemblerRecipes.recipeList.size() ? AssemblerRecipes.recipeList.get(stack.getItemDamage()).toStack() : null; ItemStack out = stack.getItemDamage() < AssemblerRecipes.recipeList.size() ? AssemblerRecipes.recipeList.get(stack.getItemDamage()).toStack() : null;
String s1 = ("" + StatCollector.translateToLocal((out != null ? out.getUnlocalizedName() : "") + ".name")).trim(); String s1 = ("" + StatCollector.translateToLocal((out != null ? out.getUnlocalizedName() : "") + ".name")).trim();
if (s1 != null) if(s1 != null) {
{
s = s + " " + s1; s = s + " " + s1;
} }
@ -86,7 +106,10 @@ public class ItemAssemblyTemplate extends Item {
if(i < 0 || i >= AssemblerRecipes.recipeList.size()) if(i < 0 || i >= AssemblerRecipes.recipeList.size())
return 100; return 100;
ComparableStack out = AssemblerRecipes.recipeList.get(i); //NEW
ComparableStack out = readType(stack);
//LEGACY
if(out == null) out = AssemblerRecipes.recipeList.get(i);
Integer time = AssemblerRecipes.time.get(out); Integer time = AssemblerRecipes.time.get(out);
if(time != null) if(time != null)
@ -108,12 +131,25 @@ public class ItemAssemblyTemplate extends Item {
return; return;
} }
ComparableStack out = AssemblerRecipes.recipeList.get(i); boolean nbtType = true;
//NEW
ComparableStack out = readType(stack);
//LEGACY
if(out == null) {
out = AssemblerRecipes.recipeList.get(i);
nbtType = false;
}
Integer time = AssemblerRecipes.time.get(out);
HashSet<Item> folders = AssemblerRecipes.hidden.get(out); HashSet<Item> folders = AssemblerRecipes.hidden.get(out);
if(folders == null) if(folders == null)
folders = new HashSet() {{ add(ModItems.template_folder); }}; folders = new HashSet() {
{
add(ModItems.template_folder);
}
};
String[] names = new String[folders.size()]; String[] names = new String[folders.size()];
@ -124,6 +160,13 @@ public class ItemAssemblyTemplate extends Item {
} }
list.add(EnumChatFormatting.YELLOW + I18nUtil.resolveKey("info.templatefolder", String.join(" / ", names))); list.add(EnumChatFormatting.YELLOW + I18nUtil.resolveKey("info.templatefolder", String.join(" / ", names)));
if(nbtType) {
list.add(EnumChatFormatting.GREEN + "Persistent template");
} else {
list.add(EnumChatFormatting.RED + "Volatile template");
}
list.add(""); list.add("");
if(out == null) { if(out == null) {
@ -167,114 +210,77 @@ public class ItemAssemblyTemplate extends Item {
list.add(Math.floor((float) (getProcessTime(stack)) / 20 * 100) / 100 + " " + I18nUtil.resolveKey("info.template_seconds")); list.add(Math.floor((float) (getProcessTime(stack)) / 20 * 100) / 100 + " " + I18nUtil.resolveKey("info.template_seconds"));
} }
/*@Override /*
@SideOnly(Side.CLIENT) * @Override
public boolean requiresMultipleRenderPasses() *
{ * @SideOnly(Side.CLIENT) public boolean requiresMultipleRenderPasses() {
return true; * return true; }
} *
* public int getRenderPasses(int metadata) { return 8; }
*
* IIcon[] overlays;
*
* @Override
*
* @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister
* p_94581_1_) { super.registerIcons(p_94581_1_);
*
* this.overlays = new IIcon[7];
*
* for(int i = 0; i < 7; i++) overlays[i] =
* p_94581_1_.registerIcon("hbm:assembly_template_" + i); }
*
* @Override
*
* @SideOnly(Side.CLIENT) public IIcon getIconFromDamageForRenderPass(int a,
* int b) { return b < 7 ? overlays[b] :
* super.getIconFromDamageForRenderPass(a, b); }
*
* @Override
*
* @SideOnly(Side.CLIENT) public int getColorFromItemStack(ItemStack stack,
* int layer) { if (layer == 7) { return 0xFFFFFF; } else if(layer < 7) {
* int j = colorFromSeed(getSeedFromMeta(stack.getItemDamage(), layer));
*
* if (j < 0) { j = 0xFFFFFF; }
*
* return j; }
*
* return 0; }
*
* private int getSeedFromMeta(int i, int count) { Random rand = new
* Random(i);
*
* int cap = 11;
*
* for(int j = 0; j < count - 1; j++) rand.nextInt(cap);
*
* return rand.nextInt(cap); }
*
* private int colorFromSeed(int i) { switch(i) { case 0: return 0x334077;
* case 1: return 0x6A298F; case 2: return 0xDF3795; case 3: return
* 0xFF0000; case 4: return 0x00FF00; case 5: return 0x0000FF; case 6:
* return 0xFFFF00; case 7: return 0x00FFFF; case 8: return 0x888888; case
* 9: return 0xFFFFFF; case 10: return 0x000000; default: return 0xFFFFFF; }
* }
*/
public int getRenderPasses(int metadata) /*
{ * public Motif getColorMotifFromTemplate(EnumAssemblyTemplate temp) {
return 8; *
} * //using deprecated value operator, will remove soon if(temp.getValue() >
* 0) { Motif scheme = new Motif(temp.getValue, null);
IIcon[] overlays; * scheme.setTextureSize(16, 16); //scheme.applyUniversalScheme();
* scheme.colorCount = 4; //universal scheme configuration for testing
@Override * //todo: get textures properly baked, display color for shield
@SideOnly(Side.CLIENT) * scheme.addColor(0x334077); scheme.addColor(0x6A298F);
public void registerIcons(IIconRegister p_94581_1_) * scheme.addColor(0xDF3795); scheme.addColor(0x334077);
{ *
super.registerIcons(p_94581_1_); * //different test config; prpl, lprpl, cyn, prpl
*
this.overlays = new IIcon[7]; * scheme.unify(); return scheme;
*
for(int i = 0; i < 7; i++) * } else { //return null; return Motif.defaultInstance; } }
overlays[i] = p_94581_1_.registerIcon("hbm:assembly_template_" + i); */
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamageForRenderPass(int a, int b)
{
return b < 7 ? overlays[b] : super.getIconFromDamageForRenderPass(a, b);
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int layer)
{
if (layer == 7)
{
return 0xFFFFFF;
}
else if(layer < 7)
{
int j = colorFromSeed(getSeedFromMeta(stack.getItemDamage(), layer));
if (j < 0)
{
j = 0xFFFFFF;
}
return j;
}
return 0;
}
private int getSeedFromMeta(int i, int count) {
Random rand = new Random(i);
int cap = 11;
for(int j = 0; j < count - 1; j++)
rand.nextInt(cap);
return rand.nextInt(cap);
}
private int colorFromSeed(int i) {
switch(i) {
case 0: return 0x334077;
case 1: return 0x6A298F;
case 2: return 0xDF3795;
case 3: return 0xFF0000;
case 4: return 0x00FF00;
case 5: return 0x0000FF;
case 6: return 0xFFFF00;
case 7: return 0x00FFFF;
case 8: return 0x888888;
case 9: return 0xFFFFFF;
case 10: return 0x000000;
default: return 0xFFFFFF;
}
}*/
/*public Motif getColorMotifFromTemplate(EnumAssemblyTemplate temp) {
//using deprecated value operator, will remove soon
if(temp.getValue() > 0) {
Motif scheme = new Motif(temp.getValue, null);
scheme.setTextureSize(16, 16);
//scheme.applyUniversalScheme();
scheme.colorCount = 4;
//universal scheme configuration for testing
//todo: get textures properly baked, display color for shield
scheme.addColor(0x334077);
scheme.addColor(0x6A298F);
scheme.addColor(0xDF3795);
scheme.addColor(0x334077);
//different test config; prpl, lprpl, cyn, prpl
scheme.unify();
return scheme;
} else {
//return null;
return Motif.defaultInstance;
}
}*/
} }

View File

@ -1,5 +1,7 @@
package com.hbm.packet; package com.hbm.packet;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.recipes.AssemblerRecipes;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemAssemblyTemplate; import com.hbm.items.machine.ItemAssemblyTemplate;
import com.hbm.items.machine.ItemCassette; import com.hbm.items.machine.ItemCassette;
@ -146,6 +148,15 @@ public class ItemFolderPacket implements IMessage {
} }
} }
if(output.getItem() == ModItems.assembly_template) {
ComparableStack out = AssemblerRecipes.recipeList.get(output.getItemDamage());
if(out != null) {
out.meta = 0;
ItemAssemblyTemplate.writeType(output, out);
}
}
if(!player.inventory.addItemStackToInventory(output)) if(!player.inventory.addItemStackToInventory(output))
player.dropPlayerItemWithRandomChoice(output, true); player.dropPlayerItemWithRandomChoice(output, true);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB