Tidier implementation of previous commit. Should fix for subclasses of individual tools too

This commit is contained in:
Christian 2013-12-27 21:48:42 -05:00
parent 78b1b54e2b
commit cf3447feea
2 changed files with 39 additions and 23 deletions

View File

@ -1,6 +1,13 @@
--- ../src-base/minecraft/net/minecraft/item/ItemTool.java
+++ ../src-work/minecraft/net/minecraft/item/ItemTool.java
@@ -10,6 +10,7 @@
@@ -1,5 +1,6 @@
package net.minecraft.item;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -10,6 +11,7 @@
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.World;
@ -8,32 +15,53 @@
public class ItemTool extends Item
{
@@ -91,4 +92,34 @@
@@ -30,6 +32,18 @@
this.efficiencyOnProperMaterial = p_i45333_2_.getEfficiencyOnProperMaterial();
this.damageVsEntity = p_i45333_1_ + p_i45333_2_.getDamageVsEntity();
this.setCreativeTab(CreativeTabs.tabTools);
+ if (this instanceof ItemPickaxe)
+ {
+ toolClass = "pickaxe";
+ }
+ else if (this instanceof ItemAxe)
+ {
+ toolClass = "axe";
+ }
+ else if (this instanceof ItemSpade)
+ {
+ toolClass = "shovel";
+ }
}
public float func_150893_a(ItemStack p_150893_1_, Block p_150893_2_)
@@ -91,4 +105,36 @@
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double)this.damageVsEntity, 0));
return multimap;
}
+
+ /*===================================== FORGE START =================================*/
+ private String toolClass;
+ @Override
+ public int getHarvestLevel(ItemStack stack, String toolClass)
+ {
+ if ("pickaxe".equals(toolClass) && this instanceof ItemPickaxe)
+ if (toolClass != null && toolClass.equals(this.toolClass))
+ {
+ return this.toolMaterial.getHarvestLevel();
+ }
+ else if ("axe".equals(toolClass) && this instanceof ItemAxe)
+ else
+ {
+ return this.toolMaterial.getHarvestLevel();
+ return super.getHarvestLevel(stack, toolClass);
+ }
+ else if ("shovel".equals(toolClass) && this instanceof ItemSpade)
+ {
+ return this.toolMaterial.getHarvestLevel();
+ }
+ return super.getHarvestLevel(stack, toolClass);
+ }
+
+ @Override
+ public float getDigSpeed(ItemStack stack, Block block, int meta)
+ public Set<String> getToolClasses(ItemStack stack)
+ {
+ return toolClass != null ? ImmutableSet.of(toolClass) : super.getToolClasses(stack);
+ }
+
+ @Override
+ public float getDigSpeed(ItemStack stack, Block block, int meta)
+ {
+ if (ForgeHooks.isToolEffective(stack, block, meta))
+ {

View File

@ -152,20 +152,17 @@ public class ForgeHooks
toolInit = true;
Set<Block> blocks = ReflectionHelper.getPrivateValue(ItemPickaxe.class, null, 0);
setHarvestForItem(Arrays.asList(Items.wooden_pickaxe, Items.stone_pickaxe, Items.iron_pickaxe, Items.diamond_pickaxe), "pickaxe");
for (Block block : blocks)
{
block.setHarvestLevel("pickaxe", 0);
}
setHarvestForItem(Arrays.asList(Items.wooden_shovel, Items.stone_shovel, Items.iron_shovel, Items.diamond_shovel), "shovel");
blocks = ReflectionHelper.getPrivateValue(ItemSpade.class, null, 0);
for (Block block : blocks)
{
block.setHarvestLevel("shovel", 0);
}
setHarvestForItem(Arrays.asList(Items.wooden_axe, Items.stone_axe, Items.iron_axe, Items.diamond_axe), "axe");
blocks = ReflectionHelper.getPrivateValue(ItemAxe.class, null, 0);
for (Block block : blocks)
{
@ -183,15 +180,6 @@ public class ForgeHooks
Blocks.lapis_block.setHarvestLevel("pickaxe", 1);
}
private static void setHarvestForItem(List<Item> itemList, String toolClass)
{
for (int i = 0; i < itemList.size(); i++)
{
Item item = itemList.get(i);
item.setHarvestLevel("pickaxe", i);
}
}
public static int getTotalArmorValue(EntityPlayer player)
{
int ret = 0;