|
9 | 9 | import net.minecraft.Util; |
10 | 10 | import net.minecraft.core.Holder; |
11 | 11 | import net.minecraft.core.HolderLookup; |
| 12 | +import net.minecraft.core.component.DataComponentMap; |
12 | 13 | import net.minecraft.core.component.DataComponentType; |
13 | 14 | import net.minecraft.world.inventory.CraftingContainer; |
14 | 15 | import net.minecraft.world.item.ItemStack; |
|
22 | 23 | public class ClearConfigurationRecipe extends CustomRecipe { |
23 | 24 |
|
24 | 25 | //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 |
26 | 26 | private static final Set<Holder<DataComponentType<?>>> CLEARABLE_ATTACHMENTS = Util.make(new HashSet<>(), set -> { |
27 | 27 | set.add(MekanismDataComponents.EDIT_MODE); |
28 | 28 | set.add(MekanismDataComponents.DUMP_MODE); |
@@ -98,13 +98,22 @@ public ItemStack assemble(CraftingContainer container, HolderLookup.Provider pro |
98 | 98 | return ItemStack.EMPTY; |
99 | 99 | } |
100 | 100 | ItemStack output = target.copyWithCount(1); |
| 101 | + DataComponentMap prototype = output.getPrototype(); |
101 | 102 | //Only match the recipe if it has at least one attachment that we can clear |
102 | 103 | for (Holder<DataComponentType<?>> clearableAttachment : CLEARABLE_ATTACHMENTS) { |
103 | | - output.remove(clearableAttachment.value()); |
| 104 | + resetComponent(output, prototype, clearableAttachment.value()); |
104 | 105 | } |
105 | 106 | return output; |
106 | 107 | } |
107 | 108 |
|
| 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 | + |
108 | 117 | private ItemStack getTargetStack(CraftingContainer container) { |
109 | 118 | ItemStack target = ItemStack.EMPTY; |
110 | 119 | //Note: We don't use inv#getItems as that may do unnecessary copies depending on impl |
|
0 commit comments