Joseph Norman
Joseph Norman

Reputation: 43

Spigot change stained clay color

This is my searching code:

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);
            }
        }
    }
}

In the static class ConstantsManager

public static final Material ground_material = Material.STAINED_CLAY;

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

It is supposed to search through the 100*50*100 volume for red or blue stained clay, calling on ConstantsManager for the material and color values. The code is able to detect whether the block is clay or not, but is not able to detect if it is red or blue. What can I change in my code in order to detect the clay colors?

Upvotes: 1

Views: 749

Answers (2)

Luke Morfill
Luke Morfill

Reputation: 131

You're problem is you're using block.getType().getData(). You want to be using

block.getData()

block.getType().getData() seems to be returning Class<? extends MaterialData> which is most definitely not equals to the int that you're trying to compare it to. (Not too sure what that method returns myself)

To summarize one of your if statements should look like this.

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

Note: You can't use .equals on primitive Java data types, hence the ==

Upvotes: 2

RAZ_Muh_Taz
RAZ_Muh_Taz

Reputation: 4099

After a quick search the Block class should contain a public int variable called blockID. Therefore you should be able to call it and do the following

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);
    }
}

Upvotes: 0

Related Questions