/** * Creates a packet describing a stack of items inside a pipe. * * @param data * @return */ public Packet createItemPacket(TravelingItem data) { PacketPipeTransportContent packet = new PacketPipeTransportContent(data); return packet.getPacket(); }
/** * Handles a packet describing a stack of items inside a pipe. * * @param packet */ public void handleItemPacket(PacketPipeTransportContent packet) { if (packet.getID() != PacketIds.PIPE_CONTENTS) return; TravelingItem item = items.get(packet.getTravellingItemId()); if (item == null) { item = new TravelingItem(packet.getTravellingItemId()); items.add(item); } if (item.getItemStack() == null) { item.setItemStack( new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage())); if (packet.hasNBT()) { PacketDispatcher.sendPacketToServer( new PacketSimpleId( PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getTravellingItemId()) .getPacket()); } } else { if (item.getItemStack().itemID != packet.getItemId() || item.getItemStack().stackSize != packet.getStackSize() || item.getItemStack().getItemDamage() != packet.getItemDamage() || item.getItemStack().hasTagCompound() != packet.hasNBT()) { item.setItemStack( new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage())); if (packet.hasNBT()) { PacketDispatcher.sendPacketToServer( new PacketSimpleId( PacketIds.REQUEST_ITEM_NBT, container.xCoord, container.yCoord, container.zCoord, packet.getTravellingItemId()) .getPacket()); } } } item.setPosition(packet.getItemX(), packet.getItemY(), packet.getItemZ()); item.setSpeed(packet.getSpeed()); item.input = packet.getInputOrientation(); item.output = packet.getOutputOrientation(); item.color = packet.getColor(); }