Allows you to "whitelist" a location for a certain bot, but "blacklist" it for others. Create with 'LocationWhitelistCollection.Create(...)'.

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.

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");
    // 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()}.");
    // 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.

Last updated