Search in sources :

Example 51 with CompoundTag

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

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

the class ItemMinecart method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartEmpty minecart = new EntityMinecartEmpty(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityMinecartEmpty(cn.nukkit.entity.item.EntityMinecartEmpty) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 53 with CompoundTag

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

the class ItemMinecartChest method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartChest minecart = new EntityMinecartChest(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) EntityMinecartChest(cn.nukkit.entity.item.EntityMinecartChest) FloatTag(cn.nukkit.nbt.tag.FloatTag) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 54 with CompoundTag

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

the class ItemMinecartHopper method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartHopper minecart = new EntityMinecartHopper(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) FloatTag(cn.nukkit.nbt.tag.FloatTag) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) EntityMinecartHopper(cn.nukkit.entity.item.EntityMinecartHopper) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 55 with CompoundTag

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

the class ItemMinecartTNT method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartTNT minecart = new EntityMinecartTNT(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityMinecartTNT(cn.nukkit.entity.item.EntityMinecartTNT) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) 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