mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-24 17:05:22 +02:00
remove block in way, include inventory in system
This commit is contained in:
parent
3dece90f0c
commit
f3b379addf
2 changed files with 25 additions and 11 deletions
|
@ -491,13 +491,28 @@ export async function placeBlock(bot, blockType, x, y, z) {
|
|||
* await skills.placeBlock(bot, "oak_log", position.x + 1, position.y - 1, position.x);
|
||||
**/
|
||||
console.log('placing block...')
|
||||
const target_dest = new Vec3(Math.floor(x), Math.floor(y), Math.floor(z));
|
||||
const empty_blocks = ['air', 'water', 'lava', 'grass', 'tall_grass', 'snow', 'dead_bush', 'fern'];
|
||||
const targetBlock = bot.blockAt(target_dest);
|
||||
if (!empty_blocks.includes(targetBlock.name)) {
|
||||
log(bot, `Cannot place block at ${targetBlock.position} because ${targetBlock.name} is in the way.`);
|
||||
let block = bot.inventory.items().find(item => item.name === blockType);
|
||||
if (!block) {
|
||||
log(bot, `Don't have any ${blockType} to place.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const target_dest = new Vec3(Math.floor(x), Math.floor(y), Math.floor(z));
|
||||
const targetBlock = bot.blockAt(target_dest);
|
||||
if (targetBlock.name === blockType) {
|
||||
log(bot, `${blockType} already at ${targetBlock.position}.`);
|
||||
return false;
|
||||
}
|
||||
const empty_blocks = ['air', 'water', 'lava', 'grass', 'tall_grass', 'snow', 'dead_bush', 'fern'];
|
||||
if (!empty_blocks.includes(targetBlock.name)) {
|
||||
log(bot, `${blockType} in the way at ${targetBlock.position}.`);
|
||||
const removed = await breakBlockAt(bot, x, y, z);
|
||||
if (!removed) {
|
||||
log(bot, `Cannot place ${blockType} at ${targetBlock.position}: block in the way.`);
|
||||
return false;
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 200)); // wait for block to break
|
||||
}
|
||||
// get the buildoffblock and facevec based on whichever adjacent block is not empty
|
||||
let buildOffBlock = null;
|
||||
let faceVec = null;
|
||||
|
@ -515,11 +530,6 @@ export async function placeBlock(bot, blockType, x, y, z) {
|
|||
return false;
|
||||
}
|
||||
|
||||
let block = bot.inventory.items().find(item => item.name === blockType);
|
||||
if (!block) {
|
||||
log(bot, `Don't have any ${blockType} to place.`);
|
||||
return false;
|
||||
}
|
||||
const pos = bot.entity.position;
|
||||
const pos_above = pos.plus(Vec3(0,1,0));
|
||||
const dont_move_for = ['torch', 'redstone_torch', 'redstone', 'lever', 'button', 'rail', 'detector_rail', 'powered_rail', 'activator_rail', 'tripwire_hook', 'tripwire', 'water_bucket'];
|
||||
|
|
|
@ -54,6 +54,10 @@ export class Prompter {
|
|||
let stats = await getCommand('!stats').perform(this.agent);
|
||||
prompt = prompt.replaceAll('$STATS', stats);
|
||||
}
|
||||
if (prompt.includes('$INVENTORY')) {
|
||||
let inventory = await getCommand('!inventory').perform(this.agent);
|
||||
prompt = prompt.replaceAll('$INVENTORY', inventory);
|
||||
}
|
||||
if (prompt.includes('$COMMAND_DOCS'))
|
||||
prompt = prompt.replaceAll('$COMMAND_DOCS', getCommandDocs());
|
||||
if (prompt.includes('$CODE_DOCS'))
|
||||
|
@ -68,7 +72,7 @@ export class Prompter {
|
|||
// check if there are any remaining placeholders with syntax $<word>
|
||||
let remaining = prompt.match(/\$[A-Z_]+/g);
|
||||
if (remaining !== null) {
|
||||
console.warn('Unknown prompt placeholders:', remaining);
|
||||
console.warn('Unknown prompt placeholders:', remaining.join(', '));
|
||||
}
|
||||
return prompt;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue