Search in sources :

Example 1 with InventoryContentPacket

use of com.nukkitx.protocol.bedrock.packet.InventoryContentPacket in project Geyser by GeyserMC.

the class ChestedHorseInventoryTranslator method updateInventory.

@Override
public void updateInventory(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] = inventory.getItem(this.size + i + offset).getItemData(session);
    }
    InventoryContentPacket contentPacket = new InventoryContentPacket();
    contentPacket.setContainerId(ContainerId.INVENTORY);
    contentPacket.setContents(Arrays.asList(bedrockItems));
    session.sendUpstreamPacket(contentPacket);
    ItemData[] horseItems = new ItemData[chestSize + 1];
    // Manually specify the first slot - Java always has two slots (armor and saddle) and one is invisible.
    // Bedrock doesn't have this invisible slot.
    horseItems[0] = inventory.getItem(this.equipSlot).getItemData(session);
    for (int i = 1; i < horseItems.length; i++) {
        horseItems[i] = inventory.getItem(i + 1).getItemData(session);
    }
    InventoryContentPacket horseContentsPacket = new InventoryContentPacket();
    horseContentsPacket.setContainerId(inventory.getId());
    horseContentsPacket.setContents(Arrays.asList(horseItems));
    session.sendUpstreamPacket(horseContentsPacket);
}
Also used : InventoryContentPacket(com.nukkitx.protocol.bedrock.packet.InventoryContentPacket) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 2 with InventoryContentPacket

use of com.nukkitx.protocol.bedrock.packet.InventoryContentPacket in project JukeboxMC by LucGamesYT.

the class ContainerInventory method sendContents.

@Override
public void sendContents(Player player) {
    InventoryContentPacket inventoryContentPacket = new InventoryContentPacket();
    inventoryContentPacket.setContainerId(WindowId.OPEN_CONTAINER.getId());
    List<ItemData> itemDataList = new ArrayList<>();
    for (Item content : this.getContents()) {
        itemDataList.add(content.toNetwork());
    }
    inventoryContentPacket.setContents(itemDataList);
    player.sendPacket(inventoryContentPacket);
}
Also used : Item(org.jukeboxmc.item.Item) ArrayList(java.util.ArrayList) InventoryContentPacket(com.nukkitx.protocol.bedrock.packet.InventoryContentPacket) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 3 with InventoryContentPacket

use of com.nukkitx.protocol.bedrock.packet.InventoryContentPacket in project Geyser by GeyserMC.

the class ChestInventoryUpdater method updateInventory.

@Override
public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
    super.updateInventory(translator, session, inventory);
    List<ItemData> bedrockItems = new ArrayList<>(paddedSize);
    for (int i = 0; i < paddedSize; i++) {
        if (i < translator.size) {
            bedrockItems.add(inventory.getItem(i).getItemData(session));
        } else {
            bedrockItems.add(UNUSUABLE_SPACE_BLOCK.apply(session.getUpstream().getProtocolVersion()));
        }
    }
    InventoryContentPacket contentPacket = new InventoryContentPacket();
    contentPacket.setContainerId(inventory.getId());
    contentPacket.setContents(bedrockItems);
    session.sendUpstreamPacket(contentPacket);
}
Also used : ArrayList(java.util.ArrayList) InventoryContentPacket(com.nukkitx.protocol.bedrock.packet.InventoryContentPacket) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 4 with InventoryContentPacket

use of com.nukkitx.protocol.bedrock.packet.InventoryContentPacket in project Geyser by GeyserMC.

the class ContainerInventoryUpdater method updateInventory.

@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)] = inventory.getItem(i).getItemData(session);
    }
    InventoryContentPacket contentPacket = new InventoryContentPacket();
    contentPacket.setContainerId(inventory.getId());
    contentPacket.setContents(Arrays.asList(bedrockItems));
    session.sendUpstreamPacket(contentPacket);
}
Also used : InventoryContentPacket(com.nukkitx.protocol.bedrock.packet.InventoryContentPacket) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 5 with InventoryContentPacket

use of com.nukkitx.protocol.bedrock.packet.InventoryContentPacket in project Geyser by GeyserMC.

the class HorseInventoryUpdater method updateInventory.

@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)] = inventory.getItem(i).getItemData(session);
    }
    InventoryContentPacket contentPacket = new InventoryContentPacket();
    contentPacket.setContainerId(inventory.getId());
    contentPacket.setContents(Arrays.asList(bedrockItems));
    session.sendUpstreamPacket(contentPacket);
}
Also used : InventoryContentPacket(com.nukkitx.protocol.bedrock.packet.InventoryContentPacket) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Aggregations

ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)6 InventoryContentPacket (com.nukkitx.protocol.bedrock.packet.InventoryContentPacket)6 ArrayList (java.util.ArrayList)2 Item (org.jukeboxmc.item.Item)1