Search in sources :

Example 11 with NbtMapBuilder

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

the class BlockEntityContainer method toCompound.

@Override
public NbtMapBuilder toCompound() {
    NbtMapBuilder compound = super.toCompound();
    compound.put("CustomName", this.customName);
    return compound;
}
Also used : NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 12 with NbtMapBuilder

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

the class BlockEntityFurnace method toCompound.

@Override
public NbtMapBuilder toCompound() {
    NbtMapBuilder builder = super.toCompound();
    List<NbtMap> itemsCompoundList = new ArrayList<>();
    for (int slot = 0; slot < this.furnaceInventory.getSize(); slot++) {
        NbtMapBuilder itemCompound = NbtMap.builder();
        Item item = this.furnaceInventory.getItem(slot);
        itemCompound.putByte("Slot", (byte) slot);
        this.fromItem(item, itemCompound);
        itemsCompoundList.add(itemCompound.build());
    }
    builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
    return builder;
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 13 with NbtMapBuilder

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

the class BlockUndyedShulkerBox method toItem.

@Override
public ItemUndyedShulkerBox toItem() {
    ItemUndyedShulkerBox itemShulkerBox = new ItemUndyedShulkerBox();
    BlockEntityShulkerBox blockEntity = this.getBlockEntity();
    if (blockEntity == null) {
        return itemShulkerBox;
    }
    ShulkerBoxInventory shulkerBoxInventory = blockEntity.getShulkerBoxInventory();
    NbtMapBuilder builder = NbtMap.builder();
    List<NbtMap> itemsCompoundList = new ArrayList<>();
    for (int slot = 0; slot < shulkerBoxInventory.getSize(); slot++) {
        Item item = shulkerBoxInventory.getItem(slot);
        if (item != null && !(item instanceof ItemAir)) {
            NbtMapBuilder itemCompound = NbtMap.builder();
            itemCompound.putByte("Slot", (byte) slot);
            blockEntity.fromItem(item, itemCompound);
            itemsCompoundList.add(itemCompound.build());
        }
    }
    builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
    itemShulkerBox.setNBT(builder.build());
    return itemShulkerBox;
}
Also used : BlockEntityShulkerBox(org.jukeboxmc.blockentity.BlockEntityShulkerBox) Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) ShulkerBoxInventory(org.jukeboxmc.inventory.ShulkerBoxInventory) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) ItemAir(org.jukeboxmc.item.ItemAir) ItemUndyedShulkerBox(org.jukeboxmc.item.ItemUndyedShulkerBox)

Example 14 with NbtMapBuilder

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

the class BlockShulkerBox method toItem.

@Override
public ItemShulkerBox toItem() {
    ItemShulkerBox itemShulkerBox = new ItemShulkerBox(this.runtimeId);
    BlockEntityShulkerBox blockEntity = this.getBlockEntity();
    if (blockEntity == null) {
        return itemShulkerBox;
    }
    ShulkerBoxInventory shulkerBoxInventory = blockEntity.getShulkerBoxInventory();
    NbtMapBuilder builder = NbtMap.builder();
    List<NbtMap> itemsCompoundList = new ArrayList<>();
    for (int slot = 0; slot < shulkerBoxInventory.getSize(); slot++) {
        Item item = shulkerBoxInventory.getItem(slot);
        if (item != null && !(item instanceof ItemAir)) {
            NbtMapBuilder itemCompound = NbtMap.builder();
            itemCompound.putByte("Slot", (byte) slot);
            blockEntity.fromItem(item, itemCompound);
            itemsCompoundList.add(itemCompound.build());
        }
    }
    builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
    itemShulkerBox.setNBT(builder.build());
    return itemShulkerBox;
}
Also used : BlockEntityShulkerBox(org.jukeboxmc.blockentity.BlockEntityShulkerBox) Item(org.jukeboxmc.item.Item) ItemShulkerBox(org.jukeboxmc.item.ItemShulkerBox) NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) ShulkerBoxInventory(org.jukeboxmc.inventory.ShulkerBoxInventory) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) ItemAir(org.jukeboxmc.item.ItemAir)

Example 15 with NbtMapBuilder

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

the class TagUtils method toImmutable.

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

Aggregations

NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)30 NbtMap (com.nukkitx.nbt.NbtMap)15 ArrayList (java.util.ArrayList)11 Item (org.jukeboxmc.item.Item)7 Vector3i (com.nukkitx.math.vector.Vector3i)3 ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)3 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Container (org.geysermc.geyser.inventory.Container)2 ItemMapping (org.geysermc.geyser.registry.type.ItemMapping)2 BlockEntityShulkerBox (org.jukeboxmc.blockentity.BlockEntityShulkerBox)2 ShulkerBoxInventory (org.jukeboxmc.inventory.ShulkerBoxInventory)2 ItemAir (org.jukeboxmc.item.ItemAir)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)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