Skip to content

Commit

Permalink
Add "icon" parameter to potion effects (and fix missing "particles" k…
Browse files Browse the repository at this point in the history
…ey in potion meta)
  • Loading branch information
PseudoKnight committed Aug 5, 2018
1 parent 26b2c61 commit ff30bd0
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 30 deletions.
18 changes: 17 additions & 1 deletion src/main/java/com/laytonsmith/abstraction/MCLivingEntity.java
Expand Up @@ -8,7 +8,7 @@

public interface MCLivingEntity extends MCEntity, MCProjectileSource {

void addEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, Target t);
void addEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, boolean icon);

boolean removeEffect(int potionID);

Expand Down Expand Up @@ -118,13 +118,15 @@ class MCEffect {
private int ticksRemaining;
private boolean ambient;
private boolean particles;
private boolean icon;

public MCEffect(int potionID, int strength, int ticks, boolean ambient) {
this.potionID = potionID;
this.strength = strength;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = true;
this.icon = true;
}

public MCEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles) {
Expand All @@ -133,6 +135,16 @@ public MCEffect(int potionID, int strength, int ticks, boolean ambient, boolean
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = particles;
this.icon = particles;
}

public MCEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
this.potionID = potionID;
this.strength = strength;
this.ticksRemaining = ticks;
this.ambient = ambient;
this.particles = particles;
this.icon = icon;
}

