Skip to content

Commit

Permalink
Fix utility predicates not being instantiated on start (#10593)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodor12 authored Jan 13, 2025
1 parent 09c81a1 commit 6758621
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/minecolonies/api/util/FoodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FoodUtils
/**
* Predicate describing food which can be eaten (is not raw).
*/
public static Predicate<ItemStack> EDIBLE;
public static final Predicate<ItemStack> EDIBLE = itemStack -> ItemStackUtils.ISFOOD.test(itemStack) && !ItemStackUtils.ISCOOKABLE.test(itemStack);

/**
* @param stack
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/minecolonies/api/util/ItemStackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,12 +116,12 @@ public final class ItemStackUtils
/**
* Predicate describing things which work in the furnace.
*/
public static Predicate<ItemStack> IS_SMELTABLE;
public static Predicate<ItemStack> IS_SMELTABLE = itemStack -> !ItemStackUtils.isEmpty(FurnaceRecipes.getInstance().getSmeltingResult(itemStack));

/**
* Predicate describing cookables.
*/
public static Predicate<ItemStack> ISCOOKABLE;
public static Predicate<ItemStack> ISCOOKABLE = itemStack -> ItemStackUtils.ISFOOD.test(FurnaceRecipes.getInstance().getSmeltingResult(itemStack));

/**
* Predicate to check for compost items.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 5 additions & 19 deletions src/main/java/com/minecolonies/core/util/FurnaceRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,15 +21,15 @@
public class FurnaceRecipes implements IFurnaceRecipes
{
/**
* Furnace recipes.
* Instance of the furnace recipes.
*/
private Map<ItemStorage, RecipeStorage> recipes = new HashMap<>();
private Map<ItemStorage, RecipeStorage> reverseRecipes = new HashMap<>();
private static FurnaceRecipes instance;

/**
* Instance of the furnace recipes.
* Furnace recipes.
*/
public static FurnaceRecipes instance;
private Map<ItemStorage, RecipeStorage> recipes = new HashMap<>();
private Map<ItemStorage, RecipeStorage> reverseRecipes = new HashMap<>();

/**
* Load all the recipes in the recipe storage.
Expand All @@ -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<Ingredient> list = recipe.getIngredients();
if (list.size() == 1)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 6758621

Please sign in to comment.