Fix recipe book auto-fill not working for OreDictionary ingredients.

This commit is contained in:
LexManos 2017-08-24 15:21:47 -07:00
parent 0e789f3543
commit 7930adec70

View file

@ -29,14 +29,13 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class OreIngredient extends Ingredient public class OreIngredient extends Ingredient
{ {
private NonNullList<ItemStack> ores; private NonNullList<ItemStack> ores;
private IntList itemIds = null; private IntList itemIds = null;
private ItemStack[] array = null; private ItemStack[] array = null;
private int lastSizeA = -1, lastSizeL = -1;
public OreIngredient(String ore) public OreIngredient(String ore)
{ {
@ -48,7 +47,7 @@ public class OreIngredient extends Ingredient
@Nonnull @Nonnull
public ItemStack[] getMatchingStacks() public ItemStack[] getMatchingStacks()
{ {
if (array == null || this.array.length != ores.size()) if (array == null || this.lastSizeA != ores.size())
{ {
NonNullList<ItemStack> lst = NonNullList.create(); NonNullList<ItemStack> lst = NonNullList.create();
for (ItemStack itemstack : this.ores) for (ItemStack itemstack : this.ores)
@ -59,6 +58,7 @@ public class OreIngredient extends Ingredient
lst.add(itemstack); lst.add(itemstack);
} }
this.array = lst.toArray(new ItemStack[lst.size()]); this.array = lst.toArray(new ItemStack[lst.size()]);
this.lastSizeA = ores.size();
} }
return this.array; return this.array;
} }
@ -66,10 +66,9 @@ public class OreIngredient extends Ingredient
@Override @Override
@Nonnull @Nonnull
@SideOnly(Side.CLIENT)
public IntList getValidItemStacksPacked() public IntList getValidItemStacksPacked()
{ {
if (this.itemIds == null || this.itemIds.size() != ores.size()) if (this.itemIds == null || this.lastSizeL != ores.size())
{ {
this.itemIds = new IntArrayList(this.ores.size()); this.itemIds = new IntArrayList(this.ores.size());
@ -89,6 +88,7 @@ public class OreIngredient extends Ingredient
} }
this.itemIds.sort(IntComparators.NATURAL_COMPARATOR); this.itemIds.sort(IntComparators.NATURAL_COMPARATOR);
this.lastSizeL = ores.size();
} }
return this.itemIds; return this.itemIds;
@ -112,5 +112,6 @@ public class OreIngredient extends Ingredient
protected void invalidate() protected void invalidate()
{ {
this.itemIds = null; this.itemIds = null;
this.array = null;
} }
} }