    001package net.minecraft.network.packet;
    002
    003import java.io.DataInputStream;
    004import java.io.DataOutputStream;
    005import java.io.IOException;
    006import java.util.List;
    007import net.minecraft.item.ItemStack;
    008
    009public class Packet104WindowItems extends Packet
    010{
    011    /**
    012     * The id of window which items are being sent for. 0 for player inventory.
    013     */
    014    public int windowId;
    015
    016    /** Stack of items */
    017    public ItemStack[] itemStack;
    018
    019    public Packet104WindowItems() {}
    020
    021    public Packet104WindowItems(int par1, List par2List)
    022    {
    023        this.windowId = par1;
    024        this.itemStack = new ItemStack[par2List.size()];
    025
    026        for (int var3 = 0; var3 < this.itemStack.length; ++var3)
    027        {
    028            ItemStack var4 = (ItemStack)par2List.get(var3);
    029            this.itemStack[var3] = var4 == null ? null : var4.copy();
    030        }
    031    }
    032
    033    /**
    034     * Abstract. Reads the raw packet data from the data stream.
    035     */
    036    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    037    {
    038        this.windowId = par1DataInputStream.readByte();
    039        short var2 = par1DataInputStream.readShort();
    040        this.itemStack = new ItemStack[var2];
    041
    042        for (int var3 = 0; var3 < var2; ++var3)
    043        {
    044            this.itemStack[var3] = readItemStack(par1DataInputStream);
    045        }
    046    }
    047
    048    /**
    049     * Abstract. Writes the raw packet data to the data stream.
    050     */
    051    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    052    {
    053        par1DataOutputStream.writeByte(this.windowId);
    054        par1DataOutputStream.writeShort(this.itemStack.length);
    055
    056        for (int var2 = 0; var2 < this.itemStack.length; ++var2)
    057        {
    058            writeItemStack(this.itemStack[var2], par1DataOutputStream);
    059        }
    060    }
    061
    062    /**
    063     * Passes this Packet on to the NetHandler for processing.
    064     */
    065    public void processPacket(NetHandler par1NetHandler)
    066    {
    067        par1NetHandler.handleWindowItems(this);
    068    }
    069
    070    /**
    071     * Abstract. Return the size of the packet (not counting the header).
    072     */
    073    public int getPacketSize()
    074    {
    075        return 3 + this.itemStack.length * 5;
    076    }
    077}