Implement Item.isRepairable in Crafting and Grindstone. Closes #5917

This commit is contained in:
LexManos 2019-07-09 17:39:20 -07:00
parent 983e0a93db
commit 2cc264645b
5 changed files with 56 additions and 4 deletions

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/inventory/container/GrindstoneContainer.java --- a/net/minecraft/inventory/container/GrindstoneContainer.java
+++ b/net/minecraft/inventory/container/GrindstoneContainer.java +++ b/net/minecraft/inventory/container/GrindstoneContainer.java
@@ -141,10 +141,10 @@ @@ -141,12 +141,13 @@
} }
Item item = itemstack.func_77973_b(); Item item = itemstack.func_77973_b();
@ -13,5 +13,9 @@
+ int i1 = k + l + itemstack.func_77958_k() * 5 / 100; + int i1 = k + l + itemstack.func_77958_k() * 5 / 100;
+ i = Math.max(itemstack.func_77958_k() - i1, 0); + i = Math.max(itemstack.func_77958_k() - i1, 0);
itemstack2 = this.func_217011_b(itemstack, itemstack1); itemstack2 = this.func_217011_b(itemstack, itemstack1);
if (!itemstack2.func_77984_f()) { - if (!itemstack2.func_77984_f()) {
+ if (!itemstack2.isRepairable()) i = itemstack.func_77952_i();
+ if (!itemstack2.func_77984_f() || !itemstack2.isRepairable()) {
if (!ItemStack.func_77989_b(itemstack, itemstack1)) { if (!ItemStack.func_77989_b(itemstack, itemstack1)) {
this.field_217013_c.func_70299_a(0, ItemStack.field_190927_a);
this.func_75142_b();

View file

@ -92,7 +92,7 @@
+ protected final boolean canRepair; + protected final boolean canRepair;
+ +
+ @Override + @Override
+ public boolean isRepairable() { + public boolean isRepairable(ItemStack stack) {
+ return canRepair && func_77645_m(); + return canRepair && func_77645_m();
+ } + }
+ +

View file

@ -0,0 +1,38 @@
--- a/net/minecraft/item/crafting/RepairItemRecipe.java
+++ b/net/minecraft/item/crafting/RepairItemRecipe.java
@@ -24,7 +24,7 @@
list.add(itemstack);
if (list.size() > 1) {
ItemStack itemstack1 = list.get(0);
- if (itemstack.func_77973_b() != itemstack1.func_77973_b() || itemstack1.func_190916_E() != 1 || itemstack.func_190916_E() != 1 || !itemstack1.func_77973_b().func_77645_m()) {
+ if (itemstack.func_77973_b() != itemstack1.func_77973_b() || itemstack1.func_190916_E() != 1 || itemstack.func_190916_E() != 1 || !itemstack1.isRepairable()) {
return false;
}
}
@@ -43,7 +43,7 @@
list.add(itemstack);
if (list.size() > 1) {
ItemStack itemstack1 = list.get(0);
- if (itemstack.func_77973_b() != itemstack1.func_77973_b() || itemstack1.func_190916_E() != 1 || itemstack.func_190916_E() != 1 || !itemstack1.func_77973_b().func_77645_m()) {
+ if (itemstack.func_77973_b() != itemstack1.func_77973_b() || itemstack1.func_190916_E() != 1 || itemstack.func_190916_E() != 1 || !itemstack1.isRepairable()) {
return ItemStack.field_190927_a;
}
}
@@ -53,12 +53,12 @@
if (list.size() == 2) {
ItemStack itemstack3 = list.get(0);
ItemStack itemstack4 = list.get(1);
- if (itemstack3.func_77973_b() == itemstack4.func_77973_b() && itemstack3.func_190916_E() == 1 && itemstack4.func_190916_E() == 1 && itemstack3.func_77973_b().func_77645_m()) {
+ if (itemstack3.func_77973_b() == itemstack4.func_77973_b() && itemstack3.func_190916_E() == 1 && itemstack4.func_190916_E() == 1 && itemstack3.isRepairable()) {
Item item = itemstack3.func_77973_b();
- int j = item.func_77612_l() - itemstack3.func_77952_i();
- int k = item.func_77612_l() - itemstack4.func_77952_i();
- int l = j + k + item.func_77612_l() * 5 / 100;
- int i1 = item.func_77612_l() - l;
+ int j = itemstack3.func_77958_k() - itemstack3.func_77952_i();
+ int k = itemstack3.func_77958_k() - itemstack4.func_77952_i();
+ int l = j + k + itemstack3.func_77958_k() * 5 / 100;
+ int i1 = itemstack3.func_77958_k() - l;
if (i1 < 0) {
i1 = 0;
}

View file

@ -114,7 +114,7 @@ public interface IForgeItem
* *
* @return True if reparable * @return True if reparable
*/ */
boolean isRepairable(); boolean isRepairable(ItemStack stack);
/** /**
* Determines the amount of durability the mending enchantment * Determines the amount of durability the mending enchantment

View file

@ -425,4 +425,14 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundNBT>
return !other.isEmpty() && getStack().getCount() == other.getCount() && getStack().getItem() == other.getItem() && return !other.isEmpty() && getStack().getCount() == other.getCount() && getStack().getItem() == other.getItem() &&
(limitTags ? getStack().areShareTagsEqual(other) : ItemStack.areItemStackTagsEqual(getStack(), other)); (limitTags ? getStack().areShareTagsEqual(other) : ItemStack.areItemStackTagsEqual(getStack(), other));
} }
/**
* Determines if a item is reparable, used by Repair recipes and Grindstone.
*
* @return True if reparable
*/
default boolean isRepairable()
{
return getStack().getItem().isRepairable(getStack());
}
} }