com.nukkitx.protocol.bedrock.data.ItemData Java Examples

The following examples show how to use com.nukkitx.protocol.bedrock.data.ItemData. 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: BannerTranslator.java    From Geyser with MIT License 6 votes vote down vote up
@Override
public ItemData translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
    if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, itemEntry);

    ItemData itemData = super.translateToBedrock(itemStack, itemEntry);

    CompoundTag blockEntityTag = itemStack.getNbt().get("BlockEntityTag");
    if (blockEntityTag.contains("Patterns")) {
        ListTag patterns = blockEntityTag.get("Patterns");

        CompoundTagBuilder builder = itemData.getTag().toBuilder();
        builder.tag(convertBannerPattern(patterns));

        itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.buildRootTag());
    }

    return itemData;
}
 
Example #2
Source File: BannerTranslator.java    From Geyser with MIT License 6 votes vote down vote up
@Override
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
    if (itemData.getTag() == null) return super.translateToJava(itemData, itemEntry);

    ItemStack itemStack = super.translateToJava(itemData, itemEntry);

    com.nukkitx.nbt.tag.CompoundTag nbtTag = itemData.getTag();
    if (nbtTag.contains("Patterns")) {
        com.nukkitx.nbt.tag.ListTag<?> patterns = nbtTag.get("Patterns");

        CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag");
        blockEntityTag.put(convertBannerPattern(patterns));

        itemStack.getNbt().put(blockEntityTag);
    }

    return itemStack;
}
 
Example #3
Source File: ChestInventoryUpdater.java    From Geyser with MIT License 6 votes vote down vote up
@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 #4
Source File: ItemTranslator.java    From Geyser with MIT License 6 votes vote down vote up
public static ItemStack translateToJava(ItemData data) {
    if (data == null) {
        return new ItemStack(0);
    }
    ItemEntry javaItem = ItemRegistry.getItem(data);

    ItemStack itemStack;
    ItemTranslator itemStackTranslator = ITEM_STACK_TRANSLATORS.get(javaItem.getJavaId());
    if (itemStackTranslator != null) {
        itemStack = itemStackTranslator.translateToJava(data, javaItem);
    } else {
        itemStack = DEFAULT_TRANSLATOR.translateToJava(data, javaItem);
    }

    if (itemStack != null && itemStack.getNbt() != null) {
        for (NbtItemStackTranslator translator : NBT_TRANSLATORS) {
            if (translator.acceptItem(javaItem)) {
                translator.translateToJava(itemStack.getNbt(), javaItem);
            }
        }
    }
    return itemStack;
}
 
Example #5
Source File: InventoryContentSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #6
Source File: InventoryContentSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #8
Source File: InventoryContentSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #10
Source File: InventoryContentSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #12
Source File: InventoryContentSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: CraftingDataSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CraftingDataPacket packet) {
    BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> {
        VarInts.writeInt(buf, craftingData.getType().ordinal());
        switch (craftingData.getType()) {
            case SHAPELESS:
            case SHAPELESS_CHEMISTRY:
            case SHULKER_BOX:
                BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case SHAPED:
            case SHAPED_CHEMISTRY:
                VarInts.writeInt(buf, craftingData.getWidth());
                VarInts.writeInt(buf, craftingData.getHeight());
                int count = craftingData.getWidth() * craftingData.getHeight();
                ItemData[] inputs = craftingData.getInputs();
                for (int i = 0; i < count; i++) {
                    BedrockUtils.writeItemData(buf, inputs[i]);
                }
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case FURNACE:
            case FURNACE_DATA:
                VarInts.writeInt(buf, craftingData.getInputId());
                if (craftingData.getType() == CraftingType.FURNACE_DATA) {
                    VarInts.writeInt(buf, craftingData.getInputDamage());
                }
                BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]);
                break;
            case MULTI:
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
        }
    });
    buffer.writeBoolean(packet.isCleanRecipes());
}
 
Example #14
Source File: InventoryUtils.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Returns a barrier block with custom name and lore to explain why
 * part of the inventory is unusable.
 */
