我给方块设置了一个特性,但是这个特性同时作用的对象过多时,会导致游戏崩溃,怎么样在一个循环里面加入一个延迟的功能,使得有关特性的循环执行得慢一些?我用了try…catch语句,结果导致了循环中的功能不起作用了,也就是方块的“特性”消失了。这个是我的代码:
private boolean absorb(World worldIn, BlockPos pos) {
Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
queue.add(new Tuple<>(pos, 0));
int i = 0;
while(!queue.isEmpty()) {
Tuple<BlockPos, Integer> tuple = queue.poll();
BlockPos blockpos = tuple.getA();
int j = tuple.getB();
for(Direction direction : Direction.values()) {
BlockPos blockpos1 = blockpos.offset(direction);
BlockState blockstate = worldIn.getBlockState(blockpos1);
if (blockstate.getBlock() == Blocks.OBSIDIAN) {
TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null;
spawnDrops(blockstate, worldIn, blockpos1, tileentity);
worldIn.setBlockState(blockpos1, BlockHelper.obsidianRemover.getDefaultState(), 3);
++i;
if (j < 6) {
queue.add(new Tuple<>(blockpos1, j + 1));
}
}
try{
Thread.currentThread().sleep(100);
}
catch(InterruptedException e){
e.printStackTrace();
}
}
if (i > 1) {
break;
}
}
return i > 0;
}
}