本帖最后由 好大一坨翔哟 于 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) 等等,没有办法“得到”
William_Shi 发表于 2023-1-26 21:13
“玩家周围的所有坐标”包含了无限个坐标,比如 (0, 0, 0.1) 、(0, 0, 0.2) 等等,没有办法“得到” ...
对的 所以我这个问题其实想要问的是如何获得玩家周围圆形所有的方块的中心点
r为定值吗 如果r为定值的话打个偏移量表(
本帖最后由 BlessAzek 于 2023-1-26 21:34 编辑
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;
}
还算是简单吧, 就是遍历的问题(
浅写了一下,
(代码未经验证,但应该没什么问题)
返回的是周围所有的location
注意,这里的是一个三维球体,如果不想要z轴的话直接去掉z轴这块遍历即可
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;
}
还算是简单吧, 就是遍历的问题(
浅写了一下,
(代码未经验证,但应该没什么问题)
返回的是周围所有的location
注意,这里的是一个三维球体,如果不想要z轴的话直接去掉z轴这块遍历即可
BlessAzek 发表于 2023-1-26 21:32
List getLocationsAroundPlayer(Player player, double radius) {
World world = player.getWorld();
...
好的我去试试
BlessAzek 发表于 2023-1-26 21:32
List getLocationsAroundPlayer(Player player, double radius) {
World world = player.getWorld();
...
emmmm这是一个球形 有木有圆型的...
凌语丶 发表于 2023-1-26 21:25
r为定值吗 如果r为定值的话打个偏移量表(
emmm 并不是哦