use of cn.nukkit.level.particle.InstantSpellParticle in project Nukkit by Nukkit.
the class EntityPotion method onUpdate.
@Override
public boolean onUpdate(int currentTick) {
if (this.closed) {
return false;
}
this.timing.startTiming();
int tickDiff = currentTick - this.lastUpdate;
boolean hasUpdate = super.onUpdate(currentTick);
if (this.age > 1200) {
this.kill();
hasUpdate = true;
}
if (this.isCollided) {
this.kill();
Potion potion = Potion.getPotion(this.potionId);
PotionCollideEvent event = new PotionCollideEvent(potion, this);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
potion = event.getPotion();
if (potion == null) {
return false;
}
potion.setSplash(true);
Particle particle;
int r;
int g;
int b;
Effect effect = Potion.getEffect(potion.getId(), true);
if (effect == null) {
r = 40;
g = 40;
b = 255;
} else {
int[] colors = effect.getColor();
r = colors[0];
g = colors[1];
b = colors[2];
}
if (Potion.isInstant(potion.getId())) {
particle = new InstantSpellParticle(this, r, g, b);
} else {
particle = new SpellParticle(this, r, g, b);
}
this.getLevel().addParticle(particle);
hasUpdate = true;
Entity[] entities = this.getLevel().getNearbyEntities(this.getBoundingBox().grow(8.25, 4.24, 8.25));
for (Entity anEntity : entities) {
double distance = anEntity.distanceSquared(this);
if (distance < 16) {
double d = 1 - Math.sqrt(distance) / 4;
potion.applyPotion(anEntity, d);
}
}
}
this.timing.stopTiming();
return hasUpdate;
}
Aggregations