Skip to content

Commit

Permalink
Throw custom block breaking code overboard since the forge code can h…
Browse files Browse the repository at this point in the history
…andle it quite well nowadays. No change to AOE-Tools yet.
  • Loading branch information
bonii-xx committed Sep 16, 2014
1 parent 99cb5e8 commit 218f282
Showing 1 changed file with 19 additions and 64 deletions.
83 changes: 19 additions & 64 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -31,63 +31,31 @@ public HarvestTool(int baseDamage)
@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
// this is called both clientside directly when the block is destroyed, as well as serverside when the C07PacketPlayerDigging with data 2 is received
TConstruct.logger.info("PANIC: " + player.worldObj.isRemote);

if (!stack.hasTagCompound())
return false;

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = player.worldObj;
Block block = player.worldObj.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);

// broken tools don't harvest anything
if(tags.getBoolean("Broken"))
return true;
// only harvest actual blocks
if (block == null || block == Blocks.air)
return false;

// check harvestlevel
int hlvl = -1;
if (block.getHarvestTool(meta) != null && block.getHarvestTool(meta).equals(this.getHarvestType()))
hlvl = block.getHarvestLevel(meta);
int toolLevel = tags.getInteger("HarvestLevel");

// harvestlevel too low. abort
if(hlvl > toolLevel)
return true;

// the regular stuff, ActiveToolMods etc
if(super.onBlockStartBreak(stack, x,y,z, player))
return true;

// not effective?
boolean isEffective = false;
return super.onBlockStartBreak(stack, x,y,z, player);
}

for (int iter = 0; iter < getEffectiveMaterials().length; iter++)
{
if (getEffectiveMaterials()[iter] == block.getMaterial() || block == Blocks.monster_egg)
{
isEffective = true;
break;
}
}
@Override
public int getHarvestLevel(ItemStack stack, String toolClass) {
// well, we can only get the harvestlevel if we have an item to get it from!
if(stack == null || !(stack.getItem() instanceof HarvestTool))
return -1;
// invalid query or wrong toolclass
if(toolClass == null || !this.getHarvestType().equals(toolClass))
return -1;

// Microblocks are registered as rock but no HarvestTool is set
if (block.getMaterial().isToolNotRequired() || block.getHarvestTool(meta) == null)
{
isEffective = true;
}
if(!stack.hasTagCompound())
return -1;

// non-effective?
if(!isEffective)
return true;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
// broken tools suck.
if (tags.getBoolean("Broken"))
return -1;

return false;
// tadaaaa
return tags.getInteger("HarvestLevel");
}


@Override
public float getDigSpeed (ItemStack stack, Block block, int meta)
{
Expand Down Expand Up @@ -251,19 +219,6 @@ public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int
return used;
}

@Override
public int getHarvestLevel (ItemStack stack, String toolClass)
{
if (!(stack.getItem() instanceof HarvestTool) || !getHarvestType().equals(toolClass))
{
return -1;
}

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int harvestLvl = tags.getInteger("HarvestLevel");
return harvestLvl;
}

// The Scythe is not a HarvestTool and can't call this method, if you change something here you might change it there too.
public void mineBlock (World world, int x, int y, int z, int meta, EntityPlayer player, Block block)
{
Expand Down

0 comments on commit 218f282

Please sign in to comment.