Search in sources :

Example 1 with InstantSpellParticle

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;
}
Also used : SpellParticle(cn.nukkit.level.particle.SpellParticle) InstantSpellParticle(cn.nukkit.level.particle.InstantSpellParticle) Particle(cn.nukkit.level.particle.Particle) SpellParticle(cn.nukkit.level.particle.SpellParticle) InstantSpellParticle(cn.nukkit.level.particle.InstantSpellParticle) Entity(cn.nukkit.entity.Entity) Potion(cn.nukkit.potion.Potion) InstantSpellParticle(cn.nukkit.level.particle.InstantSpellParticle) PotionCollideEvent(cn.nukkit.event.potion.PotionCollideEvent) Effect(cn.nukkit.potion.Effect)

Aggregations

Entity (cn.nukkit.entity.Entity)1 PotionCollideEvent (cn.nukkit.event.potion.PotionCollideEvent)1 InstantSpellParticle (cn.nukkit.level.particle.InstantSpellParticle)1 Particle (cn.nukkit.level.particle.Particle)1 SpellParticle (cn.nukkit.level.particle.SpellParticle)1 Effect (cn.nukkit.potion.Effect)1 Potion (cn.nukkit.potion.Potion)1