Search in sources :

Example 21 with Entity

use of cn.nukkit.entity.Entity in project Nukkit by Nukkit.

the class BaseFullChunk method unload.

@Override
public boolean unload(boolean save, boolean safe) {
    LevelProvider level = this.getProvider();
    if (level == null) {
        return true;
    }
    if (save && this.changes != 0) {
        level.saveChunk(this.getX(), this.getZ());
    }
    if (safe) {
        for (Entity entity : this.getEntities().values()) {
            if (entity instanceof Player) {
                return false;
            }
        }
    }
    for (Entity entity : new ArrayList<>(this.getEntities().values())) {
        if (entity instanceof Player) {
            continue;
        }
        entity.close();
    }
    for (BlockEntity blockEntity : new ArrayList<>(this.getBlockEntities().values())) {
        blockEntity.close();
    }
    this.provider = null;
    return true;
}
Also used : Entity(cn.nukkit.entity.Entity) BlockEntity(cn.nukkit.blockentity.BlockEntity) Player(cn.nukkit.Player) LevelProvider(cn.nukkit.level.format.LevelProvider) ArrayList(java.util.ArrayList) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 22 with Entity

use of cn.nukkit.entity.Entity 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 23 with Entity

use of cn.nukkit.entity.Entity in project Nukkit by Nukkit.

the class BlockEntityPistonArm method pushEntities.

private void pushEntities() {
    float lastProgress = this.getExtendedProgress(this.lastProgress);
    double x = (double) (lastProgress * (float) this.facing.getXOffset());
    double y = (double) (lastProgress * (float) this.facing.getYOffset());
    double z = (double) (lastProgress * (float) this.facing.getZOffset());
    AxisAlignedBB bb = new SimpleAxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D);
    Entity[] entities = this.level.getCollidingEntities(bb);
    if (entities.length != 0) {
        ;
    }
}
Also used : SimpleAxisAlignedBB(cn.nukkit.math.SimpleAxisAlignedBB) AxisAlignedBB(cn.nukkit.math.AxisAlignedBB) Entity(cn.nukkit.entity.Entity) SimpleAxisAlignedBB(cn.nukkit.math.SimpleAxisAlignedBB)

Example 24 with Entity

use of cn.nukkit.entity.Entity in project Nukkit by Nukkit.

the class BlockTripWire method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        if (!isPowered()) {
            return type;
        }
        boolean found = false;
        for (Entity entity : this.level.getCollidingEntities(this.getCollisionBoundingBox())) {
            if (!entity.doesTriggerPressurePlate()) {
                continue;
            }
            found = true;
        }
        if (found) {
            this.level.scheduleUpdate(this, 10);
        } else {
            this.setPowered(false);
            this.level.setBlock(this, this, true, false);
            this.updateHook(false);
        }
        return type;
    }
    return 0;
}
Also used : Entity(cn.nukkit.entity.Entity)

Example 25 with Entity

use of cn.nukkit.entity.Entity in project Nukkit by Nukkit.

the class BlockRailDetector method updateState.

protected void updateState() {
    boolean wasPowered = isActive();
    boolean isPowered = false;
    for (Entity entity : level.getNearbyEntities(new SimpleAxisAlignedBB(getFloorX() + 0.125D, getFloorY(), getFloorZ() + 0.125D, getFloorX() + 0.875D, getFloorY() + 0.525D, getFloorZ() + 0.875D))) {
        if (entity instanceof EntityMinecartAbstract) {
            isPowered = true;
        }
    }
    if (isPowered && !wasPowered) {
        setActive(true);
        level.scheduleUpdate(this, this, 0);
        level.scheduleUpdate(this, this.down(), 0);
    }
    if (!isPowered && wasPowered) {
        setActive(false);
        level.scheduleUpdate(this, this, 0);
        level.scheduleUpdate(this, this.down(), 0);
    }
    level.updateComparatorOutputLevel(this);
}
Also used : Entity(cn.nukkit.entity.Entity) EntityMinecartAbstract(cn.nukkit.entity.item.EntityMinecartAbstract) SimpleAxisAlignedBB(cn.nukkit.math.SimpleAxisAlignedBB)

Aggregations

Entity (cn.nukkit.entity.Entity)36 BlockEntity (cn.nukkit.blockentity.BlockEntity)17 Player (cn.nukkit.Player)13 Block (cn.nukkit.block.Block)7 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)7 ItemBlock (cn.nukkit.item.ItemBlock)6 Item (cn.nukkit.item.Item)5 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)5 ListTag (cn.nukkit.nbt.tag.ListTag)5 FullChunk (cn.nukkit.level.format.FullChunk)4 BlockAir (cn.nukkit.block.BlockAir)3 EntityDamageByEntityEvent (cn.nukkit.event.entity.EntityDamageByEntityEvent)3 EmptyChunkSection (cn.nukkit.level.format.generic.EmptyChunkSection)3 Vector3 (cn.nukkit.math.Vector3)3 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)3 FloatTag (cn.nukkit.nbt.tag.FloatTag)3 IOException (java.io.IOException)3 EntityItem (cn.nukkit.entity.item.EntityItem)2 BlockUpdateEvent (cn.nukkit.event.block.BlockUpdateEvent)2 EntityInventoryChangeEvent (cn.nukkit.event.entity.EntityInventoryChangeEvent)2