unstuck mode, patch pathfinder

This commit is contained in:
MaxRobinsonTheGreat 2024-09-25 00:15:55 -05:00
parent ce5bfbc3bc
commit e95c082786
4 changed files with 54 additions and 13 deletions

View file

@ -1,5 +1,5 @@
diff --git a/node_modules/mineflayer-collectblock/lib/CollectBlock.js b/node_modules/mineflayer-collectblock/lib/CollectBlock.js
index 2c11e8c..bc47dc7 100644
index 2c11e8c..4697873 100644
--- a/node_modules/mineflayer-collectblock/lib/CollectBlock.js
+++ b/node_modules/mineflayer-collectblock/lib/CollectBlock.js
@@ -77,7 +77,7 @@ function mineBlock(bot, block, options) {
@ -11,3 +11,12 @@ index 2c11e8c..bc47dc7 100644
options.targets.removeTarget(block);
return;
}
@@ -195,6 +195,8 @@ class CollectBlock {
throw (0, Util_1.error)('UnresolvedDependency', 'The mineflayer-collectblock plugin relies on the mineflayer-tool plugin to run!');
}
if (this.movements != null) {
+ this.movements.dontMineUnderFallingBlock = false;
+ this.movements.dontCreateFlow = false;
this.bot.pathfinder.setMovements(this.movements);
}
if (!optionsFull.append)

View file

@ -1,5 +1,5 @@
diff --git a/node_modules/mineflayer-pathfinder/index.js b/node_modules/mineflayer-pathfinder/index.js
index b38bd30..ae3754f 100644
index b38bd30..cfaa677 100644
--- a/node_modules/mineflayer-pathfinder/index.js
+++ b/node_modules/mineflayer-pathfinder/index.js
@@ -541,7 +541,7 @@ function inject (bot) {
@ -7,7 +7,7 @@ index b38bd30..ae3754f 100644
if (placingBlock.jump) {
bot.setControlState('jump', true)
- canPlace = placingBlock.y + 1 < bot.entity.position.y
+ canPlace = placingBlock.y + 1.9 < bot.entity.position.y
+ canPlace = placingBlock.y + 1.8 < bot.entity.position.y
}
if (canPlace) {
if (!lockEquipItem.tryAcquire()) return

View file

@ -10,6 +10,8 @@ export class Coder {
this.generating = false;
this.code_template = '';
this.timedout = false;
this.interruptible = true;
this.cur_action_name = '';
readFile('./bots/template.js', 'utf8', (err, data) => {
if (err) throw err;
@ -156,10 +158,9 @@ export class Coder {
return {success: false, message: null, interrupted: false, timedout: true};
}
async executeResume(func=null, name=null, timeout=10) {
async executeResume(func=null, timeout=10) {
if (func != null) {
this.resume_func = func;
this.resume_name = name;
}
if (this.resume_func != null && this.agent.isIdle() && !this.agent.self_prompter.on) {
console.log('resuming code...')
@ -174,7 +175,10 @@ export class Coder {
cancelResume() {
this.resume_func = null;
this.resume_name = null;
}
setCurActionName(name) {
this.cur_action_name = name.replace(/!/g, '');
}
// returns {success: bool, message: string, interrupted: bool, timedout: false}

View file

@ -22,7 +22,7 @@ function say(agent, message) {
const modes = [
{
name: 'self_preservation',
description: 'Respond to drowning, burning, and damage at low health. Interrupts other actions.',
description: 'Respond to drowning, burning, and damage at low health. Interrupts all actions.',
interrupts: ['all'],
on: true,
active: false,
@ -70,9 +70,38 @@ const modes = [
}
}
},
{
name: 'unstuck',
description: 'Attempt to get unstuck when in the same place for a while. Interrupts some actions.',
interrupts: ['collectBlocks', 'goToPlayer', 'collectAllBlocks'],
on: true,
active: false,
prev_location: null,
stuck_time: 0,
last_time: Date.now(),
max_stuck_time: 10,
update: async function (agent) {
if (agent.isIdle()) return;
const bot = agent.bot;
if (this.prev_location && this.prev_location.distanceTo(bot.entity.position) < 1) {
this.stuck_time += (Date.now() - this.last_time) / 1000;
}
else {
this.prev_location = bot.entity.position.clone();
this.stuck_time = 0;
}
if (this.stuck_time > this.max_stuck_time) {
say(agent, 'I\'m stuck!');
execute(this, agent, async () => {
await skills.moveAway(bot, 5);
});
}
this.last_time = Date.now();
}
},
{
name: 'cowardice',
description: 'Run away from enemies. Interrupts other actions.',
description: 'Run away from enemies. Interrupts all actions.',
interrupts: ['all'],
on: true,
active: false,
@ -88,7 +117,7 @@ const modes = [
},
{
name: 'self_defense',
description: 'Attack nearby enemies. Interrupts other actions.',
description: 'Attack nearby enemies. Interrupts all actions.',
interrupts: ['all'],
on: true,
active: false,
@ -105,7 +134,7 @@ const modes = [
{
name: 'hunting',
description: 'Hunt nearby animals when idle.',
interrupts: ['defaults'],
interrupts: [],
on: true,
active: false,
update: async function (agent) {
@ -281,9 +310,8 @@ class ModeController {
this.unPauseAll();
}
for (let mode of this.modes_list) {
let available = mode.interrupts.includes('all') || this.agent.isIdle();
let interruptible = this.agent.coder.interruptible && (mode.interrupts.includes('defaults') || mode.interrupts.includes(this.agent.coder.resume_name));
if (mode.on && !mode.paused && !mode.active && (available || interruptible)) {
let interruptible = this.agent.coder.interruptible && (mode.interrupts.includes('all') || mode.interrupts.some(i => i === this.agent.coder.cur_action_name));
if (mode.on && !mode.paused && !mode.active && (this.agent.isIdle() || interruptible)) {
await mode.update(this.agent);
}
if (mode.active) break;