From 951a6d110c0a9ab16a245cebfd94b15fc2ec6c1d Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 19 Dec 2023 15:06:48 +0100 Subject: [PATCH] Fixed some Recipe related issues --- .../client/gui/EndStoneSmelterMenu.java | 5 +- .../gui/EndStoneSmelterRecipeBookScreen.java | 10 +- .../integration/rei/REIAlloyingDisplay.java | 30 +-- .../integration/rei/REIAnvilDisplay.java | 22 +- .../integration/rei/REIBlastingDisplay.java | 5 +- .../integration/rei/REIInfusionDisplay.java | 18 +- .../recipe/builders/InfusionRecipe.java | 202 +++++++++--------- .../betterend/rituals/InfusionRitual.java | 22 +- 8 files changed, 170 insertions(+), 144 deletions(-) diff --git a/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterMenu.java b/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterMenu.java index 3209c7f3..216fd74a 100644 --- a/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterMenu.java +++ b/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterMenu.java @@ -14,6 +14,7 @@ import net.minecraft.world.entity.player.StackedContents; import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; import net.fabricmc.api.EnvType; @@ -89,8 +90,8 @@ public class EndStoneSmelterMenu extends RecipeBookMenu { } @Override - public boolean recipeMatches(Recipe recipe) { - return recipe.matches(inventory, world); + public boolean recipeMatches(RecipeHolder> recipeHolder) { + return recipeHolder.value().matches(inventory, world); } @Override diff --git a/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java b/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java index 8cc2f5ce..41ee26de 100644 --- a/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java +++ b/src/main/java/org/betterx/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java @@ -10,6 +10,7 @@ import net.minecraft.world.item.Item; 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.RecipeHolder; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -17,6 +18,7 @@ import net.fabricmc.api.Environment; import java.util.Iterator; import java.util.List; import java.util.Set; +import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) public class EndStoneSmelterRecipeBookScreen extends BlastingRecipeBookComponent { @@ -24,7 +26,7 @@ public class EndStoneSmelterRecipeBookScreen extends BlastingRecipeBookComponent private Slot fuelSlot; @Override - protected Set getFuelItems() { + protected @NotNull Set getFuelItems() { return EndStoneSmelterBlockEntity.availableFuels().keySet(); } @@ -37,10 +39,12 @@ public class EndStoneSmelterRecipeBookScreen extends BlastingRecipeBookComponent } @Override - public void setupGhostRecipe(Recipe recipe, List slots) { + public void setupGhostRecipe(RecipeHolder recipeHolder, List slots) { + if (Minecraft.getInstance().level == null) return; this.ghostRecipe.clear(); + final Recipe recipe = recipeHolder.value(); ItemStack result = recipe.getResultItem(Minecraft.getInstance().level.registryAccess()); - this.ghostRecipe.setRecipe(recipe); + this.ghostRecipe.setRecipe(recipeHolder); this.ghostRecipe.addIngredient(Ingredient.of(result), (slots.get(3)).x, (slots.get(3)).y); NonNullList inputs = recipe.getIngredients(); diff --git a/src/main/java/org/betterx/betterend/integration/rei/REIAlloyingDisplay.java b/src/main/java/org/betterx/betterend/integration/rei/REIAlloyingDisplay.java index 3829e4ad..901c7af3 100644 --- a/src/main/java/org/betterx/betterend/integration/rei/REIAlloyingDisplay.java +++ b/src/main/java/org/betterx/betterend/integration/rei/REIAlloyingDisplay.java @@ -8,7 +8,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; -import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; @@ -25,21 +25,27 @@ import org.jetbrains.annotations.NotNull; public class REIAlloyingDisplay extends BasicDisplay implements SimpleGridMenuDisplay { - private static final List fuel; + private static final List> fuel; - private final Recipe recipe; + private final RecipeHolder recipe; private final float xp; private final double smeltTime; - public REIAlloyingDisplay(AlloyingRecipe recipe) { - this(recipe, recipe.getExperience(), recipe.getSmeltTime()); + public REIAlloyingDisplay(RecipeHolder recipe) { + this(recipe, recipe.value().getExperience(), recipe.value().getSmeltTime()); } - protected REIAlloyingDisplay(Recipe recipe, float xp, double smeltTime) { + protected REIAlloyingDisplay(RecipeHolder recipe, float xp, double smeltTime) { super( - EntryIngredients.ofIngredients(recipe.getIngredients()), - Collections.singletonList(EntryIngredients.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess()))) + EntryIngredients.ofIngredients(recipe.value().getIngredients()), + Collections.singletonList( + EntryIngredients.of( + recipe + .value() + .getResultItem(Minecraft.getInstance().level.registryAccess()) + ) + ) ); this.recipe = recipe; this.xp = xp; @@ -47,13 +53,13 @@ public class REIAlloyingDisplay extends BasicDisplay implements SimpleGridMenuDi } - public static List getFuel() { + public static List> getFuel() { return fuel; } @Override public @NotNull Optional getDisplayLocation() { - return Optional.ofNullable(recipe).map(Recipe::getId); + return Optional.ofNullable(recipe).map(RecipeHolder::id); } @Override @@ -74,10 +80,6 @@ public class REIAlloyingDisplay extends BasicDisplay implements SimpleGridMenuDi return this.smeltTime; } - public Optional> getOptionalRecipe() { - return Optional.ofNullable(recipe); - } - @Override public int getWidth() { return 2; diff --git a/src/main/java/org/betterx/betterend/integration/rei/REIAnvilDisplay.java b/src/main/java/org/betterx/betterend/integration/rei/REIAnvilDisplay.java index f130503e..0e0ae3f0 100644 --- a/src/main/java/org/betterx/betterend/integration/rei/REIAnvilDisplay.java +++ b/src/main/java/org/betterx/betterend/integration/rei/REIAnvilDisplay.java @@ -5,7 +5,7 @@ import org.betterx.bclib.recipes.AnvilRecipe; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; @@ -18,33 +18,37 @@ import org.jetbrains.annotations.NotNull; public class REIAnvilDisplay extends BasicDisplay implements SimpleGridMenuDisplay { - private final AnvilRecipe recipe; + private final RecipeHolder recipe; - public REIAnvilDisplay(AnvilRecipe recipe) { + public REIAnvilDisplay(RecipeHolder recipe) { super( - EntryIngredients.ofIngredients(recipe.getIngredients()), - Collections.singletonList(EntryIngredients.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess()))) + EntryIngredients.ofIngredients(recipe.value().getIngredients()), + Collections.singletonList( + EntryIngredients.of( + recipe.value().getResultItem(Minecraft.getInstance().level.registryAccess()) + ) + ) ); this.recipe = recipe; inputs.get(1).forEach(entryStack -> { if (entryStack.getValue() instanceof ItemStack itemStack) { - itemStack.setCount(recipe.getInputCount()); + itemStack.setCount(recipe.value().getInputCount()); } }); } public int getDamage() { - return recipe.getDamage(); + return recipe.value().getDamage(); } public int getAnvilLevel() { - return recipe.getAnvilLevel(); + return recipe.value().getAnvilLevel(); } @Override public @NotNull Optional getDisplayLocation() { - return Optional.ofNullable(recipe).map(Recipe::getId); + return Optional.ofNullable(recipe).map(RecipeHolder::id); } @Override diff --git a/src/main/java/org/betterx/betterend/integration/rei/REIBlastingDisplay.java b/src/main/java/org/betterx/betterend/integration/rei/REIBlastingDisplay.java index 2d752276..aa7c835e 100644 --- a/src/main/java/org/betterx/betterend/integration/rei/REIBlastingDisplay.java +++ b/src/main/java/org/betterx/betterend/integration/rei/REIBlastingDisplay.java @@ -1,9 +1,10 @@ package org.betterx.betterend.integration.rei; import net.minecraft.world.item.crafting.BlastingRecipe; +import net.minecraft.world.item.crafting.RecipeHolder; public class REIBlastingDisplay extends REIAlloyingDisplay { - public REIBlastingDisplay(BlastingRecipe recipe) { - super(recipe, recipe.getExperience(), recipe.getCookingTime()); + public REIBlastingDisplay(RecipeHolder recipe) { + super(recipe, recipe.value().getExperience(), recipe.value().getCookingTime()); } } \ No newline at end of file diff --git a/src/main/java/org/betterx/betterend/integration/rei/REIInfusionDisplay.java b/src/main/java/org/betterx/betterend/integration/rei/REIInfusionDisplay.java index 07b28ad5..b5538a3b 100644 --- a/src/main/java/org/betterx/betterend/integration/rei/REIInfusionDisplay.java +++ b/src/main/java/org/betterx/betterend/integration/rei/REIInfusionDisplay.java @@ -4,7 +4,7 @@ import org.betterx.betterend.recipe.builders.InfusionRecipe; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; @@ -17,16 +17,20 @@ import org.jetbrains.annotations.NotNull; public class REIInfusionDisplay extends BasicDisplay implements SimpleGridMenuDisplay { - private final InfusionRecipe recipe; + private final RecipeHolder recipe; private final int time; - public REIInfusionDisplay(InfusionRecipe recipe) { + public REIInfusionDisplay(RecipeHolder recipe) { super( - EntryIngredients.ofIngredients(recipe.getIngredients()), - Collections.singletonList(EntryIngredients.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess()))) + EntryIngredients.ofIngredients(recipe.value().getIngredients()), + Collections.singletonList( + EntryIngredients.of( + recipe.value().getResultItem(Minecraft.getInstance().level.registryAccess()) + ) + ) ); this.recipe = recipe; - this.time = recipe.getInfusionTime(); + this.time = recipe.value().getInfusionTime(); } public int getInfusionTime() { @@ -35,7 +39,7 @@ public class REIInfusionDisplay extends BasicDisplay implements SimpleGridMenuDi @Override public @NotNull Optional getDisplayLocation() { - return Optional.ofNullable(recipe).map(Recipe::getId); + return Optional.ofNullable(recipe).map(RecipeHolder::id); } @Override diff --git a/src/main/java/org/betterx/betterend/recipe/builders/InfusionRecipe.java b/src/main/java/org/betterx/betterend/recipe/builders/InfusionRecipe.java index e63b695d..b2296408 100644 --- a/src/main/java/org/betterx/betterend/recipe/builders/InfusionRecipe.java +++ b/src/main/java/org/betterx/betterend/recipe/builders/InfusionRecipe.java @@ -8,12 +8,14 @@ import org.betterx.bclib.util.ItemUtil; import org.betterx.betterend.BetterEnd; import org.betterx.betterend.rituals.InfusionRitual; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; -import net.minecraft.util.GsonHelper; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.EnchantedBookItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -30,12 +32,35 @@ import net.minecraft.world.level.Level; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - import java.util.Arrays; +import java.util.Optional; +import org.jetbrains.annotations.NotNull; public class InfusionRecipe implements Recipe, UnknownReceipBookCategory { + public static final Codec CODEC_CATALYSTS = RecordCodecBuilder.create(instance -> instance + .group( + Builder.catalyst(Catalysts.NORTH), + Builder.catalyst(Catalysts.NORTH_EAST), + Builder.catalyst(Catalysts.EAST), + Builder.catalyst(Catalysts.SOUTH_EAST), + Builder.catalyst(Catalysts.SOUTH), + Builder.catalyst(Catalysts.SOUTH_WEST), + Builder.catalyst(Catalysts.WEST), + Builder.catalyst(Catalysts.NORTH_WEST) + ).apply(instance, Builder::fromCodec) + ); + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance + .group( + ItemUtil.CODEC_INGREDIENT_WITH_NBT.fieldOf("input").forGetter(i -> i.input), + ItemUtil.CODEC_ITEM_STACK_WITH_NBT.fieldOf("result").forGetter(i -> i.output), + Codec.INT.optionalFieldOf("time", 1).forGetter(InfusionRecipe::getInfusionTime), + CODEC_CATALYSTS.fieldOf("catalysts").forGetter(i -> i.catalysts), + ExtraCodecs.strictOptionalField(Codec.STRING, "group") + .forGetter(i -> Optional.ofNullable(i.group)) + ).apply(instance, InfusionRecipe::new) + + ); public final static String GROUP = "infusion"; public final static RecipeType TYPE = BCLRecipeManager.registerType(BetterEnd.MOD_ID, GROUP); public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer( @@ -44,25 +69,39 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook new Serializer() ); - private final ResourceLocation id; private final Ingredient[] catalysts; private Ingredient input; private ItemStack output; - private int time = 1; + private int time; private String group; - private InfusionRecipe(ResourceLocation id) { - this(id, null, null); + private InfusionRecipe() { + this(null, null); } - private InfusionRecipe(ResourceLocation id, Ingredient input, ItemStack output) { - this.id = id; - this.input = input; - this.output = output; - this.catalysts = new Ingredient[]{ + private InfusionRecipe(Ingredient input, ItemStack output) { + this(input, output, 1, new Ingredient[]{ Ingredient.EMPTY, Ingredient.EMPTY, Ingredient.EMPTY, Ingredient.EMPTY, Ingredient.EMPTY, Ingredient.EMPTY, Ingredient.EMPTY, Ingredient.EMPTY - }; + }, (String) null); + } + + private InfusionRecipe( + Ingredient input, + ItemStack output, + int time, + Ingredient[] catalysts, + Optional group + ) { + this(input, output, time, catalysts, group.orElse(null)); + } + + private InfusionRecipe(Ingredient input, ItemStack output, int time, Ingredient[] catalysts, String group) { + this.input = input; + this.output = output; + this.catalysts = catalysts; + this.time = time; + this.group = group; } public static Builder create(String id, ItemLike output) { @@ -110,7 +149,7 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook } @Override - public ItemStack assemble(InfusionRitual ritual, RegistryAccess acc) { + public @NotNull ItemStack assemble(InfusionRitual ritual, RegistryAccess acc) { return output.copy(); } @@ -120,7 +159,7 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook } @Override - public NonNullList getIngredients() { + public @NotNull NonNullList getIngredients() { NonNullList defaultedList = NonNullList.create(); defaultedList.add(input); defaultedList.addAll(Arrays.asList(catalysts)); @@ -128,32 +167,60 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook } @Override - public ItemStack getResultItem(RegistryAccess acc) { + public @NotNull ItemStack getResultItem(RegistryAccess acc) { return this.output; } - @Override - public ResourceLocation getId() { - return this.id; - } @Override @Environment(EnvType.CLIENT) - public String getGroup() { + public @NotNull String getGroup() { return this.group; } @Override - public RecipeSerializer getSerializer() { + public @NotNull RecipeSerializer getSerializer() { return SERIALIZER; } @Override - public RecipeType getType() { + public @NotNull RecipeType getType() { return TYPE; } public static class Builder extends AbstractSingleInputRecipeBuilder { + @NotNull + private static RecordCodecBuilder> catalyst(Catalysts slot) { + return ExtraCodecs.strictOptionalField(ItemUtil.CODEC_INGREDIENT_WITH_NBT, slot.key) + .forGetter(builder -> + builder[slot.index] == null || builder[slot.index].isEmpty() + ? Optional.empty() + : Optional.of(builder[slot.index]) + ); + } + + private static Ingredient[] fromCodec( + Optional north, + Optional north_east, + Optional east, + Optional south_east, + Optional south, + Optional south_west, + Optional west, + Optional north_west + ) { + Ingredient[] result = new Ingredient[8]; + result[Catalysts.NORTH.index] = north.orElse(null); + result[Catalysts.NORTH_EAST.index] = north_east.orElse(null); + result[Catalysts.EAST.index] = east.orElse(null); + result[Catalysts.SOUTH_EAST.index] = south_east.orElse(null); + result[Catalysts.SOUTH.index] = south.orElse(null); + result[Catalysts.SOUTH_WEST.index] = south_west.orElse(null); + result[Catalysts.WEST.index] = west.orElse(null); + result[Catalysts.NORTH_WEST.index] = north_west.orElse(null); + return result; + } + private final Ingredient[] catalysts; private int time; @@ -170,14 +237,20 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook this.time = 1; } + @Override + protected InfusionRecipe createRecipe(ResourceLocation id) { + checkRecipe(); + return new InfusionRecipe(this.primaryInput, this.output, this.time, this.catalysts, this.group); + } + @Override public Builder setGroup(String group) { return super.setGroup(group); } /** - * @param input - * @return + * @param input - + * @return - * @deprecated use {@link #setPrimaryInput(ItemLike...)} */ @Deprecated(forRemoval = true) @@ -218,23 +291,6 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook return super.checkRecipe(); } - @Override - protected void serializeRecipeData(JsonObject root) { - super.serializeRecipeData(root); - - if (time != 1) { - root.addProperty("time", time); - } - - JsonObject catalystObject = new JsonObject(); - for (var cat : Catalysts.values()) { - if (catalysts[cat.index] != null && !catalysts[cat.index].isEmpty()) { - catalystObject.add(cat.key, ItemUtil.toJsonIngredientWithNBT(catalysts[cat.index])); - } - } - root.add("catalysts", catalystObject); - } - @Override protected RecipeSerializer getSerializer() { return SERIALIZER; @@ -261,64 +317,14 @@ public class InfusionRecipe implements Recipe, UnknownReceipBook } public static class Serializer implements RecipeSerializer { - private Ingredient readIngredient(JsonObject obj, String key) { - if (obj.has(key)) { - JsonElement el = obj.get(key); - if (el.isJsonObject()) { - JsonObject o = el.getAsJsonObject(); - //directly read as ingredient - if (o.has("tag")) { - final Ingredient res = ItemUtil.fromJsonIngredientWithNBT(o); - if (res == null) return Ingredient.EMPTY; - return res; - } else { - final Ingredient res = Ingredient.of(ItemUtil.fromJsonRecipeWithNBT(o)); - if (res == null) return Ingredient.EMPTY; - return res; - } - } else if (el.isJsonArray()) { - //this is an Ingredient-Array, so read as such - final Ingredient res = Ingredient.fromJson(el); - if (res == null) return Ingredient.EMPTY; - return res; - } else if (obj.isJsonPrimitive()) { - String s = GsonHelper.getAsString(obj, key, ""); - ItemStack catalyst = ItemUtil.fromStackString(s); - return (catalyst != null && !catalyst.isEmpty()) - ? Ingredient.of(catalyst.getItem()) - : Ingredient.EMPTY; - } else { - throw new IllegalStateException("Invalid catalyst ingredient for " + key + ": " + el.toString()); - } - } - return Ingredient.EMPTY; + @Override + public @NotNull Codec codec() { + return InfusionRecipe.CODEC; } @Override - public InfusionRecipe fromJson(ResourceLocation id, JsonObject json) { - InfusionRecipe recipe = new InfusionRecipe(id); - JsonObject inputObject = GsonHelper.getAsJsonObject(json, "input"); - recipe.input = ItemUtil.fromJsonIngredientWithNBT(inputObject); - - JsonObject result = GsonHelper.getAsJsonObject(json, "result"); - recipe.output = ItemUtil.fromJsonRecipeWithNBT(result); - if (recipe.output == null) { - throw new IllegalStateException("Output item does not exists!"); - } - recipe.group = GsonHelper.getAsString(json, "group", GROUP); - recipe.time = GsonHelper.getAsInt(json, "time", 1); - - JsonObject catalysts = GsonHelper.getAsJsonObject(json, "catalysts"); - for (var cat : Catalysts.values()) { - recipe.catalysts[cat.index] = readIngredient(catalysts, cat.key); - } - - return recipe; - } - - @Override - public InfusionRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) { - InfusionRecipe recipe = new InfusionRecipe(id); + public @NotNull InfusionRecipe fromNetwork(FriendlyByteBuf buffer) { + InfusionRecipe recipe = new InfusionRecipe(); recipe.input = Ingredient.fromNetwork(buffer); recipe.output = buffer.readItem(); recipe.group = buffer.readUtf(); diff --git a/src/main/java/org/betterx/betterend/rituals/InfusionRitual.java b/src/main/java/org/betterx/betterend/rituals/InfusionRitual.java index f37a96a2..1b5b10d9 100644 --- a/src/main/java/org/betterx/betterend/rituals/InfusionRitual.java +++ b/src/main/java/org/betterx/betterend/rituals/InfusionRitual.java @@ -14,6 +14,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.chunk.LevelChunk.EntityCreationType; @@ -22,6 +23,7 @@ import net.minecraft.world.phys.Vec3; import java.awt.*; import java.util.Arrays; import java.util.Objects; +import org.jetbrains.annotations.NotNull; public class InfusionRitual implements Container { private static final Point[] PEDESTALS_MAP = new Point[]{ @@ -37,7 +39,7 @@ public class InfusionRitual implements Container { private Level world; private BlockPos worldPos; - private InfusionRecipe activeRecipe; + private RecipeHolder activeRecipe; private boolean isDirty = false; private boolean hasRecipe = false; private int progress = 0; @@ -70,12 +72,14 @@ public class InfusionRitual implements Container { public boolean checkRecipe() { if (!isValid()) return false; - InfusionRecipe recipe = world.getRecipeManager().getRecipeFor(InfusionRecipe.TYPE, this, world).orElse(null); + RecipeHolder recipe = world.getRecipeManager() + .getRecipeFor(InfusionRecipe.TYPE, this, world) + .orElse(null); if (hasRecipe()) { if (recipe == null) { reset(); return false; - } else if (activeRecipe == null || recipe.getInfusionTime() != time) { + } else if (activeRecipe == null || recipe.value().getInfusionTime() != time) { updateRecipe(recipe); } return true; @@ -87,7 +91,7 @@ public class InfusionRitual implements Container { return false; } - private void updateRecipe(InfusionRecipe recipe) { + private void updateRecipe(RecipeHolder recipe) { activeRecipe = recipe; hasRecipe = true; resetTimer(); @@ -95,7 +99,7 @@ public class InfusionRitual implements Container { } private void resetTimer() { - time = activeRecipe != null ? activeRecipe.getInfusionTime() : 0; + time = activeRecipe != null ? activeRecipe.value().getInfusionTime() : 0; progress = 0; } @@ -115,7 +119,7 @@ public class InfusionRitual implements Container { progress++; if (progress == time) { clearContent(); - input.setItem(0, activeRecipe.assemble(this, world.registryAccess())); + input.setItem(0, activeRecipe.value().assemble(this, world.registryAccess())); if (world instanceof ServerLevel sl) { sl.getPlayers(p -> p.position() .subtract(new Vec3(worldPos.getX(), worldPos.getY(), worldPos.getZ())) @@ -190,7 +194,7 @@ public class InfusionRitual implements Container { } @Override - public ItemStack getItem(int slot) { + public @NotNull ItemStack getItem(int slot) { if (slot > 8) return ItemStack.EMPTY; if (slot == 0) { return input.getItem(0); @@ -200,12 +204,12 @@ public class InfusionRitual implements Container { } @Override - public ItemStack removeItem(int slot, int amount) { + public @NotNull ItemStack removeItem(int slot, int amount) { return removeItemNoUpdate(slot); } @Override - public ItemStack removeItemNoUpdate(int slot) { + public @NotNull ItemStack removeItemNoUpdate(int slot) { if (slot > 8) return ItemStack.EMPTY; if (slot == 0) { return input.removeItemNoUpdate(0);