Skip to content

Commit 29fdeee

Browse files
committed
Fixed #71
1 parent 2f89af4 commit 29fdeee

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/main/java/com/xxmicloxx/NoteBlockAPI/NoteBlockAPI.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ public void run() {
200200
}
201201
}
202202
}, 20*10, 20 * 60 * 60 * 24);
203-
204-
new MathUtils();
205203
}
206204

207205
@Override

src/main/java/com/xxmicloxx/NoteBlockAPI/utils/MathUtils.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,31 @@
44

55
public class MathUtils {
66

7-
private static MathUtils instance;
8-
private double[] cos = new double[360];
9-
private double[] sin = new double[360];
10-
11-
public MathUtils(){
12-
instance = this;
7+
private static double[] cos = new double[360];
8+
private static double[] sin = new double[360];
9+
10+
static {
1311
for (int deg = 0; deg < 360; deg++) {
14-
cos[deg] = Math.cos(Math.toRadians(deg));
15-
sin[deg] = Math.sin(Math.toRadians(deg));
12+
cos[deg] = Math.cos(Math.toRadians(deg));
13+
sin[deg] = Math.sin(Math.toRadians(deg));
1614
}
1715
}
1816

1917
private static double[] getCos(){
20-
return MathUtils.instance.cos;
18+
return cos;
2119
}
2220

2321
private static double[] getSin(){
24-
return MathUtils.instance.sin;
22+
return sin;
2523
}
2624

2725
public static Location stereoSourceLeft(Location location, float distance) {
28-
float yaw = location.getYaw();
29-
return location.clone().add(-getCos()[(int) (yaw + 360) % 360] * distance, 0, -getSin()[(int) (yaw + 360) % 360] * distance);
26+
int angle = getAngle(location.getYaw());
27+
return location.clone().add(-getCos()[angle] * distance, 0, -getSin()[angle] * distance);
3028
}
3129
public static Location stereoSourceRight(Location location, float distance) {
32-
float yaw = location.getYaw();
33-
return location.clone().add(getCos()[(int) (yaw + 360) % 360] * distance, 0, getSin()[(int) (yaw + 360) % 360] * distance);
30+
int angle = getAngle(location.getYaw());
31+
return location.clone().add(getCos()[angle] * distance, 0, getSin()[angle] * distance);
3432
}
3533

3634
/**
@@ -40,8 +38,14 @@ public static Location stereoSourceRight(Location location, float distance) {
4038
* @return
4139
*/
4240
public static Location stereoPan(Location location, float distance){
43-
float yaw = location.getYaw();
44-
return location.clone().add( getCos()[(int) (yaw + 360) % 360] * distance, 0, getSin()[(int) (yaw + 360) % 360] * distance);
41+
int angle = getAngle(location.getYaw());
42+
return location.clone().add( getCos()[angle] * distance, 0, getSin()[angle] * distance);
43+
}
44+
45+
private static int getAngle(float yaw){
46+
int angle = (int) yaw;
47+
while (angle < 0) angle += 360;
48+
return angle % 360;
4549
}
4650

4751
}

0 commit comments

Comments
 (0)