11package de .clientapi .airswap ;
22
3-
43import com .projectkorra .projectkorra .ProjectKorra ;
54import com .projectkorra .projectkorra .ability .AddonAbility ;
65import com .projectkorra .projectkorra .ability .ComboAbility ;
1413import org .bukkit .entity .Player ;
1514import org .bukkit .scheduler .BukkitRunnable ;
1615import org .bukkit .util .Vector ;
17- import org .bukkit .util .RayTraceResult ;
1816
1917import java .util .ArrayList ;
2018
2119public class AirSwap extends AirAbility implements ComboAbility , AddonAbility {
2220 private long cooldown ;
2321 private Location origin ;
2422 private Location targetLocation ;
25- private Vector direction ;
2623 private boolean swapped ;
2724 private LivingEntity target ;
2825 private double swapRange ;
@@ -81,7 +78,6 @@ public void progress() {
8178 target = getTargetEntity (player , swapRange );
8279 if (target != null ) {
8380 targetLocation = target .getLocation ();
84- direction = targetLocation .toVector ().subtract (player .getLocation ().toVector ()).normalize ().multiply (0.5 );
8581 ParticleEffect .CLOUD .display (player .getLocation (), 10 , 0.5 , 0.5 , 0.5 , 0.05 );
8682 ParticleEffect .CLOUD .display (targetLocation , 10 , 0.5 , 0.5 , 0.5 , 0.05 );
8783
@@ -95,7 +91,6 @@ public void run() {
9591 } else {
9692 new BukkitRunnable () {
9793 public void run () {
98- //player.setVelocity(new Vector(0, 1, 0));
9994 ParticleEffect .CLOUD .display (player .getLocation (), 10 , 0.5 , 0.5 , 0.5 , 0.05 );
10095 }
10196 }.runTaskLater (ProjectKorra .plugin , 5L );
@@ -114,7 +109,6 @@ private LivingEntity getTargetEntity(Player player, double range) {
114109 LivingEntity closestEntity = null ;
115110 double closestDistance = tolerance ;
116111
117-
118112 for (double i = 0 ; i <= range ; i += 0.5 ) { // Check all 0.5 blocks for an entity
119113 Location currentLocation = eyeLocation .clone ().add (direction .clone ().multiply (i ));
120114
@@ -141,10 +135,9 @@ private LivingEntity getTargetEntity(Player player, double range) {
141135 return closestEntity ;
142136 }
143137
144-
145138 private void pushUpward () {
146139 player .setVelocity (new Vector (0 , 0.5 , 0 ));
147- target .setVelocity (new Vector (0 , 0.53 , 0 )); // feels better
140+ target .setVelocity (new Vector (0 , 0.53 , 0 )); // Small boost upward
148141
149142 new BukkitRunnable () {
150143 @ Override
@@ -154,13 +147,12 @@ public void run() {
154147 }.runTaskLater (ProjectKorra .plugin , 8L );
155148 }
156149
157- // funny ellipse
158- private double elipfactor (double factor , double x ){
159- return factor *( x * x - x )+ 1 ;
150+ // Thanks @turpo2098 for fixxing my horrendous math
151+ private double elipfactor (double factor , double x ) {
152+ return factor * ( x * x - x ) + 1 ;
160153 }
161154
162-
163- // thanks to @turpo2098 for fixxing my horrendous math
155+ // Rotation matrix by @turpo2098
164156 private Vector rMatrix (double angle , Vector vector ) {
165157 double cos = Math .cos (angle );
166158 double sin = Math .sin (angle );
@@ -174,11 +166,10 @@ private void swapPositions() {
174166 Location playerLocation = player .getLocation ();
175167 Location targetLocation = target .getLocation ();
176168
177-
178-
179169 new BukkitRunnable () {
180170 private int ticks = 0 ;
181171 private final int duration = 20 ;
172+ private final int decelerationDuration = 16 ; // smooth out longer
182173 private final Vector playerStart = playerLocation .toVector ();
183174 private final Vector targetStart = targetLocation .toVector ();
184175 private final Vector playerEnd = targetStart .clone ();
@@ -189,8 +180,18 @@ public void run() {
189180 ticks ++;
190181 double progress = (double ) ticks / duration ;
191182 if (progress >= 1.2 ) { // feels better
192- cancel ();
193- remove ();
183+ if (ticks >= duration + decelerationDuration ) {
184+ cancel ();
185+ player .setVelocity (new Vector (0 , player .getVelocity ().getY (), 0 ));
186+ target .setVelocity (new Vector (0 , target .getVelocity ().getY (), 0 ));
187+ remove ();
188+ } else {
189+ double decelerationProgress = (double ) (ticks - duration ) / decelerationDuration ;
190+ Vector playerVelocity = player .getVelocity ().multiply (1 - decelerationProgress );
191+ Vector targetVelocity = target .getVelocity ().multiply (1 - decelerationProgress );
192+ player .setVelocity (new Vector (playerVelocity .getX (), player .getVelocity ().getY (), playerVelocity .getZ ()));
193+ target .setVelocity (new Vector (targetVelocity .getX (), target .getVelocity ().getY (), targetVelocity .getZ ()));
194+ }
194195 } else {
195196 double angle = progress * Math .PI ;
196197 double factor = elipfactor (2 , progress );
@@ -199,11 +200,12 @@ public void run() {
199200
200201 Vector playerCurrent = rMatrix (angle , U .clone ().multiply (-1 )).multiply (factor ).add (C );
201202 Vector targetCurrent = rMatrix (angle , U ).multiply (factor ).add (C );
202- Vector playerVelocity = playerCurrent .subtract (player .getLocation ().toVector ()).multiply (swapSpeedMultiplier ); // changes the speed of the swap
203- Vector targetVelocity = targetCurrent .subtract (target .getLocation ().toVector ()).multiply (swapSpeedMultiplier ); // changes the speed of the swap
203+ Vector playerVelocity = playerCurrent .subtract (player .getLocation ().toVector ()).multiply (swapSpeedMultiplier );
204+ Vector targetVelocity = targetCurrent .subtract (target .getLocation ().toVector ()).multiply (swapSpeedMultiplier );
204205
205206 player .setVelocity (playerVelocity );
206207 target .setVelocity (targetVelocity );
208+
207209 ParticleEffect .SWEEP_ATTACK .display (player .getLocation (), 1 , 0.1 , 0.1 , 0.1 , 0.01 );
208210 ParticleEffect .SWEEP_ATTACK .display (target .getLocation (), 1 , 0.1 , 0.1 , 0.1 , 0.01 );
209211 }
@@ -219,17 +221,17 @@ public String getAuthor() {
219221
220222 @ Override
221223 public String getDescription () {
222- return "AirSwap allows the bender to swap positions with a target" ;
224+ return "AirSwap allows the bender to swap positions with a target. " ;
223225 }
224226
225227 @ Override
226228 public String getInstructions () {
227- return "AirShield (Hold Sneak) > AirBlast (Left-Click) > AirSuction ( Release Sneak) " ;
229+ return "Hold AirShield (Sneak), Click AirBlast (Left-Click), Release Sneak to activate AirSuction. " ;
228230 }
229231
230232 @ Override
231233 public String getVersion () {
232- return "0.4 " ;
234+ return "0.6 " ;
233235 }
234236
235237 @ Override
@@ -241,7 +243,6 @@ public void load() {
241243 ConfigManager .defaultConfig .save ();
242244 }
243245
244-
245246 @ Override
246247 public void stop () {
247248 remove ();
@@ -257,7 +258,7 @@ public ArrayList<ComboManager.AbilityInformation> getCombination() {
257258 ArrayList <ComboManager .AbilityInformation > combo = new ArrayList <>();
258259 combo .add (new ComboManager .AbilityInformation ("AirShield" , ClickType .SHIFT_DOWN ));
259260 combo .add (new ComboManager .AbilityInformation ("AirBlast" , ClickType .LEFT_CLICK ));
260- combo .add (new ComboManager .AbilityInformation ("AirSuction" , ClickType .SHIFT_UP ));
261+ combo .add (new ComboManager .AbilityInformation ("AirSuction" , ClickType .SHIFT_UP )); // Tap Sneak for AirSuction
261262 return combo ;
262263 }
263- }
264+ }
0 commit comments