mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-16 21:15:17 +02:00
Added Requested Changes for Awareness
This commit is contained in:
parent
67eb491568
commit
154e75d199
2 changed files with 39 additions and 41 deletions
|
@ -18,11 +18,8 @@ export const queryList = [
|
||||||
// display position to 2 decimal places
|
// display position to 2 decimal places
|
||||||
res += `\n- Position: x: ${pos.x.toFixed(2)}, y: ${pos.y.toFixed(2)}, z: ${pos.z.toFixed(2)}`;
|
res += `\n- Position: x: ${pos.x.toFixed(2)}, y: ${pos.y.toFixed(2)}, z: ${pos.z.toFixed(2)}`;
|
||||||
// Environmental Awareness
|
// Environmental Awareness
|
||||||
res += `\n- Block Above: ${world.getBlockAtPosition(bot, 0, 2, 0).name}`;
|
res += '\n- ' + world.getSurroundingBlocks(bot).join('\n- ')
|
||||||
res += `\n- Block Below: ${world.getBlockAtPosition(bot, 0, -1, 0).name}`;
|
res += `\n- First Solid Block Above Head: ${world.getFirstBlockAboveHead(bot, null, 32)}`;
|
||||||
res += `\n- Block at Head: ${world.getBlockAtPosition(bot, 0, 1, 0).name}`;
|
|
||||||
res += `\n- Block at Legs: ${world.getBlockAtPosition(bot, 0, 0, 0).name}`;
|
|
||||||
res += `\n- Lowest Block Above: ${world.getLowestBlock(bot, null, null, 32).name}`;
|
|
||||||
// Gameplay
|
// Gameplay
|
||||||
res += `\n- Gamemode: ${bot.game.gameMode}`;
|
res += `\n- Gamemode: ${bot.game.gameMode}`;
|
||||||
res += `\n- Health: ${Math.round(bot.health)} / 20`;
|
res += `\n- Health: ${Math.round(bot.health)} / 20`;
|
||||||
|
@ -108,11 +105,8 @@ export const queryList = [
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Environmental Awareness
|
// Environmental Awareness
|
||||||
res += `\nBLOCK_ABOVE: ${world.getBlockAtPosition(bot, 0, 2, 0).name}`;
|
res += '\n- ' + world.getSurroundingBlocks(bot).join('\n- ')
|
||||||
res += `\nBLOCK_BELOW: ${world.getBlockAtPosition(bot, 0, -1, 0).name}`;
|
res += `\n- First Solid Block Above Head: ${world.getFirstBlockAboveHead(bot, null, 32)}`;
|
||||||
res += `\nBLOCK_AT_HEAD: ${world.getBlockAtPosition(bot, 0, 1, 0).name}`;
|
|
||||||
res += `\nBLOCK_AT_LEGS: ${world.getBlockAtPosition(bot, 0, 0, 0).name}`;
|
|
||||||
res += `\nLOWEST_BLOCK_ABOVE: ${world.getLowestBlock(bot, null, null, 32).name}`;
|
|
||||||
}
|
}
|
||||||
return pad(res);
|
return pad(res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,29 +58,37 @@ export function getBlockAtPosition(bot, x=0, y=0, z=0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getLowestBlock(bot, block_types=null, ignore_types=null, distance=32) {
|
export function getSurroundingBlocks(bot) {
|
||||||
/**
|
/**
|
||||||
* Searches a column from the bot's position for the lowest block
|
* Get the surrounding blocks from the bot's environment.
|
||||||
* @param {Bot} bot - The bot to get the block for.
|
* @param {Bot} bot - The bot to get the block for.
|
||||||
* @param {string[]} block_types - The names of the blocks to search for.
|
* @returns {string[]} - A list of block results as strings.
|
||||||
* @param {string[]} block_types - The names of the blocks to ignore.
|
|
||||||
* @param {number} distance - The maximum distance to search, default 32.
|
|
||||||
* @returns {Block} - The lowest block.
|
|
||||||
* @example
|
* @example
|
||||||
* let lowestBlock = world.getLowestBlock(bot, null, null, 32);
|
|
||||||
**/
|
**/
|
||||||
// if blocktypes is not a list, make it a list
|
// Create a list of block position results that can be unpacked.
|
||||||
let search_blocks = [];
|
let res = [];
|
||||||
if (block_types) {
|
res.push(`Block Above: ${getBlockAtPosition(bot, 0, 2, 0).name}`);
|
||||||
if (!Array.isArray(block_types))
|
res.push(`Block Below: ${getBlockAtPosition(bot, 0, -1, 0).name}`);
|
||||||
block_types = [block_types];
|
res.push(`Block at Head: ${getBlockAtPosition(bot, 0, 1, 0).name}`);
|
||||||
for(let block_type of block_types) {
|
res.push(`Block at Legs: ${getBlockAtPosition(bot, 0, 0, 0).name}`);
|
||||||
if (mc.getBlockId(block_type)) search_blocks.push(block_type);
|
|
||||||
}
|
return res;
|
||||||
}
|
}
|
||||||
// if ignore_types is not a list, make it a list
|
|
||||||
|
|
||||||
|
export function getFirstBlockAboveHead(bot, ignore_types=null, distance=32) {
|
||||||
|
/**
|
||||||
|
* Searches a column from the bot's position for the first solid block above its head
|
||||||
|
* @param {Bot} bot - The bot to get the block for.
|
||||||
|
* @param {string[]} ignore_types - The names of the blocks to ignore.
|
||||||
|
* @param {number} distance - The maximum distance to search, default 32.
|
||||||
|
* @returns {string} - The fist block above head.
|
||||||
|
* @example
|
||||||
|
* let firstBlockAboveHead = world.getFirstBlockAboveHead(bot, null, 32);
|
||||||
|
**/
|
||||||
|
// if ignore_types is not a list, make it a list.
|
||||||
let ignore_blocks = [];
|
let ignore_blocks = [];
|
||||||
if (ignore_types === null) ignore_blocks = ['air'];
|
if (ignore_types === null) ignore_blocks = ['air', 'cave_air'];
|
||||||
else {
|
else {
|
||||||
if (!Array.isArray(ignore_types))
|
if (!Array.isArray(ignore_types))
|
||||||
ignore_types = [ignore_types];
|
ignore_types = [ignore_types];
|
||||||
|
@ -88,25 +96,21 @@ export function getLowestBlock(bot, block_types=null, ignore_types=null, distanc
|
||||||
if (mc.getBlockId(ingnore_type)) ignore_blocks.push(ingnore_type);
|
if (mc.getBlockId(ingnore_type)) ignore_blocks.push(ingnore_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The lowest block, stops when it finds a block
|
// The block above, stops when it finds a solid block .
|
||||||
let lowest_block = {name: 'air'};
|
let block_above = {name: 'air'};
|
||||||
|
let height = 0
|
||||||
for (let i = 0; i < distance; i++) {
|
for (let i = 0; i < distance; i++) {
|
||||||
let block = bot.blockAt(bot.entity.position.offset(0, i+2, 0));
|
let block = bot.blockAt(bot.entity.position.offset(0, i+2, 0));
|
||||||
if (!block) block = {name: 'air'};
|
if (!block) block = {name: 'air'};
|
||||||
// Ignore and continue
|
// Ignore and continue
|
||||||
if (ignore_blocks.includes(block.name)) continue;
|
if (ignore_blocks.includes(block.name)) continue;
|
||||||
// Defaults to any block
|
// Defaults to any block
|
||||||
else if (block_types === null) {
|
block_above = block;
|
||||||
lowest_block = block;
|
height = i;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
else if (search_blocks.includes(block.name)) {
|
|
||||||
lowest_block = block;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lowest_block;
|
return `${block_above.name} (${height} blocks up)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue