代码之家  ›  专栏  ›  技术社区  ›  Joseph Norman

插口变化染色粘土颜色

  •  1
  • Joseph Norman  · 技术社区  · 7 年前

    这是我的搜索代码:

    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;
    

    2 回复  |  直到 7 年前
        1
  •  2
  •   Zachary Craig    7 年前

    你的问题是你在使用 block.getType().getData() . 你想使用

    block.getData()

    块getType()。getData() Class<? extends MaterialData> 这绝对不等于你想要比较的int。(我自己不太确定该方法返回了什么)

    总结一下你的if语句应该是这样的。

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

    .equals ==

        2
  •  0
  •   RAZ_Muh_Taz    7 年前

    Block class 应包含名为blockID的公共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);
        }
    }