2020-12-31 00:12:03 +01:00
|
|
|
package net.minestom.server.potion;
|
|
|
|
|
2020-12-31 01:29:07 +01:00
|
|
|
import net.minestom.server.entity.Entity;
|
2020-12-31 00:12:03 +01:00
|
|
|
import net.minestom.server.entity.Player;
|
|
|
|
import net.minestom.server.network.packet.server.play.EntityEffectPacket;
|
|
|
|
import net.minestom.server.network.packet.server.play.RemoveEntityEffectPacket;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
public class Potion {
|
2020-12-31 02:07:07 +01:00
|
|
|
private final PotionEffect effect;
|
|
|
|
private final byte amplifier;
|
|
|
|
private final int duration;
|
|
|
|
private final byte flags;
|
2020-12-31 00:12:03 +01:00
|
|
|
|
|
|
|
public Potion(PotionEffect effect, byte amplifier, int duration) {
|
|
|
|
this(effect, amplifier, duration, true, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles) {
|
|
|
|
this(effect, amplifier, duration, particles, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles, boolean icon) {
|
|
|
|
this(effect, amplifier, duration, particles, icon, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles, boolean icon, boolean ambient) {
|
|
|
|
this.effect = effect;
|
|
|
|
this.amplifier = amplifier;
|
|
|
|
this.duration = duration;
|
2020-12-31 02:07:07 +01:00
|
|
|
byte flags = 0;
|
|
|
|
if (ambient) flags = (byte)(flags | 0x01);
|
|
|
|
if (particles) flags = (byte)(flags | 0x02);
|
|
|
|
if (icon) flags = (byte)(flags | 0x04);
|
|
|
|
this.flags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PotionEffect getEffect() {
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
|
|
|
public byte getAmplifier() {
|
|
|
|
return amplifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDuration() {
|
|
|
|
return duration;
|
2020-12-31 00:12:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public byte getFlags() {
|
2020-12-31 02:07:07 +01:00
|
|
|
return flags;
|
2020-12-31 00:12:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-31 01:29:07 +01:00
|
|
|
public void sendAddPacket(@NotNull Entity entity) {
|
2020-12-31 00:12:03 +01:00
|
|
|
EntityEffectPacket eep = new EntityEffectPacket();
|
2020-12-31 01:29:07 +01:00
|
|
|
eep.entityId = entity.getEntityId();
|
2020-12-31 00:12:03 +01:00
|
|
|
eep.potion = this;
|
2020-12-31 01:29:07 +01:00
|
|
|
entity.sendPacketToViewersAndSelf(eep);
|
2020-12-31 00:12:03 +01:00
|
|
|
}
|
|
|
|
|
2020-12-31 01:29:07 +01:00
|
|
|
public void sendRemovePacket(@NotNull Entity entity) {
|
2020-12-31 00:12:03 +01:00
|
|
|
RemoveEntityEffectPacket reep = new RemoveEntityEffectPacket();
|
2020-12-31 01:29:07 +01:00
|
|
|
reep.entityId = entity.getEntityId();
|
2020-12-31 00:12:03 +01:00
|
|
|
reep.effect = effect;
|
2020-12-31 01:29:07 +01:00
|
|
|
entity.sendPacketToViewersAndSelf(reep);
|
2020-12-31 00:12:03 +01:00
|
|
|
}
|
|
|
|
}
|