public static ItemData createUnusableSpaceBlock(String description) {
    CompoundTagBuilder root = CompoundTagBuilder.builder();
    CompoundTagBuilder display = CompoundTagBuilder.builder();

    display.stringTag("Name", ChatColor.RESET + "Unusable inventory space");
    display.listTag("Lore", StringTag.class, Collections.singletonList(new StringTag("", ChatColor.RESET + ChatColor.DARK_PURPLE + description)));

    root.tag(display.build("display"));
    return ItemData.of(ItemRegistry.ITEM_ENTRIES.get(ItemRegistry.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.buildRootTag());
}
 
Example #15
Source File: CraftingDataSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CraftingDataPacket packet) {
    BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> {
        VarInts.writeInt(buf, craftingData.getType().ordinal());
        switch (craftingData.getType()) {
            case SHAPELESS:
            case SHAPELESS_CHEMISTRY:
            case SHULKER_BOX:
                BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case SHAPED:
            case SHAPED_CHEMISTRY:
                VarInts.writeInt(buf, craftingData.getWidth());
                VarInts.writeInt(buf, craftingData.getHeight());
                int count = craftingData.getWidth() * craftingData.getHeight();
                ItemData[] inputs = craftingData.getInputs();
                for (int i = 0; i < count; i++) {
                    BedrockUtils.writeItemData(buf, inputs[i]);
                }
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case FURNACE:
            case FURNACE_DATA:
                VarInts.writeInt(buf, craftingData.getInputId());
                if (craftingData.getType() == CraftingType.FURNACE_DATA) {
                    VarInts.writeInt(buf, craftingData.getInputDamage());
                }
                BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]);
                break;
            case MULTI:
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
        }
    });
    buffer.writeBoolean(packet.isCleanRecipes());
}
 
Example #16
Source File: InventoryContentSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #17
Source File: InventoryContentSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: CraftingDataSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CraftingDataPacket packet) {
    BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> {
        VarInts.writeInt(buf, craftingData.getType().ordinal());
        switch (craftingData.getType()) {
            case SHAPELESS:
            case SHAPELESS_CHEMISTRY:
            case SHULKER_BOX:
                BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case SHAPED:
            case SHAPED_CHEMISTRY:
                VarInts.writeInt(buf, craftingData.getWidth());
                VarInts.writeInt(buf, craftingData.getHeight());
                int count = craftingData.getWidth() * craftingData.getHeight();
                ItemData[] inputs = craftingData.getInputs();
                for (int i = 0; i < count; i++) {
                    BedrockUtils.writeItemData(buf, inputs[i]);
                }
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case FURNACE:
            case FURNACE_DATA:
                VarInts.writeInt(buf, craftingData.getInputId());
                if (craftingData.getType() == CraftingType.FURNACE_DATA) {
                    VarInts.writeInt(buf, craftingData.getInputDamage());
                }
                BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]);
                break;
            case MULTI:
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
        }
    });
    buffer.writeBoolean(packet.isCleanRecipes());
}
 
Example #19
Source File: InventoryContentSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: InventoryContentSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #21
Source File: PlayerInventoryTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@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 #22
Source File: LlamaEntity.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
    // Strength
    if (entityMetadata.getId() == 19) {
        metadata.put(EntityData.STRENGTH, entityMetadata.getValue());
    }
    // Color equipped on the llama
    if (entityMetadata.getId() == 20) {
        // Bedrock treats llama decoration as armor
        MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket();
        equipmentPacket.setRuntimeEntityId(getGeyserId());
        // -1 means no armor
        if ((int) entityMetadata.getValue() != -1) {
            // The damage value is the dye color that Java sends us
            // Always going to be a carpet so we can hardcode 171 in BlockTranslator
            // The int then short conversion is required or we get a ClassCastException
            equipmentPacket.setChestplate(ItemData.of(BlockTranslator.CARPET, (short)((int) entityMetadata.getValue()), 1));
        } else {
            equipmentPacket.setChestplate(ItemData.AIR);
        }
        // Required to fill out the rest of the equipment or Bedrock ignores it, including above else statement if removing armor
        equipmentPacket.setBoots(ItemData.AIR);
        equipmentPacket.setHelmet(ItemData.AIR);
        equipmentPacket.setLeggings(ItemData.AIR);

        session.sendUpstreamPacket(equipmentPacket);
    }
    // Color of the llama
    if (entityMetadata.getId() == 21) {
        metadata.put(EntityData.VARIANT, entityMetadata.getValue());
    }
    super.updateBedrockMetadata(entityMetadata, session);
}
 
