# LocationBlacklistCollection

### Example usage

The code below finds the closest diamond block and attempts to move to it and then mine it. If the block is unreachable then it's added to the blacklist for 1 hour. The blacklist ensures that the same block is no longer picked in the search with the code `!blacklist.IsBlocked(context, block.GetLocation())`.

*Optionally the code below could also use LocationWhitelistCollection to make sure that multiple bots don't try to move to the same diamond ore block.*

```csharp
private static LocationBlacklistCollection blacklist = 
LocationBlacklistCollection.CreateGlobal(3, // 3 bots need to blacklist to blacklist globally.
                                         13600000, // 1 hour in milliseconds.
                                         2); // block a 2x2 radius around a block as well.

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 => !blacklist.IsBlocked(context, block.GetLocation())); // do not include blocks that are blacklisted.

    if(block == null) {
        Console.WriteLine("Could not find any reachable diamond ores");
        return;
    }
    
    // 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()}, blacklisting it.");
        blacklist.AddToBlockCounter(context, block.GetLocation());
        return;
    }
    
    // Reached the block, mine it.
    await block.Dig();
}
```


---

# 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/locationblacklistcollection.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.
