Search in sources :

Example 6 with ItemData

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

the class CraftingDataSerializer_v291 method readShapelessRecipe.

protected CraftingData readShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
    List<ItemData> inputs = new ObjectArrayList<>();
    helper.readArray(buffer, inputs, buf -> helper.readItem(buf, session));
    List<ItemData> outputs = new ObjectArrayList<>();
    helper.readArray(buffer, outputs, buf -> helper.readItem(buf, session));
    UUID uuid = helper.readUuid(buffer);
    return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, null);
}
Also used : ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) CraftingData(com.nukkitx.protocol.bedrock.data.inventory.CraftingData) UUID(java.util.UUID) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 7 with ItemData

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

the class CraftingDataSerializer_v291 method readShapedRecipe.

protected CraftingData readShapedRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
    int width = VarInts.readInt(buffer);
    int height = VarInts.readInt(buffer);
    int inputCount = width * height;
    List<ItemData> inputs = new ObjectArrayList<>(inputCount);
    for (int i = 0; i < inputCount; i++) {
        inputs.add(helper.readItem(buffer, session));
    }
    List<ItemData> outputs = new ObjectArrayList<>();
    helper.readArray(buffer, outputs, buf -> helper.readItem(buf, session));
    UUID uuid = helper.readUuid(buffer);
    return new CraftingData(type, width, height, -1, -1, inputs, outputs, uuid, null);
}
Also used : ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) CraftingData(com.nukkitx.protocol.bedrock.data.inventory.CraftingData) UUID(java.util.UUID) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 8 with ItemData

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

the class CreativeContentSerializer_v407 method readCreativeItem.

protected ItemData readCreativeItem(ByteBuf buffer, BedrockPacketHelper helper, BedrockSession session) {
    int netId = VarInts.readUnsignedInt(buffer);
    ItemData item = helper.readItemInstance(buffer, session);
    item.setNetId(netId);
    return item;
}
Also used : ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 9 with ItemData

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

the class CraftingDataSerializer_v407 method readShapelessRecipe.

protected CraftingData readShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
    String recipeId = helper.readString(buffer);
    List<ItemData> inputs = new ObjectArrayList<>();
    helper.readArray(buffer, inputs, helper::readRecipeIngredient);
    List<ItemData> outputs = new ObjectArrayList<>();
    helper.readArray(buffer, outputs, buf -> helper.readItemInstance(buf, session));
    UUID uuid = helper.readUuid(buffer);
    String craftingTag = helper.readString(buffer);
    int priority = VarInts.readInt(buffer);
    int networkId = VarInts.readUnsignedInt(buffer);
    return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, outputs, uuid, craftingTag, priority, networkId);
}
Also used : ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) CraftingData(com.nukkitx.protocol.bedrock.data.inventory.CraftingData) UUID(java.util.UUID) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 10 with ItemData

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

the class DownstreamPacketHandler method dumpCreativeItems.

private void dumpCreativeItems(ItemData[] contents) {
    // Load up block palette for conversion, if we can find it.
    Object object = proxy.loadGzipNBT("block_palette.nbt");
    List<NbtMap> paletteTags = null;
    if (object instanceof NbtMap) {
        NbtMap map = (NbtMap) object;
        paletteTags = map.getList("blocks", NbtType.COMPOUND);
    } else {
        log.warn("Failed to load block palette for creative content dump. Output will contain block runtime IDs!");
    }
    List<CreativeItemEntry> entries = new ArrayList<>();
    for (ItemData data : contents) {
        int runtimeId = data.getId();
        StartGamePacket.ItemEntry entry = this.itemEntries.get(runtimeId);
        if (entry == null) {
            log.info("Could not find entry for item with runtime ID {}", runtimeId);
            continue;
        }
        String id = entry.getIdentifier();
        Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage();
        String blockTag = null;
        Integer blockRuntimeId = null;
        if (data.getBlockRuntimeId() != 0 && paletteTags != null) {
            blockTag = encodeNbtToString(paletteTags.get(data.getBlockRuntimeId()));
        } else if (data.getBlockRuntimeId() != 0) {
            blockRuntimeId = data.getBlockRuntimeId();
        }
        NbtMap tag = data.getTag();
        String tagData = null;
        if (tag != null) {
            tagData = encodeNbtToString(tag);
        }
        entries.add(new CreativeItemEntry(id, damage, blockRuntimeId, blockTag, tagData));
    }
    CreativeItems items = new CreativeItems(entries);
    proxy.saveJson("creative_items.json", items);
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) 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