Example #23
Source File: JavaTradeListTranslator.java    From Geyser with MIT License 5 votes vote down vote up
private CompoundTag getItemTag(GeyserSession session, ItemStack stack, String name, int specialPrice) {
    ItemData itemData = ItemTranslator.translateToBedrock(session, stack);
    ItemEntry itemEntry = ItemRegistry.getItem(stack);
    CompoundTagBuilder builder = CompoundTagBuilder.builder();
    builder.byteTag("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1)));
    builder.shortTag("Damage", itemData.getDamage());
    builder.shortTag("id", (short) itemEntry.getBedrockId());
    if (itemData.getTag() != null) {
        CompoundTag tag = itemData.getTag().toBuilder().build("tag");
        builder.tag(tag);
    }
    return builder.build(name);
}
 
Example #24
Source File: CraftingDataSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CraftingDataPacket packet) {
    BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> {
        VarInts.writeInt(buf, craftingData.getType().ordinal());
        switch (craftingData.getType()) {
            case SHAPELESS:
            case SHAPELESS_CHEMISTRY:
            case SHULKER_BOX:
                BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case SHAPED:
            case SHAPED_CHEMISTRY:
                VarInts.writeInt(buf, craftingData.getWidth());
                VarInts.writeInt(buf, craftingData.getHeight());
                int count = craftingData.getWidth() * craftingData.getHeight();
                ItemData[] inputs = craftingData.getInputs();
                for (int i = 0; i < count; i++) {
                    BedrockUtils.writeItemData(buf, inputs[i]);
                }
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case FURNACE:
            case FURNACE_DATA:
                VarInts.writeInt(buf, craftingData.getInputId());
                if (craftingData.getType() == CraftingType.FURNACE_DATA) {
                    VarInts.writeInt(buf, craftingData.getInputDamage());
                }
                BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]);
                break;
            case MULTI:
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
        }
    });
    buffer.writeBoolean(packet.isCleanRecipes());
}
 
Example #25
Source File: PotionTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public ItemData translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
    if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, itemEntry);
    Tag potionTag = itemStack.getNbt().get("Potion");
    if (potionTag instanceof StringTag) {
        Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue());
        if (potion != null) {
            return ItemData.of(itemEntry.getBedrockId(), potion.getBedrockId(), itemStack.getAmount(), translateNbtToBedrock(itemStack.getNbt()));
        }
        GeyserConnector.getInstance().getLogger().debug("Unknown java potion: " + potionTag.getValue());
    }
    return super.translateToBedrock(itemStack, itemEntry);
}
 
Example #26
Source File: PotionTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
    Potion potion = Potion.getByBedrockId(itemData.getDamage());
    ItemStack itemStack = super.translateToJava(itemData, itemEntry);
    if (potion != null) {
        StringTag potionTag = new StringTag("Potion", potion.getJavaIdentifier());
        itemStack.getNbt().put(potionTag);
    }
    return itemStack;
}
 
Example #27
Source File: ItemTranslator.java    From Geyser with MIT License 5 votes vote down vote up
public ItemData translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
    if (itemStack == null) {
        return ItemData.AIR;
    }
    if (itemStack.getNbt() == null) {
        return ItemData.of(itemEntry.getBedrockId(), (short) itemEntry.getBedrockData(), itemStack.getAmount());
    }
    return ItemData.of(itemEntry.getBedrockId(), (short) itemEntry.getBedrockData(), itemStack.getAmount(), this.translateNbtToBedrock(itemStack.getNbt()));
}
 
Example #28
Source File: ItemTranslator.java    From Geyser with MIT License 5 votes vote down vote up
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
    if (itemData == null) return null;
    if (itemData.getTag() == null) {
        return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag(""));
    }
    return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT(itemData.getTag()));
}
 
Example #29
Source File: InventoryContentSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, InventoryContentPacket packet) {
    VarInts.writeUnsignedInt(buffer, packet.getContainerId());

    ItemData[] contents = packet.getContents();
    VarInts.writeUnsignedInt(buffer, contents.length);
    for (ItemData content : contents) {
        BedrockUtils.writeItemData(buffer, content);
    }
}
 
Example #30
Source File: PlayerInventoryTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@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);
    }
}