Make Ingredient explode wildcard values like OreIngredient.

Fixes some issues related to Grums order fix for Shapeless recipes.
Other more advanced usages need to be documented and tested.
This commit is contained in:
LexManos committed 2017-11-14 00:10:33 -08:00
1 parent 7d21b324ec
commit fc87d83d73
5 files changed
+101 -10

No files matched your search

@@ -9,8 +9,11 @@
public static final Ingredient field_193370_a = new Ingredient(new ItemStack[0])
{
public boolean apply(@Nullable ItemStack p_apply_1_)
@@ -23,12 +25,17 @@
@@ -21,17 +23,34 @@
}
};
private final ItemStack[] field_193371_b;
+ private final ItemStack[] matchingStacksExploded;
private IntList field_194140_c;
+ protected Ingredient(int size)
@@ -21,14 +24,41 @@
protected Ingredient(ItemStack... p_i47503_1_)
{
this.field_193371_b = p_i47503_1_;
+ net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.func_191196_a();
+ for (ItemStack s : p_i47503_1_)
+ {
+ if (s.func_190926_b())
+ continue;
+ if (s.func_77960_j() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE)
+ s.func_77973_b().func_150895_a(net.minecraft.creativetab.CreativeTabs.field_78027_g, lst);
+ else
+ lst.add(s);
+ }
+ this.matchingStacksExploded = lst.toArray(new ItemStack[lst.size()]);
+ Ingredient.INSTANCES.add(this);
}
- @SideOnly(Side.CLIENT)
public ItemStack[] func_193365_a()
{
return this.field_193371_b;
@@ -76,6 +83,18 @@
- return this.field_193371_b;
+ return this.matchingStacksExploded;
}
public boolean apply(@Nullable ItemStack p_apply_1_)
@@ -63,9 +82,9 @@
{
if (this.field_194140_c == null)
{
- this.field_194140_c = new IntArrayList(this.field_193371_b.length);
+ this.field_194140_c = new IntArrayList(this.matchingStacksExploded.length);
- for (ItemStack itemstack : this.field_193371_b)
+ for (ItemStack itemstack : this.matchingStacksExploded)
{
this.field_194140_c.add(RecipeItemHelper.func_194113_b(itemstack));
}
@@ -76,6 +95,18 @@
return this.field_194140_c;
}
@@ -47,3 +77,21 @@
public static Ingredient func_193367_a(Item p_193367_0_)
{
return func_193369_a(new ItemStack(p_193367_0_, 1, 32767));
@@ -108,4 +139,17 @@
return field_193370_a;
}
+
+ // 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.func_191196_a();
+ for (Ingredient part : parts)
+ {
+ for (ItemStack stack : part.field_193371_b)
+ lst.add(stack);
+ }
+ return new Ingredient(lst.toArray(new ItemStack[lst.size()]));
+ }
}
@@ -143,14 +143,15 @@ public class CraftingHelper {
if (json.isJsonArray())
{
List<Ingredient> ingredients = Lists.newArrayList();
List<ItemStack> vanilla = Lists.newArrayList();
json.getAsJsonArray().forEach((ele) -> {
List<Ingredient> vanilla = Lists.newArrayList();
json.getAsJsonArray().forEach((ele) ->
{
Ingredient ing = CraftingHelper.getIngredient(ele, context);
if (ing.getClass() == Ingredient.class) {
if (ing.getClass() == Ingredient.class)
{
//Vanilla, Due to how we read it splits each itemstack, so we pull out to re-merge later
for (ItemStack stack : ing.getMatchingStacks())
vanilla.add(stack);
vanilla.add(ing);
}
else
{
@@ -160,8 +161,7 @@ public class CraftingHelper {
if (!vanilla.isEmpty())
{
ItemStack[] items = vanilla.toArray(new ItemStack[vanilla.size()]);
ingredients.add(Ingredient.fromStacks(items));
ingredients.add(Ingredient.merge(vanilla));
}
if (ingredients.size() == 0)
@@ -0,0 +1,15 @@
[
{
"name": "forge:some_wool",
"ingredient": [
{
"item": "minecraft:wool",
"data": 1
},
{
"item": "minecraft:wool",
"data": 2
}
]
}
]
@@ -0,0 +1,15 @@
{
"type": "minecraft:crafting_shapeless",
"result": {
"item": "minecraft:stone",
"data": 0
},
"ingredients": [
{
"item": "#forge:some_wool"
},
{
"item": "#forge:some_wool"
}
]
}
@@ -0,0 +1,13 @@
{
"result": {
"item": "minecraft:dirt",
"data": 1
},
"ingredients": [
{
"item": "minecraft:stone",
"data": 32767
}
],
"type": "minecraft:crafting_shapeless"
}