Search in sources :

Example 6 with Tag

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

the class BlockTrappedChest 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 };
    BlockEntityChest chest = null;
    this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
    for (BlockFace side : Plane.HORIZONTAL) {
        if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == BlockFace.WEST || side == BlockFace.EAST)) {
            continue;
        } else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == BlockFace.NORTH || side == BlockFace.SOUTH)) {
            continue;
        }
        Block c = this.getSide(side);
        if (c instanceof BlockTrappedChest && c.getDamage() == this.getDamage()) {
            BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
            if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
                chest = (BlockEntityChest) blockEntity;
                break;
            }
        }
    }
    this.getLevel().setBlock(block, this, true, true);
    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);
    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());
        }
    }
    BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
    if (chest != null) {
        chest.pairWith(((BlockEntityChest) blockEntity));
        ((BlockEntityChest) blockEntity).pairWith(chest);
    }
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) BlockEntityChest(cn.nukkit.blockentity.BlockEntityChest) 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) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 7 with Tag

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

the class BlockSignPost method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (face != BlockFace.DOWN) {
        CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.SIGN).putInt("x", (int) block.x).putInt("y", (int) block.y).putInt("z", (int) block.z).putString("Text1", "").putString("Text2", "").putString("Text3", "").putString("Text4", "");
        if (face == BlockFace.UP) {
            setDamage((int) Math.floor(((player.yaw + 180) * 16 / 360) + 0.5) & 0x0f);
            getLevel().setBlock(block, new BlockSignPost(getDamage()), true);
        } else {
            setDamage(face.getIndex());
            getLevel().setBlock(block, new BlockWallSign(getDamage()), true);
        }
        if (player != null) {
            nbt.putString("Creator", player.getUniqueId().toString());
        }
        if (item.hasCustomBlockData()) {
            for (Tag aTag : item.getCustomBlockData().getAllTags()) {
                nbt.put(aTag.getName(), aTag);
            }
        }
        new BlockEntitySign(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
        return true;
    }
    return false;
}
Also used : BlockEntitySign(cn.nukkit.blockentity.BlockEntitySign) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 8 with Tag

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

the class BlockSkull method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    switch(face) {
        case NORTH:
        case SOUTH:
        case EAST:
        case WEST:
        case UP:
            this.setDamage(face.getIndex());
            break;
        case DOWN:
        default:
            return false;
    }
    this.getLevel().setBlock(block, this, true, true);
    CompoundTag nbt = new CompoundTag().putString("id", BlockEntity.SKULL).putByte("SkullType", item.getDamage()).putInt("x", block.getFloorX()).putInt("y", block.getFloorY()).putInt("z", block.getFloorZ()).putByte("Rot", (int) Math.floor((player.yaw * 16 / 360) + 0.5) & 0x0f);
    if (item.hasCustomBlockData()) {
        for (Tag aTag : item.getCustomBlockData().getAllTags()) {
            nbt.put(aTag.getName(), aTag);
        }
    }
    new BlockEntitySkull(getLevel().getChunk((int) block.x >> 4, (int) block.z >> 4), nbt);
    return true;
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntitySkull(cn.nukkit.blockentity.BlockEntitySkull)

Example 9 with Tag

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

the class Item method getLore.

public String[] getLore() {
    Tag tag = this.getNamedTagEntry("display");
    ArrayList<String> lines = new ArrayList<>();
    if (tag instanceof CompoundTag) {
        CompoundTag nbt = (CompoundTag) tag;
        ListTag<StringTag> lore = nbt.getList("Lore", StringTag.class);
        if (lore.size() > 0) {
            for (StringTag stringTag : lore.getAll()) {
                lines.add(stringTag.data);
            }
        }
    }
    return lines.toArray(new String[0]);
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) ArrayList(java.util.ArrayList) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) StringTag(cn.nukkit.nbt.tag.StringTag) Tag(cn.nukkit.nbt.tag.Tag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 10 with Tag

use of cn.nukkit.nbt.tag.Tag 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)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)13 Tag (cn.nukkit.nbt.tag.Tag)13 Map (java.util.Map)7 ListTag (cn.nukkit.nbt.tag.ListTag)6 StringTag (cn.nukkit.nbt.tag.StringTag)6 BlockEntity (cn.nukkit.blockentity.BlockEntity)2 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)2 BlockEntityBrewingStand (cn.nukkit.blockentity.BlockEntityBrewingStand)1 BlockEntityCauldron (cn.nukkit.blockentity.BlockEntityCauldron)1 BlockEntityEnderChest (cn.nukkit.blockentity.BlockEntityEnderChest)1 BlockEntityFlowerPot (cn.nukkit.blockentity.BlockEntityFlowerPot)1 BlockEntityFurnace (cn.nukkit.blockentity.BlockEntityFurnace)1 BlockEntityItemFrame (cn.nukkit.blockentity.BlockEntityItemFrame)1 BlockEntitySign (cn.nukkit.blockentity.BlockEntitySign)1 BlockEntitySkull (cn.nukkit.blockentity.BlockEntitySkull)1 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)1 BlockFace (cn.nukkit.math.BlockFace)1 NBTInputStream (cn.nukkit.nbt.stream.NBTInputStream)1 BinaryStream (cn.nukkit.utils.BinaryStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1