Skip to content

Commit 12c1014

Browse files
committed
Only take into account changed components when creating a data component ingredient
1 parent a8bb435 commit 12c1014

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package mekanism.api.recipes.ingredients.creator;
22

3+
import java.util.Map;
34
import java.util.Objects;
5+
import java.util.Optional;
46
import mekanism.api.annotations.NothingNullByDefault;
57
import mekanism.api.recipes.ingredients.ItemStackIngredient;
68
import net.minecraft.core.Holder;
9+
import net.minecraft.core.component.DataComponentPredicate;
10+
import net.minecraft.core.component.DataComponentType;
711
import net.minecraft.tags.TagKey;
812
import net.minecraft.world.item.Item;
913
import net.minecraft.world.item.ItemStack;
@@ -37,8 +41,17 @@ default ItemStackIngredient from(ItemStack stack, int amount) {
3741
stack = stack.copy();
3842
//Support Components that are on the stack in case it matters
3943
// Note: Only bother making it a data component ingredient if the stack has data, otherwise there is no point in doing the extra checks
40-
if (!stack.getComponentsPatch().isEmpty()) {
41-
return from(DataComponentIngredient.of(false, stack), amount);
44+
if (!stack.isComponentsPatchEmpty()) {
45+
DataComponentPredicate.Builder builder = DataComponentPredicate.builder();
46+
for (Map.Entry<DataComponentType<?>, Optional<?>> entry : stack.getComponentsPatch().entrySet()) {
47+
Optional<?> value = entry.getValue();
48+
//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
49+
if (value.isPresent()) {
50+
//noinspection rawtypes,unchecked
51+
builder.expect((DataComponentType) entry.getKey(), value);
52+
}
53+
}
54+
return from(DataComponentIngredient.of(false, builder.build(), stack.getItemHolder()), amount);
4255
}
4356
return from(Ingredient.of(stack), amount);
4457
}

src/main/java/mekanism/client/recipe_viewer/jei/MekanismJEI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static RecipeType<?>[] recipeType(IRecipeViewerRecipeType<?>... recipeTyp
153153

154154
private static final IIngredientSubtypeInterpreter<ItemStack> MEKANISM_NBT_INTERPRETER = (stack, context) -> {
155155
//TODO - 1.20.5: Re-evaluate if we want the components check or if it should check it slightly differently?
156-
if (context == UidContext.Ingredient && !stack.getComponentsPatch().isEmpty()) {
156+
if (context == UidContext.Ingredient && !stack.isComponentsPatchEmpty()) {
157157
String representation = getChemicalComponent(stack, ContainerType.GAS, Capabilities.GAS.item());
158158
representation = addInterpretation(representation, getChemicalComponent(stack, ContainerType.INFUSION, Capabilities.INFUSION.item()));
159159
representation = addInterpretation(representation, getChemicalComponent(stack, ContainerType.PIGMENT, Capabilities.PIGMENT.item()));

src/main/java/mekanism/common/recipe/ClearConfigurationRecipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private ItemStack getTargetStack(CraftingContainer container) {
111111
for (int i = 0, slots = container.getContainerSize(); i < slots; ++i) {
112112
ItemStack stackInSlot = container.getItem(i);
113113
if (!stackInSlot.isEmpty()) {
114-
if (stackInSlot.getComponentsPatch().isEmpty()) {
114+
if (stackInSlot.isComponentsPatchEmpty()) {
115115
//We currently only want to target block items that have at least one component
116116
return ItemStack.EMPTY;
117117
}

src/main/java/mekanism/common/recipe/upgrade/MekanismShapedRecipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ItemStack assemble(CraftingContainer inv, HolderLookup.Provider provider)
3737
List<ItemStack> componentInputs = new ArrayList<>();
3838
for (int i = 0; i < inv.getContainerSize(); i++) {
3939
ItemStack stack = inv.getItem(i);
40-
if (!stack.isEmpty() && !stack.getComponentsPatch().isEmpty()) {
40+
if (!stack.isEmpty() && !stack.isComponentsPatchEmpty()) {
4141
componentInputs.add(stack);
4242
}
4343
}

0 commit comments

Comments
 (0)