ForgePatch/patches/minecraft/net/minecraft/item/crafting/ShapelessRecipe.java.patch

59 lines
3.1 KiB
Diff

--- a/net/minecraft/item/crafting/ShapelessRecipe.java
+++ b/net/minecraft/item/crafting/ShapelessRecipe.java
@@ -17,12 +17,14 @@
private final String field_194138_c;
private final ItemStack field_77580_a;
private final NonNullList<Ingredient> field_77579_b;
+ private final boolean isSimple;
public ShapelessRecipe(ResourceLocation p_i48161_1_, String p_i48161_2_, ItemStack p_i48161_3_, NonNullList<Ingredient> p_i48161_4_) {
this.field_199562_a = p_i48161_1_;
this.field_194138_c = p_i48161_2_;
this.field_77580_a = p_i48161_3_;
this.field_77579_b = p_i48161_4_;
+ this.isSimple = p_i48161_4_.stream().allMatch(Ingredient::isSimple);
}
public ResourceLocation func_199560_c() {
@@ -47,17 +49,20 @@
public boolean func_77569_a(CraftingInventory p_77569_1_, World p_77569_2_) {
RecipeItemHelper recipeitemhelper = new RecipeItemHelper();
+ java.util.List<ItemStack> inputs = new java.util.ArrayList<>();
int i = 0;
for(int j = 0; j < p_77569_1_.func_70302_i_(); ++j) {
ItemStack itemstack = p_77569_1_.func_70301_a(j);
if (!itemstack.func_190926_b()) {
++i;
+ if (isSimple)
recipeitemhelper.func_221264_a(itemstack, 1);
+ else inputs.add(itemstack);
}
}
- return i == this.field_77579_b.size() && recipeitemhelper.func_194116_a(this, (IntList)null);
+ return i == this.field_77579_b.size() && (isSimple ? recipeitemhelper.func_194116_a(this, (IntList)null) : net.minecraftforge.common.util.RecipeMatcher.findMatches(inputs, this.field_77579_b) != null);
}
public ItemStack func_77572_b(CraftingInventory p_77572_1_) {
@@ -68,14 +73,15 @@
return p_194133_1_ * p_194133_2_ >= this.field_77579_b.size();
}
- public static class Serializer implements IRecipeSerializer<ShapelessRecipe> {
+ public static class Serializer extends net.minecraftforge.registries.ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<ShapelessRecipe> {
+ private static final ResourceLocation NAME = new ResourceLocation("minecraft", "crafting_shapeless");
public ShapelessRecipe func_199425_a_(ResourceLocation p_199425_1_, JsonObject p_199425_2_) {
String s = JSONUtils.func_151219_a(p_199425_2_, "group", "");
NonNullList<Ingredient> nonnulllist = func_199568_a(JSONUtils.func_151214_t(p_199425_2_, "ingredients"));
if (nonnulllist.isEmpty()) {
throw new JsonParseException("No ingredients for shapeless recipe");
- } else if (nonnulllist.size() > 9) {
- throw new JsonParseException("Too many ingredients for shapeless recipe");
+ } else if (nonnulllist.size() > ShapedRecipe.MAX_WIDTH * ShapedRecipe.MAX_HEIGHT) {
+ throw new JsonParseException("Too many ingredients for shapeless recipe the max is " + (ShapedRecipe.MAX_WIDTH * ShapedRecipe.MAX_HEIGHT));
} else {
ItemStack itemstack = ShapedRecipe.func_199798_a(JSONUtils.func_152754_s(p_199425_2_, "result"));
return new ShapelessRecipe(p_199425_1_, s, itemstack, nonnulllist);