Permalink
Browse files

Support doubles for potion effect seconds

  • Loading branch information...
PseudoKnight committed Dec 22, 2017
1 parent 8e6f8e6 commit cc354416c2d12cd742de8a7a968fba5b47550281
@@ -13,7 +13,7 @@
*/
public interface MCLivingEntity extends MCEntity, MCProjectileSource {
void addEffect(int potionID, int strength, int seconds, boolean ambient, boolean particles, Target t);
void addEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, Target t);
public boolean removeEffect(int potionID);
/**
* Returns the maximum effect id, inclusive.
@@ -76,21 +76,21 @@
private int potionID;
private int strength;
private int secondsRemaining;
private int ticksRemaining;
private boolean ambient;
private boolean particles;
public MCEffect(int potionID, int strength, int secondsRemaining, boolean ambient){
public MCEffect(int potionID, int strength, int ticks, boolean ambient){
this.potionID = potionID;
this.strength = strength;
this.secondsRemaining = secondsRemaining;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = true;
}
public MCEffect(int potionID, int strength, int secondsRemaining, boolean ambient, boolean particles){
public MCEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles){
this.potionID = potionID;
this.strength = strength;
this.secondsRemaining = secondsRemaining;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = particles;
}
@@ -103,8 +103,8 @@ public int getStrength() {
return strength;
}
public int getSecondsRemaining() {
return secondsRemaining;
public int getTicksRemaining() {
return ticksRemaining;
}
public boolean isAmbient() {
@@ -8,7 +8,7 @@
public MCPotionData getBasePotionData();
public void setBasePotionData(MCPotionData pd);
public boolean addCustomEffect(int potionID, int strength, int seconds, boolean ambient, boolean overwrite, Target t);
public boolean addCustomEffect(int potionID, int strength, int ticks, boolean ambient, boolean overwrite, Target t);
public boolean clearCustomEffects();
public List<MCEffect> getCustomEffects();
public boolean hasCustomEffect(int id);
@@ -32,12 +32,12 @@ public void setBasePotionData(MCPotionData bpd){
}
@Override
public boolean addCustomEffect(int potionID, int strength, int seconds, boolean ambient, boolean overwrite, Target t) {
public boolean addCustomEffect(int potionID, int strength, int ticks, boolean ambient, boolean overwrite, Target t) {
int maxID = PotionEffectType.values().length;
if (potionID < 1 || potionID > maxID) {
throw new CRERangeException("Invalid effect ID, must be from 1-" + maxID, t);
}
PotionEffect pe = new PotionEffect(PotionEffectType.getById(potionID), seconds * 20, strength, ambient);
PotionEffect pe = new PotionEffect(PotionEffectType.getById(potionID), ticks, strength, ambient);
return pm.addCustomEffect(pe, overwrite);
}
@@ -50,7 +50,7 @@ public boolean clearCustomEffects() {
public List<MCEffect> getCustomEffects() {
List<MCEffect> list = new ArrayList<MCEffect>();
for (PotionEffect pe : pm.getCustomEffects()) {
list.add(new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration() / 20, pe.isAmbient()));
list.add(new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient()));
}
return list;
}
@@ -48,7 +48,7 @@ public MCColor getColor(){
List<MCLivingEntity.MCEffect> list = new ArrayList<>();
for (PotionEffect pe : aec.getCustomEffects()) {
list.add(new MCLivingEntity.MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration() / 20, pe.isAmbient(), pe.hasParticles()));
pe.getDuration(), pe.isAmbient(), pe.hasParticles()));
}
return list;
}
@@ -105,7 +105,7 @@ public int getWaitTime(){
@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect){
PotionEffect pe = new PotionEffect(PotionEffectType.getById(effect.getPotionID()),
effect.getSecondsRemaining() * 20, effect.getStrength(), effect.isAmbient(), effect.hasParticles());
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles());
aec.addCustomEffect(pe, true);
}
@@ -197,18 +197,18 @@ public boolean hasAI() {
/**
* @param potionID - ID of the potion
* @param strength - potion strength
* @param seconds - duration of the potion in seconds
* @param ticks - duration of the potion in server ticks
* @param ambient - make particles less noticable
* @param particles - enable or disable particles entirely
* @param t - target
*/
@Override
public void addEffect(int potionID, int strength, int seconds, boolean ambient, boolean particles, Target t) {
public void addEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, Target t) {
PotionEffect pe;
if (Static.getServer().getMinecraftVersion().lt(MCVersion.MC1_8)) {
pe = new PotionEffect(PotionEffectType.getById(potionID), seconds * 20, strength, ambient);
pe = new PotionEffect(PotionEffectType.getById(potionID), ticks, strength, ambient);
} else {
pe = new PotionEffect(PotionEffectType.getById(potionID), seconds * 20, strength, ambient, particles);
pe = new PotionEffect(PotionEffectType.getById(potionID), ticks, strength, ambient, particles);
}
try{
if(le != null){
@@ -246,15 +246,13 @@ public boolean removeEffect(int potionID) {
@Override
public List<MCEffect> getEffects(){
List<MCEffect> effects = new ArrayList<MCEffect>();
List<MCEffect> effects = new ArrayList<>();
for(PotionEffect pe : le.getActivePotionEffects()){
MCEffect e;
if (Static.getServer().getMinecraftVersion().lt(MCVersion.MC1_8)) {
e = new MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration() / 20, pe.isAmbient(), true);
e = new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient(), true);
} else {
e = new MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration() / 20, pe.isAmbient(), pe.hasParticles());
e = new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient(), pe.hasParticles());
}
effects.add(e);
}
@@ -33,15 +33,15 @@ public MCPotionData getBasePotionData() {
List<MCLivingEntity.MCEffect> list = new ArrayList<>();
for (PotionEffect pe : ta.getCustomEffects()) {
list.add(new MCLivingEntity.MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration() / 20, pe.isAmbient(), pe.hasParticles()));
pe.getDuration(), pe.isAmbient(), pe.hasParticles()));
}
return list;
}
@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect){
PotionEffect pe = new PotionEffect(PotionEffectType.getById(effect.getPotionID()),
effect.getSecondsRemaining() * 20, effect.getStrength(), effect.isAmbient(), effect.hasParticles());
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles());
ta.addCustomEffect(pe, true);
}
@@ -773,7 +773,7 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
if (effects instanceof CArray) {
for (MCLivingEntity.MCEffect e : potions((CArray) effects, t)) {
((MCPotionMeta) meta).addCustomEffect(e.getPotionID(), e.getStrength(),
e.getSecondsRemaining(), e.isAmbient(), true, t);
e.getTicksRemaining(), e.isAmbient(), true, t);
}
} else {
throw new CREFormatException("Effects was expected to be an array of potion arrays.", t);
@@ -1038,7 +1038,7 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t) {
CArray effect = CArray.GetAssociativeArray(t);
effect.set("id", new CInt(eff.getPotionID(), t), t);
effect.set("strength", new CInt(eff.getStrength(), t), t);
effect.set("seconds", new CInt(eff.getSecondsRemaining(), t), t);
effect.set("seconds", new CDouble(eff.getTicksRemaining() / 20.0, t), t);
effect.set("ambient", CBoolean.get(eff.isAmbient()), t);
effect.set("particles", CBoolean.get(eff.hasParticles()), t);
ea.push(effect, t);
@@ -1051,7 +1051,8 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t) {
for (String key : ea.stringKeySet()) {
if (ea.get(key, t) instanceof CArray) {
CArray effect = (CArray) ea.get(key, t);
int potionID = 0, strength = 0, seconds = 30;
int potionID = 0, strength = 0;
double seconds = 30.0;
boolean ambient = false;
boolean particles = true;
if (effect.containsKey("id")) {
@@ -1063,10 +1064,10 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t) {
strength = Static.getInt32(effect.get("strength", t), t);
}
if (effect.containsKey("seconds")) {
seconds = Static.getInt32(effect.get("seconds", t), t);
if(seconds < 0) {
seconds = Static.getDouble(effect.get("seconds", t), t);
if(seconds < 0.0) {
throw new CRERangeException("Seconds cannot be less than 0", t);
} else if(seconds > Integer.MAX_VALUE / 20) {
} else if(seconds * 20 > Integer.MAX_VALUE) {
throw new CRERangeException("Seconds cannot be greater than 107374182", t);
}
}
@@ -1076,7 +1077,7 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t) {
if (effect.containsKey("particles")) {
particles = Static.getBoolean(effect.get("particles", t));
}
ret.add(new MCLivingEntity.MCEffect(potionID, strength, seconds, ambient, particles));
ret.add(new MCLivingEntity.MCEffect(potionID, strength, (int)(seconds * 20), ambient, particles));
} else {
throw new CREFormatException("Expected a potion array at index" + key, t);
}
@@ -823,7 +823,7 @@ public String getName() {
@Override
public String docs() {
return "boolean {entityId, potionID, strength, [seconds], [ambient], [particles]} Effect is 1-23. Seconds"
+ " defaults to 30. If the potionID is out of range, a RangeException is thrown, because out of"
+ " defaults to 30.0. If the potionID is out of range, a RangeException is thrown, because out of"
+ " range potion effects cause the client to crash, fairly hardcore. See"
+ " http://www.minecraftwiki.net/wiki/Potion_effects for a complete list of potions that can be"
+ " added. To remove an effect, set the seconds to 0. If seconds is less than 0 or greater than"
@@ -848,15 +848,15 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
int effect = Static.getInt32(args[1], t);
int strength = Static.getInt32(args[2], t);
int seconds = 30;
double seconds = 30.0;
boolean ambient = false;
boolean particles = true;
if (args.length >= 4) {
seconds = Static.getInt32(args[3], t);
if(seconds < 0) {
throw new CRERangeException("Seconds cannot be less than 0", t);
} else if(seconds > Integer.MAX_VALUE / 20) {
throw new CRERangeException("Seconds cannot be greater than 107374182", t);
seconds = Static.getDouble(args[3], t);
if(seconds < 0.0) {
throw new CRERangeException("Seconds cannot be less than 0.0", t);
} else if(seconds * 20 > Integer.MAX_VALUE) {
throw new CRERangeException("Seconds cannot be greater than 107374182.0", t);
}
}
if (args.length == 5) {
@@ -866,10 +866,10 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
particles = Static.getBoolean(args[5]);
}
if (seconds == 0) {
if (seconds == 0.0) {
return CBoolean.get(mob.removeEffect(effect));
} else {
mob.addEffect(effect, strength, seconds, ambient, particles, t);
mob.addEffect(effect, strength, (int)(seconds * 20), ambient, particles, t);
return CBoolean.TRUE;
}
}
@@ -2110,8 +2110,8 @@ public String getName() {
@Override
public String docs() {
return "boolean {player, potionID, strength, [seconds], [ambient], [particles]} Effect is 1-23."
+ " Seconds defaults to 30. If the potionID is out of range, a RangeException is thrown, because out"
+ " of range potion effects cause the client to crash, fairly hardcore. See"
+ " Seconds defaults to 30.0. If the potionID is out of range, a RangeException is thrown, because"
+ " out of range potion effects cause the client to crash, fairly hardcore. See"
+ " http://www.minecraftwiki.net/wiki/Potion_effects for a complete list of potions that can be"
+ " added. To remove an effect, set the seconds to 0. Strength is the number of levels to add to the"
+ " base power (effect level 1). Ambient takes a boolean of whether the particles should be less"
@@ -2155,15 +2155,15 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
}
int strength = Static.getInt32(args[2], t);
int seconds = 30;
double seconds = 30.0;
boolean ambient = false;
boolean particles = true;
if (args.length >= 4) {
seconds = Static.getInt32(args[3], t);
if(seconds < 0) {
throw new CRERangeException("Seconds cannot be less than 0", t);
} else if(seconds > Integer.MAX_VALUE / 20) {
throw new CRERangeException("Seconds cannot be greater than 107374182", t);
seconds = Static.getDouble(args[3], t);
if(seconds < 0.0) {
throw new CRERangeException("Seconds cannot be less than 0.0", t);
} else if(seconds * 20 > Integer.MAX_VALUE) {
throw new CRERangeException("Seconds cannot be greater than 107374182.0", t);
}
}
if (args.length >= 5) {
@@ -2173,10 +2173,10 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
particles = Static.getBoolean(args[5]);
}
Static.AssertPlayerNonNull(m, t);
if (seconds == 0) {
if (seconds == 0.0) {
return CBoolean.get(m.removeEffect(effect));
} else {
m.addEffect(effect, strength, seconds, ambient, particles, t);
m.addEffect(effect, strength, (int)(seconds * 20), ambient, particles, t);
return CBoolean.TRUE;
}
}

0 comments on commit cc35441

Please sign in to comment.