Skip to content

Commit

Permalink
Break blocks on clientside. Eliminates server latency.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Aug 23, 2014
1 parent 72e6bce commit 699b0f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
29 changes: 15 additions & 14 deletions src/main/java/tconstruct/items/tools/Scythe.java
Expand Up @@ -4,8 +4,11 @@
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;
Expand All @@ -14,6 +17,8 @@
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;
Expand Down Expand Up @@ -220,25 +225,21 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
}
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
int exp = localBlock.getExpDrop(world, localMeta, fortune);
if (!butter)
localBlock.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

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);
}

if (localHardness > 0f)
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
@@ -1,15 +1,21 @@
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;
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;
Expand Down Expand Up @@ -299,26 +305,20 @@ 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)
{
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);

}
}
}

0 comments on commit 699b0f5

Please sign in to comment.