2017-09-05 81 views
1

这是我的搜索代码:插口改变染色陶土色

for(int x = -100; x < 100; x ++) 
{ 
    for(int z = -100; z < 100; z ++) 
    { 
     for(int y = 0; y < 50; y ++) 
     { 
      Location loc = new Location(Bukkit.getWorld(map_name), x, y, z); 
      Block block = loc.getBlock(); 
      if(block.getType() 
       .equals(ConstantsManager.ground_material)) 
      { 
       if(block.getType().getData() 
        .equals(ConstantsManager.ground_redId)) 
        orig_redClay.add(block); 
       if(block.getType().getData() 
        .equals(ConstantsManager.ground_blueId)) 
        orig_blueClay.add(block); 
      } 
     } 
    } 
} 

在静态类ConstantsManager

public static final Material ground_material = Material.STAINED_CLAY; 

public static final int ground_blueId = 3; 
public static final int ground_redId = 14; 

它应该通过100 * 50 * 100的体积为红色或蓝色搜索弄脏粘土,为ConstantsManager调用材质和颜色值。该代码能够检测块是否粘土,但无法检测到它是红色还是蓝色。我可以在我的代码中更改哪些内容以检测粘土颜色?

+0

什么的getData()返回? –

回答

2

您遇到的问题是block.getType().getData()。你想使用

block.getData()

block.getType().getData()似乎回到Class<? extends MaterialData>这是最绝对不是等于说你要比较它为int。 (不太确定那个方法自己返回的结果)

总结一下你的if语句应该看起来像这样。

if (block.getData() == ConstantsManager.ground_redId)

注:不能对原始Java数据类型使用.equals,因此==

0

快速搜索后,Block class应该包含一个名为blockID的public int变量。因此,您应该可以调用它并执行以下操作:

if(block.getType().equals(ConstantsManager.ground_material)) 
{ 
    if(block.blockID == ConstantsManager.ground_blueId) 
    { 
     orig_blueClay.add(block); 
    } 
    else if(block.blockID == ConstantsManager.ground_redId) 
    { 
     orig_redClay.add(block); 
    } 
}