Search in sources :

Example 1 with Particle

use of cn.nukkit.level.particle.Particle 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)

Example 2 with Particle

use of cn.nukkit.level.particle.Particle 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;
}
Also used : EnchantParticle(cn.nukkit.level.particle.EnchantParticle) SpellParticle(cn.nukkit.level.particle.SpellParticle) Particle(cn.nukkit.level.particle.Particle) SpellParticle(cn.nukkit.level.particle.SpellParticle) EnchantParticle(cn.nukkit.level.particle.EnchantParticle) NukkitRandom(cn.nukkit.math.NukkitRandom)

Aggregations

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