Skip to content

Commit

Permalink
unified use of block / localBlock like it is in Hammer.
Browse files Browse the repository at this point in the history
block harvesting is in own method in HarvestTool except the scythe.
fix for some blocks drop nothing or not breaking at all.
fix for dropping exp with silktouch.
  • Loading branch information
jodamm committed Jul 31, 2014
1 parent e3aeca1 commit e9822db
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 89 deletions.
29 changes: 8 additions & 21 deletions src/main/java/tconstruct/items/tools/Battleaxe.java
Expand Up @@ -249,18 +249,16 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
return false;

World world = player.worldObj;
final Block wood = world.getBlock(x, y, z);
final Block block = world.getBlock(x, y, z);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
final int meta = world.getBlockMetadata(x, y, z);
final int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int yPos = y + 1; yPos < y + 9; yPos++)
{
Block block = world.getBlock(x, yPos, z);
if (!(tags.getBoolean("Broken")) && block != null && block.getMaterial() == Material.wood)
Block localBlock = world.getBlock(x, yPos, z);
if (!(tags.getBoolean("Broken")) && localBlock != null && localBlock.getMaterial() == Material.wood)
{
Block localblock = world.getBlock(x, yPos, z);
int localMeta = world.getBlockMetadata(x, yPos, z);
int hlvl = block.getHarvestLevel(meta);
int hlvl = localBlock.getHarvestLevel(localMeta);

if (hlvl <= tags.getInteger("HarvestLevel"))
{
Expand All @@ -273,23 +271,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl

if (!cancelHarvest)
{
if (block != null && block.getMaterial() == Material.wood)
if (localBlock != null && localBlock.getMaterial() == Material.wood)
{
localMeta = world.getBlockMetadata(x, yPos, z);
if (!player.capabilities.isCreativeMode)
{
if (block.removedByPlayer(world, player, x, yPos, z))
{
block.onBlockDestroyedByPlayer(world, x, yPos, z, localMeta);
}

// Workaround for dropping experience
int exp = block.getExpDrop(world, localMeta, fortune);
block.dropXpOnBlockBreak(world, x, y, z, exp);

block.harvestBlock(world, player, x, yPos, z, localMeta);
block.onBlockHarvested(world, x, yPos, z, localMeta, player);
onBlockDestroyed(stack, world, block, x, yPos, z, player);
mineBlock(world, x, yPos, z, localMeta, player, localBlock);
onBlockDestroyed(stack, world, localBlock, x, yPos, z, player);
}
else
{
Expand All @@ -303,7 +290,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
break;
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return super.onBlockStartBreak(stack, x, y, z, player);
}
}
28 changes: 8 additions & 20 deletions src/main/java/tconstruct/items/tools/Excavator.java
Expand Up @@ -185,7 +185,6 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
break;
}
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
Expand All @@ -194,11 +193,10 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
if (!(tags.getBoolean("Broken")))
{
Block localblock = world.getBlock(xPos, yPos, zPos);
block = localblock;
Block localBlock = world.getBlock(xPos, yPos, zPos);
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = block.getHarvestLevel(meta);
float localHardness = block == null ? Float.MAX_VALUE : block.getBlockHardness(world, xPos, yPos, zPos);
int hlvl = localBlock.getHarvestLevel(localMeta);
float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos);

if (hlvl <= tags.getInteger("HarvestLevel") && localHardness - 1.5 <= blockHardness)
{
Expand All @@ -211,27 +209,17 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl

if (!cancelHarvest)
{
if (block != null && !(localHardness < 0))
if (localBlock != null && !(localHardness < 0))
{
for (int iter = 0; iter < materials.length; iter++)
{
if (materials[iter] == block.getMaterial())
if (materials[iter] == localBlock.getMaterial())
{
if (!player.capabilities.isCreativeMode)
{
if (block.removedByPlayer(world, player, xPos, yPos, zPos))
{
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}

// Workaround for dropping experience
int exp = block.getExpDrop(world, localMeta, fortune);
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

block.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
block.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (blockHardness > 0f)
onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player);
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
if (localHardness > 0f)
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
}
else
{
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/tconstruct/items/tools/Hammer.java
Expand Up @@ -284,7 +284,6 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int toolLevel = tags.getInteger("HarvestLevel");
int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
Expand All @@ -300,6 +299,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
hlvl = localBlock.getHarvestLevel(localMeta);
float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos);

//Choose blocks that aren't too much harder than the first block. Stone: 2.0, Ores: 3.0
if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness)
{
boolean cancelHarvest = false;
Expand All @@ -319,17 +319,8 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
if (!player.capabilities.isCreativeMode)
{
if (localBlock.removedByPlayer(world, player, xPos, yPos, zPos))
{
localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);

// Workaround for dropping experience
int exp = localBlock.getExpDrop(world, localMeta, fortune);
localBlock.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
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);
Expand Down
49 changes: 15 additions & 34 deletions src/main/java/tconstruct/items/tools/LumberAxe.java
Expand Up @@ -198,9 +198,6 @@ else if (wood.getMaterial() == Material.wood)

void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayer player)
{
Block block;
final int fortune = EnchantmentHelper.getFortuneModifier(player);

for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y; yPos <= y + 1; yPos++)
Expand All @@ -209,12 +206,11 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun
{
if (!(tags.getBoolean("Broken")))
{
Block localblock = world.getBlock(xPos, yPos, zPos);
if (bID == localblock)
Block localBlock = world.getBlock(xPos, yPos, zPos);
if (bID == localBlock)
{
block = localblock;
meta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = block.getHarvestLevel(meta);
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = localBlock.getHarvestLevel(localMeta);

if (hlvl <= tags.getInteger("HarvestLevel"))
{
Expand All @@ -231,7 +227,7 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun
}
else
{
if (localblock == bID && world.getBlockMetadata(xPos, yPos, zPos) % 4 == meta % 4)
if (localBlock == bID && localMeta % 4 == meta % 4)
{
/*
* world.setBlock(xPos, yPos, zPos, 0,
Expand All @@ -245,24 +241,15 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun
*/
if (!player.capabilities.isCreativeMode)
{
if (block.removedByPlayer(world, player, xPos, yPos, zPos))
{
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
}

// Workaround for dropping experience
int exp = localblock.getExpDrop(world, meta, fortune);
localblock.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

block.harvestBlock(world, player, xPos, yPos, zPos, meta);
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player);
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
}
else
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
}
breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
if (!world.isRemote)
breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
}
/*
* else { Block leaves =
Expand All @@ -288,8 +275,6 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun

void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayer player)
{
final int fortune = EnchantmentHelper.getFortuneModifier(player);

for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y - 1; yPos <= y + 1; yPos++)
Expand All @@ -298,11 +283,11 @@ void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompo
{
if (!(tags.getBoolean("Broken")))
{
Block block = world.getBlock(xPos, yPos, zPos);
int meta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = block.getHarvestLevel(meta);
Block localBlock = world.getBlock(xPos, yPos, zPos);
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = localBlock.getHarvestLevel(localMeta);

if (block != null && block.getMaterial() == Material.wood)
if (localBlock != null && localBlock.getMaterial() == Material.wood)
{
if (hlvl <= tags.getInteger("HarvestLevel"))
{
Expand All @@ -317,12 +302,8 @@ void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompo
{
if (!player.capabilities.isCreativeMode)
{
// TODO harvestBlock
int exp = block.getExpDrop(world, meta, fortune);
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

block.harvestBlock(world, player, xPos, yPos, zPos, meta);
onBlockDestroyed(stack, world, block, xPos, yPos, zPos, player);
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
}
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
world.func_147479_m(xPos, yPos, zPos);
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/tconstruct/items/tools/Scythe.java
Expand Up @@ -169,6 +169,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
return false;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
boolean butter = EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, stack) > 0;
int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y - 1; yPos <= y + 1; yPos++)
Expand Down Expand Up @@ -222,12 +223,26 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
}
else
{
if (localBlock.removedByPlayer(world, player, xPos, yPos, zPos))
if (!world.isRemote)
{
// Workaround for dropping experience
int exp = localBlock.getExpDrop(world, localMeta, fortune);

localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (localBlock.removedByPlayer(world, player, xPos, yPos, zPos, true))
{
localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
// Workaround for dropping experience
if (!butter)
localBlock.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);
}
}
else
{
localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}
localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);

if (localHardness > 0f)
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
}
Expand Down

0 comments on commit e9822db

Please sign in to comment.