use of cn.nukkit.entity.passive.EntityWaterAnimal in project Nukkit by Nukkit.
the class EntityLiving method entityBaseTick.
@Override
public boolean entityBaseTick(int tickDiff) {
Timings.livingEntityBaseTickTimer.startTiming();
boolean isBreathing = !this.isInsideOfWater();
if (this instanceof Player && ((Player) this).isCreative()) {
isBreathing = true;
}
this.setDataFlag(DATA_FLAGS, DATA_FLAG_BREATHING, isBreathing);
boolean hasUpdate = super.entityBaseTick(tickDiff);
if (this.isAlive()) {
if (this.isInsideOfSolid()) {
hasUpdate = true;
this.attack(new EntityDamageEvent(this, DamageCause.SUFFOCATION, 1));
}
if (!this.hasEffect(Effect.WATER_BREATHING) && this.isInsideOfWater()) {
if (this instanceof EntityWaterAnimal) {
this.setDataProperty(new ShortEntityData(DATA_AIR, 400));
} else {
hasUpdate = true;
int airTicks = this.getDataPropertyShort(DATA_AIR) - tickDiff;
if (airTicks <= -20) {
airTicks = 0;
this.attack(new EntityDamageEvent(this, DamageCause.DROWNING, 2));
}
this.setDataProperty(new ShortEntityData(DATA_AIR, airTicks));
}
} else {
if (this instanceof EntityWaterAnimal) {
hasUpdate = true;
int airTicks = this.getDataPropertyInt(DATA_AIR) - tickDiff;
if (airTicks <= -20) {
airTicks = 0;
this.attack(new EntityDamageEvent(this, DamageCause.SUFFOCATION, 2));
}
this.setDataProperty(new ShortEntityData(DATA_AIR, airTicks));
} else {
this.setDataProperty(new ShortEntityData(DATA_AIR, 400));
}
}
}
if (this.attackTime > 0) {
this.attackTime -= tickDiff;
}
if (this.riding == null) {
for (Entity entity : level.getNearbyEntities(this.boundingBox.grow(0.20000000298023224D, 0.0D, 0.20000000298023224D), this)) {
if (entity instanceof EntityRideable) {
this.collidingWith(entity);
}
}
}
Timings.livingEntityBaseTickTimer.stopTiming();
return hasUpdate;
}
Aggregations