mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-22 06:02:07 +02:00
replaced world function, removed bad example
This commit is contained in:
parent
f41417d059
commit
5e25536d37
3 changed files with 12 additions and 27 deletions
|
@ -25,11 +25,6 @@
|
||||||
{"role": "assistant", "content": "Here!"}
|
{"role": "assistant", "content": "Here!"}
|
||||||
],
|
],
|
||||||
|
|
||||||
[
|
|
||||||
{"role": "user", "content": "sarah_O.o: can you fly up in the air?"},
|
|
||||||
{"role": "assistant", "content": "I can't do that."}
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
[
|
||||||
{"role": "user", "content": "joe: Follow me!"},
|
{"role": "user", "content": "joe: Follow me!"},
|
||||||
{"role": "assistant", "content": "Sure!\n```\n// I am going to follow joe.\nawait skills.followPlayer(bot, 'joe');\n```"}
|
{"role": "assistant", "content": "Sure!\n```\n// I am going to follow joe.\nawait skills.followPlayer(bot, 'joe');\n```"}
|
||||||
|
|
|
@ -22,7 +22,7 @@ export async function craftItem(bot, itemName, num=1) {
|
||||||
let recipes = bot.recipesFor(getItemId(itemName), null, num, null); // get recipes that don't require a crafting table
|
let recipes = bot.recipesFor(getItemId(itemName), null, num, null); // get recipes that don't require a crafting table
|
||||||
let craftingTable = undefined;
|
let craftingTable = undefined;
|
||||||
if (!recipes || recipes.length === 0) {
|
if (!recipes || recipes.length === 0) {
|
||||||
craftingTable = getNearestBlock(bot, 'crafting_table');
|
craftingTable = getNearestBlock(bot, 'crafting_table', 6);
|
||||||
if (craftingTable === null){
|
if (craftingTable === null){
|
||||||
log(bot, `${itemName} requires crafting table, but there is none nearby.`)
|
log(bot, `${itemName} requires crafting table, but there is none nearby.`)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
import { getAllBlockIds, getAllBlocks, getAllItems } from './mcdata.js';
|
import { getAllBlockIds, getAllBlocks, getAllItems } from './mcdata.js';
|
||||||
|
|
||||||
|
|
||||||
export function getNearestBlock(bot, block_type) {
|
export function getNearestBlock(bot, block_type, distance=16) {
|
||||||
|
/**
|
||||||
|
* Get the position of the nearest block of the given type.
|
||||||
|
* @param {Bot} bot - The bot to get the nearest block for.
|
||||||
|
* @param {string} block_type - The name of the block to search for.
|
||||||
|
* @param {number} distance - The maximum distance to search.
|
||||||
|
* @returns {Block} - The nearest block of the given type.
|
||||||
|
* @example
|
||||||
|
* let coalBlock = world.getNearestBlock(bot, 'coal_ore', 16);
|
||||||
|
**/
|
||||||
let block_locs = bot.findBlocks({
|
let block_locs = bot.findBlocks({
|
||||||
matching: (block) => {
|
matching: (block) => {
|
||||||
return block && block.type === bot.registry.blocksByName[block_type].id
|
return block && block.type === bot.registry.blocksByName[block_type].id
|
||||||
},
|
},
|
||||||
maxDistance: 6,
|
maxDistance: distance,
|
||||||
count: 1
|
count: 1
|
||||||
});
|
});
|
||||||
if (block_locs.length > 0) {
|
if (block_locs.length > 0) {
|
||||||
|
@ -173,22 +182,3 @@ export function getNearbyBlockTypes(bot) {
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getNearestBlockPosition(bot, blockType) {
|
|
||||||
/**
|
|
||||||
* Get the position of the nearest block of the given type.
|
|
||||||
* @param {Bot} bot - The bot to get the nearest block for.
|
|
||||||
* @param {string} blockType - The type of the block to search for.
|
|
||||||
* @returns {Vec3} - The position of the nearest block of the given type if found else null.
|
|
||||||
* @example
|
|
||||||
* let position = world.getNearestBlockPosition(bot, 'coal_ore');
|
|
||||||
**/
|
|
||||||
let blocks = getNearbyBlocks(bot, 16);
|
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
|
||||||
if (blocks[i].name == blockType) {
|
|
||||||
return blocks[i].position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue