From 3fab131d938358cec72b44f35abe08eedf599778 Mon Sep 17 00:00:00 2001 From: TelepathicGrunt <40846040+TelepathicGrunt@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:05:16 -0500 Subject: [PATCH 1/3] Rename isRepairable to isCombineRepairable and make it not reliant on Repairable Data Component fixes https://github.com/neoforged/NeoForge/issues/1747 --- .../neoforge/common/extensions/IItemExtension.java | 6 +++--- .../neoforge/common/extensions/IItemStackExtension.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java index 662f8169441..25a80929d28 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java @@ -129,11 +129,11 @@ default boolean makesPiglinsNeutral(ItemStack stack, LivingEntity wearer) { } /** - * Called by CraftingManager to determine if an item is reparable. + * Called by CraftingManager and Grindstone to determine if an item is repairable by combining two damaged versions together. * - * @return True if reparable + * @return True if reparable by combining */ - boolean isRepairable(ItemStack stack); + boolean isCombineRepairable(ItemStack stack); /** * Determines the amount of durability the mending enchantment diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java index 0b18ba462f3..609f9cf52b2 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java @@ -317,12 +317,12 @@ default boolean doesSneakBypassUse(net.minecraft.world.level.LevelReader level, } /** - * Determines if a item is reparable, used by Repair recipes and Grindstone. + * Determines if an item is repairable by combining, used by Repair recipes and Grindstone. * - * @return True if reparable + * @return True if repairable by combining */ - default boolean isRepairable() { - return self().getItem().isRepairable(self()); + default boolean isCombineRepairable() { + return self().getItem().isCombineRepairable(self()); } /** From cc4091dc34cb67f4f032e43801def03417bbf6ca Mon Sep 17 00:00:00 2001 From: TelepathicGrunt <40846040+TelepathicGrunt@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:08:06 -0500 Subject: [PATCH 2/3] gen patches --- .../world/inventory/GrindstoneMenu.java.patch | 4 +-- .../net/minecraft/world/item/Item.java.patch | 29 ++++++++++++++++--- .../item/crafting/RepairItemRecipe.java.patch | 4 +-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/patches/net/minecraft/world/inventory/GrindstoneMenu.java.patch b/patches/net/minecraft/world/inventory/GrindstoneMenu.java.patch index fce1cf64627..132f01160c0 100644 --- a/patches/net/minecraft/world/inventory/GrindstoneMenu.java.patch +++ b/patches/net/minecraft/world/inventory/GrindstoneMenu.java.patch @@ -54,7 +54,7 @@ int l = j + k + i * 5 / 100; int i1 = 1; - if (!p_332723_.isDamageableItem()) { -+ if (!p_332723_.isDamageableItem() || !p_332723_.isRepairable()) { ++ if (!p_332723_.isDamageableItem() || !p_332723_.isCombineRepairable()) { if (p_332723_.getMaxStackSize() < 2 || !ItemStack.matches(p_332723_, p_332686_)) { return ItemStack.EMPTY; } @@ -62,7 +62,7 @@ if (itemstack.isDamageableItem()) { itemstack.set(DataComponents.MAX_DAMAGE, i); itemstack.setDamageValue(Math.max(i - l, 0)); -+ if (!p_332686_.isRepairable()) itemstack.setDamageValue(p_332723_.getDamageValue()); ++ if (!p_332686_.isCombineRepairable()) itemstack.setDamageValue(p_332723_.getDamageValue()); } this.mergeEnchantsFrom(itemstack, p_332686_); diff --git a/patches/net/minecraft/world/item/Item.java.patch b/patches/net/minecraft/world/item/Item.java.patch index f4964bdec54..63ce8433900 100644 --- a/patches/net/minecraft/world/item/Item.java.patch +++ b/patches/net/minecraft/world/item/Item.java.patch @@ -18,7 +18,7 @@ public static final ResourceLocation BASE_ATTACK_DAMAGE_ID = ResourceLocation.withDefaultNamespace("base_attack_damage"); public static final ResourceLocation BASE_ATTACK_SPEED_ID = ResourceLocation.withDefaultNamespace("base_attack_speed"); public static final int DEFAULT_MAX_STACK_SIZE = 64; -@@ -110,7 +_,7 @@ +@@ -110,12 +_,13 @@ this.components = p_41383_.buildAndValidateComponents(Component.translatable(this.descriptionId), p_41383_.effectiveModel()); this.craftingRemainingItem = p_41383_.craftingRemainingItem; this.requiredFeatures = p_41383_.requiredFeatures; @@ -27,6 +27,12 @@ String s = this.getClass().getSimpleName(); if (!s.endsWith("Item")) { LOGGER.error("Item classes should end with Item and {} doesn't.", s); + } + } ++ this.canCombineRepair = p_41383_.canCombineRepair; + } + + @Deprecated @@ -127,6 +_,15 @@ return this.components; } @@ -76,7 +82,7 @@ public final ItemStack getCraftingRemainder() { return this.craftingRemainingItem == null ? ItemStack.EMPTY : new ItemStack(this.craftingRemainingItem); } -@@ -302,7 +_,12 @@ +@@ -302,7 +_,14 @@ } public boolean useOnRelease(ItemStack p_41464_) { @@ -84,9 +90,11 @@ + return p_41464_.getItem() == Items.CROSSBOW; + } + ++ protected final boolean canCombineRepair; ++ + @Override -+ public boolean isRepairable(ItemStack stack) { -+ return stack.has(DataComponents.REPAIRABLE) && isDamageable(stack); ++ public boolean isCombineRepairable(ItemStack stack) { ++ return canCombineRepair && isDamageable(stack); } public ItemStack getDefaultInstance() { @@ -99,6 +107,19 @@ private static final DependantName BLOCK_DESCRIPTION_ID = p_371954_ -> Util.makeDescriptionId("block", p_371954_.location()); private static final DependantName ITEM_DESCRIPTION_ID = p_371511_ -> Util.makeDescriptionId("item", p_371511_.location()); private final DataComponentMap.Builder components = DataComponentMap.builder().addAll(DataComponents.COMMON_ITEM_COMPONENTS); +@@ -337,6 +_,12 @@ + private ResourceKey id; + private DependantName descriptionId = ITEM_DESCRIPTION_ID; + private DependantName model = ResourceKey::location; ++ private boolean canCombineRepair = true; ++ ++ public Item.Properties setNoCombineRepair() { ++ canCombineRepair = false; ++ return this; ++ } + + public Item.Properties food(FoodProperties p_41490_) { + return this.food(p_41490_, Consumables.DEFAULT_FOOD); @@ -437,6 +_,7 @@ } diff --git a/patches/net/minecraft/world/item/crafting/RepairItemRecipe.java.patch b/patches/net/minecraft/world/item/crafting/RepairItemRecipe.java.patch index 91780eb1f28..4e7fabb17d7 100644 --- a/patches/net/minecraft/world/item/crafting/RepairItemRecipe.java.patch +++ b/patches/net/minecraft/world/item/crafting/RepairItemRecipe.java.patch @@ -6,8 +6,8 @@ && p_336139_.has(DataComponents.DAMAGE) - && p_335795_.has(DataComponents.DAMAGE); + && p_335795_.has(DataComponents.DAMAGE) -+ && p_336139_.isRepairable() -+ && p_335795_.isRepairable(); ++ && p_336139_.isCombineRepairable() ++ && p_335795_.isCombineRepairable(); } public boolean matches(CraftingInput p_345243_, Level p_44139_) { From 32c5e0212806c7b0d4eebc2f52baf0b972919987 Mon Sep 17 00:00:00 2001 From: TelepathicGrunt <40846040+TelepathicGrunt@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:53:33 -0500 Subject: [PATCH 3/3] Fix javadoc --- .../neoforged/neoforge/common/extensions/IItemExtension.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java index 25a80929d28..7db002d6090 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java @@ -129,9 +129,9 @@ default boolean makesPiglinsNeutral(ItemStack stack, LivingEntity wearer) { } /** - * Called by CraftingManager and Grindstone to determine if an item is repairable by combining two damaged versions together. + * Determines if an item is repairable by combining, used by Repair recipes and Grindstone. * - * @return True if reparable by combining + * @return True if repairable by combining */ boolean isCombineRepairable(ItemStack stack);