Optimize ArrowStopper
Dieser Commit ist enthalten in:
Ursprung
7b2d61eac6
Commit
988f392c4e
|
@ -61,18 +61,23 @@ public class ArrowStopper {
|
|||
|
||||
private boolean checkBlocks(Block start, Block end) {
|
||||
Block cursor = start;
|
||||
BlockFace from = BlockFace.SELF;
|
||||
|
||||
while (!cursor.getLocation().equals(end.getLocation())) {
|
||||
BlockFace nearest = BlockFace.SELF;
|
||||
double nearestDistance = cursor.getLocation().distance(end.getLocation());
|
||||
double nearestDistance = getSquareDistance(cursor.getLocation(), end.getLocation());
|
||||
for (BlockFace face : BLOCK_FACES) {
|
||||
if(face == from) {
|
||||
continue;
|
||||
}
|
||||
Block relative = cursor.getRelative(face);
|
||||
double distance = relative.getLocation().distance(end.getLocation());
|
||||
double distance = getSquareDistance(relative.getLocation(), end.getLocation());
|
||||
if(distance < nearestDistance) {
|
||||
nearestDistance = distance;
|
||||
nearest = face;
|
||||
}
|
||||
}
|
||||
from = nearest;
|
||||
cursor = cursor.getRelative(nearest);
|
||||
if(checkBlock(cursor))
|
||||
return true;
|
||||
|
@ -81,6 +86,10 @@ public class ArrowStopper {
|
|||
return false;
|
||||
}
|
||||
|
||||
private double getSquareDistance(Location loc1, Location loc2) {
|
||||
return loc1.getX() * loc2.getX() + loc1.getY() * loc2.getY() + loc1.getZ() * loc2.getZ();
|
||||
}
|
||||
|
||||
private boolean checkBlock(Block block) {
|
||||
return Config.HiddenBlocks.contains(block.getType().name().toLowerCase());
|
||||
}
|
||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren