Fixed a bug with placement packets and the new network handler

Fixed multiple torches in one space bug with normal occlusion
This commit is contained in:
Chicken Bones committed 2013-05-23 16:29:08 +10:00
1 parent 95d6d3c708
commit a95f579e88
11 files changed
+274 -192

No files matched your search

@@ -24,51 +24,63 @@ public class EventHandler
@ForgeSubscribe
public void playerInteract(PlayerInteractEvent event)
{
MovingObjectPosition hit = RayTracer.reTrace(event.entityPlayer.worldObj, event.entityPlayer);
if(event.action == Action.RIGHT_CLICK_BLOCK && place(event.entityPlayer, event.entityPlayer.worldObj, hit))
if(event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote && place(event.entityPlayer, event.entityPlayer.worldObj))
event.setCanceled(true);
}
public boolean place(EntityPlayer player, World world, MovingObjectPosition hit)
public static boolean place(EntityPlayer player, World world)
{
MovingObjectPosition hit = RayTracer.reTrace(world, player);
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ).offset(hit.sideHit);
ItemStack held = player.getHeldItem();
TileMultipart tile = TileMultipartObj.getOrConvertTile(world, pos);
if(tile == null)
return false;
TMultiPart part = null;
McBlockPart part = null;
if(held.itemID == Block.torchWood.blockID)
part = TorchPart.placement(world, pos, hit.sideHit);
if(part == null)
return false;
if(tile.canAddPart(part))
if(world.isRemote && !player.isSneaking())//attempt to use block activated like normal and tell the server the right stuff
{
if(!world.isRemote)
{
TileMultipartObj.addPart(world, pos, part);
if(!player.capabilities.isCreativeMode)
{
held.stackSize--;
if (held.stackSize == 0)
{
player.inventory.mainInventory[player.inventory.currentItem] = null;
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
}
}
}
else
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
Block block = Block.blocksList[world.getBlockId(hit.blockX, hit.blockY, hit.blockZ)];
if(block != null && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z))
{
player.swingItem();
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
PacketCustom.sendToServer(new Packet15Place(
hit.blockX, hit.blockY, hit.blockZ, hit.sideHit,
player.inventory.getCurrentItem(),
(float)f.x, (float)f.y, (float)f.z));
return false;
}
return true;
}
return false;
TileMultipart tile = TileMultipartObj.getOrConvertTile(world, pos);
if(tile == null || !tile.canAddPart(part))
return false;
if(!world.isRemote)
{
TileMultipartObj.addPart(world, pos, part);
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5,
part.getBlock().stepSound.getPlaceSound(),
(part.getBlock().stepSound.getVolume() + 1.0F) / 2.0F,
part.getBlock().stepSound.getPitch() * 0.8F);
if(!player.capabilities.isCreativeMode)
{
held.stackSize--;
if (held.stackSize == 0)
{
player.inventory.mainInventory[player.inventory.currentItem] = null;
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
}
}
}
else
{
player.swingItem();
new PacketCustom(McMultipartSPH.channel, 1).sendToServer();
}
return true;
}
}