From 6758621aaedfa4b03c675822cc9ff5e9897f9667 Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Mon, 13 Jan 2025 14:13:03 +0100 Subject: [PATCH] Fix utility predicates not being instantiated on start (#10593) --- .../com/minecolonies/api/util/FoodUtils.java | 2 +- .../minecolonies/api/util/ItemStackUtils.java | 5 ++-- .../UpdateClientWithCompatibilityMessage.java | 2 -- .../core/util/FurnaceRecipes.java | 24 ++++--------------- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/minecolonies/api/util/FoodUtils.java b/src/main/java/com/minecolonies/api/util/FoodUtils.java index 0334a6db5a5..a463281b5c6 100644 --- a/src/main/java/com/minecolonies/api/util/FoodUtils.java +++ b/src/main/java/com/minecolonies/api/util/FoodUtils.java @@ -30,7 +30,7 @@ public class FoodUtils /** * Predicate describing food which can be eaten (is not raw). */ - public static Predicate EDIBLE; + public static final Predicate EDIBLE = itemStack -> ItemStackUtils.ISFOOD.test(itemStack) && !ItemStackUtils.ISCOOKABLE.test(itemStack); /** * @param stack diff --git a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java index e3d25492cbe..80b715fcb43 100755 --- a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java +++ b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java @@ -17,6 +17,7 @@ import com.minecolonies.api.items.ModTags; import com.minecolonies.core.items.ItemBowlFood; import com.minecolonies.core.util.AdvancementUtils; +import com.minecolonies.core.util.FurnaceRecipes; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -115,12 +116,12 @@ public final class ItemStackUtils /** * Predicate describing things which work in the furnace. */ - public static Predicate IS_SMELTABLE; + public static Predicate IS_SMELTABLE = itemStack -> !ItemStackUtils.isEmpty(FurnaceRecipes.getInstance().getSmeltingResult(itemStack)); /** * Predicate describing cookables. */ - public static Predicate ISCOOKABLE; + public static Predicate ISCOOKABLE = itemStack -> ItemStackUtils.ISFOOD.test(FurnaceRecipes.getInstance().getSmeltingResult(itemStack)); /** * Predicate to check for compost items. diff --git a/src/main/java/com/minecolonies/core/network/messages/client/UpdateClientWithCompatibilityMessage.java b/src/main/java/com/minecolonies/core/network/messages/client/UpdateClientWithCompatibilityMessage.java index b5233248a53..c907f7df80d 100644 --- a/src/main/java/com/minecolonies/core/network/messages/client/UpdateClientWithCompatibilityMessage.java +++ b/src/main/java/com/minecolonies/core/network/messages/client/UpdateClientWithCompatibilityMessage.java @@ -3,7 +3,6 @@ import com.minecolonies.api.IMinecoloniesAPI; import com.minecolonies.api.network.IMessage; import com.minecolonies.api.util.Log; -import com.minecolonies.core.util.FurnaceRecipes; import io.netty.buffer.Unpooled; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -65,7 +64,6 @@ public LogicalSide getExecutionSide() public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) { final ClientLevel world = Minecraft.getInstance().level; - FurnaceRecipes.getInstance().loadUtilityPredicates(); try { IMinecoloniesAPI.getInstance().getColonyManager().getCompatibilityManager().deserialize(this.buffer, world); diff --git a/src/main/java/com/minecolonies/core/util/FurnaceRecipes.java b/src/main/java/com/minecolonies/core/util/FurnaceRecipes.java index 23f679c7c7c..694beeb7e20 100755 --- a/src/main/java/com/minecolonies/core/util/FurnaceRecipes.java +++ b/src/main/java/com/minecolonies/core/util/FurnaceRecipes.java @@ -5,8 +5,6 @@ import com.minecolonies.api.compatibility.IFurnaceRecipes; import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.crafting.RecipeStorage; -import com.minecolonies.api.util.FoodUtils; -import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.constant.TypeConstants; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; @@ -23,15 +21,15 @@ public class FurnaceRecipes implements IFurnaceRecipes { /** - * Furnace recipes. + * Instance of the furnace recipes. */ - private Map recipes = new HashMap<>(); - private Map reverseRecipes = new HashMap<>(); + private static FurnaceRecipes instance; /** - * Instance of the furnace recipes. + * Furnace recipes. */ - public static FurnaceRecipes instance; + private Map recipes = new HashMap<>(); + private Map reverseRecipes = new HashMap<>(); /** * Load all the recipes in the recipe storage. @@ -42,7 +40,6 @@ public void loadRecipes(final RecipeManager recipeManager, final Level level) { recipes.clear(); reverseRecipes.clear(); - loadUtilityPredicates(); recipeManager.byType(RecipeType.SMELTING).values().forEach(recipe -> { final NonNullList list = recipe.getIngredients(); if (list.size() == 1) @@ -71,17 +68,6 @@ public void loadRecipes(final RecipeManager recipeManager, final Level level) }); } - /** - * Load all the utility predicates. - */ - public void loadUtilityPredicates() - { - ItemStackUtils.IS_SMELTABLE = itemStack -> !ItemStackUtils.isEmpty(instance.getSmeltingResult(itemStack)); - ItemStackUtils.ISCOOKABLE = itemStack -> ItemStackUtils.ISFOOD.test(instance.getSmeltingResult(itemStack)); - FoodUtils.EDIBLE = - itemStack -> ItemStackUtils.ISFOOD.test(itemStack) && !ItemStackUtils.ISCOOKABLE.test(itemStack); - } - @Override public ItemStack getSmeltingResult(final ItemStack itemStack) {