Skip to content

Commit 01f8259

Browse files
committed
Make clear configuration recipe reset components back to their default value
1 parent af32797 commit 01f8259

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.Util;
1010
import net.minecraft.core.Holder;
1111
import net.minecraft.core.HolderLookup;
12+
import net.minecraft.core.component.DataComponentMap;
1213
import net.minecraft.core.component.DataComponentType;
1314
import net.minecraft.world.inventory.CraftingContainer;
1415
import net.minecraft.world.item.ItemStack;
@@ -22,7 +23,6 @@
2223
public class ClearConfigurationRecipe extends CustomRecipe {
2324

2425
//TODO: Evaluate supporting some of these in some sort of generic way in RecipeUpgradeType?
25-
//TODO - 1.20.5: Validate how this is handled, and whether removing removes from the patch and sets it back to default or if it entirely gets rid of it
2626
private static final Set<Holder<DataComponentType<?>>> CLEARABLE_ATTACHMENTS = Util.make(new HashSet<>(), set -> {
2727
set.add(MekanismDataComponents.EDIT_MODE);
2828
set.add(MekanismDataComponents.DUMP_MODE);
@@ -98,13 +98,22 @@ public ItemStack assemble(CraftingContainer container, HolderLookup.Provider pro
9898
return ItemStack.EMPTY;
9999
}
100100
ItemStack output = target.copyWithCount(1);
101+
DataComponentMap prototype = output.getPrototype();
101102
//Only match the recipe if it has at least one attachment that we can clear
102103
for (Holder<DataComponentType<?>> clearableAttachment : CLEARABLE_ATTACHMENTS) {
103-
output.remove(clearableAttachment.value());
104+
resetComponent(output, prototype, clearableAttachment.value());
104105
}
105106
return output;
106107
}
107108

109+
private <TYPE> void resetComponent(ItemStack output, DataComponentMap prototype, DataComponentType<TYPE> componentType) {
110+
if (prototype.has(componentType)) {
111+
output.set(componentType, prototype.get(componentType));
112+
} else {
113+
output.remove(componentType);
114+
}
115+
}
116+
108117
private ItemStack getTargetStack(CraftingContainer container) {
109118
ItemStack target = ItemStack.EMPTY;
110119
//Note: We don't use inv#getItems as that may do unnecessary copies depending on impl

0 commit comments

Comments
 (0)