Skip to content

Commit

Permalink
Fix break-speed not taking harvest-tool for blocks into account (-> d…
Browse files Browse the repository at this point in the history
…oesn't work with custom materials) and AOE tools not taking it into account either.
  • Loading branch information
bonii-xx committed Sep 19, 2014
1 parent 52b365d commit 61e2f1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/main/java/tconstruct/library/tools/AOEHarvestTool.java
Expand Up @@ -30,7 +30,8 @@ public AOEHarvestTool(int baseDamage, int breakRadius, int breakDepth) {
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;
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -62,20 +62,9 @@ public float getDigSpeed (ItemStack stack, Block block, int meta)
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);
}

Expand Down Expand Up @@ -125,6 +114,14 @@ public String[] getTraits ()

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())
Expand Down Expand Up @@ -226,7 +223,7 @@ protected void breakExtraBlock(World world, int x, int y, int z, int sidehit, En
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
Expand Down

0 comments on commit 61e2f1a

Please sign in to comment.