Search in sources :

Example 6 with FloatTag

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

the class ItemPainting method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);
    if (chunk == null) {
        return false;
    }
    if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
        int[] direction = { 2, 0, 1, 3 };
        int[] right = { 4, 5, 3, 2 };
        List<EntityPainting.Motive> validMotives = new ArrayList<>();
        for (EntityPainting.Motive motive : EntityPainting.motives) {
            boolean valid = true;
            for (int x = 0; x < motive.width && valid; x++) {
                for (int z = 0; z < motive.height && valid; z++) {
                    if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() || target.up(z).isTransparent() || block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() || block.up(z).isSolid()) {
                        valid = false;
                    }
                }
            }
            if (valid) {
                validMotives.add(motive);
            }
        }
        CompoundTag nbt = new CompoundTag().putByte("Direction", direction[face.getIndex() - 2]).putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title).putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("0", target.x)).add(new DoubleTag("1", target.y)).add(new DoubleTag("2", target.z))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("0", 0)).add(new DoubleTag("1", 0)).add(new DoubleTag("2", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("0", direction[face.getIndex() - 2] * 90)).add(new FloatTag("1", 0)));
        EntityPainting entity = new EntityPainting(chunk, nbt);
        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) EntityPainting(cn.nukkit.entity.item.EntityPainting) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) FullChunk(cn.nukkit.level.format.FullChunk) FloatTag(cn.nukkit.nbt.tag.FloatTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 7 with FloatTag

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

the class ItemSpawnEgg method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4);
    if (chunk == null) {
        return false;
    }
    CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", block.getX() + 0.5)).add(new DoubleTag("", block.getY())).add(new DoubleTag("", block.getZ() + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", new Random().nextFloat() * 360)).add(new FloatTag("", 0)));
    if (this.hasCustomName()) {
        nbt.putString("CustomName", this.getCustomName());
    }
    Entity entity = Entity.createEntity(this.meta, chunk, nbt);
    if (entity != null) {
        if (player.isSurvival()) {
            Item item = player.getInventory().getItemInHand();
            item.setCount(item.getCount() - 1);
            player.getInventory().setItemInHand(item);
        }
        entity.spawnToAll();
        return true;
    }
    return false;
}
Also used : Entity(cn.nukkit.entity.Entity) FullChunk(cn.nukkit.level.format.FullChunk) FloatTag(cn.nukkit.nbt.tag.FloatTag) Random(java.util.Random) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 8 with FloatTag

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

the class ProjectileItem method onClickAir.

public boolean onClickAir(Player player, Vector3 directionVector) {
    CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", player.x)).add(new DoubleTag("", player.y + player.getEyeHeight())).add(new DoubleTag("", player.z))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", directionVector.x)).add(new DoubleTag("", directionVector.y)).add(new DoubleTag("", directionVector.z))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", (float) player.yaw)).add(new FloatTag("", (float) player.pitch)));
    this.correctNBT(nbt);
    Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player);
    if (projectile != null) {
        projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce()));
        this.count--;
        if (projectile instanceof EntityProjectile) {
            ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile);
            player.getServer().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                projectile.kill();
            } else {
                projectile.spawnToAll();
                player.getLevel().addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values());
            }
        } else {
            projectile.spawnToAll();
        }
    } else {
        return false;
    }
    return true;
}
Also used : Entity(cn.nukkit.entity.Entity) FloatTag(cn.nukkit.nbt.tag.FloatTag) ProjectileLaunchEvent(cn.nukkit.event.entity.ProjectileLaunchEvent) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) EntityProjectile(cn.nukkit.entity.projectile.EntityProjectile)

Example 9 with FloatTag

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

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

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)13 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 ListTag (cn.nukkit.nbt.tag.ListTag)13 BlockRail (cn.nukkit.block.BlockRail)4 Rail (cn.nukkit.utils.Rail)4 Entity (cn.nukkit.entity.Entity)3 EntityProjectile (cn.nukkit.entity.projectile.EntityProjectile)2 ProjectileLaunchEvent (cn.nukkit.event.entity.ProjectileLaunchEvent)2 FullChunk (cn.nukkit.level.format.FullChunk)2 Random (java.util.Random)2 Player (cn.nukkit.Player)1 BlockAir (cn.nukkit.block.BlockAir)1 EntityBoat (cn.nukkit.entity.item.EntityBoat)1 EntityFallingBlock (cn.nukkit.entity.item.EntityFallingBlock)1 EntityMinecartChest (cn.nukkit.entity.item.EntityMinecartChest)1 EntityMinecartEmpty (cn.nukkit.entity.item.EntityMinecartEmpty)1 EntityMinecartHopper (cn.nukkit.entity.item.EntityMinecartHopper)1 EntityMinecartTNT (cn.nukkit.entity.item.EntityMinecartTNT)1 EntityPainting (cn.nukkit.entity.item.EntityPainting)1