use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class BlockEntityBrewingStand method updateBlock.
public void updateBlock() {
Block block = this.getLevelBlock();
if (!(block instanceof BlockBrewingStand)) {
return;
}
int meta = 0;
for (int i = 1; i <= 3; ++i) {
Item potion = this.inventory.getItem(i);
if (potion.getId() == Item.POTION && potion.getCount() > 0) {
meta |= 1 << i;
}
}
block.setDamage(meta);
this.level.setBlock(block, block, false, false);
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class EntityFallingBlock method onUpdate.
@Override
public boolean onUpdate(int currentTick) {
if (closed) {
return false;
}
this.timing.startTiming();
int tickDiff = currentTick - lastUpdate;
if (tickDiff <= 0 && !justCreated) {
return true;
}
lastUpdate = currentTick;
boolean hasUpdate = entityBaseTick(tickDiff);
if (isAlive()) {
motionY -= getGravity();
move(motionX, motionY, motionZ);
float friction = 1 - getDrag();
motionX *= friction;
motionY *= 1 - getDrag();
motionZ *= friction;
Vector3 pos = (new Vector3(x - 0.5, y, z - 0.5)).round();
if (onGround) {
kill();
Block block = level.getBlock(pos);
if (block.getId() > 0 && block.isTransparent() && !block.canBeReplaced()) {
if (this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) {
getLevel().dropItem(this, Item.get(this.getBlock(), this.getDamage(), 1));
}
} else {
EntityBlockChangeEvent event = new EntityBlockChangeEvent(this, block, Block.get(getBlock(), getDamage()));
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
getLevel().setBlock(pos, event.getTo(), true);
if (event.getTo().getId() == Item.ANVIL) {
getLevel().addSound(pos, Sound.RANDOM_ANVIL_LAND);
}
}
}
hasUpdate = true;
}
updateMovement();
}
this.timing.stopTiming();
return hasUpdate || !onGround || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class EntityMinecartAbstract method onUpdate.
@Override
public boolean onUpdate(int currentTick) {
if (this.closed) {
return false;
}
if (!this.isAlive()) {
++this.deadTicks;
if (this.deadTicks >= 10) {
this.despawnFromAll();
this.close();
}
return this.deadTicks < 10;
}
int tickDiff = currentTick - this.lastUpdate;
if (tickDiff <= 0) {
return false;
}
this.lastUpdate = currentTick;
if (isAlive()) {
super.onUpdate(currentTick);
// Entity variables
lastX = x;
lastY = y;
lastZ = z;
motionY -= 0.03999999910593033D;
int dx = MathHelper.floor(x);
int dy = MathHelper.floor(y);
int dz = MathHelper.floor(z);
// Some hack to check rails
if (Rail.isRailBlock(level.getBlockIdAt(dx, dy - 1, dz))) {
--dy;
}
Block block = level.getBlock(new Vector3(dx, dy, dz));
// Ensure that the block is a rail
if (Rail.isRailBlock(block)) {
processMovement(dx, dy, dz, (BlockRail) block);
if (block instanceof BlockRailActivator) {
// Activate the minecart/TNT
activate(dx, dy, dz, (block.getDamage() & 0x8) != 0);
}
} else {
setFalling();
}
checkBlockCollision();
// Minecart head
pitch = 0;
double diffX = this.lastX - this.x;
double diffZ = this.lastZ - this.z;
double yawToChange = yaw;
if (diffX * diffX + diffZ * diffZ > 0.001D) {
yawToChange = (Math.atan2(diffZ, diffX) * 180 / 3.141592653589793D);
}
// Reverse yaw if yaw is below 0
if (yawToChange < 0) {
// -90-(-90)-(-90) = 90
yawToChange -= yawToChange - yawToChange;
}
setRotation(yawToChange, pitch);
Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level);
Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level);
this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this));
if (!from.equals(to)) {
this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to));
}
// Collisions
for (Entity entity : level.getNearbyEntities(boundingBox.grow(0.2D, 0, 0.2D), this)) {
if (entity != linkedEntity && entity instanceof EntityMinecartAbstract) {
entity.applyEntityCollision(this);
}
}
// Easier
if ((linkedEntity != null) && (!linkedEntity.isAlive())) {
if (linkedEntity.riding == this) {
linkedEntity.riding = null;
}
linkedEntity = null;
}
// No need to onGround or Motion diff! This always have an update
return true;
}
return false;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Entity method isInsideOfSolid.
public boolean isInsideOfSolid() {
double y = this.y + this.getEyeHeight();
Block block = this.level.getBlock(this.temporalVector.setComponents(NukkitMath.floorDouble(this.x), NukkitMath.floorDouble(y), NukkitMath.floorDouble(this.z)));
AxisAlignedBB bb = block.getBoundingBox();
return bb != null && block.isSolid() && !block.isTransparent() && bb.intersectsWith(this.getBoundingBox());
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Entity method checkBlockCollision.
protected void checkBlockCollision() {
Vector3 vector = new Vector3(0, 0, 0);
boolean portal = false;
for (Block block : this.getCollisionBlocks()) {
if (block.getId() == Block.NETHER_PORTAL) {
portal = true;
continue;
}
block.onEntityCollide(this);
block.addVelocityToEntity(this, vector);
}
if (portal) {
inPortalTicks++;
} else {
this.inPortalTicks = 0;
}
if (vector.lengthSquared() > 0) {
vector = vector.normalize();
double d = 0.014d;
this.motionX += vector.x * d;
this.motionY += vector.y * d;
this.motionZ += vector.z * d;
}
}
Aggregations