【发布时间】:2014-09-28 19:31:53
【问题描述】:
我有一个小问题,我的数组列表中的元素没有被删除。这是一个数组列表。这是我的代码:
package net.lucrecious.armorconstruct.helpers;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class WorldHelper {
public static void replace_coord_with_block(World world, ArrayList<int[]> coords, Block result_block){
for (int[] c : coords){
world.setBlock(c[0], c[1], c[2], result_block);
}
}
public static ArrayList<int[]> get_blocks_in_sphere(EntityPlayer player, World world, int radius, Class<?>...block_types){
ArrayList<int[]> coord_list = new ArrayList<int[]>();
int r = radius;
int i = MathHelper.floor_double(player.posX);
int j = MathHelper.floor_double(player.posY);
int k = MathHelper.floor_double(player.posZ);
for(int x = -r; x < r; x++){
for(int y = -r; y < r; y++){
for(int z = -r; z < r; z++){
double dist = MathHelper.sqrt_double((x*x + y*y + z*z)); //Calculates the distance
if(dist > r)
continue;
Block block = world.getBlock(i+x, j+y, k+z);
for (Class<?> cls : block_types){
if (cls.isInstance(block)){
coord_list.add(new int[]{i+x, j+y, k+z});
}
}
}
}
}
return coord_list;
}
public static ArrayList<int[]> get_blocks_in_sphere_holo(EntityPlayer player, World world, int radius, Class<?>...block_types){
ArrayList<int[]> sphere = get_blocks_in_sphere(player, world, radius, block_types);
ArrayList<int[]> inner_sphere = get_blocks_in_sphere(player, world, radius-1, block_types);
sphere.removeAll(inner_sphere);
return sphere;
}
public static ArrayList<int[]> get_blocks_in_sphere_filled(EntityPlayer player, World world, int radius, Class<?>...block_types){
return get_blocks_in_sphere(player, world, radius, block_types);
}
}
这个想法是获取一个填充球体的坐标,然后抓取一个稍小的填充球体的坐标并删除相似的坐标,从而有效地制作一个未填充的球体。
我知道里面有一些我的世界代码 - 但它仍然应该是可以理解的。我也确信会有类似的坐标。我什至在没有减小半径的情况下尝试了这个,但这仍然不起作用。所以即使所有坐标都相同,这也行不通。
关于导致此问题的原因或如何使其发挥作用的任何想法?
【问题讨论】:
-
在执行
sphere.removeAll(inner_sphere);打印来自Arrays.toString (sphere.toArray ())和Arrays.toString (inner_sphere.toArray ())的结果之前
标签: java list arraylist removeall