diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-12-02 16:53:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-02 16:53:40 +0100 |
commit | c0a6800447fdb87e266acfb47f35b5f765c74fe3 (patch) | |
tree | 2066554d22848e6818689d41cd4ca7f683ebebb7 /src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java | |
parent | 03b6fb248b1a20b9ccce7ac4da4c1a76875fa966 (diff) | |
download | GT5-Unofficial-c0a6800447fdb87e266acfb47f35b5f765c74fe3.tar.gz GT5-Unofficial-c0a6800447fdb87e266acfb47f35b5f765c74fe3.tar.bz2 GT5-Unofficial-c0a6800447fdb87e266acfb47f35b5f765c74fe3.zip |
add select circuit gui for machine and circuits itself (#773)
also fixed some issue with basic machine gui introduced in 9d42b299def1c41bbc7a1f01efe445be28f54399
also retrofitted volumetric flask to use the new INetworkUpdatableItem and GT_Packet_UpdateItem, deprecating MessageSetFlaskCapacity in the meanwhile.
To open the gui for machine, shift-left-click the circuit slot
To open the gui for circuit, click any block (need to be sneaking if it's chest, furnace, etc) with the circuit held in hand.
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java')
-rw-r--r-- | src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java b/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java new file mode 100644 index 0000000000..537f62ccec --- /dev/null +++ b/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java @@ -0,0 +1,61 @@ +package gregtech.api.net; + +import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.common.network.ByteBufUtils; +import gregtech.api.interfaces.INetworkUpdatableItem; +import gregtech.api.util.ISerializableObject; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetHandler; +import net.minecraft.network.NetHandlerPlayServer; +import net.minecraft.world.IBlockAccess; + +/** + * Client -> Server: send arbitrary data to server and update the currently held item. + */ +public class GT_Packet_UpdateItem extends GT_Packet_New { + private NBTTagCompound tag; + private EntityPlayerMP mPlayer; + + public GT_Packet_UpdateItem() { + super(true); + } + + public GT_Packet_UpdateItem(NBTTagCompound tag) { + super(false); + this.tag = tag; + } + + @Override + public byte getPacketID() { + return 13; + } + + @Override + public void setINetHandler(INetHandler aHandler) { + if (aHandler instanceof NetHandlerPlayServer) { + mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity; + } + } + + @Override + public void encode(ByteBuf aOut) { + ByteBufUtils.writeTag(aOut, tag); + } + + @Override + public GT_Packet_New decode(ByteArrayDataInput aData) { + return new GT_Packet_UpdateItem(ISerializableObject.readCompoundTagFromGreggyByteBuf(aData)); + } + + @Override + public void process(IBlockAccess aWorld) { + if (mPlayer == null) return; + ItemStack stack = mPlayer.inventory.getCurrentItem(); + if (stack != null && stack.getItem() instanceof INetworkUpdatableItem) { + ((INetworkUpdatableItem) stack.getItem()).receive(stack, mPlayer, tag); + } + } +} |