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 j = 0; j < this.itemStack.length; ++j) 027 { 028 ItemStack itemstack = (ItemStack)par2List.get(j); 029 this.itemStack[j] = itemstack == null ? null : itemstack.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 short1 = par1DataInputStream.readShort(); 040 this.itemStack = new ItemStack[short1]; 041 042 for (int i = 0; i < short1; ++i) 043 { 044 this.itemStack[i] = 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 i = 0; i < this.itemStack.length; ++i) 057 { 058 writeItemStack(this.itemStack[i], 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}