Search in sources :

Example 31 with NbtMap

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

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

Example 32 with NbtMap

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

the class BlockEntityChest 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.chestInventory.addItem(item, false);
        } else {
            this.chestInventory.setItem(slot, item, false);
        }
    }
    this.pairX = compound.getInt("pairx", 0);
    this.pairZ = compound.getInt("pairz", 0);
    this.findable = compound.getBoolean("Findable", false);
    if (this.isPaired()) {
        BlockEntityChest paired = this.getPaired();
        if (paired == null) {
            return;
        }
        this.pair(paired);
    } else {
        this.unpair();
    }
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap)

Example 33 with NbtMap

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

the class BlockEntityChest method toCompound.

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

Example 34 with NbtMap

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

the class BlockShulkerBox method placeBlock.

@Override
public boolean placeBlock(Player player, World world, Vector blockPosition, Vector placePosition, Vector clickedPosition, Item itemIndHand, BlockFace blockFace) {
    boolean value = super.placeBlock(player, world, blockPosition, placePosition, clickedPosition, itemIndHand, blockFace);
    if (value) {
        BlockEntityShulkerBox blockEntityShulkerBox = (BlockEntityShulkerBox) BlockEntityType.SHULKER_BOX.<BlockEntityShulkerBox>createBlockEntity(this).setUndyed(false).spawn();
        if (itemIndHand.getNBT() != null && itemIndHand.getNBT().containsKey("Items")) {
            NbtMap nbt = itemIndHand.getNBT();
            List<NbtMap> items = nbt.getList("Items", NbtType.COMPOUND);
            for (NbtMap nbtMap : items) {
                Item item = blockEntityShulkerBox.toItem(nbtMap);
                byte slot = nbtMap.getByte("Slot", (byte) 127);
                if (slot == 127) {
                    blockEntityShulkerBox.getShulkerBoxInventory().addItem(item, false);
                } else {
                    blockEntityShulkerBox.getShulkerBoxInventory().setItem(slot, item, false);
                }
            }
        }
    }
    return value;
}
Also used : BlockEntityShulkerBox(org.jukeboxmc.blockentity.BlockEntityShulkerBox) Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap)

Example 35 with NbtMap

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

the class BlockUndyedShulkerBox method placeBlock.

@Override
public boolean placeBlock(Player player, World world, Vector blockPosition, Vector placePosition, Vector clickedPosition, Item itemIndHand, BlockFace blockFace) {
    boolean value = super.placeBlock(player, world, blockPosition, placePosition, clickedPosition, itemIndHand, blockFace);
    if (value) {
        BlockEntityShulkerBox blockEntityShulkerBox = (BlockEntityShulkerBox) BlockEntityType.SHULKER_BOX.<BlockEntityShulkerBox>createBlockEntity(this).setUndyed(true).spawn();
        if (itemIndHand.getNBT() != null && itemIndHand.getNBT().containsKey("Items")) {
            NbtMap nbt = itemIndHand.getNBT();
            List<NbtMap> items = nbt.getList("Items", NbtType.COMPOUND);
            for (NbtMap nbtMap : items) {
                Item item = blockEntityShulkerBox.toItem(nbtMap);
                byte slot = nbtMap.getByte("Slot", (byte) 127);
                if (slot == 127) {
                    blockEntityShulkerBox.getShulkerBoxInventory().addItem(item, false);
                } else {
                    blockEntityShulkerBox.getShulkerBoxInventory().setItem(slot, item, false);
                }
            }
        }
    }
    return value;
}
Also used : BlockEntityShulkerBox(org.jukeboxmc.blockentity.BlockEntityShulkerBox) Item(org.jukeboxmc.item.Item) 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