Skip to content

Commit

Permalink
Rename isRepairable to isCombineRepairable and make it not reliant on…
Browse files Browse the repository at this point in the history
… Repairable Data Component (#1748)
  • Loading branch information
TelepathicGrunt authored Dec 9, 2024
1 parent 1e73806 commit ac0abaf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
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;
}
@@ -158,6 +_,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_);
29 changes: 25 additions & 4 deletions patches/net/minecraft/world/item/Item.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -76,17 +82,19 @@
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_) {
- return false;
+ 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() {
Expand All @@ -99,6 +107,19 @@
private static final DependantName<Item, String> BLOCK_DESCRIPTION_ID = p_371954_ -> Util.makeDescriptionId("block", p_371954_.location());
private static final DependantName<Item, String> 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<Item> id;
private DependantName<Item, String> descriptionId = ITEM_DESCRIPTION_ID;
private DependantName<Item, ResourceLocation> 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 @@
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ default boolean makesPiglinsNeutral(ItemStack stack, LivingEntity wearer) {
}

/**
* Called by CraftingManager to determine if an item is reparable.
* Determines if an item is repairable by combining, used by Repair recipes and Grindstone.
*
* @return True if reparable
* @return True if repairable by combining
*/
boolean isRepairable(ItemStack stack);
boolean isCombineRepairable(ItemStack stack);

/**
* Determines the amount of durability the mending enchantment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit ac0abaf

Please sign in to comment.