use of cn.nukkit.level.particle.SpellParticle 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;
}
use of cn.nukkit.level.particle.SpellParticle in project Nukkit by Nukkit.
the class EntityExpBottle 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();
Particle particle1 = new EnchantParticle(this);
this.getLevel().addParticle(particle1);
Particle particle2 = new SpellParticle(this, 0x00385dc6);
this.getLevel().addParticle(particle2);
hasUpdate = true;
NukkitRandom random = new NukkitRandom();
int add = 1;
for (int ii = 1; ii <= random.nextRange(3, 11); ii += add) {
getLevel().dropExpOrb(this, add);
add = random.nextRange(1, 3);
}
}
this.timing.stopTiming();
return hasUpdate;
}
Aggregations