SteamWar/FightSystem
Archiviert
13
1

Improve Tracking

Dieser Commit ist enthalten in:
Chaoscaot 2020-12-30 17:11:02 +01:00
Ursprung 6d9a8683db
Commit 7b055a37be

Datei anzeigen

@ -37,7 +37,7 @@ public class ArrowStopper extends BasicListener {
private BukkitTask task;
private static final Vector NULL_VECTOR = new Vector(0, 0, 0);
private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
public ArrowStopper() {
super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class));
}
@ -74,28 +74,20 @@ public class ArrowStopper extends BasicListener {
private boolean checkBlocks(Block start, Block end) {
Block cursor = start;
while (cursor.getY() != end.getY()) {
boolean negativ = cursor.getY() - end.getY() < 0;
BlockFace face = negativ?BlockFace.UP:BlockFace.DOWN;
while (!cursor.getLocation().equals(end.getLocation())) {
BlockFace nearest = BlockFace.SELF;
double nearestDistance = cursor.getLocation().distance(end.getLocation());
for (BlockFace face : BLOCK_FACES) {
Block relative = cursor.getRelative(face);
double distance = relative.getLocation().distance(end.getLocation());
if(distance < nearestDistance) {
nearestDistance = distance;
nearest = face;
}
}
cursor = cursor.getRelative(nearest);
if(checkBlock(cursor))
return true;
cursor = cursor.getRelative(face);
}
while (cursor.getX() != end.getX()) {
boolean negativ = cursor.getX() - end.getX() < 0;
BlockFace face = negativ?BlockFace.EAST:BlockFace.WEST;
if(checkBlock(cursor))
return true;
cursor = cursor.getRelative(face);
}
while (cursor.getZ() != end.getZ()) {
boolean negativ = cursor.getZ() - end.getZ() < 0;
BlockFace face = negativ?BlockFace.SOUTH:BlockFace.NORTH;
if(checkBlock(cursor))
return true;
cursor = cursor.getRelative(face);
}
return false;