Skip to content

Commit ac0abaf

Browse files
Rename isRepairable to isCombineRepairable and make it not reliant on Repairable Data Component (#1748)
1 parent 1e73806 commit ac0abaf

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

patches/net/minecraft/world/inventory/GrindstoneMenu.java.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454
int l = j + k + i * 5 / 100;
5555
int i1 = 1;
5656
- if (!p_332723_.isDamageableItem()) {
57-
+ if (!p_332723_.isDamageableItem() || !p_332723_.isRepairable()) {
57+
+ if (!p_332723_.isDamageableItem() || !p_332723_.isCombineRepairable()) {
5858
if (p_332723_.getMaxStackSize() < 2 || !ItemStack.matches(p_332723_, p_332686_)) {
5959
return ItemStack.EMPTY;
6060
}
6161
@@ -158,6 +_,7 @@
6262
if (itemstack.isDamageableItem()) {
6363
itemstack.set(DataComponents.MAX_DAMAGE, i);
6464
itemstack.setDamageValue(Math.max(i - l, 0));
65-
+ if (!p_332686_.isRepairable()) itemstack.setDamageValue(p_332723_.getDamageValue());
65+
+ if (!p_332686_.isCombineRepairable()) itemstack.setDamageValue(p_332723_.getDamageValue());
6666
}
6767

6868
this.mergeEnchantsFrom(itemstack, p_332686_);

patches/net/minecraft/world/item/Item.java.patch

+25-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public static final ResourceLocation BASE_ATTACK_DAMAGE_ID = ResourceLocation.withDefaultNamespace("base_attack_damage");
1919
public static final ResourceLocation BASE_ATTACK_SPEED_ID = ResourceLocation.withDefaultNamespace("base_attack_speed");
2020
public static final int DEFAULT_MAX_STACK_SIZE = 64;
21-
@@ -110,7 +_,7 @@
21+
@@ -110,12 +_,13 @@
2222
this.components = p_41383_.buildAndValidateComponents(Component.translatable(this.descriptionId), p_41383_.effectiveModel());
2323
this.craftingRemainingItem = p_41383_.craftingRemainingItem;
2424
this.requiredFeatures = p_41383_.requiredFeatures;
@@ -27,6 +27,12 @@
2727
String s = this.getClass().getSimpleName();
2828
if (!s.endsWith("Item")) {
2929
LOGGER.error("Item classes should end with Item and {} doesn't.", s);
30+
}
31+
}
32+
+ this.canCombineRepair = p_41383_.canCombineRepair;
33+
}
34+
35+
@Deprecated
3036
@@ -127,6 +_,15 @@
3137
return this.components;
3238
}
@@ -76,17 +82,19 @@
7682
public final ItemStack getCraftingRemainder() {
7783
return this.craftingRemainingItem == null ? ItemStack.EMPTY : new ItemStack(this.craftingRemainingItem);
7884
}
79-
@@ -302,7 +_,12 @@
85+
@@ -302,7 +_,14 @@
8086
}
8187

8288
public boolean useOnRelease(ItemStack p_41464_) {
8389
- return false;
8490
+ return p_41464_.getItem() == Items.CROSSBOW;
8591
+ }
8692
+
93+
+ protected final boolean canCombineRepair;
94+
+
8795
+ @Override
88-
+ public boolean isRepairable(ItemStack stack) {
89-
+ return stack.has(DataComponents.REPAIRABLE) && isDamageable(stack);
96+
+ public boolean isCombineRepairable(ItemStack stack) {
97+
+ return canCombineRepair && isDamageable(stack);
9098
}
9199

92100
public ItemStack getDefaultInstance() {
@@ -99,6 +107,19 @@
99107
private static final DependantName<Item, String> BLOCK_DESCRIPTION_ID = p_371954_ -> Util.makeDescriptionId("block", p_371954_.location());
100108
private static final DependantName<Item, String> ITEM_DESCRIPTION_ID = p_371511_ -> Util.makeDescriptionId("item", p_371511_.location());
101109
private final DataComponentMap.Builder components = DataComponentMap.builder().addAll(DataComponents.COMMON_ITEM_COMPONENTS);
110+
@@ -337,6 +_,12 @@
111+
private ResourceKey<Item> id;
112+
private DependantName<Item, String> descriptionId = ITEM_DESCRIPTION_ID;
113+
private DependantName<Item, ResourceLocation> model = ResourceKey::location;
114+
+ private boolean canCombineRepair = true;
115+
+
116+
+ public Item.Properties setNoCombineRepair() {
117+
+ canCombineRepair = false;
118+
+ return this;
119+
+ }
120+
121+
public Item.Properties food(FoodProperties p_41490_) {
122+
return this.food(p_41490_, Consumables.DEFAULT_FOOD);
102123
@@ -437,6 +_,7 @@
103124
}
104125

patches/net/minecraft/world/item/crafting/RepairItemRecipe.java.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
&& p_336139_.has(DataComponents.DAMAGE)
77
- && p_335795_.has(DataComponents.DAMAGE);
88
+ && p_335795_.has(DataComponents.DAMAGE)
9-
+ && p_336139_.isRepairable()
10-
+ && p_335795_.isRepairable();
9+
+ && p_336139_.isCombineRepairable()
10+
+ && p_335795_.isCombineRepairable();
1111
}
1212

1313
public boolean matches(CraftingInput p_345243_, Level p_44139_) {

src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ default boolean makesPiglinsNeutral(ItemStack stack, LivingEntity wearer) {
129129
}
130130

131131
/**
132-
* Called by CraftingManager to determine if an item is reparable.
132+
* Determines if an item is repairable by combining, used by Repair recipes and Grindstone.
133133
*
134-
* @return True if reparable
134+
* @return True if repairable by combining
135135
*/
136-
boolean isRepairable(ItemStack stack);
136+
boolean isCombineRepairable(ItemStack stack);
137137

138138
/**
139139
* Determines the amount of durability the mending enchantment

src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ default boolean doesSneakBypassUse(net.minecraft.world.level.LevelReader level,
317317
}
318318

319319
/**
320-
* Determines if a item is reparable, used by Repair recipes and Grindstone.
320+
* Determines if an item is repairable by combining, used by Repair recipes and Grindstone.
321321
*
322-
* @return True if reparable
322+
* @return True if repairable by combining
323323
*/
324-
default boolean isRepairable() {
325-
return self().getItem().isRepairable(self());
324+
default boolean isCombineRepairable() {
325+
return self().getItem().isCombineRepairable(self());
326326
}
327327

328328
/**

0 commit comments

Comments
 (0)