2023-08-17 00:00:57 -07:00
|
|
|
import { getAllBlockIds } from './mcdata.js';
|
|
|
|
|
|
|
|
|
2023-09-29 12:53:56 -07:00
|
|
|
export function getNearbyBlocks(bot, distance) {
|
|
|
|
let positions = bot.findBlocks({matching: getAllBlockIds(['air']), maxDistance: distance, count: 10000});
|
|
|
|
let found = [];
|
|
|
|
for (let i = 0; i < positions.length; i++) {
|
|
|
|
let block = bot.blockAt(positions[i]);
|
|
|
|
found.push(block);
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-17 00:00:57 -07:00
|
|
|
/**
|
2023-09-29 12:53:56 -07:00
|
|
|
* Get a list of all nearby block names.
|
2023-08-17 00:00:57 -07:00
|
|
|
* @param {Bot} bot - The bot to get nearby blocks for.
|
|
|
|
* @returns {string[]} - A list of all nearby blocks.
|
|
|
|
* @example
|
2023-09-29 12:53:56 -07:00
|
|
|
* let blocks = world.getNearbyBlockTypes(bot);
|
2023-08-17 00:00:57 -07:00
|
|
|
**/
|
2023-09-29 12:53:56 -07:00
|
|
|
export function getNearbyBlockTypes(bot) {
|
|
|
|
let blocks = getNearbyBlocks(bot, 16);
|
2023-08-17 00:00:57 -07:00
|
|
|
let found = [];
|
2023-09-29 12:53:56 -07:00
|
|
|
for (let i = 0; i < blocks.length; i++) {
|
|
|
|
if (!found.includes(blocks[i].name)) {
|
|
|
|
found.push(blocks[i].name);
|
2023-08-17 00:00:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|