Search in sources :

Example 21 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData 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 22 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData 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 23 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData 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)

Example 24 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Geyser by GeyserMC.

the class InventoryUpdater method updateInventory.

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] = inventory.getItem(translator.size + i + offset).getItemData(session);
    }
    InventoryContentPacket contentPacket = new InventoryContentPacket();
    contentPacket.setContainerId(ContainerId.INVENTORY);
    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 25 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.

the class BedrockPacketHelper_v431 method readInventoryActions.

@Override
public boolean readInventoryActions(ByteBuf buffer, BedrockSession session, List<InventoryActionData> actions) {
    this.readArray(buffer, actions, session, (buf, helper, aSession) -> {
        InventorySource source = helper.readSource(buf);
        int slot = VarInts.readUnsignedInt(buf);
        ItemData fromItem = helper.readItem(buf, aSession);
        ItemData toItem = helper.readItem(buf, aSession);
        return new InventoryActionData(source, slot, fromItem, toItem);
    });
    return false;
}
Also used : InventoryActionData(com.nukkitx.protocol.bedrock.data.inventory.InventoryActionData) InventorySource(com.nukkitx.protocol.bedrock.data.inventory.InventorySource) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Aggregations

ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)30 ObjectArrayList (it.unimi.dsi.fastutil.objects.ObjectArrayList)13 CraftingData (com.nukkitx.protocol.bedrock.data.inventory.CraftingData)9 UUID (java.util.UUID)8 NbtMap (com.nukkitx.nbt.NbtMap)6 InventoryContentPacket (com.nukkitx.protocol.bedrock.packet.InventoryContentPacket)6 ArrayList (java.util.ArrayList)6 Item (org.jukeboxmc.item.Item)4 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)3 ItemMapping (org.geysermc.geyser.registry.type.ItemMapping)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 Map (java.util.Map)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Ingredient (com.github.steveice10.mc.protocol.data.game.recipe.Ingredient)1 ServerboundContainerButtonClickPacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket)1 ServerboundContainerClosePacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket)1 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 Vector3i (com.nukkitx.math.vector.Vector3i)1 EntityData (com.nukkitx.protocol.bedrock.data.entity.EntityData)1