Search in sources :

Example 11 with Tag

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

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

Example 13 with Tag

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

the class BlockChest method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockEntityChest chest = null;
    int[] faces = { 2, 5, 3, 4 };
    this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
    for (int side = 2; side <= 5; ++side) {
        if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == 4 || side == 5)) {
            continue;
        } else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == 2 || side == 3)) {
            continue;
        }
        Block c = this.getSide(BlockFace.fromIndex(side));
        if (c instanceof BlockChest && 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 : BlockEntityChest(cn.nukkit.blockentity.BlockEntityChest) 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) BlockEntity(cn.nukkit.blockentity.BlockEntity)

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