From 2c44e50846da6e849e9f1017641da5e7ce33efd9 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 17 Apr 2026 11:13:14 +0200 Subject: [PATCH] Fix Action.MoveAction Fix NavMesh.isWalkable --- .../de/steamwar/fightsystem/ai/Action.java | 12 +++++++-- .../de/steamwar/fightsystem/ai/NavMesh.java | 26 +++++++++---------- .../fightsystem/ai/yoyonow/YoyoNowAI.java | 1 - 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/Action.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/Action.java index b0a5f0e2..d7df800f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/Action.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/Action.java @@ -64,9 +64,17 @@ public interface Action { } AI.MoveResult moveResult = ai.checkMove(coordinate); - if (moveResult == AI.MoveResult.OVERDISTANCE && overDistanceCounter++ > 5) { - return Result.FAILED; + if (moveResult == AI.MoveResult.OVERDISTANCE) { + if (overDistanceCounter == 5) { + path = ai.navMesh.pathToNearest(ai.getPosition().toWorld(ai.team), destination); + return path.isEmpty() ? Result.FAILED : Result.ONGOING; + } + if (overDistanceCounter++ > 5) { + return Result.FAILED; + } + return Result.ONGOING; } + overDistanceCounter = 0; if (moveResult == AI.MoveResult.FALLING) { return Result.ONGOING; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/NavMesh.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/NavMesh.java index 16b7e2bd..b89a30af 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/NavMesh.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/NavMesh.java @@ -23,6 +23,7 @@ import de.steamwar.entity.RBlockDisplay; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; @@ -32,12 +33,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.util.BoundingBox; +import org.bukkit.util.NumberConversions; import org.bukkit.util.Transformation; -import org.bukkit.util.Vector; import org.bukkit.util.VoxelShape; import org.joml.AxisAngle4f; import org.joml.Vector3f; @@ -48,7 +48,6 @@ import java.util.stream.Stream; public class NavMesh { - private static final World WORLD = Bukkit.getWorlds().get(0); private static final double PLAYER_FALL_DISTANCE = 3; private static final double PLAYER_JUMP_HEIGHT = 1.25; private static final double PLAYER_HEIGHT = 1.8; @@ -103,7 +102,7 @@ public class NavMesh { } private void calculatePosition(Pos pos, Map walkable) { - Block block = WORLD.getBlockAt(pos.x, pos.y, pos.z); + Block block = Config.world.getBlockAt(pos.x, pos.y, pos.z); // Air is not walkable if (block.isPassable()) return; @@ -120,7 +119,7 @@ public class NavMesh { // Ceiling Position pos.ceiling = fightTeam.getExtendRegion().getMaxY() - pos.y; for (int y = pos.y + 1; y <= fightTeam.getExtendRegion().getMaxY() + 3; y++) { - block = WORLD.getBlockAt(pos.x, y, pos.z); + block = Config.world.getBlockAt(pos.x, y, pos.z); if (block.isPassable()) continue; double min = playerCollisionMin(block.getCollisionShape()); if (min >= 1.0) continue; @@ -244,13 +243,14 @@ public class NavMesh { } public void update(WorldCoordinate coordinate) { - Pos pos = toPos(coordinate); - if (pos == null) return; + final int px = coordinate.getBlockX(); + final int py = coordinate.getBlockY(); + final int pz = coordinate.getBlockZ(); for (int x = -2; x <= 2; x++) { for (int z = -2; z <= 2; z++) { - for (int y = fightTeam.getSchemRegion().getMinY(); y <= pos.y + 2; y++) { - Pos current = new Pos(pos.x + x, y, pos.z + z); + for (int y = fightTeam.getSchemRegion().getMinY(); y <= py + 2; y++) { + Pos current = new Pos(px + x, y, pz + z); walkable.remove(current); calculatePosition(current, walkable); } @@ -269,8 +269,8 @@ public class NavMesh { Pos other = walkable.get(pos.add(relative)); if (other == null) continue; - Block thisBlock = WORLD.getBlockAt(pos.x, pos.y, pos.z); - Block otherBlock = WORLD.getBlockAt(other.x, other.y, other.z); + Block thisBlock = Config.world.getBlockAt(pos.x, pos.y, pos.z); + Block otherBlock = Config.world.getBlockAt(other.x, other.y, other.z); if (thisBlock.getType() != Material.LADDER && otherBlock.getType() == Material.LADDER) { if ((relative.x != 0 || relative.z != 0) && pos.y != other.y) continue; @@ -294,7 +294,7 @@ public class NavMesh { } public boolean isWalkable(WorldCoordinate coordinate) { - Pos pos = new Pos(coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ()); + Pos pos = new Pos(coordinate.getBlockX(), NumberConversions.floor(coordinate.getY() - 0.0625), coordinate.getBlockZ()); return walkable.containsKey(pos); } @@ -376,7 +376,7 @@ public class NavMesh { List coordinates = path.stream().skip(1).map(Pos::toWorld).collect(Collectors.toList()); coordinates.forEach(coordinate -> { - RBlockDisplay block = new RBlockDisplay(server, coordinate.toLocation(WORLD)); + RBlockDisplay block = new RBlockDisplay(server, coordinate.toLocation(Config.world)); block.setBlock(PATH_BLOCK); block.setTransform(new Transformation(new Vector3f(0, 0, 0), new AxisAngle4f(0, 0, 0, 0), new Vector3f(1, 0.001F, 1), new AxisAngle4f(0, 0, 0, 0))); }); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/yoyonow/YoyoNowAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/yoyonow/YoyoNowAI.java index e6d4196c..68512445 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/yoyonow/YoyoNowAI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/yoyonow/YoyoNowAI.java @@ -81,7 +81,6 @@ public class YoyoNowAI extends AI { WorldCoordinate destination = walkable.get(random.nextInt(walkable.size())); Action action = new Action.MoveAction(this, destination); if (!action.isCompletable()) return; - chat("Now moving to: " + destination); actions.add(action); } }