本帖最后由 好大一坨翔哟 于 2023-1-26 22:08 编辑
解决方法:
List<Location> getLocationsAroundPlayer(Player player, double radius) {
World world = player.getWorld();
Location playerLocation = player.getLocation();
double x = playerLocation.getX();
double y = playerLocation.getY();
double z = playerLocation.getZ();
List<Location> locations = new ArrayList<Location>();
for (double nowX = x - radius; nowX <= x + radius; nowX++) {
for (double nowY = y - radius; nowY <= y + radius; nowY++) {
for (double nowZ = z - radius; nowZ <= z + radius; nowZ++) {
Location location = new Location(world, nowX, nowY, nowZ);
double distance = playerLocation.distance(location);
if (distance <= radius) {
locations.add(location);
}
}
}
}
return locations;
}
解决方法:
List<Location> getLocationsAroundPlayer(Player player, double radius) {
World world = player.getWorld();
Location playerLocation = player.getLocation();
double x = playerLocation.getX();
double y = playerLocation.getY();
double z = playerLocation.getZ();
List<Location> locations = new ArrayList<Location>();
for (double nowX = x - radius; nowX <= x + radius; nowX++) {
for (double nowY = y - radius; nowY <= y + radius; nowY++) {
for (double nowZ = z - radius; nowZ <= z + radius; nowZ++) {
Location location = new Location(world, nowX, nowY, nowZ);
double distance = playerLocation.distance(location);
if (distance <= radius) {
locations.add(location);
}
}
}
}
return locations;
}
“玩家周围的所有坐标”包含了无限个坐标,比如 (0, 0, 0.1) 、(0, 0, 0.2) 等等,没有办法“得到”