From 225da1ca9726c90a88cd189e5d2a7664f12a612c Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Mon, 31 Mar 2025 19:41:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(bukkit):=20=E4=BF=AE=E5=A4=8D=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6=E4=B8=8B=E5=BA=A7=E4=BD=8D=E4=BC=9A=E5=9C=A8=E5=AE=B6?= =?UTF-8?q?=E5=85=B7=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../furniture/BukkitFurnitureManager.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java index a7a8f24a2..02ec11299 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java @@ -362,9 +362,51 @@ public class BukkitFurnitureManager implements FurnitureManager { } Vector3f seatPos = MiscUtils.getVector3f(vector3f); furniture.removeOccupiedSeat(seatPos); + + Location vehicleLocation = vehicle.getLocation(); + Location originalLocation = vehicleLocation.clone(); + originalLocation.setY(furniture.location().getY()); + Location targetLocation = originalLocation.clone().add(vehicleLocation.getDirection()); + if (!isSafeLocation(targetLocation)) { + targetLocation = findSafeLocationNearby(originalLocation); + if (targetLocation == null) return; + } + targetLocation.setYaw(player.getLocation().getYaw()); + targetLocation.setPitch(player.getLocation().getPitch()); + player.teleport(targetLocation); } protected boolean isSeatCarrierType(Entity entity) { return (entity instanceof ArmorStand || entity instanceof ItemDisplay); } + + private boolean isSafeLocation(Location location) { + World world = location.getWorld(); + if (world == null) return false; + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + if (!world.getBlockAt(x, y - 1, z).getType().isSolid()) return false; + if (!world.getBlockAt(x, y, z).isPassable()) return false; + return world.getBlockAt(x, y + 1, z).isPassable(); + } + + @Nullable + private Location findSafeLocationNearby(Location center) { + World world = center.getWorld(); + if (world == null) return null; + int centerX = center.getBlockX(); + int centerY = center.getBlockY(); + int centerZ = center.getBlockZ(); + for (int dx = -1; dx <= 1; dx++) { + for (int dz = -1; dz <= 1; dz++) { + if (dx == 0 && dz == 0) continue; + int x = centerX + dx; + int z = centerZ + dz; + Location nearbyLocation = new Location(world, x + 0.5, centerY, z + 0.5); + if (isSafeLocation(nearbyLocation)) return nearbyLocation; + } + } + return null; + } }