Skip to content

Instantly share code, notes, and snippets.

@Densyakun
Created June 5, 2017 18:32
Show Gist options
  • Save Densyakun/e513e84c86cff2d8c2e12f74fa20e65f to your computer and use it in GitHub Desktop.
Save Densyakun/e513e84c86cff2d8c2e12f74fa20e65f to your computer and use it in GitHub Desktop.
Minecraftのベクトルの方向を方角に変換します。
package io.github.densyakun.bukkit.automine;
public enum Direction {
zero, left, right, down, up, back, forward;
public static Direction getDirection(double x, double y, double z) {
if (x < y) {
if (y < -x) {
if (-x < z) {
return forward;
} else if (-x < -z) {
return back;
} else {
return left;
}
} else {
if (y < z) {
return forward;
} else if (y < -z) {
return back;
} else {
return up;
}
}
} else if (x == 0 && y == 0) {
return zero;
} else {
if (-y < x) {
if (x < z) {
return forward;
} else if (x < -z) {
return back;
} else {
return right;
}
} else {
if (-y < z) {
return forward;
} else if (-y < -z) {
return back;
} else {
return down;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment