Skip to content

Commit c42ad5e

Browse files
ShinyDeagleTheComputerGeek2
authored andcommitted
Safe Upgrade from Effectlib 5.9 -> 6.x+
Temporary
1 parent d821ebf commit c42ad5e

7 files changed

Lines changed: 63 additions & 19 deletions

File tree

src/com/nisovin/magicspells/spelleffects/ParticleLineEffect.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ public void loadFromString(String string) {
2727
if (data.length >= 8) color = ColorUtil.getColorFromHexString(data[7]);
2828
}
2929
EffectPackage pkg = ParticleNameUtil.findEffectPackage(name);
30-
data = pkg.data;
31-
effect = pkg.effect;
30+
canRender = pkg.canRender();
31+
if (canRender) {
32+
data = pkg.data;
33+
effect = pkg.effect;
34+
}
3235
}
3336

3437
@Override

src/com/nisovin/magicspells/spelleffects/ParticlesEffect.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public class ParticlesEffect extends SpellEffect {
163163
Color color = null;
164164
ParticleData data = null;
165165

166+
boolean canRender;
167+
166168
@Override
167169
public void loadFromString(String string) {
168170
if (string != null && !string.isEmpty()) {
@@ -179,8 +181,11 @@ public void loadFromString(String string) {
179181
if (data.length >= 7) color = ColorUtil.getColorFromHexString(data[6]);
180182
}
181183
EffectPackage pkg = ParticleNameUtil.findEffectPackage(name);
182-
this.data = pkg.data;
183-
this.effect = pkg.effect;
184+
canRender = pkg.canRender();
185+
if (canRender) {
186+
data = pkg.data;
187+
effect = pkg.effect;
188+
}
184189
}
185190

186191
@Override
@@ -198,14 +203,17 @@ public void loadFromConfig(ConfigurationSection config) {
198203
renderDistance = config.getInt("render-distance", renderDistance);
199204
color = ColorUtil.getColorFromHexString(config.getString("color", null));
200205
EffectPackage pkg = ParticleNameUtil.findEffectPackage(name);
201-
data = pkg.data;
202-
effect = pkg.effect;
206+
canRender = pkg.canRender();
207+
if (canRender) {
208+
data = pkg.data;
209+
effect = pkg.effect;
210+
}
203211
}
204212

205213
@Override
206214
public Runnable playEffectLocation(Location location) {
207215
//ParticleData data, Location center, Color color, double range, float offsetX, float offsetY, float offsetZ, float speed, int amount
208-
effect.display(data, location.clone().add(0, yOffset, 0), color, renderDistance, xSpread, ySpread, zSpread, speed, count);
216+
if (canRender) effect.display(data, location.clone().add(0, yOffset, 0), color, renderDistance, xSpread, ySpread, zSpread, speed, count);
209217
//MagicSpells.getVolatileCodeHandler().playParticleEffect(location, name, xSpread, ySpread, zSpread, speed, count, renderDistance, yOffset);
210218
return null;
211219
}

src/com/nisovin/magicspells/spells/instant/ParticleProjectileSpell.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public class ParticleProjectileSpell extends InstantSpell implements TargetedLoc
107107
ParticleEffect effect;
108108
ParticleData data;
109109

110+
boolean canRender;
111+
110112
public ParticleProjectileSpell(MagicConfig config, String spellName) {
111113
super(config, spellName);
112114

@@ -191,8 +193,11 @@ public ParticleProjectileSpell(MagicConfig config, String spellName) {
191193
this.durationSpellName = getConfigString("spell-on-duration-end", defaultSpellName);
192194

193195
EffectPackage pkg = ParticleNameUtil.findEffectPackage(this.particleName);
194-
this.effect = pkg.effect;
195-
this.data = pkg.data;
196+
canRender = pkg.canRender();
197+
if (canRender) {
198+
data = pkg.data;
199+
effect = pkg.effect;
200+
}
196201
}
197202

198203
@Override
@@ -375,7 +380,7 @@ public void run() {
375380
if (projectileHorizGravity != 0 || projectileVertGravity != 0) this.currentLocation.setDirection(currentVelocity);
376381

377382
// Show particle
378-
effect.display(data, this.currentLocation, null, renderDistance, particleXSpread, particleYSpread, particleZSpread, particleSpeed, particleCount);
383+
if (canRender) effect.display(data, this.currentLocation, null, renderDistance, particleXSpread, particleYSpread, particleZSpread, particleSpeed, particleCount);
379384

380385
// Play effects
381386
if (specialEffectInterval > 0 && this.counter % specialEffectInterval == 0) playSpellEffects(EffectPosition.SPECIAL, this.currentLocation);

src/com/nisovin/magicspells/spells/targeted/HomingMissileSpell.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class HomingMissileSpell extends TargetedSpell implements TargetedEntityS
7474

7575
int intermediateSpecialEffects = 0;
7676

77+
boolean canRender;
78+
7779
public HomingMissileSpell(MagicConfig config, String spellName) {
7880
super(config, spellName);
7981

@@ -116,9 +118,12 @@ public HomingMissileSpell(MagicConfig config, String spellName) {
116118
intermediateSpecialEffects = getConfigInt("intermediate-special-effect-locations", 0);
117119
if (intermediateSpecialEffects < 0) intermediateSpecialEffects = 0;
118120

119-
EffectPackage pkg = ParticleNameUtil.findEffectPackage(particleName);
120-
effect = pkg.effect;
121-
data = pkg.data;
121+
EffectPackage pkg = ParticleNameUtil.findEffectPackage(this.particleName);
122+
canRender = pkg.canRender();
123+
if (canRender) {
124+
data = pkg.data;
125+
effect = pkg.effect;
126+
}
122127
}
123128

124129
@Override
@@ -336,7 +341,7 @@ private void playIntermediateEffectLocations(Location old, Vector movement) {
336341

337342
private void playMissileEffect(Location loc) {
338343
// Show particle
339-
if (useParticles) {
344+
if (useParticles && canRender) {
340345
//MagicSpells.getVolatileCodeHandler().playParticleEffect(currentLocation, particleName, particleHorizontalSpread, particleVerticalSpread, particleSpeed, particleCount, renderDistance, 0F);
341346

342347
effect.display(data, loc, null, renderDistance, particleHorizontalSpread, particleVerticalSpread, particleHorizontalSpread, particleSpeed, particleCount);

src/com/nisovin/magicspells/spells/targeted/OrbitSpell.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class OrbitSpell extends TargetedSpell implements TargetedEntitySpell {
7777
ParticleEffect effect;
7878
ParticleData data;
7979

80+
boolean canRender;
81+
8082
public OrbitSpell(MagicConfig config, String spellName) {
8183
super(config, spellName);
8284

@@ -114,9 +116,12 @@ public OrbitSpell(MagicConfig config, String spellName) {
114116
stopOnHitEntity = getConfigBoolean("stop-on-hit-entity", false);
115117
stopOnHitGround = getConfigBoolean("stop-on-hit-ground", false);
116118
//TODO add color config
117-
EffectPackage pkg = ParticleNameUtil.findEffectPackage(particleName);
118-
effect = pkg.effect;
119-
data = pkg.data;
119+
EffectPackage pkg = ParticleNameUtil.findEffectPackage(this.particleName);
120+
canRender = pkg.canRender();
121+
if (canRender) {
122+
data = pkg.data;
123+
effect = pkg.effect;
124+
}
120125

121126
groundSpellName = getConfigString("spell-on-hit-ground", "");
122127
entitySpellName = getConfigString("spell-on-hit-entity", "");
@@ -250,7 +255,7 @@ public void run() {
250255
//MagicSpells.getVolatileCodeHandler().playParticleEffect(loc, particleName, particleHorizontalSpread, particleVerticalSpread, particleSpeed, particleCount, renderDistance, 0F);
251256

252257
playSpellEffects(EffectPosition.SPECIAL, loc);
253-
effect.display(data, loc, particleColor, renderDistance, particleHorizontalSpread, particleVerticalSpread, particleHorizontalSpread, particleSpeed, particleCount);
258+
if (canRender) effect.display(data, loc, particleColor, renderDistance, particleHorizontalSpread, particleVerticalSpread, particleHorizontalSpread, particleSpeed, particleCount);
254259

255260
// Cast the spell at the location if it isn't null
256261
if (orbitSpell != null) orbitSpell.castAtLocation(caster, loc, power);

src/com/nisovin/magicspells/util/EffectPackage.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ public class EffectPackage {
77

88
public ParticleEffect effect;
99
public ParticleData data;
10-
10+
11+
/**
12+
* Whether or not the particle effect should be rendered
13+
*/
14+
public boolean render;
15+
16+
/**
17+
* An empty effect package with render set to false.
18+
*/
19+
public EffectPackage() {
20+
this.render = false;
21+
}
22+
1123
public EffectPackage(ParticleEffect effect, ParticleData data) {
1224
this.effect = effect;
1325
this.data = data;
26+
this.render = true;
27+
}
28+
29+
public boolean canRender() {
30+
return this.render;
1431
}
1532

1633
}

src/com/nisovin/magicspells/util/ParticleNameUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static EffectPackage findEffectPackage(String name) {
2222
ParticleData data = null;
2323
ParticleEffect effect = null;
2424
String[] splits = name.split("_");
25+
if (splits[0].equalsIgnoreCase("take")) return new EffectPackage();
2526
effect = ParticleEffect.fromName(splits[0]);
2627

2728
if (splits.length > 1) {

0 commit comments

Comments
 (0)