    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common.network;
    014
    015import net.minecraft.entity.player.EntityPlayer;
    016import net.minecraft.network.INetworkManager;
    017import net.minecraft.network.packet.NetHandler;
    018
    019import com.google.common.io.ByteArrayDataInput;
    020import com.google.common.io.ByteArrayDataOutput;
    021import com.google.common.io.ByteStreams;
    022
    023public class OpenGuiPacket extends FMLPacket
    024{
    025    private int windowId;
    026    private int networkId;
    027    private int modGuiId;
    028    private int x;
    029    private int y;
    030    private int z;
    031
    032    public OpenGuiPacket()
    033    {
    034        super(Type.GUIOPEN);
    035    }
    036
    037    @Override
    038    public byte[] generatePacket(Object... data)
    039    {
    040        ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    041        dat.writeInt((Integer) data[0]); // windowId
    042        dat.writeInt((Integer) data[1]); // networkId
    043        dat.writeInt((Integer) data[2]); // modGuiId
    044        dat.writeInt((Integer) data[3]); // x
    045        dat.writeInt((Integer) data[4]); // y
    046        dat.writeInt((Integer) data[5]); // z
    047        return dat.toByteArray();
    048    }
    049
    050    @Override
    051    public FMLPacket consumePacket(byte[] data)
    052    {
    053        ByteArrayDataInput dat = ByteStreams.newDataInput(data);
    054        windowId = dat.readInt();
    055        networkId = dat.readInt();
    056        modGuiId = dat.readInt();
    057        x = dat.readInt();
    058        y = dat.readInt();
    059        z = dat.readInt();
    060        return this;
    061    }
    062
    063    @Override
    064    public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName)
    065    {
    066        EntityPlayer player = netHandler.getPlayer();
    067        player.openGui(networkId, modGuiId, player.worldObj, x, y, z);
    068        player.openContainer.windowId = windowId;
    069    }
    070
    071}