Skip to content

Commit ff38901

Browse files
committed
Fix the nutritional liquifier being unable to handle suspicious stew (#8143)
1 parent c2933c0 commit ff38901

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

src/api/java/mekanism/api/recipes/ingredients/creator/IngredientCreatorAccess.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ static DataComponentPredicate getComponentPatchPredicate(DataComponentPatch patc
155155
for (Map.Entry<DataComponentType<?>, Optional<?>> entry : patch.entrySet()) {
156156
Optional<?> value = entry.getValue();
157157
//Note: We only add if the value is added, we don't check ones that have been removed from default, as that isn't easily feasible
158+
//noinspection OptionalIsPresent - Capturing lambda
158159
if (value.isPresent()) {
159160
//noinspection rawtypes,unchecked
160-
builder.expect((DataComponentType) entry.getKey(), value);
161+
builder.expect((DataComponentType) entry.getKey(), value.get());
161162
}
162163
}
163164
return builder.build();

src/main/java/mekanism/client/recipe_viewer/RecipeViewerUtils.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,23 @@
1919
import mekanism.api.recipes.chemical.ItemStackToChemicalRecipe;
2020
import mekanism.api.recipes.ingredients.ChemicalStackIngredient;
2121
import mekanism.api.recipes.ingredients.SlurryStackIngredient;
22-
import mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess;
2322
import mekanism.client.gui.element.bar.GuiBar.IBarInfoHandler;
2423
import mekanism.client.gui.element.progress.IProgressInfoHandler;
2524
import mekanism.common.Mekanism;
2625
import mekanism.common.MekanismLang;
2726
import mekanism.common.recipe.IMekanismRecipeTypeProvider;
2827
import mekanism.common.recipe.MekanismRecipeType;
29-
import mekanism.common.recipe.impl.NutritionalLiquifierIRecipe;
30-
import mekanism.common.registries.MekanismFluids;
3128
import mekanism.common.tier.ChemicalTankTier;
29+
import mekanism.common.tile.machine.TileEntityNutritionalLiquifier;
3230
import mekanism.common.util.ChemicalUtil;
3331
import mekanism.common.util.RegistryUtils;
3432
import net.minecraft.SharedConstants;
3533
import net.minecraft.core.HolderSet.Named;
36-
import net.minecraft.core.component.DataComponents;
3734
import net.minecraft.core.registries.BuiltInRegistries;
3835
import net.minecraft.network.chat.Component;
3936
import net.minecraft.resources.ResourceLocation;
4037
import net.minecraft.tags.TagKey;
4138
import net.minecraft.util.TimeUtil;
42-
import net.minecraft.world.food.FoodProperties;
4339
import net.minecraft.world.item.Item;
4440
import net.minecraft.world.item.ItemStack;
4541
import net.minecraft.world.item.crafting.RecipeHolder;
@@ -139,18 +135,9 @@ public static Map<ResourceLocation, ItemStackToFluidOptionalItemRecipe> getLiqui
139135
// CreativeModeTabs.searchTab().getDisplayItems(). The bigger issue is how to come up with unique synthetic
140136
// names for the recipes as EMI requires they be unique. (Maybe index them?)
141137
for (Item item : BuiltInRegistries.ITEM) {
142-
ItemStack stack = new ItemStack(item);
143-
if (stack.has(DataComponents.FOOD)) {
144-
FoodProperties food = stack.getFoodProperties(null);
145-
//Only display consuming foods that provide healing as otherwise no paste will be made
146-
if (food != null && food.nutrition() > 0) {
147-
ResourceLocation id = RecipeViewerUtils.synthetic(RegistryUtils.getName(stack.getItem()), "liquification", Mekanism.MODID);
148-
liquification.put(id, new NutritionalLiquifierIRecipe(
149-
IngredientCreatorAccess.item().from(stack),
150-
MekanismFluids.NUTRITIONAL_PASTE.getFluidStack(food.nutrition() * 50),
151-
food.usingConvertsTo().orElse(ItemStack.EMPTY)
152-
));
153-
}
138+
ItemStackToFluidOptionalItemRecipe recipe = TileEntityNutritionalLiquifier.getRecipe(item.getDefaultInstance());
139+
if (recipe != null) {
140+
liquification.put(RecipeViewerUtils.synthetic(RegistryUtils.getName(item), "liquification", Mekanism.MODID), recipe);
154141
}
155142
}
156143
return liquification;

src/main/java/mekanism/common/tile/machine/TileEntityNutritionalLiquifier.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import net.minecraft.SharedConstants;
5252
import net.minecraft.core.BlockPos;
5353
import net.minecraft.core.HolderLookup;
54-
import net.minecraft.core.component.DataComponents;
5554
import net.minecraft.nbt.CompoundTag;
5655
import net.minecraft.world.food.FoodProperties;
5756
import net.minecraft.world.item.ItemStack;
@@ -142,12 +141,9 @@ protected IInventorySlotHolder getInitialInventory(IContentsListener listener, I
142141
}
143142

144143
public static boolean isValidInput(ItemStack stack) {
145-
if (stack.has(DataComponents.FOOD)) {//Double-check the stack is food
146-
FoodProperties food = stack.getFoodProperties(null);
147-
//And only allow inserting foods that actually would provide paste
148-
return food != null && food.nutrition() > 0;
149-
}
150-
return false;
144+
FoodProperties food = stack.getFoodProperties(null);
145+
//And only allow inserting foods that actually would provide paste
146+
return food != null && food.nutrition() > 0;
151147
}
152148

153149
@Override
@@ -191,8 +187,12 @@ public IRecipeViewerRecipeType<ItemStackToFluidOptionalItemRecipe> recipeViewerT
191187
@Nullable
192188
@Override
193189
public ItemStackToFluidOptionalItemRecipe getRecipe(int cacheIndex) {
194-
ItemStack stack = inputHandler.getInput();
195-
if (stack.isEmpty() || !stack.has(DataComponents.FOOD)) {
190+
return getRecipe(inputHandler.getInput());
191+
}
192+
193+
@Nullable
194+
public static ItemStackToFluidOptionalItemRecipe getRecipe(ItemStack stack) {
195+
if (stack.isEmpty()) {
196196
return null;
197197
}
198198
FoodProperties food = stack.getFoodProperties(null);

0 commit comments

Comments
 (0)