Changed ToolMaterial's repair material to ItemStack version to allow metadata sensitive versions. Closes #1355

This commit is contained in:
Lex Manos 2014-12-07 04:29:55 -08:00
parent 83bcebf3b1
commit 35fac1f691
3 changed files with 89 additions and 34 deletions

View file

@ -43,6 +43,15 @@
public class Item
{
@@ -64,7 +74,7 @@
protected String field_111218_cA;
private static final String __OBFID = "CL_00000041";
- public final cpw.mods.fml.common.registry.RegistryDelegate<Item> delegate =
+ public final cpw.mods.fml.common.registry.RegistryDelegate<Item> delegate =
((cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry)field_150901_e).getDelegate(this, Item.class);
public static int func_150891_b(Item p_150891_0_)
{
@@ -450,6 +460,7 @@
return p_77654_1_;
}
@ -317,9 +326,9 @@
+ }
+
+ /**
+ * Called by the default implemetation of EntityItem's onUpdate method, allowing for cleaner
+ * Called by the default implemetation of EntityItem's onUpdate method, allowing for cleaner
+ * control over the update of the item without having to write a subclass.
+ *
+ *
+ * @param entityItem The entity Item
+ * @return Return true to skip any further update code.
+ */
@ -390,7 +399,7 @@
+ *
+ * Should this item, when held, allow sneak-clicks to pass through to the underlying block?
+ *
+ * @param world The world
+ * @param world The world
+ * @param x The X Position
+ * @param y The X Position
+ * @param z The X Position
@ -450,12 +459,12 @@
+ }
+
+ /**
+ * Called by RenderBiped and RenderPlayer to determine the armor texture that
+ * Called by RenderBiped and RenderPlayer to determine the armor texture that
+ * should be use for the currently equiped item.
+ * This will only be called on instances of ItemArmor.
+ *
+ * This will only be called on instances of ItemArmor.
+ *
+ * Returning null from this function will use the default value.
+ *
+ *
+ * @param stack ItemStack for the equpt armor
+ * @param entity The entity wearing the armor
+ * @param slot The slot the armor is in
@ -470,7 +479,7 @@
+ /**
+ * Returns the font renderer used to render tooltips and overlays for this item.
+ * Returning null will use the standard font renderer.
+ *
+ *
+ * @param stack The current item stack
+ * @return A instance of FontRenderer or null to use default
+ */
@ -482,11 +491,11 @@
+
+ /**
+ * Override this method to have an item handle its own armor rendering.
+ *
+ * @param entityLiving The entity wearing the armor
+ * @param itemStack The itemStack to render the model of
+ *
+ * @param entityLiving The entity wearing the armor
+ * @param itemStack The itemStack to render the model of
+ * @param armorSlot 0=head, 1=torso, 2=legs, 3=feet
+ *
+ *
+ * @return A ModelBiped to render instead of the default
+ */
+ @SideOnly(Side.CLIENT)
@ -497,10 +506,10 @@
+
+ /**
+ * Called when a entity tries to play the 'swing' animation.
+ *
+ *
+ * @param entityLiving The entity swinging the item.
+ * @param stack The Item stack
+ * @return True to cancel any further processing by EntityLiving
+ * @return True to cancel any further processing by EntityLiving
+ */
+ public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack)
+ {
@ -508,9 +517,9 @@
+ }
+
+ /**
+ * Called when the client starts rendering the HUD, for whatever item the player currently has as a helmet.
+ * Called when the client starts rendering the HUD, for whatever item the player currently has as a helmet.
+ * This is where pumpkins would render there overlay.
+ *
+ *
+ * @param stack The ItemStack that is equipped
+ * @param player Reference to the current client entity
+ * @param resolution Resolution information about the current viewport and configured GUI Scale
@ -543,7 +552,7 @@
+ * Determines if the durability bar should be rendered for this item.
+ * Defaults to vanilla stack.isDamaged behavior.
+ * But modders can use this for any data they wish.
+ *
+ *
+ * @param stack The current Item Stack
+ * @return True if it should render the 'durability' bar.
+ */
@ -554,7 +563,7 @@
+
+ /**
+ * Queries the percentage of the 'Durability' bar that should be drawn.
+ *
+ *
+ * @param stack The current ItemStack
+ * @return 1.0 for 100% 0 for 0%
+ */
@ -562,9 +571,9 @@
+ {
+ return (double)stack.func_77952_i() / (double)stack.func_77958_k();
+ }
+
+
+ /**
+ * Return the maxDamage for this ItemStack. Defaults to the maxDamage field in this item,
+ * Return the maxDamage for this ItemStack. Defaults to the maxDamage field in this item,
+ * but can be overridden here for other sources such as NBT.
+ *
+ * @param stack The itemstack that is damaged
@ -601,14 +610,14 @@
+ }
+
+ /**
+ * ItemStack sensitive version of {@link #canHarvestBlock(Block)}
+ * ItemStack sensitive version of {@link #canHarvestBlock(Block)}
+ * @param par1Block The block trying to harvest
+ * @param itemStack The itemstack used to harvest the block
+ * @return true if can harvest the block
+ */
+ public boolean canHarvestBlock(Block par1Block, ItemStack itemStack)
+ {
+ return func_150897_b(par1Block);
+ return func_150897_b(par1Block);
+ }
+
+ /**
@ -621,9 +630,9 @@
+ }
+
+ /**
+ * Gets the maximum number of items that this stack should be able to hold.
+ * Gets the maximum number of items that this stack should be able to hold.
+ * This is a ItemStack (and thus NBT) sensitive version of Item.getItemStackLimit()
+ *
+ *
+ * @param stack The ItemStack
+ * @return THe maximum number this item can be stacked to
+ */
@ -635,7 +644,7 @@
+ private HashMap<String, Integer> toolClasses = new HashMap<String, Integer>();
+ /**
+ * Sets or removes the harvest level for the specified tool class.
+ *
+ *
+ * @param toolClass Class
+ * @param level Harvest level:
+ * Wood: 0
@ -660,7 +669,7 @@
+ /**
+ * Queries the harvest level of this item stack for the specifred tool class,
+ * Returns -1 if this tool is not of the specified type
+ *
+ *
+ * @param stack This item stack instance
+ * @param toolClass Tool Class
+ * @return Harvest level, or -1 if not the specified tool type.
@ -668,12 +677,12 @@
+ public int getHarvestLevel(ItemStack stack, String toolClass)
+ {
+ Integer ret = toolClasses.get(toolClass);
+ return ret == null ? -1 : ret;
+ return ret == null ? -1 : ret;
+ }
+
+
+ /**
+ * ItemStack sensitive version of getItemEnchantability
+ *
+ *
+ * @param stack The ItemStack
+ * @return the item echantability value
+ */
@ -681,7 +690,7 @@
+ {
+ return func_77619_b();
+ }
+
+
+ /**
+ * Whether this Item can be used as a payment to activate the vanilla beacon.
+ * @param stack the ItemStack
@ -696,18 +705,22 @@
public static enum ToolMaterial
{
WOOD(0, 59, 2.0F, 0.0F, 15),
@@ -743,6 +1346,9 @@
@@ -743,6 +1346,10 @@
private static final String __OBFID = "CL_00000042";
+ //Added by forge for custom Tool materials.
+ public Item customCraftingMaterial = null;
+ @Deprecated public Item customCraftingMaterial = null;
+ private ItemStack repairMaterial = null;
+
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_;
@@ -779,7 +1385,15 @@
@@ -777,9 +1384,36 @@
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 == EMERALD ? Items.field_151045_i : null))));
@ -721,5 +734,23 @@
+ default: return customCraftingMaterial;
+ }
}
+
+ public ToolMaterial setRepairItem(ItemStack stack)
+ {
+ if (this.repairMaterial != null || customCraftingMaterial != null) throw new RuntimeException("Can not change already set repair material");
+ if (this == WOOD || this == STONE || this == GOLD || this == IRON || this == EMERALD) throw new RuntimeException("Can not change vanilla tool repair materials");
+ this.repairMaterial = stack;
+ this.customCraftingMaterial = stack.func_77973_b();
+ return this;
+ }
+
+ public ItemStack getRepairItemStack()
+ {
+ if (repairMaterial != null) return repairMaterial;
+ Item ret = this.func_150995_f();
+ if (ret == null) return null;
+ repairMaterial = new ItemStack(ret, 1, net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE);
+ return repairMaterial;
+ }
}
}

View file

@ -0,0 +1,13 @@
--- ../src-base/minecraft/net/minecraft/item/ItemSword.java
+++ ../src-work/minecraft/net/minecraft/item/ItemSword.java
@@ -101,7 +101,9 @@
public boolean func_82789_a(ItemStack p_82789_1_, ItemStack p_82789_2_)
{
- return this.field_150933_b.func_150995_f() == p_82789_2_.func_77973_b() ? true : super.func_82789_a(p_82789_1_, p_82789_2_);
+ ItemStack mat = this.field_150933_b.getRepairItemStack();
+ if (mat != null && net.minecraftforge.oredict.OreDictionary.itemMatches(mat, p_82789_2_, false)) return true;
+ return super.func_82789_a(p_82789_1_, p_82789_2_);
}
public Multimap func_111205_h()

View file

@ -34,7 +34,18 @@
}
public float func_150893_a(ItemStack p_150893_1_, Block p_150893_2_)
@@ -83,4 +97,37 @@
@@ -74,7 +88,9 @@
public boolean func_82789_a(ItemStack p_82789_1_, ItemStack p_82789_2_)
{
- return this.field_77862_b.func_150995_f() == p_82789_2_.func_77973_b() ? true : super.func_82789_a(p_82789_1_, p_82789_2_);
+ ItemStack mat = this.field_77862_b.getRepairItemStack();
+ if (mat != null && net.minecraftforge.oredict.OreDictionary.itemMatches(mat, p_82789_2_, false)) return true;
+ return super.func_82789_a(p_82789_1_, p_82789_2_);
}
public Multimap func_111205_h()
@@ -83,4 +99,37 @@
multimap.put(SharedMonsterAttributes.field_111264_e.func_111108_a(), new AttributeModifier(field_111210_e, "Tool modifier", (double)this.field_77865_bY, 0));
return multimap;
}