LocationWhitelistCollection
Allows you to "whitelist" a location for a certain bot, but "blacklist" it for others. Create with 'LocationWhitelistCollection.Create(...)'.
Example usage
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);
}Last updated