public static Packet getPacket(TileEntityIronChest tileEntityIronChest) { ByteArrayOutputStream bos = new ByteArrayOutputStream(140); DataOutputStream dos = new DataOutputStream(bos); int x = tileEntityIronChest.xCoord; int y = tileEntityIronChest.yCoord; int z = tileEntityIronChest.zCoord; int typ = tileEntityIronChest.getType().ordinal(); int[] items = tileEntityIronChest.buildIntDataList(); boolean hasStacks = (items != null); try { dos.writeInt(x); dos.writeInt(y); dos.writeInt(z); dos.writeByte(typ); dos.writeByte(hasStacks ? 1 : 0); if (hasStacks) { for (int i = 0; i < 24; i++) { dos.writeInt(items[i]); } } } catch (IOException e) { // UNPOSSIBLE? } Packet250CustomPayload pkt = new Packet250CustomPayload(); pkt.channel = "IronChest"; pkt.data = bos.toByteArray(); pkt.length = bos.size(); pkt.isChunkDataPacket = true; return pkt; }
void generateChannelRegistration( EntityPlayer player, NetHandler netHandler, NetworkManager manager) { Packet250CustomPayload pkt = new Packet250CustomPayload(); pkt.channel = "REGISTER"; pkt.data = getPacketRegistry(player instanceof EntityPlayerMP ? Side.SERVER : Side.CLIENT); pkt.length = pkt.data.length; manager.addToSendQueue(pkt); }
void openRemoteGui( ModContainer mc, EntityPlayerMP player, int modGuiId, World world, int x, int y, int z) { IGuiHandler handler = serverGuiHandlers.get(mc); NetworkModHandler nmh = FMLNetworkHandler.instance().findNetworkModHandler(mc); if (handler != null && nmh != null) { Container container = (Container) handler.getServerGuiElement(modGuiId, player, world, x, y, z); if (container != null) { player.incrementWindowID(); player.closeInventory(); int windowId = player.currentWindowId; Packet250CustomPayload pkt = new Packet250CustomPayload(); pkt.channel = "FML"; pkt.data = FMLPacket.makePacket(Type.GUIOPEN, windowId, nmh.getNetworkId(), modGuiId, x, y, z); pkt.length = pkt.data.length; player.serverForThisPlayer.sendPacketToPlayer(pkt); player.craftingInventory = container; player.craftingInventory.windowId = windowId; player.craftingInventory.addCraftingToCrafters(player); } } }