Search in sources :

Example 26 with NbtMap

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

the class BlockEntityShulkerBox method toCompound.

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

Example 27 with NbtMap

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

the class BlockEntityShulkerBox method fromCompound.

@Override
public void fromCompound(NbtMap compound) {
    super.fromCompound(compound);
    List<NbtMap> items = compound.getList("Items", NbtType.COMPOUND);
    for (NbtMap nbtMap : items) {
        Item item = this.toItem(nbtMap);
        byte slot = nbtMap.getByte("Slot", (byte) 127);
        if (slot == 127) {
            this.shulkerBoxInventory.addItem(item, false);
        } else {
            this.shulkerBoxInventory.setItem(slot, item, false);
        }
    }
    this.facing = compound.getByte("facing");
    this.undyed = compound.getBoolean("isUndyed");
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap)

Example 28 with NbtMap

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

the class BlockEntityBanner method toCompound.

@Override
public NbtMapBuilder toCompound() {
    NbtMapBuilder compound = super.toCompound();
    compound.putInt("Base", this.baseColor);
    compound.putInt("Type", this.type);
    if (this.patterns.size() > 0) {
        List<NbtMap> pattern = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : this.patterns.entrySet()) {
            NbtMapBuilder patternBuilder = NbtMap.builder();
            patternBuilder.putString("Pattern", entry.getKey());
            patternBuilder.putInt("Color", entry.getValue());
            pattern.add(patternBuilder.build());
        }
        compound.putList("Patterns", NbtType.COMPOUND, pattern);
    }
    return compound;
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) NbtMap(com.nukkitx.nbt.NbtMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 29 with NbtMap

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

the class BlockEntityBarrel method fromCompound.

@Override
public void fromCompound(NbtMap compound) {
    super.fromCompound(compound);
    List<NbtMap> items = compound.getList("Items", NbtType.COMPOUND);
    for (NbtMap nbtMap : items) {
        Item item = this.toItem(nbtMap);
        byte slot = nbtMap.getByte("Slot", (byte) 127);
        if (slot == 127) {
            this.barrelInventory.addItem(item, false);
        } else {
            this.barrelInventory.setItem(slot, item, false);
        }
    }
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap)

Example 30 with NbtMap

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

the class BlockEntityBarrel method toCompound.

@Override
public NbtMapBuilder toCompound() {
    NbtMapBuilder builder = super.toCompound();
    List<NbtMap> itemsCompoundList = new ArrayList<>();
    for (int slot = 0; slot < this.barrelInventory.getSize(); slot++) {
        NbtMapBuilder itemCompound = NbtMap.builder();
        Item item = this.barrelInventory.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)

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