Search in sources :

Example 16 with NbtMap

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

the class BlockEntityBlastFurnace method toCompound.

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

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

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

the class BlockEntityFurnace 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.furnaceInventory.addItem(item, false);
        } else {
            this.furnaceInventory.setItem(slot, item, false);
        }
    }
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap)

Example 19 with NbtMap

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

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

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