diff --git a/src/main/java/growthcraft/cellar/block/entity/BrewKettleBlockEntity.java b/src/main/java/growthcraft/cellar/block/entity/BrewKettleBlockEntity.java index 978b1025..28bc0169 100644 --- a/src/main/java/growthcraft/cellar/block/entity/BrewKettleBlockEntity.java +++ b/src/main/java/growthcraft/cellar/block/entity/BrewKettleBlockEntity.java @@ -210,6 +210,8 @@ public void tick(Level level, BlockPos blockPos, BlockState blockState, BrewKett } else { this.resetTickClock(); } + } else { + this.resetTickClock(); } } else { // Do nothing on the client side. diff --git a/src/main/java/growthcraft/cellar/compat/jei/category/BrewKettleRecipeCategory.java b/src/main/java/growthcraft/cellar/compat/jei/category/BrewKettleRecipeCategory.java index 493013fa..e8f672bc 100644 --- a/src/main/java/growthcraft/cellar/compat/jei/category/BrewKettleRecipeCategory.java +++ b/src/main/java/growthcraft/cellar/compat/jei/category/BrewKettleRecipeCategory.java @@ -24,6 +24,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; public class BrewKettleRecipeCategory implements IRecipeCategory { @@ -85,9 +86,11 @@ public void setRecipe(IRecipeLayoutBuilder builder, BrewKettleRecipe recipe, IFo .addItemStack(new ItemStack(GrowthcraftCellarItems.BREW_KETTLE_LID.get())); } - // Input Item - builder.addSlot(RecipeIngredientRole.INPUT, 70, 25) - .addItemStack(recipe.getInputItemStack()); + // Input Item with Tag Support + for (Ingredient ingredient : recipe.getIngredients()) { + builder.addSlot(RecipeIngredientRole.INPUT, 70, 25) + .addIngredients(ingredient); + } // TODO: Input Fluid builder.addSlot(RecipeIngredientRole.INPUT, 36, 7) diff --git a/src/main/java/growthcraft/cellar/recipe/BrewKettleRecipe.java b/src/main/java/growthcraft/cellar/recipe/BrewKettleRecipe.java index fb6b2953..7b4530ae 100644 --- a/src/main/java/growthcraft/cellar/recipe/BrewKettleRecipe.java +++ b/src/main/java/growthcraft/cellar/recipe/BrewKettleRecipe.java @@ -4,12 +4,14 @@ import growthcraft.cellar.GrowthcraftCellar; import growthcraft.cellar.shared.Reference; import growthcraft.lib.utils.CraftingUtils; +import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import net.minecraft.world.SimpleContainer; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; @@ -19,11 +21,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; + public class BrewKettleRecipe implements Recipe { private final ResourceLocation recipeId; private final FluidStack inputFluidStack; - private final ItemStack inputItemStack; + private final NonNullList inputIngredients; + private final FluidStack outputFluidStack; private final ItemStack byProduct; private final boolean requiresLid; @@ -31,11 +36,10 @@ public class BrewKettleRecipe implements Recipe { private final int byProductChance; private final int processingTime; - - public BrewKettleRecipe(ResourceLocation recipeId, FluidStack inputFluidStack, ItemStack inputItem, FluidStack outputFluidStack, ItemStack byProduct, int byProductChance, int processingTime, boolean requiresHeat, boolean requiresLid) { + public BrewKettleRecipe(ResourceLocation recipeId, FluidStack inputFluidStack, NonNullList inputIngredients, FluidStack outputFluidStack, ItemStack byProduct, int byProductChance, int processingTime, boolean requiresHeat, boolean requiresLid) { this.recipeId = recipeId; this.inputFluidStack = inputFluidStack; - this.inputItemStack = inputItem; + this.inputIngredients = inputIngredients; this.outputFluidStack = outputFluidStack; this.byProduct = byProduct; this.processingTime = processingTime; @@ -51,14 +55,18 @@ public boolean matches(SimpleContainer container, Level level) { public boolean matches(ItemStack itemStack, FluidStack fluidStack, boolean needsLid, boolean needsHeat) { - boolean inputItemTypeMatches = this.inputItemStack.getItem() == itemStack.getItem(); - boolean inputItemCountLessThan = this.inputItemStack.getCount() <= itemStack.getCount(); + boolean inputItemTypeMatches = Arrays.stream( + this.inputIngredients.get(0).getItems()).anyMatch( + ingredientItem -> ingredientItem.is(itemStack.getItem()) && ingredientItem.getCount() <= itemStack.getCount() + ); + + //boolean inputItemCountLessThan = this.inputIngredients.get(0).getItems()[0].getCount() <= itemStack.getCount(); boolean inputFluidTypeMatches = this.inputFluidStack.getFluid() == fluidStack.getFluid(); boolean inputFluidAmountLessThan = this.inputFluidStack.getAmount() <= fluidStack.getAmount(); boolean hasRequiredLid = this.requiresLid == needsLid && this.requiresHeat == needsHeat; return inputItemTypeMatches - && inputItemCountLessThan + //&& inputItemCountLessThan && inputFluidTypeMatches && inputFluidAmountLessThan && hasRequiredLid; @@ -93,7 +101,12 @@ public FluidStack getOutputFluidStack() { } public ItemStack getInputItemStack() { - return inputItemStack; + return inputIngredients.get(0).getItems()[0]; + } + + @Override + public @NotNull NonNullList getIngredients() { + return this.inputIngredients; } public ItemStack getByProduct() { @@ -144,7 +157,8 @@ public static class Serializer implements RecipeSerializer { @Override public @NotNull BrewKettleRecipe fromJson(ResourceLocation recipeId, JsonObject json) { - ItemStack inputItemStack = CraftingHelper.getItemStack(GsonHelper.getAsJsonObject(json, "input_item"), false); + NonNullList inputIngredient = CraftingUtils.readIngredient(GsonHelper.getAsJsonObject(json, "input_item")); + ItemStack byProductItemStack = CraftingHelper.getItemStack(GsonHelper.getAsJsonObject(json, "by_product"), false); FluidStack inputFluid = CraftingUtils.getFluidStack(GsonHelper.getAsJsonObject(json, "input_fluid")); @@ -156,7 +170,7 @@ public static class Serializer implements RecipeSerializer { int processingTime = GsonHelper.getAsInt(json, "processing_time", 600); int byProductChance = GsonHelper.getAsInt(json, "by_product_chance", 10); - return new BrewKettleRecipe(recipeId, inputFluid, inputItemStack, + return new BrewKettleRecipe(recipeId, inputFluid, inputIngredient, outputFluid, byProductItemStack, byProductChance, processingTime, requiresHeat, requiresLid); } @@ -164,7 +178,15 @@ public static class Serializer implements RecipeSerializer { @Override public @Nullable BrewKettleRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) { try { - ItemStack inputItemStack = buffer.readItem(); + + int i = buffer.readVarInt(); + NonNullList inputIngredients = NonNullList.withSize(i, Ingredient.EMPTY); + + for (int j = 0; j < inputIngredients.size(); ++j) { + inputIngredients.set(j, Ingredient.fromNetwork(buffer)); + + } + ItemStack byProductItemStack = buffer.readItem(); FluidStack inputFluidStack = buffer.readFluidStack(); FluidStack outputFluidStack = buffer.readFluidStack(); @@ -173,7 +195,7 @@ public static class Serializer implements RecipeSerializer { int processingTime = buffer.readVarInt(); int byProductChance = buffer.readVarInt(); - return new BrewKettleRecipe(recipeId, inputFluidStack, inputItemStack, + return new BrewKettleRecipe(recipeId, inputFluidStack, inputIngredients, outputFluidStack, byProductItemStack, byProductChance, processingTime, requiresHeat, requiresLid); } catch (Exception ex) { @@ -185,7 +207,12 @@ public static class Serializer implements RecipeSerializer { @Override public void toNetwork(FriendlyByteBuf buffer, BrewKettleRecipe recipe) { - buffer.writeItemStack(recipe.getInputItemStack(), false); + buffer.writeVarInt(recipe.inputIngredients.size()); + + for (Ingredient ingredient : recipe.getIngredients()) { + ingredient.toNetwork(buffer); + } + buffer.writeItemStack(recipe.getByProduct(), false); buffer.writeFluidStack(recipe.getInputFluidStack()); buffer.writeFluidStack(recipe.getOutputFluidStack()); diff --git a/src/main/java/growthcraft/lib/utils/CraftingUtils.java b/src/main/java/growthcraft/lib/utils/CraftingUtils.java index f0c5dd5c..64b99c9c 100644 --- a/src/main/java/growthcraft/lib/utils/CraftingUtils.java +++ b/src/main/java/growthcraft/lib/utils/CraftingUtils.java @@ -1,9 +1,12 @@ package growthcraft.lib.utils; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; +import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.material.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.registries.ForgeRegistries; @@ -23,5 +26,24 @@ public static FluidStack getFluidStack(JsonObject json) { return new FluidStack(fluid, fluidAmount); } + public static NonNullList readIngredient(JsonObject ingredientObject) { + NonNullList nonnulllist = NonNullList.create(); + nonnulllist.add(Ingredient.fromJson(ingredientObject)); + return nonnulllist; + } + + public static NonNullList readIngredients(JsonArray ingredientArray) { + NonNullList nonnulllist = NonNullList.create(); + + for (int i = 0; i < ingredientArray.size(); ++i) { + Ingredient ingredient = Ingredient.fromJson(ingredientArray.get(i)); + if (!ingredient.isEmpty()) { + nonnulllist.add(ingredient); + } + } + + return nonnulllist; + } + private CraftingUtils() { /* Prevent automatic public constructor */ } } diff --git a/src/main/resources/data/growthcraft_rice/recipes/brew_kettle_rice_water_from_growthcraft_rice.json b/src/main/resources/data/growthcraft_rice/recipes/brew_kettle_rice_water_from_growthcraft_rice.json index a8fc1b81..bca3b446 100644 --- a/src/main/resources/data/growthcraft_rice/recipes/brew_kettle_rice_water_from_growthcraft_rice.json +++ b/src/main/resources/data/growthcraft_rice/recipes/brew_kettle_rice_water_from_growthcraft_rice.json @@ -1,15 +1,15 @@ { "type": "growthcraft_cellar:brew_kettle_recipe", "requires_heat": true, - "requires_lid": "false", + "requires_lid": "true", "processing_time": 300, - "by_product_chance": 1, + "by_product_chance": 100, "input_fluid": { "fluid": "minecraft:water", "amount": 125 }, "input_item": { - "item": "growthcraft_rice:rice", + "tag": "forge:grain/rice", "count": 1 }, "output_fluid": { @@ -17,7 +17,7 @@ "amount": 125 }, "by_product": { - "item": "minecraft:bone_meal", + "item": "growthcraft_rice:rice_cooked", "count": 1 } } \ No newline at end of file