feat(minecraft): improve goToCoordinate
This commit is contained in:
@@ -126,14 +126,14 @@ export const actionsList: Action[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'goToCoordinates',
|
||||
name: 'goToCoordinate',
|
||||
description: 'Go to the given x, y, z location.',
|
||||
execution: 'sequential',
|
||||
schema: z.object({
|
||||
x: z.number().describe('The x coordinate.'),
|
||||
y: z.number().describe('The y coordinate.').min(-64).max(320),
|
||||
z: z.number().describe('The z coordinate.'),
|
||||
closeness: z.number().describe('How close to get to the location in blocks.').min(0),
|
||||
closeness: z.number().describe('0 If want to be exactly at the position, otherwise a positive number in blocks for leniency.').min(0),
|
||||
}),
|
||||
perform: mineflayer => async (x: number, y: number, z: number, closeness: number) => {
|
||||
await skills.goToPosition(mineflayer, x, y, z, closeness)
|
||||
|
||||
@@ -33,6 +33,14 @@ export async function goToPosition(
|
||||
log(mineflayer, `Teleported to ${x}, ${y}, ${z}.`)
|
||||
return true
|
||||
}
|
||||
const targetBlock = mineflayer.bot.blockAt(new Vec3(Math.floor(x), Math.floor(y), Math.floor(z)))
|
||||
const blockAbove1 = mineflayer.bot.blockAt(new Vec3(Math.floor(x), Math.floor(y) + 1, Math.floor(z)))
|
||||
const blockAbove2 = mineflayer.bot.blockAt(new Vec3(Math.floor(x), Math.floor(y) + 2, Math.floor(z)))
|
||||
|
||||
if (targetBlock?.name !== 'air' && blockAbove1?.name === 'air' && blockAbove2?.name === 'air') {
|
||||
// Nudge one block up so we don't dig a silly hole in the ground when using the ground block as reference
|
||||
y += 1
|
||||
}
|
||||
|
||||
await mineflayer.bot.pathfinder.goto(new goals.GoalNear(x, y, z, minDistance))
|
||||
log(mineflayer, `You have reached ${x}, ${y}, ${z}.`)
|
||||
|
||||
Reference in New Issue
Block a user