9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 17:09:19 +00:00

fix(bukkit): 修复玩家下座位会在家具里面

This commit is contained in:
jhqwqmc
2025-03-31 19:41:13 +08:00
parent 8033fb1ca6
commit 225da1ca97

View File

@@ -362,9 +362,51 @@ public class BukkitFurnitureManager implements FurnitureManager {
} }
Vector3f seatPos = MiscUtils.getVector3f(vector3f); Vector3f seatPos = MiscUtils.getVector3f(vector3f);
furniture.removeOccupiedSeat(seatPos); 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) { protected boolean isSeatCarrierType(Entity entity) {
return (entity instanceof ArmorStand || entity instanceof ItemDisplay); 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;
}
} }