@Override public ByteArrayOutputStream asOutputStream() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(stream); writeSubchannel(data); data.writeInt(mobMagnet.xCoord); data.writeInt(mobMagnet.yCoord); data.writeInt(mobMagnet.zCoord); PacketManager.writeItemStackIntoStream(mobMagnet.getStackInSlot(0), data); data.writeBoolean(mobMagnet.adult); return stream; }
@Override public boolean readPayload( Packet250CustomPayload packet, INetworkManager manager, Player player, String subchannel) throws IOException { if (subchannel.equals(getSubchannel()) && player != null && player instanceof EntityPlayer) { ByteArrayInputStream stream = new ByteArrayInputStream(packet.data); DataInputStream inputStream = new DataInputStream(stream); skipSubchannel(inputStream); int x = inputStream.readInt(); int y = inputStream.readInt(); int z = inputStream.readInt(); TileEntityMobMagnet mobMagnet = (TileEntityMobMagnet) ((EntityPlayer) player).worldObj.getBlockTileEntity(x, y, z); ItemStack stack = PacketManager.getItemStackFromStream(inputStream); if (mobMagnet != null) { mobMagnet.setInventorySlotContents(0, stack); boolean adult = inputStream.readBoolean(); mobMagnet.adult = adult; } return true; } return false; }