Search in sources :

Example 61 with CompoundTag

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

the class BlockItemFrame method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
        switch(face) {
            case NORTH:
                this.setDamage(3);
                break;
            case SOUTH:
                this.setDamage(2);
                break;
            case WEST:
                this.setDamage(1);
                break;
            case EAST:
                this.setDamage(0);
                break;
            default:
                return false;
        }
        this.getLevel().setBlock(block, this, true, true);
        CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.ITEM_FRAME).putInt("x", (int) block.x).putInt("y", (int) block.y).putInt("z", (int) block.z).putByte("ItemRotation", 0).putFloat("ItemDropChance", 1.0f);
        if (item.hasCustomBlockData()) {
            for (Tag aTag : item.getCustomBlockData().getAllTags()) {
                nbt.put(aTag.getName(), aTag);
            }
        }
        new BlockEntityItemFrame(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
        this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_PLACE);
        return true;
    }
    return false;
}
Also used : BlockEntityItemFrame(cn.nukkit.blockentity.BlockEntityItemFrame) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 62 with CompoundTag

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

the class BlockEnderChest method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    int[] faces = { 2, 5, 3, 4 };
    this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
    this.getLevel().setBlock(block, this, true, true);
    CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.ENDER_CHEST).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 BlockEntityEnderChest(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) Map(java.util.Map) BlockEntityEnderChest(cn.nukkit.blockentity.BlockEntityEnderChest) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 63 with CompoundTag

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

the class BlockEnderChest method onActivate.

@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        Block top = this.up();
        if (!top.isTransparent()) {
            return true;
        }
        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityEnderChest chest;
        if (t instanceof BlockEntityEnderChest) {
            chest = (BlockEntityEnderChest) t;
        } else {
            CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.ENDER_CHEST).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
            chest = new BlockEntityEnderChest(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.setViewingEnderChest(this);
        player.addWindow(player.getEnderChestInventory());
    }
    return true;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) BlockEntityEnderChest(cn.nukkit.blockentity.BlockEntityEnderChest) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 64 with CompoundTag

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

the class BlockHopper method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockFace facing = face.getOpposite();
    if (facing == BlockFace.UP) {
        facing = BlockFace.DOWN;
    }
    this.setDamage(facing.getIndex());
    boolean powered = this.level.isBlockPowered(this);
    if (powered == this.isEnabled()) {
        this.setEnabled(!powered);
    }
    this.level.setBlock(this, this);
    CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.HOPPER).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
    new BlockEntityHopper(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    return true;
}
Also used : BlockEntityHopper(cn.nukkit.blockentity.BlockEntityHopper) BlockFace(cn.nukkit.math.BlockFace) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 65 with CompoundTag

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

the class BlockCauldron method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    CompoundTag nbt = new CompoundTag("").putString("id", BlockEntity.CHEST).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putShort("PotionId", 0xffff).putByte("SplashPotion", 0);
    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 BlockEntityCauldron(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    this.getLevel().setBlock(block, this, true, true);
    return true;
}
Also used : BlockEntityCauldron(cn.nukkit.blockentity.BlockEntityCauldron) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) Map(java.util.Map) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

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