From 607854f5378feef1e1135ac72360525d5981114f Mon Sep 17 00:00:00 2001 From: Chicken-Bones Date: Tue, 12 Nov 2013 12:11:17 +1000 Subject: [PATCH] Added notice javadoc to MultipartHelper.sendDescPacket on usage Expanded PacketScheduler interface to handle all numeric data types --- codechicken/multipart/MultipartHelper.scala | 3 +++ codechicken/multipart/PacketScheduler.scala | 23 +++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/codechicken/multipart/MultipartHelper.scala b/codechicken/multipart/MultipartHelper.scala index bf311d8..9a87e9c 100644 --- a/codechicken/multipart/MultipartHelper.scala +++ b/codechicken/multipart/MultipartHelper.scala @@ -45,6 +45,9 @@ object MultipartHelper return TileMultipart.createFromNBT(tag); } + /** + * Note. This method should only be used to send tiles that have been created on the server mid-game via an NBT load to clients. + */ def sendDescPacket(world:World, tile:TileEntity) { val c = world.getChunkFromBlockCoords(tile.xCoord, tile.zCoord) val pkt = MultipartSPH.getDescPacket(c, Arrays.asList(tile).iterator) diff --git a/codechicken/multipart/PacketScheduler.scala b/codechicken/multipart/PacketScheduler.scala index a890377..4b4000a 100644 --- a/codechicken/multipart/PacketScheduler.scala +++ b/codechicken/multipart/PacketScheduler.scala @@ -24,10 +24,12 @@ object PacketScheduler if(part.tile != null) { val ipart = part.asInstanceOf[IScheduledPacketPart] val w = part.getWriteStream - if(ipart.needsLong) - w.writeLong(mask) - else - w.writeInt(mask.toInt) + ipart.maskWidth match { + case 1 => w.writeByte(mask.toInt) + case 2 => w.writeShort(mask.toInt) + case 4 => w.writeInt(mask.toInt) + case 8 => w.writeLong(mask) + } ipart.writeScheduled(mask, w) } @@ -47,9 +49,9 @@ trait IScheduledPacketPart def writeScheduled(mask:Long, packet:MCDataOutput) /** - * If this returns true, the mask will be sent as a long rather than an int. Use if you have more than 32 flags + * Returns the width (in bytes) of the data type required to hold all valid mask bits. Valid values are 1, 2, 4 and 8 */ - def needsLong():Boolean + def maskWidth():Int /** * Read data matching mask. Estiablishes a method for subclasses to override. This should be called from read @@ -59,10 +61,13 @@ trait IScheduledPacketPart trait TScheduledPacketPart extends TMultiPart with IScheduledPacketPart { - def needsLong() = false - final override def read(packet:MCDataInput) { - val mask = if(needsLong) packet.readLong else packet.readInt + val mask = maskWidth match { + case 1 => packet.readUByte + case 2 => packet.readUShort + case 4 => packet.readInt + case 8 => packet.readLong + } readScheduled(mask, packet) }