Skip to content

Commit 9808bcd

Browse files
committed
fix: resolve syntax error, water pickup, and ground detection bugs
- Remove orphan bot.findBlocks() in auto_sleep that caused a syntax error breaking the entire modes.js module (sleep never triggered) - Equip empty bucket before activateItem() to actually pick up placed water - Scan 1-6 blocks below for ground instead of checking only at fixed 4-block offset, widening the activation window for MLG water - Use goToBed() return value instead of try/catch (it returns false, not throws)
1 parent 04568a1 commit 9808bcd

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/agent/modes.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,16 @@ const modes_list = [
111111
if (fallDistance > 10 && vel.y < -0.5) {
112112
const waterBucket = bot.inventory.items().find(item => item.name === 'water_bucket');
113113
if (waterBucket && !this.active) {
114-
// Check if ground is near (within 4 blocks below)
115-
const groundBlock = bot.blockAt(pos.offset(0, -4, 0));
116-
if (groundBlock && groundBlock.name !== 'air' && groundBlock.name !== 'water') {
114+
// Check if ground is near (scan up to 6 blocks below)
115+
let groundNear = false;
116+
for (let dy = 1; dy <= 6; dy++) {
117+
const block = bot.blockAt(pos.offset(0, -dy, 0));
118+
if (block && block.name !== 'air' && block.name !== 'water') {
119+
groundNear = true;
120+
break;
121+
}
122+
}
123+
if (groundNear) {
117124
execute(this, agent, async () => {
118125
const currentPos = bot.entity.position.clone();
119126
say(agent, 'MLG water!');
@@ -138,8 +145,12 @@ const modes_list = [
138145
// Pick up water after landing
139146
const waterBlock = world.getNearestBlock(bot, 'water', 3);
140147
if (waterBlock) {
141-
await bot.lookAt(waterBlock.position);
142-
bot.activateItem();
148+
const emptyBucket = bot.inventory.items().find(item => item.name === 'bucket');
149+
if (emptyBucket) {
150+
await bot.equip(emptyBucket, 'hand');
151+
await bot.lookAt(waterBlock.position);
152+
bot.activateItem();
153+
}
143154
}
144155
} catch (e) {
145156
console.log('[FALL_PROTECTION] Error:', e.message);
@@ -254,19 +265,11 @@ const modes_list = [
254265
const isNight = time >= 13000;
255266
if (!isNight || bot.isSleeping) return;
256267

257-
// Look for a bed within 32 blocks using block name matching (beds are named like 'white_bed', 'red_bed', etc.)
258-
const beds = bot.findBlocks({
259-
matching: (block) => block.name.includes('bed'),
260-
maxDistance: 32,
261-
// Let skills.goToBed handle finding a suitable bed
268+
// Let skills.goToBed handle finding and sleeping in a bed
262269
execute(this, agent, async () => {
263-
try {
264-
await skills.goToBed(bot);
270+
const result = await skills.goToBed(bot);
271+
if (result) {
265272
say(agent, 'It\'s getting dark, I should sleep.');
266-
} catch (e) {
267-
if (e && e.message && e.message.includes('occupied')) {
268-
say(agent, 'The bed is occupied.');
269-
}
270273
}
271274
});
272275
}

0 commit comments

Comments
 (0)