From 7c4e810c8d35eedfa010f0291f7d5f52794670cb Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 13 Aug 2016 18:52:03 +0200 Subject: [PATCH] Implemented a fix for #35 by implementing getUpdateTag / handleUpdateTag using the existing update package logic. --- src/main/java/appeng/tile/AEBaseTile.java | 76 +++++++++++++++++------ 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/src/main/java/appeng/tile/AEBaseTile.java b/src/main/java/appeng/tile/AEBaseTile.java index a532c8c1..608162c4 100644 --- a/src/main/java/appeng/tile/AEBaseTile.java +++ b/src/main/java/appeng/tile/AEBaseTile.java @@ -204,6 +204,41 @@ public class AEBaseTile extends TileEntity implements ITickable, IOrientable, IC @Override public SPacketUpdateTileEntity getUpdatePacket() + { + return new SPacketUpdateTileEntity( this.pos, 64, getUpdateTag() ); + } + + private boolean hasHandlerFor( final TileEventType type ) + { + final List list = this.getHandlerListFor( type ); + + return !list.isEmpty(); + } + + @Override + public void onDataPacket( final NetworkManager net, final SPacketUpdateTileEntity pkt ) + { + // / pkt.actionType + if( pkt.getTileEntityType() == 64 ) + { + handleUpdateTag( pkt.getNbtCompound() ); + } + } + + @Override + public void onChunkUnload() + { + if( !this.isInvalid() ) + { + this.invalidate(); + } + } + + /** + * This builds a tag with the actual data that should be sent to the client for update syncs. + * If the tile entity doesn't need update syncs, it returns null. + */ + private NBTTagCompound writeUpdateData() { final NBTTagCompound data = new NBTTagCompound(); @@ -224,36 +259,37 @@ public class AEBaseTile extends TileEntity implements ITickable, IOrientable, IC stream.capacity( stream.readableBytes() ); data.setByteArray( "X", stream.array() ); - return new SPacketUpdateTileEntity( this.pos, 64, data ); - } - - private boolean hasHandlerFor( final TileEventType type ) - { - final List list = this.getHandlerListFor( type ); - - return !list.isEmpty(); + return data; } + /** + * Handles tile entites that are being sent to the client as part of a full chunk. + */ @Override - public void onDataPacket( final NetworkManager net, final SPacketUpdateTileEntity pkt ) + public NBTTagCompound getUpdateTag() { - // / pkt.actionType - if( pkt.getTileEntityType() == 64 ) - { - final ByteBuf stream = Unpooled.copiedBuffer( pkt.getNbtCompound().getByteArray( "X" ) ); - if( this.readFromStream( stream ) ) - { - this.markForUpdate(); - } + final NBTTagCompound data = writeUpdateData(); + + if (data == null) { + return new NBTTagCompound(); } + + data.setInteger( "x", pos.getX() ); + data.setInteger( "y", pos.getY() ); + data.setInteger( "z", pos.getZ() ); + return data; } + /** + * Handles tile entites that are being received by the client as part of a full chunk. + */ @Override - public void onChunkUnload() + public void handleUpdateTag( NBTTagCompound tag ) { - if( !this.isInvalid() ) + final ByteBuf stream = Unpooled.copiedBuffer( tag.getByteArray( "X" ) ); + if( this.readFromStream( stream ) ) { - this.invalidate(); + this.markForUpdate(); } }