first pass at getting doors to work

This commit is contained in:
MaxRobinsonTheGreat 2025-08-12 14:35:23 -05:00
parent 00127506b1
commit 6501e83d44
3 changed files with 219 additions and 6 deletions

View file

@ -1,8 +1,35 @@
diff --git a/node_modules/mineflayer-pathfinder/index.js b/node_modules/mineflayer-pathfinder/index.js
index b38bd30..bf16a63 100644
index b38bd30..fb39b45 100644
--- a/node_modules/mineflayer-pathfinder/index.js
+++ b/node_modules/mineflayer-pathfinder/index.js
@@ -550,6 +550,7 @@ function inject (bot) {
@@ -170,6 +170,16 @@ function inject (bot) {
const curPoint = path[i]
if (curPoint.toBreak.length > 0 || curPoint.toPlace.length > 0) break
const b = bot.blockAt(new Vec3(curPoint.x, curPoint.y, curPoint.z))
+
+ // openned doors have small Collision box
+ // that may stop the bot from moving forward
+ if(i === 0 && b.name.includes('door')) {
+ curPoint.x = Math.floor(curPoint.x) + 0.5
+ curPoint.y = Math.floor(curPoint.y)
+ curPoint.z = Math.floor(curPoint.z) + 0.5
+ continue
+ }
+
if (b && (b.type === waterType || ((b.type === ladderId || b.type === vineId) && i + 1 < path.length && path[i + 1].y < curPoint.y))) {
curPoint.x = Math.floor(curPoint.x) + 0.5
curPoint.y = Math.floor(curPoint.y)
@@ -524,6 +534,9 @@ function inject (bot) {
bot.activateBlock(bot.blockAt(new Vec3(placingBlock.x, placingBlock.y, placingBlock.z))).then(() => {
lockUseBlock.release()
placingBlock = nextPoint.toPlace.shift()
+ if (!placingBlock) {
+ placing = false
+ }
}, err => {
console.error(err)
lockUseBlock.release()
@@ -550,6 +563,7 @@ function inject (bot) {
lockEquipItem.release()
const refBlock = bot.blockAt(new Vec3(placingBlock.x, placingBlock.y, placingBlock.z), false)
if (!lockPlaceBlock.tryAcquire()) return
@ -10,7 +37,7 @@ index b38bd30..bf16a63 100644
if (interactableBlocks.includes(refBlock.name)) {
bot.setControlState('sneak', true)
}
@@ -557,6 +558,7 @@ function inject (bot) {
@@ -557,6 +571,7 @@ function inject (bot) {
.then(function () {
// Dont release Sneak if the block placement was not successful
bot.setControlState('sneak', false)
@ -18,3 +45,152 @@ index b38bd30..bf16a63 100644
if (bot.pathfinder.LOSWhenPlacingBlocks && placingBlock.returnPos) returningPos = placingBlock.returnPos.clone()
})
.catch(_ignoreError => {
diff --git a/node_modules/mineflayer-pathfinder/lib/movements.js b/node_modules/mineflayer-pathfinder/lib/movements.js
index a7e3505..3c4a8f2 100644
--- a/node_modules/mineflayer-pathfinder/lib/movements.js
+++ b/node_modules/mineflayer-pathfinder/lib/movements.js
@@ -62,7 +62,13 @@
this.climbables = new Set()
this.climbables.add(registry.blocksByName.ladder.id)
- // this.climbables.add(registry.blocksByName.vine.id)
+ if (registry.blocksByName.vine) this.climbables.add(registry.blocksByName.vine.id)
+ if (registry.blocksByName.weeping_vines) this.climbables.add(registry.blocksByName.weeping_vines.id)
+ if (registry.blocksByName.weeping_vines_plant) this.climbables.add(registry.blocksByName.weeping_vines_plant.id)
+ if (registry.blocksByName.twisting_vines) this.climbables.add(registry.blocksByName.twisting_vines.id)
+ if (registry.blocksByName.twisting_vines_plant) this.climbables.add(registry.blocksByName.twisting_vines_plant.id)
+ if (registry.blocksByName.cave_vines) this.climbables.add(registry.blocksByName.cave_vines.id)
+ if (registry.blocksByName.cave_vines_plant) this.climbables.add(registry.blocksByName.cave_vines_plant.id)
this.emptyBlocks = new Set()
this.replaceables = new Set()
@@ -92,13 +98,15 @@
}
})
registry.blocksArray.forEach(block => {
- if (this.interactableBlocks.has(block.name) && block.name.toLowerCase().includes('gate') && !block.name.toLowerCase().includes('iron')) {
+ if (this.interactableBlocks.has(block.name)
+ && (block.name.toLowerCase().includes('gate') || block.name.toLowerCase().includes('door') || block.name.toLowerCase().includes('trapdoor'))
+ && !block.name.toLowerCase().includes('iron')) {
// console.info(block)
this.openable.add(block.id)
}
})
- this.canOpenDoors = false // Causes issues. Probably due to none paper servers.
+ this.canOpenDoors = true
this.exclusionAreasStep = []
this.exclusionAreasBreak = []
@@ -230,8 +238,13 @@
}
}
b.climbable = this.climbables.has(b.type)
- b.safe = (b.boundingBox === 'empty' || b.climbable || this.carpets.has(b.type)) && !this.blocksToAvoid.has(b.type)
- b.physical = b.boundingBox === 'block' && !this.fences.has(b.type)
+
+ // Enhanced trapdoor logic - open trapdoors are safe to pass through
+ const isOpenTrapdoor = this.openable.has(b.type) && b.name.includes('trapdoor') && b._properties?.open === true
+ const isClosedTrapdoor = this.openable.has(b.type) && b.name.includes('trapdoor') && b._properties?.open !== true
+
+ b.safe = (b.boundingBox === 'empty' || b.climbable || this.carpets.has(b.type) || isOpenTrapdoor) && !this.blocksToAvoid.has(b.type)
+ b.physical = (b.boundingBox === 'block' && !this.fences.has(b.type)) || isClosedTrapdoor
b.replaceable = this.replaceables.has(b.type) && !b.physical
b.liquid = this.liquids.has(b.type)
b.height = pos.y + dy
@@ -284,6 +297,18 @@
cost += this.exclusionStep(block) // Is excluded so can't move or break
cost += this.getNumEntitiesAt(block.position, 0, 0, 0) * this.entityCost
if (block.safe) return cost
+
+ // process door cost
+ if ((this.canOpenDoors && block.openable)
+ || (block.openable && block._properties?.open === true)) {
+ return cost
+ }
+
+ // Handle trapdoors specifically - they can be opened instead of broken
+ if (this.canOpenDoors && block.openable && block.name.includes('trapdoor') && !block.name.includes('iron')) {
+ return cost + 1 // Small cost for opening trapdoor
+ }
+
if (!this.safeToBreak(block)) return 100 // Can't break, so can't move
toBreak.push(block.position)
@@ -387,8 +412,8 @@
cost += this.safeOrBreak(blockB, toBreak)
if (cost > 100) return
- // Open fence gates
- if (this.canOpenDoors && blockC.openable && blockC.shapes && blockC.shapes.length !== 0) {
+ // Open fence gates and doors
+ if (this.canOpenDoors && blockC.openable && !blockC._properties.open) {
toPlace.push({ x: node.x + dir.x, y: node.y, z: node.z + dir.z, dx: 0, dy: 0, dz: 0, useOne: true }) // Indicate that a block should be used on this block not placed
} else {
cost += this.safeOrBreak(blockC, toBreak)
@@ -552,6 +577,54 @@
if (cost > 100) return
neighbors.push(new Move(node.x, node.y + 1, node.z, node.remainingBlocks - toPlace.length, cost, toBreak, toPlace))
+ }
+
+ getMoveClimbUpThroughTrapdoor (node, neighbors) {
+ const blockCurrent = this.getBlock(node, 0, 0, 0) // Current position (should be climbable)
+ const blockAbove = this.getBlock(node, 0, 1, 0) // Block directly above
+ const blockCeiling = this.getBlock(node, 0, 2, 0) // Trapdoor or ceiling block
+
+ // Only attempt this move if we're on a climbable block (ladder/vine)
+ if (!blockCurrent.climbable) return
+
+ // Check if there's a closed trapdoor above us
+ if (!blockCeiling.openable || blockCeiling._properties?.open === true) return
+
+ let cost = 2 // Base cost for climbing up and opening trapdoor
+ const toBreak = []
+ const toPlace = []
+
+ // Make sure we can break/pass through the block above if needed
+ cost += this.safeOrBreak(blockAbove, toBreak)
+ if (cost > 100) return
+
+ // Add cost for opening the trapdoor
+ toPlace.push({ x: node.x, y: node.y + 2, z: node.z, dx: 0, dy: 0, dz: 0, useOne: true })
+
+ neighbors.push(new Move(node.x, node.y + 2, node.z, node.remainingBlocks - toPlace.length, cost, toBreak, toPlace))
+ }
+
+ // Enhanced ladder/vine climbing that can handle stepping on top and jumping
+ getMoveClimbTop (node, neighbors) {
+ const blockCurrent = this.getBlock(node, 0, 0, 0) // Current position (should be climbable)
+ const blockAbove = this.getBlock(node, 0, 1, 0) // Block directly above
+
+ // Only attempt this move if we're on a climbable block (ladder/vine)
+ if (!blockCurrent.climbable) return
+
+ // Check if we can step on top of the ladder/vine and then jump up
+ if (!blockAbove.safe) return
+
+ let cost = 2 // Cost for climbing to top of ladder and jumping
+ const toBreak = []
+ const toPlace = []
+
+ // Check if there's space to jump up from the top of the ladder
+ const blockJumpTarget = this.getBlock(node, 0, 2, 0)
+ cost += this.safeOrBreak(blockJumpTarget, toBreak)
+ if (cost > 100) return
+
+ neighbors.push(new Move(node.x, node.y + 2, node.z, node.remainingBlocks - toPlace.length, cost, toBreak, toPlace))
}
// Jump up, down or forward over a 1 block gap
@@ -655,6 +728,10 @@
this.getMoveDown(node, neighbors)
this.getMoveUp(node, neighbors)
+
+ // Enhanced climbing moves for ladders, vines, and trapdoors
+ this.getMoveClimbUpThroughTrapdoor(node, neighbors)
+ this.getMoveClimbTop(node, neighbors)
return neighbors
}

View file

@ -118,6 +118,7 @@ export class Agent {
];
const respondFunc = async (username, message) => {
if (message === "") return;
if (username === this.name) return;
if (settings.only_chat_with.length > 0 && !settings.only_chat_with.includes(username)) return;
try {

View file

@ -1127,9 +1127,45 @@ export async function goToPlayer(bot, username, distance=3) {
return false;
}
const move = new pf.Movements(bot);
bot.pathfinder.setMovements(move);
await bot.pathfinder.goto(new pf.goals.GoalFollow(player, distance), true);
const dontBreakBlocks = ['glass', 'glass_pane'];
const nonDestructiveMovements = new pf.Movements(bot);
nonDestructiveMovements.canOpenDoors = true;
nonDestructiveMovements.allowFreeMotion = true;
nonDestructiveMovements.digCost = 100;
nonDestructiveMovements.blocksCantBreak.add(dontBreakBlocks.map(block => mc.getBlockId(block)));
const destructiveMovements = new pf.Movements(bot);
destructiveMovements.canOpenDoors = true;
destructiveMovements.allowFreeMotion = true;
let movements = nonDestructiveMovements;
const goal = new pf.goals.GoalFollow(player, distance);
const timeout = 5000;
try {
console.log('finding non-destructive path...');
const nonDestructivePath = await bot.pathfinder.getPathTo(nonDestructiveMovements, goal, timeout);
if (
nonDestructivePath &&
nonDestructivePath.path &&
nonDestructivePath.path.length > 0 &&
nonDestructivePath.status !== 'noPath'
) {
console.log('found non-destructive path');
movements = nonDestructiveMovements;
}
else {
console.log('no non-destructive path found, using destructive path');
movements = destructiveMovements;
}
} catch (err) {
log(bot, `Could not find a path: ${err.message}.`);
return false;
}
bot.pathfinder.setMovements(movements);
await bot.pathfinder.goto(goal, true);
log(bot, `You have reached ${username}.`);
}