55import me .eccentric_nz .TARDIS .enumeration .TardisModule ;
66import me .eccentric_nz .TARDIS .flight .vehicle .InterpolatedAnimation ;
77import me .eccentric_nz .TARDIS .flight .vehicle .VehicleUtility ;
8- import me .eccentric_nz .TARDIS .sonic .actions .TARDISSonicFreeze ;
9- import me .eccentric_nz .TARDIS .utility .TARDISVector3D ;
108import org .bukkit .Location ;
119import org .bukkit .Material ;
1210import org .bukkit .entity .*;
1311import org .bukkit .inventory .ItemStack ;
1412import org .bukkit .inventory .meta .ItemMeta ;
13+ import org .bukkit .util .RayTraceResult ;
1514
1615public class MountCommand {
1716
@@ -25,34 +24,22 @@ public boolean test(Player player, boolean mount) {
2524 if (mount ) {
2625 // get the armour stand the player is looking at
2726 Location observerPos = player .getEyeLocation ();
28- TARDISVector3D observerDir = new TARDISVector3D (observerPos .getDirection ());
29- TARDISVector3D observerStart = new TARDISVector3D (observerPos );
30- TARDISVector3D observerEnd = observerStart .add (observerDir .multiply (16 ));
31- ArmorStand as = null ;
32- // Get nearby entities
33- for (Entity target : player .getNearbyEntities (8.0d , 8.0d , 8.0d )) {
34- // Bounding box of the given player
35- TARDISVector3D targetPos = new TARDISVector3D (target .getLocation ());
36- TARDISVector3D minimum = targetPos .add (-0.5 , 0 , -0.5 );
37- TARDISVector3D maximum = targetPos .add (0.5 , 1.67 , 0.5 );
38- if (target .getType ().equals (EntityType .ARMOR_STAND ) && TARDISSonicFreeze .hasIntersection (observerStart , observerEnd , minimum , maximum )) {
39- if (as == null || as .getLocation ().distanceSquared (observerPos ) > target .getLocation ().distanceSquared (observerPos )) {
40- as = (ArmorStand ) target ;
41- }
42- }
43- }
44- if (as == null ) {
27+ RayTraceResult result = observerPos .getWorld ().rayTraceEntities (observerPos , observerPos .getDirection (), 16.0d , (s ) -> s .getType () == EntityType .ARMOR_STAND );
28+ if (result == null ) {
4529 plugin .getMessenger ().send (player , TardisModule .TARDIS , "WA_STAND" );
4630 return true ;
4731 }
48- ItemStack box = ItemStack .of (Material .BLUE_DYE , 1 );
49- ItemMeta im = box .getItemMeta ();
50- im .setItemModel (ChameleonVariant .BLUE_CLOSED .getKey ());
51- box .setItemMeta (im );
52- ItemDisplay display = VehicleUtility .getItemDisplay (player , box , 1.75f );
53- int period = 40 ;
54- plugin .getTrackerKeeper ().setAnimateTask (plugin .getServer ().getScheduler ().scheduleSyncRepeatingTask (plugin , new InterpolatedAnimation (display , period ), 5 , period ));
55- as .addPassenger (player );
32+ ArmorStand as = (ArmorStand ) result .getHitEntity ();
33+ if (as != null ) {
34+ ItemStack box = ItemStack .of (Material .BLUE_DYE , 1 );
35+ ItemMeta im = box .getItemMeta ();
36+ im .setItemModel (ChameleonVariant .BLUE_CLOSED .getKey ());
37+ box .setItemMeta (im );
38+ ItemDisplay display = VehicleUtility .getItemDisplay (player , box , 1.75f );
39+ int period = 40 ;
40+ plugin .getTrackerKeeper ().setAnimateTask (plugin .getServer ().getScheduler ().scheduleSyncRepeatingTask (plugin , new InterpolatedAnimation (display , period ), 5 , period ));
41+ as .addPassenger (player );
42+ }
5643 } else {
5744 // unmount
5845 for (Entity e : player .getPassengers ()) {
0 commit comments