Skip to content

Commit

Permalink
Fixed NPE when breaking blocks with undefined HarvestTool
Browse files Browse the repository at this point in the history
  • Loading branch information
fuj1n committed Feb 15, 2014
1 parent 87e687d commit e24b53a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/tconstruct/items/tools/Hammer.java
Expand Up @@ -291,7 +291,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
Block localBlock = world.getBlock(xPos, yPos, zPos);
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = -1;
if (block.getHarvestTool(meta).equals(this.getHarvestType()))
if (block.getHarvestTool(meta) != null && block.getHarvestTool(meta).equals(this.getHarvestType()))
hlvl = block.getHarvestLevel(meta);
float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos);

Expand Down Expand Up @@ -322,10 +322,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (blockHardness > 0f)
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
world.func_147479_m(x, y, z);
}
else
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
world.func_147479_m(x, y, z);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -39,7 +39,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
Block localBlock = world.getBlock(x, y, z);
int localMeta = world.getBlockMetadata(x, y, z);
if (block.getHarvestTool(meta).equals(this.getHarvestType()))
if (block.getHarvestTool(meta) != null && block.getHarvestTool(meta).equals(this.getHarvestType()))
hlvl = block.getHarvestLevel(meta);
int toolLevel = tags.getInteger("HarvestLevel");
float blockHardness = block.getBlockHardness(world, x, y, z);
Expand Down Expand Up @@ -72,10 +72,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
localBlock.onBlockHarvested(world, x, y, z, localMeta, player);
if (blockHardness > 0f)
onBlockDestroyed(stack, world, localBlock, x, y, z, player);
world.func_147479_m(x, y, z);
}
else
{
WorldHelper.setBlockToAir(world, x, y, z);
world.func_147479_m(x, y, z);
}
}
}
Expand Down

0 comments on commit e24b53a

Please sign in to comment.