Search in sources :

Example 11 with NbtMap

use of com.nukkitx.nbt.NbtMap 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)

Example 12 with NbtMap

use of com.nukkitx.nbt.NbtMap in project BlockStateUpdater by CloudburstMC.

the class TagUtils method toMutable.

public static Object toMutable(Object immutable) {
    if (immutable instanceof NbtMap) {
        NbtMap map = (NbtMap) immutable;
        Map<String, Object> mutable = new LinkedHashMap<>();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            mutable.put(entry.getKey(), toMutable(entry.getValue()));
        }
        return mutable;
    } else if (immutable instanceof NbtList) {
        List<Object> list = new ArrayList<>();
        for (Object value : (List<?>) immutable) {
            list.add(toMutable(value));
        }
        return list;
    }
    return immutable;
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) NbtList(com.nukkitx.nbt.NbtList) List(java.util.List) NbtList(com.nukkitx.nbt.NbtList) ArrayList(java.util.ArrayList) NbtMap(com.nukkitx.nbt.NbtMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with NbtMap

use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.

the class BlockEntity method toItem.

public Item toItem(NbtMap compound) {
    if (compound == null) {
        return new ItemAir();
    }
    short data = compound.getShort("Damage", (short) 0);
    byte amount = compound.getByte("Count", (byte) 0);
    String name = compound.getString("Name", null);
    NbtMap tag = compound.getCompound("tag", NbtMap.EMPTY);
    if (name != null) {
        return new Item(name).setAmount(amount).setMeta(data).setNBT(tag);
    }
    return new ItemAir();
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap) ItemAir(org.jukeboxmc.item.ItemAir)

Example 14 with NbtMap

use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.

the class BlockEntity method fromItem.

public void fromItem(Item item, NbtMapBuilder builder) {
    builder.putString("Name", item.getIdentifier());
    builder.putShort("Damage", (short) item.getMeta());
    builder.putByte("Count", (byte) item.getAmount());
    if (item.getNBT() != null) {
        NbtMap nbt = item.getNBT();
        builder.putCompound("tag", nbt);
    }
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap)

Example 15 with NbtMap

use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.

the class BlockEntityBanner method fromCompound.

@Override
public void fromCompound(NbtMap compound) {
    super.fromCompound(compound);
    this.baseColor = compound.getInt("Base", 0);
    this.type = compound.getInt("Type", 0);
    List<NbtMap> patterns = compound.getList("blocks", NbtType.COMPOUND);
    if (patterns != null) {
        for (NbtMap pattern : patterns) {
            this.patterns.put(pattern.getString("Pattern", "ss"), pattern.getInt("Color", 0));
        }
    }
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap)

Aggregations

NbtMap (com.nukkitx.nbt.NbtMap)50 Item (org.jukeboxmc.item.Item)16 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 NBTInputStream (com.nukkitx.nbt.NBTInputStream)9 ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)5 ByteBuf (io.netty.buffer.ByteBuf)5 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 BlockEntityShulkerBox (org.jukeboxmc.blockentity.BlockEntityShulkerBox)4 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)3 Vector3i (com.nukkitx.math.vector.Vector3i)3 InputStream (java.io.InputStream)3 ItemAir (org.jukeboxmc.item.ItemAir)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ComponentItemData (com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData)2 BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)2 UpdateBlockPacket (com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)2