public int getPotionID() {
Expand All @@ -154,5 +166,9 @@ public boolean isAmbient() {
public boolean hasParticles() {
return particles;
}

public boolean showIcon() {
return icon;
}
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/laytonsmith/abstraction/MCPotionMeta.java
Expand Up @@ -10,7 +10,7 @@ public interface MCPotionMeta extends MCItemMeta {

void setBasePotionData(MCPotionData pd);

boolean addCustomEffect(int potionID, int strength, int ticks, boolean ambient, boolean overwrite, Target t);
boolean addCustomEffect(int id, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t);

boolean clearCustomEffects();

Expand All @@ -21,6 +21,4 @@ public interface MCPotionMeta extends MCItemMeta {
boolean hasCustomEffects();

boolean removeCustomEffect(int id);

boolean setMainEffect(int id);
}
Expand Up @@ -33,13 +33,13 @@ public void setBasePotionData(MCPotionData bpd) {
}

@Override
public boolean addCustomEffect(int potionID, int strength, int ticks, boolean ambient, boolean overwrite, Target t) {
public boolean addCustomEffect(int id, int strength, int ticks, boolean ambient, boolean particles, boolean icon, boolean force, Target t) {
int maxID = PotionEffectType.values().length;
if(potionID < 1 || potionID > maxID) {
if(id < 1 || id > maxID) {
throw new CRERangeException("Invalid effect ID, must be from 1-" + maxID, t);
}
PotionEffect pe = new PotionEffect(PotionEffectType.getById(potionID), ticks, strength, ambient);
return pm.addCustomEffect(pe, overwrite);
PotionEffect pe = new PotionEffect(PotionEffectType.getById(id), ticks, strength, ambient, particles, icon);
return pm.addCustomEffect(pe, force);
}

@Override
Expand All @@ -51,7 +51,8 @@ public boolean clearCustomEffects() {
public List<MCEffect> getCustomEffects() {
List<MCEffect> list = new ArrayList<>();
for(PotionEffect pe : pm.getCustomEffects()) {
list.add(new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient()));
list.add(new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(),
pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
}
return list;
}
Expand Down
Expand Up @@ -47,7 +47,7 @@ public List<MCLivingEntity.MCEffect> getCustomEffects() {
List<MCLivingEntity.MCEffect> list = new ArrayList<>();
for(PotionEffect pe : aec.getCustomEffects()) {
list.add(new MCLivingEntity.MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration(), pe.isAmbient(), pe.hasParticles()));
pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
}
return list;
}
Expand Down Expand Up @@ -103,8 +103,9 @@ public int getWaitTime() {

@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect) {
PotionEffect pe = new PotionEffect(PotionEffectType.getById(effect.getPotionID()),
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles());
PotionEffectType type = PotionEffectType.getById(effect.getPotionID());
PotionEffect pe = new PotionEffect(type, effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(),
effect.hasParticles(), effect.showIcon());
aec.addCustomEffect(pe, true);
}

Expand Down
Expand Up @@ -184,8 +184,9 @@ public boolean hasAI() {
}

@Override
public void addEffect(int potionID, int strength, int ticks, boolean ambient, boolean particles, Target t) {
PotionEffect pe = new PotionEffect(PotionEffectType.getById(potionID), ticks, strength, ambient, particles);
public void addEffect(int id, int strength, int ticks, boolean ambient, boolean particles, boolean icon) {
PotionEffectType type = PotionEffectType.getById(id);
PotionEffect pe = new PotionEffect(type, ticks, strength, ambient, particles, icon);
le.addPotionEffect(pe, true);
}

Expand Down Expand Up @@ -219,7 +220,8 @@ public void removeEffects() {
public List<MCEffect> getEffects() {
List<MCEffect> effects = new ArrayList<>();
for(PotionEffect pe : le.getActivePotionEffects()) {
MCEffect e = new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient(), pe.hasParticles());
MCEffect e = new MCEffect(pe.getType().getId(), pe.getAmplifier(), pe.getDuration(), pe.isAmbient(),
pe.hasParticles(), pe.hasIcon());
effects.add(e);
}
return effects;
Expand Down
Expand Up @@ -32,15 +32,16 @@ public List<MCLivingEntity.MCEffect> getCustomEffects() {
List<MCLivingEntity.MCEffect> list = new ArrayList<>();
for(PotionEffect pe : ta.getCustomEffects()) {
list.add(new MCLivingEntity.MCEffect(pe.getType().getId(), pe.getAmplifier(),
pe.getDuration(), pe.isAmbient(), pe.hasParticles()));
pe.getDuration(), pe.isAmbient(), pe.hasParticles(), pe.hasIcon()));
}
return list;
}

@Override
public void addCustomEffect(MCLivingEntity.MCEffect effect) {
PotionEffect pe = new PotionEffect(PotionEffectType.getById(effect.getPotionID()),
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles());
effect.getTicksRemaining(), effect.getStrength(), effect.isAmbient(), effect.hasParticles(),
effect.showIcon());
ta.addCustomEffect(pe, true);
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Expand Up @@ -822,7 +822,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.getTicksRemaining(), e.isAmbient(), true, t);
e.getTicksRemaining(), e.isAmbient(), e.hasParticles(), e.showIcon(), true, t);
}
} else {
throw new CREFormatException("Effects was expected to be an array of potion arrays.", t);
Expand Down Expand Up @@ -1081,6 +1081,7 @@ public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target 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);
effect.set("icon", CBoolean.get(eff.showIcon()), t);
ea.push(effect, t);
}
return ea;
Expand All @@ -1096,6 +1097,7 @@ public List<MCLivingEntity.MCEffect> potions(CArray ea, Target t) {
double seconds = 30.0;
boolean ambient = false;
boolean particles = true;
boolean icon = true;
if(effect.containsKey("id")) {
potionID = Static.getInt32(effect.get("id", t), t);
} else {
Expand All @@ -1118,7 +1120,10 @@ public List<MCLivingEntity.MCEffect> potions(CArray ea, Target t) {
if(effect.containsKey("particles")) {
particles = Static.getBoolean(effect.get("particles", t), t);
}
ret.add(new MCLivingEntity.MCEffect(potionID, strength, (int) (seconds * 20), ambient, particles));
if(effect.containsKey("icon")) {
icon = Static.getBoolean(effect.get("icon", t), t);
}
ret.add(new MCLivingEntity.MCEffect(potionID, strength, (int) (seconds * 20), ambient, particles, icon));
} else {
throw new CREFormatException("Expected a potion array at index" + key, t);
}
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/laytonsmith/core/functions/MobManagement.java
Expand Up @@ -665,15 +665,16 @@ public Integer[] numArgs() {

@Override
public String docs() {
return "boolean {entityId, potionID, strength, [seconds], [ambient], [particles]} Effect is 1-23. 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"
return "boolean {entityId, potionID, strength, [seconds], [ambient], [particles], [icon]} Effect is 1-23."
+ " 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. If seconds is less than 0 or greater than"
+ " 107374182 a RangeException is thrown. 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"
+ " noticeable. Particles takes a boolean of whether the particles should be visible at all. The"
+ " function returns true if the effect was added or removed as desired, and false if it wasn't"
+ " noticeable. Particles takes a boolean of whether the particles should be visible at all."
+ " Icon takes a boolean for whether or not to show the icon to the entity if it's a player."
+ " The function returns true if the effect was added or removed as desired, and false if it wasn't"
+ " (however, this currently only will happen if an effect is attempted to be removed, yet isn't"
+ " already on the mob).";
}
Expand All @@ -694,6 +695,7 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
double seconds = 30.0;
boolean ambient = false;
boolean particles = true;
boolean icon = true;
if(args.length >= 4) {
seconds = Static.getDouble(args[3], t);
if(seconds < 0.0) {
Expand All @@ -708,11 +710,14 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
if(args.length == 6) {
particles = Static.getBoolean(args[5], t);
}
if(args.length == 7) {
icon = Static.getBoolean(args[6], t);
}

if(seconds == 0.0) {
return CBoolean.get(mob.removeEffect(effect));
} else {
mob.addEffect(effect, strength, (int) (seconds * 20), ambient, particles, t);
mob.addEffect(effect, strength, (int) (seconds * 20), ambient, particles, icon);
return CBoolean.TRUE;
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
Expand Up @@ -2108,14 +2108,15 @@ public Integer[] numArgs() {

@Override
public String docs() {
return "boolean {player, potionID, strength, [seconds], [ambient], [particles]} Effect is 1-23."
return "boolean {player, potionID, strength, [seconds], [ambient], [particles], [icon]} Effect is 1-23."
+ " 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"
+ " noticeable. Particles takes a boolean of whether the particles should be visible at all. The"
+ " function returns true if the effect was added or removed as desired, and false if it wasn't"
+ " noticeable. Particles takes a boolean of whether the particles should be visible at all."
+ " Icon takes a boolean for whether or not to show the effect's icon on the player's screen."
+ " The function returns true if the effect was added or removed as desired, and false if it wasn't"
+ " (however, this currently only will happen if an effect is attempted to be removed, yet isn't"
+ " already on the player).";
}
Expand Down Expand Up @@ -2150,13 +2151,14 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
//otherwise the client crashes, and requires deletion of
//player data to fix.
if(effect < 1 || effect > m.getMaxEffect()) {
throw new CRERangeException("Invalid effect ID recieved, must be from 1-" + m.getMaxEffect(), t);
throw new CRERangeException("Invalid effect ID received, must be from 1-" + m.getMaxEffect(), t);
}

int strength = Static.getInt32(args[2], t);
double seconds = 30.0;
boolean ambient = false;
boolean particles = true;
boolean icon = true;
if(args.length >= 4) {
seconds = Static.getDouble(args[3], t);
if(seconds < 0.0) {
Expand All @@ -2171,11 +2173,14 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
if(args.length == 6) {
particles = Static.getBoolean(args[5], t);
}
if(args.length == 7) {
icon = Static.getBoolean(args[6], t);
}
Static.AssertPlayerNonNull(m, t);
if(seconds == 0.0) {
return CBoolean.get(m.removeEffect(effect));
} else {
m.addEffect(effect, strength, (int) (seconds * 20), ambient, particles, t);
m.addEffect(effect, strength, (int) (seconds * 20), ambient, particles, icon);
return CBoolean.TRUE;
}
}
Expand Down

0 comments on commit ff30bd0

Please sign in to comment.