diff options
author | Blood Asp <Blood@Asp> | 2015-04-23 18:14:22 +0200 |
---|---|---|
committer | Blood Asp <Blood@Asp> | 2015-04-23 18:14:22 +0200 |
commit | 7224ac4299098c70efae9dbd04c50a97e3f5f583 (patch) | |
tree | c739bb7d176a9735bc8e598063918023de32330c /main/java/gregtech/api/net/GT_Packet_Block_Event.java | |
download | GT5-Unofficial-7224ac4299098c70efae9dbd04c50a97e3f5f583.tar.gz GT5-Unofficial-7224ac4299098c70efae9dbd04c50a97e3f5f583.tar.bz2 GT5-Unofficial-7224ac4299098c70efae9dbd04c50a97e3f5f583.zip |
Initial Commit
Diffstat (limited to 'main/java/gregtech/api/net/GT_Packet_Block_Event.java')
-rw-r--r-- | main/java/gregtech/api/net/GT_Packet_Block_Event.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/main/java/gregtech/api/net/GT_Packet_Block_Event.java b/main/java/gregtech/api/net/GT_Packet_Block_Event.java new file mode 100644 index 0000000000..95932d581c --- /dev/null +++ b/main/java/gregtech/api/net/GT_Packet_Block_Event.java @@ -0,0 +1,59 @@ +package gregtech.api.net; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + +/** + * Used to transfer Block Events in a much better fashion + */ +public class GT_Packet_Block_Event extends GT_Packet { + private int mX, mZ; + private short mY; + private byte mID, mValue; + + public GT_Packet_Block_Event() { + super(true); + } + + public GT_Packet_Block_Event(int aX, short aY, int aZ, byte aID, byte aValue) { + super(false); + mX = aX; + mY = aY; + mZ = aZ; + mID = aID; + mValue = aValue; + } + + @Override + public byte[] encode() { + ByteArrayDataOutput tOut = ByteStreams.newDataOutput(10); + tOut.writeInt(mX); + tOut.writeShort(mY); + tOut.writeInt(mZ); + tOut.writeByte(mID); + tOut.writeByte(mValue); + return tOut.toByteArray(); + } + + @Override + public GT_Packet decode(ByteArrayDataInput aData) { + return new GT_Packet_Block_Event(aData.readInt(), aData.readShort(), aData.readInt(), aData.readByte(), aData.readByte()); + } + + @Override + public void process(IBlockAccess aWorld) { + if (aWorld != null) { + TileEntity tTileEntity = aWorld.getTileEntity(mX, mY, mZ); + if (tTileEntity != null) tTileEntity.receiveClientEvent(mID, mValue); + } + } + + @Override + public byte getPacketID() { + return 2; + } +}
\ No newline at end of file |