Search in sources :

Example 1 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class BlockBeacon method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    boolean blockSuccess = super.place(item, block, target, face, fx, fy, fz, player);
    if (blockSuccess) {
        CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.BEACON).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
        new BlockEntityBeacon(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    }
    return blockSuccess;
}
Also used : BlockEntityBeacon(cn.nukkit.blockentity.BlockEntityBeacon) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 2 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class BlockBed method createBlockEntity.

private void createBlockEntity(Vector3 pos, int color) {
    CompoundTag nbt = BlockEntity.getDefaultCompound(pos, BlockEntity.BED);
    nbt.putByte("color", color);
    BlockEntity.createBlockEntity(BlockEntity.BED, this.level.getChunk(pos.getFloorX() >> 4, pos.getFloorZ() >> 4), nbt);
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 3 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class BlockChest method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        Block top = up();
        if (!top.isTransparent()) {
            return true;
        }
        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityChest chest;
        if (t instanceof BlockEntityChest) {
            chest = (BlockEntityChest) t;
        } else {
            CompoundTag nbt = new CompoundTag("").putList(new ListTag<>("Items")).putString("id", BlockEntity.CHEST).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            chest = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }
        if (chest.namedTag.contains("Lock") && chest.namedTag.get("Lock") instanceof StringTag) {
            if (!chest.namedTag.getString("Lock").equals(item.getCustomName())) {
                return true;
            }
        }
        player.addWindow(chest.getInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityChest(cn.nukkit.blockentity.BlockEntityChest) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 4 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class BlockBrewingStand method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (!block.down().isTransparent()) {
        getLevel().setBlock(block, this, true, true);
        CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.BREWING_STAND).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
        if (item.hasCustomName()) {
            nbt.putString("CustomName", item.getCustomName());
        }
        if (item.hasCustomBlockData()) {
            Map<String, Tag> customData = item.getCustomBlockData().getTags();
            for (Map.Entry<String, Tag> tag : customData.entrySet()) {
                nbt.put(tag.getKey(), tag.getValue());
            }
        }
        new BlockEntityBrewingStand(getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
        return true;
    }
    return false;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) ListTag(cn.nukkit.nbt.tag.ListTag) Map(java.util.Map) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntityBrewingStand(cn.nukkit.blockentity.BlockEntityBrewingStand)

Example 5 with CompoundTag

use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.

the class BlockBrewingStand method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        BlockEntity t = getLevel().getBlockEntity(this);
        BlockEntityBrewingStand brewing;
        if (t instanceof BlockEntityBrewingStand) {
            brewing = (BlockEntityBrewingStand) t;
        } else {
            CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.BREWING_STAND).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            brewing = new BlockEntityBrewingStand(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }
        if (brewing.namedTag.contains("Lock") && brewing.namedTag.get("Lock") instanceof StringTag) {
            if (!brewing.namedTag.getString("Lock").equals(item.getCustomName())) {
                return false;
            }
        }
        player.addWindow(brewing.getInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityBrewingStand(cn.nukkit.blockentity.BlockEntityBrewingStand) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)74 ListTag (cn.nukkit.nbt.tag.ListTag)28 BlockEntity (cn.nukkit.blockentity.BlockEntity)13 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 Tag (cn.nukkit.nbt.tag.Tag)13 StringTag (cn.nukkit.nbt.tag.StringTag)12 Map (java.util.Map)8 Entity (cn.nukkit.entity.Entity)7 IOException (java.io.IOException)7 Player (cn.nukkit.Player)5 BinaryStream (cn.nukkit.utils.BinaryStream)5 ArrayList (java.util.ArrayList)5 BlockRail (cn.nukkit.block.BlockRail)4 FullChunk (cn.nukkit.level.format.FullChunk)4 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)4 Rail (cn.nukkit.utils.Rail)4 File (java.io.File)4 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)3 BlockEntitySpawnable (cn.nukkit.blockentity.BlockEntitySpawnable)3