mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-28 07:36:01 +00:00
ItemStackInput - cache hash and wildcard variant to avoid constant ItemStack copying
This commit is contained in:
1 parent
933e119795
commit
66953a3734
1 file changed
+19
-1
@@ -10,10 +10,13 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
public class ItemStackInput extends MachineInput<ItemStackInput>
|
||||
{
|
||||
public ItemStack ingredient = ItemStack.EMPTY;
|
||||
private ItemStackInput wildVersion = null;
|
||||
private int ingredientHash;
|
||||
|
||||
public ItemStackInput(ItemStack stack)
|
||||
{
|
||||
ingredient = stack;
|
||||
ingredientHash = hashIngredients();
|
||||
}
|
||||
|
||||
public ItemStackInput() {}
|
||||
@@ -22,6 +25,8 @@ public class ItemStackInput extends MachineInput<ItemStackInput>
|
||||
public void load(NBTTagCompound nbtTags)
|
||||
{
|
||||
ingredient = InventoryUtils.loadFromNBT(nbtTags.getCompoundTag("input"));
|
||||
ingredientHash = hashIngredients();
|
||||
wildVersion = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +43,14 @@ public class ItemStackInput extends MachineInput<ItemStackInput>
|
||||
|
||||
public ItemStackInput wildCopy()
|
||||
{
|
||||
return new ItemStackInput(new ItemStack(ingredient.getItem(), ingredient.getCount(), OreDictionary.WILDCARD_VALUE));
|
||||
if (wildVersion == null){
|
||||
if (ingredient.getMetadata() != OreDictionary.WILDCARD_VALUE){
|
||||
this.wildVersion = new ItemStackInput(new ItemStack(ingredient.getItem(), ingredient.getCount(), OreDictionary.WILDCARD_VALUE));
|
||||
} else {
|
||||
this.wildVersion = this;
|
||||
}
|
||||
}
|
||||
return this.wildVersion;
|
||||
}
|
||||
|
||||
public boolean useItemStackFromInventory(NonNullList<ItemStack> inventory, int index, boolean deplete)
|
||||
@@ -73,4 +85,10 @@ public class ItemStackInput extends MachineInput<ItemStackInput>
|
||||
{
|
||||
return other instanceof ItemStackInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return ingredientHash;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user