use of cn.nukkit.event.entity.EntityBlockChangeEvent 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;
}
Aggregations