 # Compass Guide[1.12.2] v1.0

Sep 2nd, 2019
632
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //Example location
2. var x=8.5;
3. var y=5;
4. var z=14.5;
5.
6. //Compass refresh delay, 0 is every tick.
7. //Be careful, it will send a lots of packet to client.
8. //Not recommended above 10
9. var ti=0;
10.
11. function timer(e){
12.     if(e.id == 61){
13.         //Record current player location
14.         var px = e.player.getX();
15.         var py = e.player.getY();
16.         var pz = e.player.getZ();
17.         //Calculate the difference in plane angle between two points
18.         var ts = Math.atan2((x-px),(z-pz))*(180/Math.PI);
19.         //Get the current orientation of the player
20.         var tr = e.player.getRotation();
21.         //Calculate the angular difference toward the bottom
22.         var tp = (tr>0?tr-360:tr) + (ts<0?ts+360:ts);
23.         if(tp<-180){
24.             tp = tp+360;
25.         }else if(tp>180){
26.             tp = tp-360;
27.         }
28.         //Building compass line text
29.         var tc = "§r[";
30.         for(var i = -10;i<10;i++){
31.             if(i==0) tc = tc + "§a|";
32.             if(((i==-10||i==9) && Math.abs(tp)>105) || (tp>((-i-1)*10-5) && tp<((-i+1)*10-5))){
33.                 tc = tc + "§e-";
34.             }else{
35.                 tc = tc + "§7-";
36.             }
37.         }
38.         //End the build and calculate the distance between the two points in the three-dimensional space and round up
39.         tc = tc + "§r] " + Math.ceil(Math.sqrt(Math.abs((x-px)*(x-px)+(y-py)*(y-py)+(z-pz)*(z-pz)))) + "m";
40.         //Output compass line text
41.         e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"" + tc + "\"}");
42.     }
43. }
44.
45. function keyPressed(e){
46.     //When player click "~" key
47.     if(e.key==41){
48.         //If it have been started
49.         if(e.player.timers.has(61)){
50.             //Stop to send and clear it
51.             e.player.timers.reset(61);
52.             e.player.timers.stop(61);
53.             e.API.executeCommand(e.player.world, "/title " + e.player.getDisplayName() + " actionbar {\"text\":\"\"}");
54.         }else{
55.             //Start to send
56.             e.player.timers.forceStart(61,ti,true);
57.         }
58.     }
59. }
RAW Paste Data