2013-07-29 83 views
0

是否有可能以某种方式压缩这两个环路?Ive有加倍他们,因为与受第一循环压缩此编码?

 int count = 1; 
     for(int y = 0; y < cuboidClipboard.getHeight(); y++) 
     for(int x = 0; x < cuboidClipboard.getWidth(); x++) 
     for(int z = 0; z < cuboidClipboard.getLength(); z++) 
     { 
      BaseBlock baseBlock = cuboidClipboard.getPoint(new Vector(x, y, z)); 
      Vector relativeVector = new Vector(x,y,z).add(orign); 

      Block buildBlock = world.getBlockAt(relativeVector.getBlockX(), relativeVector.getBlockY(), relativeVector.getBlockZ()); 

      if(Material.getMaterial(baseBlock.getId()).isSolid()) 
      if(buildBlock.getTypeId() != baseBlock.getId()) 
       { 
        new PopBlockTask(buildBlock, world, baseBlock).runTaskLater(this, 20+(count*2)); 
        count++; 
       } 
     } 

     //we need to place non solid blocks last because they don't attach properly when theres no blocks around them 
     for(int y = 0; y < cuboidClipboard.getHeight(); y++) 
     for(int x = 0; x < cuboidClipboard.getWidth(); x++) 
     for(int z = 0; z < cuboidClipboard.getLength(); z++) 
     { 
      BaseBlock baseBlock = cuboidClipboard.getPoint(new Vector(x, y, z)); 
      Vector relativeVector = new Vector(x,y,z).add(orign); 

      Block buildBlock = world.getBlockAt(relativeVector.getBlockX(), relativeVector.getBlockY(), relativeVector.getBlockZ()); 

      if(!Material.getMaterial(baseBlock.getId()).isSolid()) 
      if(buildBlock.getTypeId() != baseBlock.getId()) 
       { 
        new PopBlockTask(buildBlock, world, baseBlock).runTaskLater(this, 20+(count*2)); 
        count++; 
       } 
     } 
+0

为什么这里不是一个if-else的工作? –

+0

因为使用count var的方式,它被用作抵消任务操作执行的方式,所以我只是不确定最好的方式去做什么 – clienthax

+0

@HarshalPandya,因为显然有一个错误系统需要将非固体块放在后面,因为它们没有正确连接。 – ObieMD5

回答

1

而忽略了块第二循环的交易然后做第二循环中,您应该只创建非固体块的映射/ ArrayList的

if(!Material.getMaterial(baseBlock.getId()).isSolid()) 
    // Do the code that's there 
else 
    // Add to map/list the information you need (x, y, z, count?) 
    // If you don't have some way to store the info, you could 
    // just create a small Object to do so or use a Map 

然后宁可再做整个循环,只是回路图/表和创建它们

for(Object o: theList) 
{ 
    // Do the relevant code 
} 

这不会真正压缩代码,但可以节省您不得不第二次执行大规模循环。