Search in sources :

Example 1 with DoubleTag

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

the class BlockFallable method onUpdate.

public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        Block down = this.down();
        if (down.getId() == AIR || down instanceof BlockLiquid) {
            this.level.setBlock(this, Block.get(Block.AIR), true, true);
            CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", this.x + 0.5)).add(new DoubleTag("", this.y)).add(new DoubleTag("", this.z + 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("", 0)).add(new FloatTag("", 0))).putInt("TileID", this.getId()).putByte("Data", this.getDamage());
            EntityFallingBlock fall = new EntityFallingBlock(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
            fall.spawnToAll();
        }
    }
    return type;
}
Also used : EntityFallingBlock(cn.nukkit.entity.item.EntityFallingBlock) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityFallingBlock(cn.nukkit.entity.item.EntityFallingBlock) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 2 with DoubleTag

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

the class BlockTNT method prime.

public void prime(int fuse) {
    this.getLevel().setBlock(this, new BlockAir(), true);
    double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2;
    CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", this.x + 0.5)).add(new DoubleTag("", this.y)).add(new DoubleTag("", this.z + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", -Math.sin(mot) * 0.02)).add(new DoubleTag("", 0.2)).add(new DoubleTag("", -Math.cos(mot) * 0.02))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))).putShort("Fuse", fuse);
    Entity tnt = new EntityPrimedTNT(this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    tnt.spawnToAll();
    this.level.addSound(this, Sound.RANDOM_FUSE);
}
Also used : Entity(cn.nukkit.entity.Entity) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityPrimedTNT(cn.nukkit.entity.item.EntityPrimedTNT) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) NukkitRandom(cn.nukkit.math.NukkitRandom) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 3 with DoubleTag

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

the class Entity method saveNBT.

public void saveNBT() {
    if (!(this instanceof Player)) {
        this.namedTag.putString("id", this.getSaveId());
        if (!this.getNameTag().equals("")) {
            this.namedTag.putString("CustomName", this.getNameTag());
            this.namedTag.putBoolean("CustomNameVisible", this.isNameTagVisible());
        } else {
            this.namedTag.remove("CustomName");
            this.namedTag.remove("CustomNameVisible");
        }
    }
    this.namedTag.putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("0", this.x)).add(new DoubleTag("1", this.y)).add(new DoubleTag("2", this.z)));
    this.namedTag.putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("0", this.motionX)).add(new DoubleTag("1", this.motionY)).add(new DoubleTag("2", this.motionZ)));
    this.namedTag.putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("0", (float) this.yaw)).add(new FloatTag("1", (float) this.pitch)));
    this.namedTag.putFloat("FallDistance", this.fallDistance);
    this.namedTag.putShort("Fire", this.fireTicks);
    this.namedTag.putShort("Air", this.getDataPropertyShort(DATA_AIR));
    this.namedTag.putBoolean("OnGround", this.onGround);
    this.namedTag.putBoolean("Invulnerable", this.invulnerable);
    this.namedTag.putFloat("Scale", this.scale);
    if (!this.effects.isEmpty()) {
        ListTag<CompoundTag> list = new ListTag<>("ActiveEffects");
        for (Effect effect : this.effects.values()) {
            list.add(new CompoundTag(String.valueOf(effect.getId())).putByte("Id", effect.getId()).putByte("Amplifier", effect.getAmplifier()).putInt("Duration", effect.getDuration()).putBoolean("Ambient", false).putBoolean("ShowParticles", effect.isVisible()));
        }
        this.namedTag.putList(list);
    } else {
        this.namedTag.remove("ActiveEffects");
    }
}
Also used : Player(cn.nukkit.Player) FloatTag(cn.nukkit.nbt.tag.FloatTag) Effect(cn.nukkit.potion.Effect) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 4 with DoubleTag

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

the class ItemBow method onReleaseUsing.

public boolean onReleaseUsing(Player player) {
    Item itemArrow = Item.get(Item.ARROW, 0, 1);
    if (player.isSurvival() && !player.getInventory().contains(itemArrow)) {
        player.getInventory().sendContents(player);
        return false;
    }
    double damage = 2;
    boolean flame = false;
    if (this.hasEnchantments()) {
        Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER);
        if (bowDamage != null && bowDamage.getLevel() > 0) {
            damage += 0.25 * (bowDamage.getLevel() + 1);
        }
        Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME);
        flame = flameEnchant != null && flameEnchant.getLevel() > 0;
    }
    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("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))).add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))).add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)).add(new FloatTag("", (float) -player.pitch))).putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0).putDouble("damage", damage);
    int diff = (Server.getInstance().getTick() - player.getStartActionTick());
    double p = (double) diff / 20;
    double f = Math.min((p * p + p * 2) / 3, 1) * 2;
    EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f);
    if (f < 0.1 || diff < 5) {
        entityShootBowEvent.setCancelled();
    }
    Server.getInstance().getPluginManager().callEvent(entityShootBowEvent);
    if (entityShootBowEvent.isCancelled()) {
        entityShootBowEvent.getProjectile().kill();
        player.getInventory().sendContents(player);
    } else {
        entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce()));
        if (player.isSurvival()) {
            Enchantment infinity;
            if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0)
                player.getInventory().removeItem(itemArrow);
            if (!this.isUnbreakable()) {
                Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY);
                if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) {
                    this.setDamage(this.getDamage() + 1);
                    if (this.getDamage() >= 385) {
                        player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
                    } else {
                        player.getInventory().setItemInHand(this);
                    }
                }
            }
        }
        if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) {
            ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile());
            Server.getInstance().getPluginManager().callEvent(projectev);
            if (projectev.isCancelled()) {
                entityShootBowEvent.getProjectile().kill();
            } else {
                entityShootBowEvent.getProjectile().spawnToAll();
                player.level.addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values());
            }
        } else {
            entityShootBowEvent.getProjectile().spawnToAll();
        }
    }
    return true;
}
Also used : BlockAir(cn.nukkit.block.BlockAir) EntityArrow(cn.nukkit.entity.projectile.EntityArrow) EntityShootBowEvent(cn.nukkit.event.entity.EntityShootBowEvent) ProjectileLaunchEvent(cn.nukkit.event.entity.ProjectileLaunchEvent) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) FloatTag(cn.nukkit.nbt.tag.FloatTag) Random(java.util.Random) Enchantment(cn.nukkit.item.enchantment.Enchantment) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) EntityProjectile(cn.nukkit.entity.projectile.EntityProjectile)

Example 5 with DoubleTag

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

the class ItemBoat method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (face != BlockFace.UP)
        return false;
    EntityBoat boat = new EntityBoat(level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", block.getX() + 0.5)).add(new DoubleTag("", block.getY() - 0.0625)).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("", (float) ((player.yaw + 90f) % 360))).add(new FloatTag("", 0))).putByte("woodID", this.getDamage()));
    if (player.isSurvival()) {
        Item item = player.getInventory().getItemInHand();
        item.setCount(item.getCount() - 1);
        player.getInventory().setItemInHand(item);
    }
    boat.spawnToAll();
    return true;
}
Also used : FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityBoat(cn.nukkit.entity.item.EntityBoat) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) 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