LocationBlacklistCollection
Allows you to "blacklist" (set as invalid) locations for a certain amount of times. Create with 'LocationBlacklistCollection.CreatePerBot(...)' or 'LocationBlacklistCollection.CreateGlobal(...)'.

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.
1
private static LocationBlacklistCollection blacklist =
2
LocationBlacklistCollection.CreateGlobal(3, // 3 bots need to blacklist to blacklist globally.
3
13600000, // 1 hour in milliseconds.
4
2); // block a 2x2 radius around a block as well.
5
6
public async Task OnTick() {
7
const ushort diamondOre = 56;
8
var block = Context.World.FindClosest(128, 64, // search a 256x128 area.
9
diamondOre, CpuMode.Medium_Usage, // search for diamond ore blocks.
10
block => !blacklist.IsBlocked(context, block.GetLocation())); // do not include blocks that are blacklisted.
11
12
if(block == null) {
13
Console.WriteLine("Could not find any reachable diamond ores");
14
return;
15
}
16
17
// Move to the closest diamond ore.
18
var moveTask = await block.MoveToInteractionRange().Task;
19
if(moveTask.Result != MoveResultType.Completed) {
20
Console.WriteLine(quot;Could not reach ore at {block.GetLocation()}, blacklisting it.");
21
blacklist.AddToBlockCounter(context, block.GetLocation());
22
return;
23
}
24
25
// Reached the block, mine it.
26
await block.Dig();
27
}
Copied!
Last modified 2yr ago
Copy link