Fix break-speed not taking harvest-tool for blocks into account (-> doesn't work with custom materials) and AOE tools not taking it into account either.

This commit is contained in:
Bernhard Bonigl committed 2014-09-19 22:02:29 +02:00
1 parent 52b365d0cf
commit 61e2f1a0c3
2 files changed
+14 -16

No files matched your search

@@ -30,7 +30,8 @@ public abstract class AOEHarvestTool extends HarvestTool {
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
// only effective materials matter. We don't want to aoe when beraking dirt with a hammer.
Block block = player.worldObj.getBlock(x,y,z);
if(block == null || !isEffective(block.getMaterial()))
int meta = player.worldObj.getBlockMetadata(x,y,z);
if(block == null || !isEffective(block, meta))
return super.onBlockStartBreak(stack, x,y,z, player);
boolean originalBlock = true;
@@ -62,20 +62,9 @@ public abstract class HarvestTool extends ToolCore
if (tags.getBoolean("Broken"))
return 0.1f;
Material[] materials = getEffectiveMaterials();
for (int i = 0; i < materials.length; i++)
{
if (materials[i] == block.getMaterial())
{
return calculateStrength(tags, block, meta);
}
}
if (this.getHarvestType().equals(block.getHarvestTool(meta)) && block.getHarvestLevel(meta) > 0)
{
return calculateStrength(tags, block, meta); // No issue if the
// harvest level is
// too low
}
if(isEffective(block, meta))
return calculateStrength(tags, block, meta);
return super.getDigSpeed(stack, block, meta);
}
@@ -125,6 +114,14 @@ public abstract class HarvestTool extends ToolCore
protected abstract String getHarvestType ();
public boolean isEffective (Block block, int meta)
{
if(this.getHarvestType().equals(block.getHarvestTool(meta)))
return true;
else return isEffective(block.getMaterial());
}
public boolean isEffective (Material material)
{
for (Material m : getEffectiveMaterials())
@@ -226,7 +223,7 @@ public abstract class HarvestTool extends ToolCore
int meta = world.getBlockMetadata(x, y, z);
// only effective materials
if (!isEffective(block.getMaterial()))
if (!isEffective(block, meta))
return;
// only harvestable blocks that aren't impossibly slow to harvest