Skip to content

Commit

Permalink
Adjust block breaking code to use vanilla behaviour. Aoe-Tools curren…
Browse files Browse the repository at this point in the history
…tly don't work
  • Loading branch information
bonii-xx committed Sep 16, 2014
1 parent c3d72ef commit da99630
Showing 1 changed file with 42 additions and 67 deletions.
109 changes: 42 additions & 67 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import tconstruct.TConstruct;
import tconstruct.library.*;

/* Base class for tools that should be harvesting blocks */
Expand All @@ -30,90 +31,61 @@ 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);
// Block block = Block.blocksList[bID];

// 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 (!(tags.getBoolean("Broken")))
{
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);
if (block.getHarvestTool(meta) != null && block.getHarvestTool(meta).equals(this.getHarvestType()))
hlvl = block.getHarvestLevel(meta);
int toolLevel = tags.getInteger("HarvestLevel");

if (hlvl <= toolLevel)
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, x, y, z, player))
cancelHarvest = true;
}
// harvestlevel too low. abort
if(hlvl > toolLevel)
return true;

// send blockbreak event
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
event.setCanceled(cancelHarvest);
MinecraftForge.EVENT_BUS.post(event);
cancelHarvest = event.isCanceled();
// the regular stuff, ActiveToolMods etc
if(super.onBlockStartBreak(stack, x,y,z, player))
return true;

if (!cancelHarvest)
{
if (block != null)
{
// not effective?
boolean isEffective = false;

boolean isEffective = false;

for (int iter = 0; iter < getEffectiveMaterials().length; iter++)
{
if (getEffectiveMaterials()[iter] == block.getMaterial() || block == Blocks.monster_egg)
{
isEffective = true;
break;
}
}

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

if (!player.capabilities.isCreativeMode)
{
if (isEffective)
{
mineBlock(world, x, y, z, meta, player, block);
if (blockHardness > 0f)
onBlockDestroyed(stack, world, block, 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);
}

}
else
{
WorldHelper.setBlockToAir(world, x, y, z);
world.func_147479_m(x, y, z);
}
}
}
for (int iter = 0; iter < getEffectiveMaterials().length; iter++)
{
if (getEffectiveMaterials()[iter] == block.getMaterial() || block == Blocks.monster_egg)
{
isEffective = true;
break;
}
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;

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

// non-effective?
if(!isEffective)
return true;

return false;
}

@Override
Expand Down Expand Up @@ -295,6 +267,7 @@ public int getHarvestLevel (ItemStack stack, String toolClass)
// 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)
{
TConstruct.logger.info("CCCCC: " + world.isRemote);
// Workaround for dropping experience
boolean silktouch = EnchantmentHelper.getSilkTouchModifier(player);
int fortune = EnchantmentHelper.getFortuneModifier(player);
Expand All @@ -309,6 +282,7 @@ public void mineBlock (World world, int x, int y, int z, int meta, EntityPlayer
if (!silktouch)
block.dropXpOnBlockBreak(world, x, y, z, exp);

/*
if (world.isRemote)
{
INetHandler handler = FMLClientHandler.instance().getClientPlayHandler();
Expand All @@ -319,6 +293,7 @@ public void mineBlock (World world, int x, int y, int z, int meta, EntityPlayer
handlerClient.addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
*/
}
}
}

0 comments on commit da99630

Please sign in to comment.