Skip to content

Commit d821ebf

Browse files
ShinyDeagleTheComputerGeek2
authored andcommitted
Force, Leap, Velocity spells can add velocity instead of set.
Spells affected: Forcepush, ForceToss, ForceBomb, Leap, Velocity. All these spells have an add-velocity-instead option that adds that force to the target instead of setting it. If I had 3 velocity to the right and I add 2 to the left. I will move slower. Perfect for black-hole or gravity spells. This option is false by default.
1 parent e94680d commit d821ebf

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ForcepushSpell extends InstantSpell {
1919
private int force;
2020
private int yForce;
2121
private int maxYForce;
22+
private boolean addVelocityInstead;
2223

2324
public ForcepushSpell(MagicConfig config, String spellName) {
2425
super(config, spellName);
@@ -27,6 +28,7 @@ public ForcepushSpell(MagicConfig config, String spellName) {
2728
this.force = getConfigInt("pushback-force", 30);
2829
this.yForce = getConfigInt("additional-vertical-force", 15);
2930
this.maxYForce = getConfigInt("max-vertical-force", 20);
31+
this.addVelocityInstead = getConfigBoolean("add-velocity-instead", false);
3032
}
3133

3234
@Override
@@ -64,7 +66,8 @@ public void knockback(Player player, int castingRange, float basePower) {
6466
v.setY(this.yForce/10.0 * power);
6567
}
6668
if (v.getY() > (this.maxYForce/10.0)) v.setY(this.maxYForce/10.0);
67-
target.setVelocity(v);
69+
if (!addVelocityInstead) target.setVelocity(v);
70+
else target.setVelocity(target.getVelocity().add(v));
6871
playSpellEffects(EffectPosition.TARGET, target);
6972
}
7073
playSpellEffects(EffectPosition.CASTER, player);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class LeapSpell extends InstantSpell {
2020
private float rotation;
2121
private double forwardVelocity;
2222
private double upwardVelocity;
23+
private boolean addVelocityInstead;
2324
private boolean cancelDamage;
2425
private boolean clientOnly;
2526
private Subspell landSpell;
@@ -35,6 +36,7 @@ public LeapSpell(MagicConfig config, String spellName) {
3536
this.rotation = getConfigFloat("rotation", 0F);
3637
this.forwardVelocity = getConfigInt("forward-velocity", 40) / 10D;
3738
this.upwardVelocity = getConfigInt("upward-velocity", 15) / 10D;
39+
this.addVelocityInstead = getConfigBoolean("add-velocity-instead", false);
3840
this.cancelDamage = getConfigBoolean("cancel-damage", true);
3941
this.clientOnly = getConfigBoolean("client-only", false);
4042
this.landSpellName = getConfigString("land-spell", "");
@@ -64,7 +66,8 @@ public PostCastAction castSpell(Player player, SpellCastState state, float power
6466
if (clientOnly) {
6567
MagicSpells.getVolatileCodeHandler().setClientVelocity(player, v);
6668
} else {
67-
player.setVelocity(v);
69+
if (!addVelocityInstead) player.setVelocity(v);
70+
else player.setVelocity(player.getVelocity().add(v));
6871
}
6972
jumping.add(player);
7073
playSpellEffects(EffectPosition.CASTER, player);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
public class VelocitySpell extends InstantSpell {
1313

1414
private double speed;
15+
private boolean addVelocityInstead;
1516

1617
public VelocitySpell(MagicConfig config, String spellName) {
1718
super(config, spellName);
1819

1920
this.speed = getConfigDouble("speed", 4.0);
21+
this.addVelocityInstead = getConfigBoolean("add-velocity-instead", false);
2022
}
2123

2224
@Override
@@ -25,7 +27,8 @@ public PostCastAction castSpell(Player player, SpellCastState state, float power
2527
Vector v = player.getEyeLocation().getDirection();
2628
v = v.normalize();
2729
v = v.multiply(speed * power);
28-
player.setVelocity(v);
30+
if (!addVelocityInstead) player.setVelocity(v);
31+
else player.setVelocity(player.getVelocity().add(v));
2932
playSpellEffects(EffectPosition.CASTER, player);
3033
}
3134

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ForcebombSpell extends TargetedSpell implements TargetedLocationSpe
2525
private int force;
2626
private int yForce;
2727
private int maxYForce;
28+
private boolean addVelocityInstead;
2829
private boolean callTargetEvents;
2930

3031
public ForcebombSpell(MagicConfig config, String spellName) {
@@ -36,6 +37,7 @@ public ForcebombSpell(MagicConfig config, String spellName) {
3637
force = getConfigInt("pushback-force", 30);
3738
yForce = getConfigInt("additional-vertical-force", 15);
3839
maxYForce = getConfigInt("max-vertical-force", 20);
40+
addVelocityInstead = getConfigBoolean("add-velocity-instead", false);
3941
callTargetEvents = getConfigBoolean("call-target-events", false);
4042
}
4143

@@ -97,7 +99,8 @@ public void knockback(Player player, Location location, float basePower) {
9799
v.setY(yForce/10.0 * power);
98100
}
99101
if (v.getY() > maxYForce/10.0) v.setY(maxYForce/10.0);
100-
entity.setVelocity(v);
102+
if (!addVelocityInstead) entity.setVelocity(v);
103+
else entity.setVelocity(entity.getVelocity().add(v));
101104
playSpellEffects(EffectPosition.TARGET, entity);
102105
}
103106
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ForcetossSpell extends TargetedSpell implements TargetedEntitySpell
2121
private float rotation;
2222
private boolean checkPlugins;
2323
private boolean powerAffectsForce;
24+
private boolean addVelocityInstead;
2425
private boolean avoidDamageModification;
2526

2627
public ForcetossSpell(MagicConfig config, String spellName) {
@@ -32,6 +33,7 @@ public ForcetossSpell(MagicConfig config, String spellName) {
3233
rotation = getConfigFloat("rotation", 0);
3334
checkPlugins = getConfigBoolean("check-plugins", true);
3435
powerAffectsForce = getConfigBoolean("power-affects-force", true);
36+
addVelocityInstead = getConfigBoolean("add-velocity-instead", false);
3537
avoidDamageModification = getConfigBoolean("avoid-damage-modification", false);
3638
}
3739

@@ -74,7 +76,8 @@ private void toss(Player player, LivingEntity target, float power) {
7476
if (v == null) throw new NullPointerException("v");
7577
v.setY(0).normalize().multiply(hForce * power).setY(vForce * power);
7678
if (rotation != 0) Util.rotateVector(v, rotation);
77-
target.setVelocity(v);
79+
if (!addVelocityInstead) target.setVelocity(v);
80+
else target.setVelocity(target.getVelocity().add(v));
7881
playSpellEffects(player, target);
7982
}
8083

0 commit comments

Comments
 (0)