From 249c468a75108ff9967340d74b397004cecdcd5b Mon Sep 17 00:00:00 2001 From: CoderAtParadise Date: Thu, 1 Dec 2016 11:08:30 +1000 Subject: [PATCH] Changed Armor Material to use an ItemStack aware version (#3469) --- .../net/minecraft/item/Item.java.patch | 29 +++------ .../net/minecraft/item/ItemArmor.java.patch | 60 +++++++++++++------ 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/patches/minecraft/net/minecraft/item/Item.java.patch b/patches/minecraft/net/minecraft/item/Item.java.patch index 5c915761c6..3909962958 100644 --- a/patches/minecraft/net/minecraft/item/Item.java.patch +++ b/patches/minecraft/net/minecraft/item/Item.java.patch @@ -661,39 +661,28 @@ public static void func_150900_l() { func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a)); -@@ -972,6 +1568,10 @@ +@@ -971,6 +1567,8 @@ + private final float field_78010_h; private final float field_78011_i; private final int field_78008_j; - + //Added by forge for custom Tool materials. -+ @Nullable -+ private ItemStack repairMaterial = null; -+ ++ private ItemStack repairMaterial = ItemStack.field_190927_a; + private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_) { - this.field_78001_f = p_i1874_3_; -@@ -1006,9 +1606,34 @@ +@@ -1006,9 +1604,26 @@ return this.field_78008_j; } + @Deprecated // Use getRepairItemStack below public Item func_150995_f() { -- return this == WOOD ? Item.func_150898_a(Blocks.field_150344_f) : (this == STONE ? Item.func_150898_a(Blocks.field_150347_e) : (this == GOLD ? Items.field_151043_k : (this == IRON ? Items.field_151042_j : (this == DIAMOND ? Items.field_151045_i : null)))); -+ switch (this) -+ { -+ case WOOD: return Item.func_150898_a(Blocks.field_150344_f); -+ case STONE: return Item.func_150898_a(Blocks.field_150347_e); -+ case GOLD: return Items.field_151043_k; -+ case IRON: return Items.field_151042_j; -+ case DIAMOND: return Items.field_151045_i; -+ default: return Items.field_190931_a; -+ } + return this == WOOD ? Item.func_150898_a(Blocks.field_150344_f) : (this == STONE ? Item.func_150898_a(Blocks.field_150347_e) : (this == GOLD ? Items.field_151043_k : (this == IRON ? Items.field_151042_j : (this == DIAMOND ? Items.field_151045_i : null)))); } + + public ToolMaterial setRepairItem(ItemStack stack) + { -+ if (this.repairMaterial != null) throw new RuntimeException("Repair material has already been set"); ++ if (!this.repairMaterial.func_190926_b()) throw new RuntimeException("Repair material has already been set"); + if (this == WOOD || this == STONE || this == GOLD || this == IRON || this == DIAMOND) throw new RuntimeException("Can not change vanilla tool repair materials"); + this.repairMaterial = stack; + return this; @@ -701,9 +690,9 @@ + + public ItemStack getRepairItemStack() + { -+ if (repairMaterial != null) return repairMaterial; ++ if (!repairMaterial.func_190926_b()) return repairMaterial; + Item ret = this.func_150995_f(); -+ repairMaterial = new ItemStack(ret, 1, net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE); ++ if (ret != null) repairMaterial = new ItemStack(ret, 1, net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE); + return repairMaterial; + } } diff --git a/patches/minecraft/net/minecraft/item/ItemArmor.java.patch b/patches/minecraft/net/minecraft/item/ItemArmor.java.patch index 1e9f5da7ac..1046ea8ef9 100644 --- a/patches/minecraft/net/minecraft/item/ItemArmor.java.patch +++ b/patches/minecraft/net/minecraft/item/ItemArmor.java.patch @@ -1,6 +1,17 @@ --- ../src-base/minecraft/net/minecraft/item/ItemArmor.java +++ ../src-work/minecraft/net/minecraft/item/ItemArmor.java -@@ -221,6 +221,19 @@ +@@ -187,7 +187,9 @@ + + public boolean func_82789_a(ItemStack p_82789_1_, ItemStack p_82789_2_) + { +- return this.field_77878_bZ.func_151685_b() == p_82789_2_.func_77973_b() ? true : super.func_82789_a(p_82789_1_, p_82789_2_); ++ ItemStack mat = this.field_77878_bZ.getRepairItemStack(); ++ if (!mat.func_190926_b() && net.minecraftforge.oredict.OreDictionary.itemMatches(mat,p_82789_2_,false)) return true; ++ return super.func_82789_a(p_82789_1_, p_82789_2_); + } + + public ActionResult func_77659_a(World p_77659_1_, EntityPlayer p_77659_2_, EnumHand p_77659_3_) +@@ -221,6 +223,19 @@ return multimap; } @@ -20,29 +31,42 @@ public static enum ArmorMaterial { LEATHER("leather", 5, new int[]{1, 2, 3, 1}, 15, SoundEvents.field_187728_s, 0.0F), -@@ -235,6 +248,8 @@ +@@ -235,6 +250,8 @@ private final int field_78055_h; private final SoundEvent field_185020_j; private final float field_189417_k; + //Added by forge for custom Armor materials. -+ public Item customCraftingMaterial = null; ++ public ItemStack repairMaterial = ItemStack.field_190927_a; private ArmorMaterial(String p_i47117_3_, int p_i47117_4_, int[] p_i47117_5_, int p_i47117_6_, SoundEvent p_i47117_7_, float p_i47117_8_) { -@@ -268,7 +283,15 @@ - - public Item func_151685_b() - { -- return this == LEATHER ? Items.field_151116_aA : (this == CHAIN ? Items.field_151042_j : (this == GOLD ? Items.field_151043_k : (this == IRON ? Items.field_151042_j : (this == DIAMOND ? Items.field_151045_i : null)))); -+ switch (this) -+ { -+ case LEATHER: return Items.field_151116_aA; -+ case CHAIN: return Items.field_151042_j; -+ case GOLD: return Items.field_151043_k; -+ case IRON: return Items.field_151042_j; -+ case DIAMOND: return Items.field_151045_i; -+ default: return customCraftingMaterial; -+ } +@@ -266,6 +283,7 @@ + return this.field_185020_j; } - @SideOnly(Side.CLIENT) ++ @Deprecated // Use getRepairItemStack below + public Item func_151685_b() + { + return this == LEATHER ? Items.field_151116_aA : (this == CHAIN ? Items.field_151042_j : (this == GOLD ? Items.field_151043_k : (this == IRON ? Items.field_151042_j : (this == DIAMOND ? Items.field_151045_i : null)))); +@@ -281,5 +299,21 @@ + { + return this.field_189417_k; + } ++ ++ public ArmorMaterial setRepairItem(ItemStack stack) ++ { ++ if (!this.repairMaterial.func_190926_b()) throw new RuntimeException("Repair material has already been set"); ++ if (this == LEATHER || this == CHAIN || this == GOLD || this == IRON || this == DIAMOND) throw new RuntimeException("Can not change vanilla armor repair materials"); ++ this.repairMaterial = stack; ++ return this; ++ } ++ ++ public ItemStack getRepairItemStack() ++ { ++ if (!repairMaterial.func_190926_b()) return repairMaterial; ++ Item ret = this.func_151685_b(); ++ if (ret != null) repairMaterial = new ItemStack(ret,1,net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE); ++ return repairMaterial; ++ } + } + }