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;
}
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;
}
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) {
;
}
}
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;
}
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);
}
Aggregations