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");
}
}
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();
}
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);
}
}
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();
}
}
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));
}
}
Aggregations