Search in sources :

Example 1 with Effect

use of cn.nukkit.potion.Effect in project Nukkit by Nukkit.

the class Entity method saveNBT.

public void saveNBT() {
    if (!(this instanceof Player)) {
        this.namedTag.putString("id", this.getSaveId());
        if (!this.getNameTag().equals("")) {
            this.namedTag.putString("CustomName", this.getNameTag());
            this.namedTag.putBoolean("CustomNameVisible", this.isNameTagVisible());
        } else {
            this.namedTag.remove("CustomName");
            this.namedTag.remove("CustomNameVisible");
        }
    }
    this.namedTag.putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("0", this.x)).add(new DoubleTag("1", this.y)).add(new DoubleTag("2", this.z)));
    this.namedTag.putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("0", this.motionX)).add(new DoubleTag("1", this.motionY)).add(new DoubleTag("2", this.motionZ)));
    this.namedTag.putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("0", (float) this.yaw)).add(new FloatTag("1", (float) this.pitch)));
    this.namedTag.putFloat("FallDistance", this.fallDistance);
    this.namedTag.putShort("Fire", this.fireTicks);
    this.namedTag.putShort("Air", this.getDataPropertyShort(DATA_AIR));
    this.namedTag.putBoolean("OnGround", this.onGround);
    this.namedTag.putBoolean("Invulnerable", this.invulnerable);
    this.namedTag.putFloat("Scale", this.scale);
    if (!this.effects.isEmpty()) {
        ListTag<CompoundTag> list = new ListTag<>("ActiveEffects");
        for (Effect effect : this.effects.values()) {
            list.add(new CompoundTag(String.valueOf(effect.getId())).putByte("Id", effect.getId()).putByte("Amplifier", effect.getAmplifier()).putInt("Duration", effect.getDuration()).putBoolean("Ambient", false).putBoolean("ShowParticles", effect.isVisible()));
        }
        this.namedTag.putList(list);
    } else {
        this.namedTag.remove("ActiveEffects");
    }
}
Also used : Player(cn.nukkit.Player) FloatTag(cn.nukkit.nbt.tag.FloatTag) Effect(cn.nukkit.potion.Effect) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 2 with Effect

use of cn.nukkit.potion.Effect in project Nukkit by Nukkit.

the class Entity method initEntity.

protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
        ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
        for (CompoundTag e : effects.getAll()) {
            Effect effect = Effect.getEffect(e.getByte("Id"));
            if (effect == null) {
                continue;
            }
            effect.setAmplifier(e.getByte("Amplifier")).setDuration(e.getInt("Duration")).setVisible(e.getBoolean("showParticles"));
            this.addEffect(effect);
        }
    }
    if (this.namedTag.contains("CustomName")) {
        this.setNameTag(this.namedTag.getString("CustomName"));
        if (this.namedTag.contains("CustomNameVisible")) {
            this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
        }
    }
    this.scheduleUpdate();
}
Also used : Effect(cn.nukkit.potion.Effect) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 3 with Effect

use of cn.nukkit.potion.Effect in project Nukkit by Nukkit.

the class Entity method sendPotionEffects.

public void sendPotionEffects(Player player) {
    for (Effect effect : this.effects.values()) {
        MobEffectPacket pk = new MobEffectPacket();
        pk.eid = this.getId();
        pk.effectId = effect.getId();
        pk.amplifier = effect.getAmplifier();
        pk.particles = effect.isVisible();
        pk.duration = effect.getDuration();
        pk.eventId = MobEffectPacket.EVENT_ADD;
        player.dataPacket(pk);
    }
}
Also used : Effect(cn.nukkit.potion.Effect)

Example 4 with Effect

use of cn.nukkit.potion.Effect in project Nukkit by Nukkit.

the class Entity method removeEffect.

public void removeEffect(int effectId) {
    if (this.effects.containsKey(effectId)) {
        Effect effect = this.effects.get(effectId);
        this.effects.remove(effectId);
        effect.remove(this);
        this.recalculateEffectColor();
    }
}
Also used : Effect(cn.nukkit.potion.Effect)

Example 5 with Effect

use of cn.nukkit.potion.Effect in project Nukkit by Nukkit.

the class Entity method recalculateEffectColor.

protected void recalculateEffectColor() {
    int[] color = new int[3];
    int count = 0;
    boolean ambient = true;
    for (Effect effect : this.effects.values()) {
        if (effect.isVisible()) {
            int[] c = effect.getColor();
            color[0] += c[0] * (effect.getAmplifier() + 1);
            color[1] += c[1] * (effect.getAmplifier() + 1);
            color[2] += c[2] * (effect.getAmplifier() + 1);
            count += effect.getAmplifier() + 1;
            if (!effect.isAmbient()) {
                ambient = false;
            }
        }
    }
    if (count > 0) {
        int r = (color[0] / count) & 0xff;
        int g = (color[1] / count) & 0xff;
        int b = (color[2] / count) & 0xff;
        this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, (r << 16) + (g << 8) + b));
        this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, ambient ? 1 : 0));
    } else {
        this.setDataProperty(new IntEntityData(Entity.DATA_POTION_COLOR, 0));
        this.setDataProperty(new ByteEntityData(Entity.DATA_POTION_AMBIENT, 0));
    }
}
Also used : Effect(cn.nukkit.potion.Effect)

Aggregations

Effect (cn.nukkit.potion.Effect)9 Player (cn.nukkit.Player)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)2 Entity (cn.nukkit.entity.Entity)1 PotionCollideEvent (cn.nukkit.event.potion.PotionCollideEvent)1 TranslationContainer (cn.nukkit.lang.TranslationContainer)1 InstantSpellParticle (cn.nukkit.level.particle.InstantSpellParticle)1 Particle (cn.nukkit.level.particle.Particle)1 SpellParticle (cn.nukkit.level.particle.SpellParticle)1 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)1 FloatTag (cn.nukkit.nbt.tag.FloatTag)1 ListTag (cn.nukkit.nbt.tag.ListTag)1 InstantEffect (cn.nukkit.potion.InstantEffect)1 Potion (cn.nukkit.potion.Potion)1 ServerException (cn.nukkit.utils.ServerException)1