    001    package cpw.mods.fml.common.network;
    002
    003    import net.minecraft.src.EntityPlayer;
    004    import net.minecraft.src.NetHandler;
    005    import net.minecraft.src.NetworkManager;
    006
    007    import com.google.common.io.ByteArrayDataInput;
    008    import com.google.common.io.ByteArrayDataOutput;
    009    import com.google.common.io.ByteStreams;
    010
    011    public class OpenGuiPacket extends FMLPacket
    012    {
    013        private int windowId;
    014        private int networkId;
    015        private int modGuiId;
    016        private int x;
    017        private int y;
    018        private int z;
    019
    020        public OpenGuiPacket()
    021        {
    022            super(Type.GUIOPEN);
    023        }
    024
    025        @Override
    026        public byte[] generatePacket(Object... data)
    027        {
    028            ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    029            dat.writeInt((Integer) data[0]); // windowId
    030            dat.writeInt((Integer) data[1]); // networkId
    031            dat.writeInt((Integer) data[2]); // modGuiId
    032            dat.writeInt((Integer) data[3]); // x
    033            dat.writeInt((Integer) data[4]); // y
    034            dat.writeInt((Integer) data[5]); // z
    035            return dat.toByteArray();
    036        }
    037
    038        @Override
    039        public FMLPacket consumePacket(byte[] data)
    040        {
    041            ByteArrayDataInput dat = ByteStreams.newDataInput(data);
    042            windowId = dat.readInt();
    043            networkId = dat.readInt();
    044            modGuiId = dat.readInt();
    045            x = dat.readInt();
    046            y = dat.readInt();
    047            z = dat.readInt();
    048            return this;
    049        }
    050
    051        @Override
    052        public void execute(NetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName)
    053        {
    054            EntityPlayer player = netHandler.getPlayer();
    055            player.openGui(networkId, modGuiId, player.worldObj, x, y, z);
    056            player.craftingInventory.windowId = windowId;
    057        }
    058
    059    }