# LocationWhitelistCollection

### Example usage

The code below finds the closest diamond block and attempts to move to it and then mine it. When we find a diamond ore we add it to a whitelist, where it's "whitelisted" to the current bot, but it's "blacklisted" from all other bots.

*This may not ensure that two bots don't pick the same block, due to how multi-threading works. To ensure that locking is required.*

```csharp
private static LocationWhitelistCollection whitelist = 
LocationWhitelistCollection.Create(3); // 3 blacklist 3x3 are around the location for other bots.

public async Task OnTick() {
    const ushort diamondOre = 56;
    var block = Context.World.FindClosest(128, 64, // search a 256x128 area.
    diamondOre, CpuMode.Medium_Usage, // search for diamond ore blocks.
    block => !whitelist.IsTaken(context, block.GetLocation())); // do not include blocks that are taken.
    
    if(block == null) {
        Console.WriteLine("Could not find any reachable diamond ores");
        return;
    }
    // Mark this location as taken, so other bots that are 
    // searching for a location don't take the pick this block as well.
    whitelist.Take(context, block.GetLocation());
    
    // Move to the closest diamond ore.
    var moveTask = await block.MoveToInteractionRange().Task;
    if(moveTask.Result != MoveResultType.Completed) {
        Console.WriteLine($"Could not reach ore at {block.GetLocation()}.");
        return;
    }
    
    // Reached the block, mine it.
    await block.Dig();
    
    // We mined the block and no longer care about it, nor do we 
    // have to keep it "blacklisted" from other bots. Therefore we
    // should release our current block.
    whitelist.Release(context);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.minecraftbot.com/api/utility/locationwhitelistcollection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
