From 699b0f5796050528b76f76c6056acb8ffd190fa6 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Sat, 23 Aug 2014 22:04:07 +0200 Subject: [PATCH] Break blocks on clientside. Eliminates server latency. --- .../java/tconstruct/items/tools/Scythe.java | 31 +++++++++-------- .../tconstruct/library/tools/HarvestTool.java | 34 +++++++++---------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/java/tconstruct/items/tools/Scythe.java b/src/main/java/tconstruct/items/tools/Scythe.java index 3756b29b..435fd11c 100644 --- a/src/main/java/tconstruct/items/tools/Scythe.java +++ b/src/main/java/tconstruct/items/tools/Scythe.java @@ -4,8 +4,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import cpw.mods.fml.client.FMLClientHandler; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; @@ -14,6 +17,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetHandler; +import net.minecraft.network.play.client.C07PacketPlayerDigging; import net.minecraft.stats.StatList; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; @@ -220,24 +225,20 @@ public class Scythe extends Weapon } else { - 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 + // 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); + + } } if (localHardness > 0f) diff --git a/src/main/java/tconstruct/library/tools/HarvestTool.java b/src/main/java/tconstruct/library/tools/HarvestTool.java index e1aaef37..3be07d8f 100644 --- a/src/main/java/tconstruct/library/tools/HarvestTool.java +++ b/src/main/java/tconstruct/library/tools/HarvestTool.java @@ -1,8 +1,12 @@ package tconstruct.library.tools; +import cpw.mods.fml.client.FMLClientHandler; import mantle.world.WorldHelper; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.PlayerControllerMP; +import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -10,6 +14,8 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetHandler; +import net.minecraft.network.play.client.C07PacketPlayerDigging; import net.minecraft.world.World; import tconstruct.library.ActiveToolMod; import tconstruct.library.TConstructRegistry; @@ -299,26 +305,20 @@ public abstract class HarvestTool extends ToolCore // 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) { - if (!world.isRemote) - { - // Workaround for dropping experience - boolean silktouch = EnchantmentHelper.getSilkTouchModifier(player); - int fortune = EnchantmentHelper.getFortuneModifier(player); - int exp = block.getExpDrop(world, meta, fortune); + // Workaround for dropping experience + boolean silktouch = EnchantmentHelper.getSilkTouchModifier(player); + int fortune = EnchantmentHelper.getFortuneModifier(player); + int exp = block.getExpDrop(world, meta, fortune); - block.onBlockHarvested(world, x, y, z, meta, player); - if (block.removedByPlayer(world, player, x, y, z, true)) - { - block.onBlockDestroyedByPlayer(world, x, y, z, meta); - block.harvestBlock(world, player, x, y, z, meta); - // Workaround for dropping experience - if (!silktouch) - block.dropXpOnBlockBreak(world, x, y, z, exp); - } - } - else + block.onBlockHarvested(world, x, y, z, meta, player); + if (block.removedByPlayer(world, player, x, y, z, true)) { block.onBlockDestroyedByPlayer(world, x, y, z, meta); + block.harvestBlock(world, player, x, y, z, meta); + // Workaround for dropping experience + if (!silktouch) + block.dropXpOnBlockBreak(world, x, y, z, exp); + } } }