SteamWar/FightSystem
Archiviert
13
1

Arrows Stopping in Techhider Blocks #208

Manuell gemergt
Lixfel hat 17 Commits von arrow-in-techhider nach master 2021-01-02 09:20:42 +01:00 zusammengeführt
Nur Änderungen aus Commit 7b055a37be werden angezeigt - Alle Commits anzeigen

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) {
Review

Ok, wenn ich jetzt richtig verstanden habe, was diese Funktion macht, dann tut sie linear zwischen den Blöcken interpolieren? Ich meine, das ist zwar nicht die korrekte Minecraft-Berechnungsreihenfolge, soll mir aber auch recht sein.

Ok, wenn ich jetzt richtig verstanden habe, was diese Funktion macht, dann tut sie linear zwischen den Blöcken interpolieren? Ich meine, das ist zwar nicht die korrekte Minecraft-Berechnungsreihenfolge, soll mir aber auch recht sein.
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;