Closed theblazehen closed 1 year ago
I'm getting an error of
return block.name.endsWith("_log") && block.position.distanceTo(bot.entity.position) < 32; Cannot read properties of null (reading 'distanceTo')
Python: 3.10.6 Nodejs: v20.2.0 Minecraft: 1.19 Fabric: 0.14.18
logs
mineflayer.log
****Recorder message: 3700 ticks have elapsed**** ****Recorder message: 34 iteration passed**** Critic Agent: Error occurs Your code:4 return block.name.endsWith("_log") && block.position.distanceTo(bot.entity.position) < 32; Cannot read properties of null (reading 'distanceTo') ****Action Agent human message**** Code from the last round: async function mineWoodLog(bot) { const woodLog = bot.findBlock({ matching: block => { return block.name.endsWith("_log") && block.position.distanceTo(bot.entity.position) < 32; } }); if (woodLog) { await mineBlock(bot, woodLog.name); } else { await bot.chat("No wood log found nearby."); } } async function mineOneWoodLog(bot) { await mineWoodLog(bot); } Execution error: Your code:4 return block.name.endsWith("_log") && block.position.distanceTo(bot.entity.position) < 32; Cannot read properties of null (reading 'distanceTo') Chat log: None Biome: forest Time: midnight Nearby blocks: dirt, grass_block, oak_log, grass, stone, oak_leaves Nearby entities (nearest to farthest): None Health: 20.0/20 Hunger: 20.0/20 Position: x=1.7, y=77.0, z=-3.6 Equipment: [None, None, None, None, None, None] Inventory (0/36): Empty Chests: None Task: Mine 1 wood log Context: You can mine one of oak, birch, spruce, jungle, acacia, dark oak, or mangrove logs. Critique: None ****Action Agent ai message**** Explain: The error occurs because the `bot.findBlock` function returns `null` when no matching block is found. The code tries to access the `position` property of a `null` value, causing the error. Plan: 1) Modify the `mineWoodLog` function to check if a wood log is found before accessing its properties. 2) Call the `mineWoodLog` function to mine one wood log. Code: ```javascript async function mineWoodLog(bot) { const woodLog = bot.findBlock({ matching: block => { return block && block.name.endsWith("_log") && block.position.distanceTo(bot.entity.position) < 32; } }); if (woodLog) { await mineBlock(bot, woodLog.name); } else { await bot.chat("No wood log found nearby."); } } async function mineOneWoodLog(bot) { await mineWoodLog(bot); }
I should probably read the logs before posting an issue...
Before submitting an issue, make sure you read the FAQ.md
Briefly describe your issue
I'm getting an error of
Please provide your python, nodejs, Minecraft, and Fabric versions here
Python: 3.10.6 Nodejs: v20.2.0 Minecraft: 1.19 Fabric: 0.14.18
[If applicable] Please provide the Minefalyer and Minecraft logs, you can find the log under
logs
foldermineflayer.log
[If applicable] Please provide the GPT conversations that are printed each round.