Java Code Examples for com.nukkitx.protocol.bedrock.packet.InventoryContentPacket#setContainerId()
The following examples show how to use
com.nukkitx.protocol.bedrock.packet.InventoryContentPacket#setContainerId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChestInventoryUpdater.java From Geyser with MIT License | 6 votes |
@Override public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { super.updateInventory(translator, session, inventory); ItemData[] bedrockItems = new ItemData[paddedSize]; for (int i = 0; i < bedrockItems.length; i++) { if (i < translator.size) { bedrockItems[i] = ItemTranslator.translateToBedrock(session, inventory.getItem(i)); } else { bedrockItems[i] = UNUSUABLE_SPACE_BLOCK; } } InventoryContentPacket contentPacket = new InventoryContentPacket(); contentPacket.setContainerId(inventory.getId()); contentPacket.setContents(bedrockItems); session.sendUpstreamPacket(contentPacket); }
Example 2
Source File: PlayerInventoryTranslator.java From Geyser with MIT License | 5 votes |
@Override public void updateInventory(GeyserSession session, Inventory inventory) { updateCraftingGrid(session, inventory); InventoryContentPacket inventoryContentPacket = new InventoryContentPacket(); inventoryContentPacket.setContainerId(ContainerId.INVENTORY); ItemData[] contents = new ItemData[36]; // Inventory for (int i = 9; i < 36; i++) { contents[i] = ItemTranslator.translateToBedrock(session, inventory.getItem(i)); } // Hotbar for (int i = 36; i < 45; i++) { contents[i - 36] = ItemTranslator.translateToBedrock(session, inventory.getItem(i)); } inventoryContentPacket.setContents(contents); session.sendUpstreamPacket(inventoryContentPacket); // Armor InventoryContentPacket armorContentPacket = new InventoryContentPacket(); armorContentPacket.setContainerId(ContainerId.ARMOR); contents = new ItemData[4]; for (int i = 5; i < 9; i++) { contents[i - 5] = ItemTranslator.translateToBedrock(session, inventory.getItem(i)); } armorContentPacket.setContents(contents); session.sendUpstreamPacket(armorContentPacket); // Offhand InventoryContentPacket offhandPacket = new InventoryContentPacket(); offhandPacket.setContainerId(ContainerId.OFFHAND); offhandPacket.setContents(new ItemData[]{ItemTranslator.translateToBedrock(session, inventory.getItem(45))}); session.sendUpstreamPacket(offhandPacket); }
Example 3
Source File: PlayerInventoryTranslator.java From Geyser with MIT License | 5 votes |
@Override public void updateSlot(GeyserSession session, Inventory inventory, int slot) { if (slot >= 1 && slot <= 44) { InventorySlotPacket slotPacket = new InventorySlotPacket(); if (slot >= 9) { slotPacket.setContainerId(ContainerId.INVENTORY); if (slot >= 36) { slotPacket.setSlot(slot - 36); } else { slotPacket.setSlot(slot); } } else if (slot >= 5) { slotPacket.setContainerId(ContainerId.ARMOR); slotPacket.setSlot(slot - 5); } else { slotPacket.setContainerId(ContainerId.CURSOR); slotPacket.setSlot(slot + 27); } slotPacket.setItem(ItemTranslator.translateToBedrock(session, inventory.getItem(slot))); session.sendUpstreamPacket(slotPacket); } else if (slot == 45) { InventoryContentPacket offhandPacket = new InventoryContentPacket(); offhandPacket.setContainerId(ContainerId.OFFHAND); offhandPacket.setContents(new ItemData[]{ItemTranslator.translateToBedrock(session, inventory.getItem(slot))}); session.sendUpstreamPacket(offhandPacket); } }
Example 4
Source File: InventoryUpdater.java From Geyser with MIT License | 5 votes |
public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { ItemData[] bedrockItems = new ItemData[36]; for (int i = 0; i < 36; i++) { final int offset = i < 9 ? 27 : -9; bedrockItems[i] = ItemTranslator.translateToBedrock(session, inventory.getItem(translator.size + i + offset)); } InventoryContentPacket contentPacket = new InventoryContentPacket(); contentPacket.setContainerId(ContainerId.INVENTORY); contentPacket.setContents(bedrockItems); session.sendUpstreamPacket(contentPacket); }
Example 5
Source File: ContainerInventoryUpdater.java From Geyser with MIT License | 5 votes |
@Override public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { super.updateInventory(translator, session, inventory); ItemData[] bedrockItems = new ItemData[translator.size]; for (int i = 0; i < bedrockItems.length; i++) { bedrockItems[translator.javaSlotToBedrock(i)] = ItemTranslator.translateToBedrock(session, inventory.getItem(i)); } InventoryContentPacket contentPacket = new InventoryContentPacket(); contentPacket.setContainerId(inventory.getId()); contentPacket.setContents(bedrockItems); session.sendUpstreamPacket(contentPacket); }
Example 6
Source File: InventoryContentSerializer_v354.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }
Example 7
Source File: InventoryContentSerializer_v388.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }
Example 8
Source File: InventoryContentSerializer_v340.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }
Example 9
Source File: InventoryContentSerializer_v313.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }
Example 10
Source File: InventoryContentSerializer_v361.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }
Example 11
Source File: InventoryContentSerializer_v332.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }
Example 12
Source File: InventoryContentSerializer_v291.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, InventoryContentPacket packet) { packet.setContainerId(VarInts.readUnsignedInt(buffer)); ItemData[] contents = new ItemData[VarInts.readUnsignedInt(buffer)]; for (int i = 0; i < contents.length; i++) { contents[i] = BedrockUtils.readItemData(buffer); } packet.setContents(contents); }