LocationWhitelistCollection
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.
1
private static LocationWhitelistCollection whitelist =
2
LocationWhitelistCollection.Create(3); // 3 blacklist 3x3 are around the location for other bots.
3
4
public async Task OnTick() {
5
const ushort diamondOre = 56;
6
var block = Context.World.FindClosest(128, 64, // search a 256x128 area.
7
diamondOre, CpuMode.Medium_Usage, // search for diamond ore blocks.
8
block => !whitelist.IsTaken(context, block.GetLocation())); // do not include blocks that are taken.
9
10
if(block == null) {
11
Console.WriteLine("Could not find any reachable diamond ores");
12
return;
13
}
14
// Mark this location as taken, so other bots that are
15
// searching for a location don't take the pick this block as well.
16
whitelist.Take(context, block.GetLocation());
17
18
// Move to the closest diamond ore.
19
var moveTask = await block.MoveToInteractionRange().Task;
20
if(moveTask.Result != MoveResultType.Completed) {
21
Console.WriteLine(quot;Could not reach ore at {block.GetLocation()}.");
22
return;
23
}
24
25
// Reached the block, mine it.
26
await block.Dig();
27
28
// We mined the block and no longer care about it, nor do we
29
// have to keep it "blacklisted" from other bots. Therefore we
30
// should release our current block.
31
whitelist.Release(context);
32
}
Copied!
Last modified 2yr ago
Copy link