Files
2019-02-24 22:29:41 +08:00

115 lines
4.0 KiB
Diff

--- ../src-base/minecraft/net/minecraft/item/crafting/Ingredient.java
+++ ../src-work/minecraft/net/minecraft/item/crafting/Ingredient.java
@@ -8,11 +8,11 @@
import net.minecraft.client.util.RecipeItemHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraftforge.fml.relauncher.Side;
-import net.minecraftforge.fml.relauncher.SideOnly;
public class Ingredient implements Predicate<ItemStack>
{
+ //Because Mojang caches things... we need to invalidate them.. so... here we go..
+ private static final java.util.Set<Ingredient> INSTANCES = java.util.Collections.newSetFromMap(new java.util.WeakHashMap<Ingredient, Boolean>());
public static final Ingredient EMPTY = new Ingredient(new ItemStack[0])
{
public boolean apply(@Nullable ItemStack p_apply_1_)
@@ -20,18 +20,40 @@
return p_apply_1_.isEmpty();
}
};
- private final ItemStack[] matchingStacks;
+ public final ItemStack[] matchingStacks;
+ private final ItemStack[] matchingStacksExploded;
private IntList matchingStacksPacked;
+ private final boolean isSimple;
+ protected Ingredient(int size)
+ {
+ this(new ItemStack[size]);
+ }
+
protected Ingredient(ItemStack... p_i47503_1_)
{
+ boolean simple = true;
this.matchingStacks = p_i47503_1_;
+ net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.create();
+ for (ItemStack s : p_i47503_1_)
+ {
+ if (s.isEmpty())
+ continue;
+ if (s.getItem().isDamageable())
+ simple = false;
+ if (s.getMetadata() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE)
+ s.getItem().getSubItems(net.minecraft.creativetab.CreativeTabs.SEARCH, lst);
+ else
+ lst.add(s);
+ }
+ this.matchingStacksExploded = lst.toArray(new ItemStack[lst.size()]);
+ this.isSimple = simple && this.matchingStacksExploded.length > 0;
+ Ingredient.INSTANCES.add(this);
}
- @SideOnly(Side.CLIENT)
public ItemStack[] getMatchingStacks()
{
- return this.matchingStacks;
+ return this.matchingStacksExploded;
}
public boolean apply(@Nullable ItemStack p_apply_1_)
@@ -63,9 +85,9 @@
{
if (this.matchingStacksPacked == null)
{
- this.matchingStacksPacked = new IntArrayList(this.matchingStacks.length);
+ this.matchingStacksPacked = new IntArrayList(this.matchingStacksExploded.length);
- for (ItemStack itemstack : this.matchingStacks)
+ for (ItemStack itemstack : this.matchingStacksExploded)
{
this.matchingStacksPacked.add(RecipeItemHelper.pack(itemstack));
}
@@ -76,6 +98,18 @@
return this.matchingStacksPacked;
}
+ public static void invalidateAll()
+ {
+ for (Ingredient ing : INSTANCES)
+ if (ing != null)
+ ing.invalidate();
+ }
+
+ protected void invalidate()
+ {
+ this.matchingStacksPacked = null;
+ }
+
public static Ingredient fromItem(Item p_193367_0_)
{
return fromStacks(new ItemStack(p_193367_0_, 1, 32767));
@@ -108,4 +142,22 @@
return EMPTY;
}
+
+ // Merges several vanilla Ingredients together. As a qwerk of how the json is structured, we can't tell if its a single Ingredient type or multiple so we split per item and remerge here.
+ //Only public for internal use, so we can access a private field in here.
+ public static Ingredient merge(java.util.Collection<Ingredient> parts)
+ {
+ net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.create();
+ for (Ingredient part : parts)
+ {
+ for (ItemStack stack : part.matchingStacks)
+ lst.add(stack);
+ }
+ return new Ingredient(lst.toArray(new ItemStack[lst.size()]));
+ }
+
+ public boolean isSimple()
+ {
+ return isSimple || this == EMPTY;
+ }
}