Skip to content

Commit

Permalink
Make AOE tools creative-mode compatible again
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 17, 2014
1 parent 619bfdb commit 29f72ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/main/java/tconstruct/library/tools/AOEHarvestTool.java
Expand Up @@ -48,7 +48,7 @@ public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPla
}

// the code below initiates block breaks, which again call this function. But we don't want to do the aoe-break-stuff again. This is to prevent recursive, infinite-range aoe blockbreaking.
if(originalBlock) {
if(originalBlock || player.capabilities.isCreativeMode) {
antiRecurse = true;
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(player.worldObj, player, false, 4.5d);
if(mop == null)
Expand Down Expand Up @@ -89,6 +89,9 @@ public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPla

antiRecurse = false;
}



return super.onBlockStartBreak(stack, x, y, z, player);
}

Expand Down
47 changes: 29 additions & 18 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -215,39 +215,50 @@ public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int
return used;
}

protected void breakExtraBlock(World world, int x, int y, int z, int sidehit, EntityPlayer player)
{
protected void breakExtraBlock(World world, int x, int y, int z, int sidehit, EntityPlayer player) {
// prevent calling that stuff for air blocks, could lead to unexpected behaviour since it fires events
if(world.isAirBlock(x,y,z))
if (world.isAirBlock(x, y, z))
return;

// check if the block can be broken, since extra block breaks shouldn't instantly break stuff like obsidian
// or precious ores you can't harvest while mining stone
Block block = world.getBlock(x,y,z);
int meta = world.getBlockMetadata(x,y,z);
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);

// only effective materials
if(!isEffective(block.getMaterial()))
if (!isEffective(block.getMaterial()))
return;

// only harvestable blocks that aren't impossibly slow to harvest
if(!ForgeHooks.canHarvestBlock(block, player, meta) || ForgeHooks.blockStrength(block, player, world, x,y,z) <= 0.0001f)
if (!ForgeHooks.canHarvestBlock(block, player, meta) || ForgeHooks.blockStrength(block, player, world, x, y, z) <= 0.0001f)
return;

// this should only be called on the client
if(!world.isRemote) {
if (player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, x, y, z, meta, player);
if (block.removedByPlayer(world, player, x, y, z, false))
block.onBlockDestroyedByPlayer(world, x, y, z, meta);

// send update to client
if (!world.isRemote) {
((EntityPlayerMP)player).playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
}
return;
}
// server sided handling
if (!world.isRemote) {
// serverside we
EntityPlayerMP mpPlayer = (EntityPlayerMP) player;
mpPlayer.theItemInWorldManager.tryHarvestBlock(x,y,z);

mpPlayer.theItemInWorldManager.tryHarvestBlock(x, y, z);
// send block update to client
mpPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
return;
}

// and this is the reason why ;o
PlayerControllerMP pcmp = Minecraft.getMinecraft().playerController;
// clientside we do a "this clock has been clicked on long enough to be broken" call. This should not send any new packets
// the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy.
pcmp.onPlayerDestroyBlock(x, y, z, sidehit);
// client sided handling
else {
PlayerControllerMP pcmp = Minecraft.getMinecraft().playerController;
// clientside we do a "this clock has been clicked on long enough to be broken" call. This should not send any new packets
// the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy.
pcmp.onPlayerDestroyBlock(x, y, z, sidehit);
}
}
}
}

0 comments on commit 29f72ed

Please sign in to comment.