From 47296d3526228fa078c3832b297d344b3a5e06cc Mon Sep 17 00:00:00 2001 From: Chicken Bones Date: Thu, 26 Sep 2013 11:49:18 +1000 Subject: [PATCH] Added client tile cache to fix packet sync issue when removing parts that received an update in the same tick. --- codechicken/multipart/TileMultipart.scala | 26 +++++++++++++------ .../multipart/handler/PacketHandlers.scala | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index 56b7f7d..bb7961e 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -43,6 +43,7 @@ import codechicken.lib.raytracer.ExtendedMOP import net.minecraft.util.Vec3 import java.lang.Iterable import codechicken.multipart.handler.MultipartSaveLoad +import scala.collection.mutable.{Map => MMap} class TileMultipart extends TileEntity { @@ -140,8 +141,11 @@ class TileMultipart extends TileEntity if(!isInvalid) { super.invalidate() - if(worldObj != null) + if(worldObj != null) { partList.foreach(_.onWorldSeparate()) + if(worldObj.isRemote) + TileMultipart.putClientCache(this) + } } } @@ -684,6 +688,16 @@ object TileMultipart private[multipart] def queueAddition(world:World, pos:BlockCoord, part:TMultiPart):Boolean = operationSync.queueAddition(world, pos, part) + /** + * Playerinstance will often remove the tile entity instance and set the block to air on the client before the multipart packet handler fires it's updates. + * In order to maintain the packet data, and make sure all written data is read, the tile needs to be kept around internally until + */ + private val clientFlushMap = MMap[BlockCoord, TileMultipart]() + + private[multipart] def flushClientCache() = clientFlushMap.clear() + + private[multipart] def putClientCache(t:TileMultipart) = clientFlushMap.put(new BlockCoord(t), t) + /** * Gets a multipar ttile instance at pos, converting if necessary. */ @@ -804,7 +818,7 @@ object TileMultipart */ def handlePacket(pos:BlockCoord, world:World, i:Int, packet:PacketCustom) { - var tilemp = BlockMultipart.getTile(world, pos.x, pos.y, pos.z) + lazy val tilemp = Option(BlockMultipart.getTile(world, pos.x, pos.y, pos.z)).getOrElse(clientFlushMap(pos)) i match { @@ -813,12 +827,8 @@ object TileMultipart part.readDesc(packet) MultipartGenerator.addPart(world, pos, part) } - case 254 => if(tilemp != null) { - tilemp.remPart_impl(tilemp.partList(packet.readUByte)) - } - case _ => if(tilemp != null) { - tilemp.partList(i).read(packet) - } + case 254 => tilemp.remPart_impl(tilemp.partList(packet.readUByte)) + case _ => tilemp.partList(i).read(packet) } } diff --git a/codechicken/multipart/handler/PacketHandlers.scala b/codechicken/multipart/handler/PacketHandlers.scala index fa93558..35f94c8 100644 --- a/codechicken/multipart/handler/PacketHandlers.scala +++ b/codechicken/multipart/handler/PacketHandlers.scala @@ -76,6 +76,7 @@ object MultipartCPH extends MultipartPH with IClientPacketHandler } x = packet.readInt } + TileMultipart.flushClientCache() } }