From 9239ed33b195a59561e9a74bd7063640a97ab514 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sat, 15 May 2021 16:27:06 +0800 Subject: Allow client to proactively request fluid display updates Currently client will only request update on blocks being looked at. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../common/net/MessageUpdateFluidDisplayItem.java | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java (limited to 'src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java') diff --git a/src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java b/src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java new file mode 100644 index 0000000000..46af08134d --- /dev/null +++ b/src/main/java/gregtech/common/net/MessageUpdateFluidDisplayItem.java @@ -0,0 +1,64 @@ +package gregtech.common.net; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import gregtech.api.interfaces.IHasFluidDisplayItem; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.net.GT_Packet; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; + +public class MessageUpdateFluidDisplayItem extends GT_Packet { + private int mBlockX, mBlockY, mBlockZ, mDim; + + public MessageUpdateFluidDisplayItem() { + super(true); + } + + public MessageUpdateFluidDisplayItem(int mBlockX, int mBlockY, int mBlockZ, int mDim) { + super(false); + this.mBlockX = mBlockX; + this.mBlockY = mBlockY; + this.mBlockZ = mBlockZ; + this.mDim = mDim; + } + + @Override + public byte getPacketID() { + return 8; + } + + @Override + public byte[] encode() { + ByteArrayDataOutput os = ByteStreams.newDataOutput(32); + os.writeInt(mBlockX); + os.writeInt(mBlockY); + os.writeInt(mBlockZ); + os.writeInt(mDim); + return os.toByteArray(); + } + + @Override + public GT_Packet decode(ByteArrayDataInput aData) { + return new MessageUpdateFluidDisplayItem(aData.readInt(), aData.readInt(), aData.readInt(), aData.readInt()); + } + + @Override + public void process(IBlockAccess aWorld) { + WorldServer world = DimensionManager.getWorld(mDim); + if (world != null) { + if (world.blockExists(mBlockX, mBlockY, mBlockZ)) { + TileEntity tileEntity = world.getTileEntity(mBlockX, mBlockY, mBlockZ); + if (tileEntity instanceof IGregTechTileEntity) { + IGregTechTileEntity gtTile = (IGregTechTileEntity) tileEntity; + if (gtTile.getMetaTileEntity() instanceof IHasFluidDisplayItem) { + ((IHasFluidDisplayItem) gtTile.getMetaTileEntity()).updateFluidDisplayItem(); + } + } + } + } + } +} -- cgit