PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.93k stars 903 forks source link

[python] Bot crash. physicsTick #2996

Closed ghost closed 4 weeks ago

ghost commented 1 year ago

Versions

Detailed description of a problem

I am trying to create a bot that will view players, but with frequent chat messages (even if you check the text of the message), an error occurs and the bot crashes

What did you try yet?

Did you try any method from the API?

Yes, bot.lookAt

Did you try any example? Any error from those?

I took an example from here https://github.com/TheDudeFromCI/Mineflayer-Youtube-Tutorials/blob/master/lookAt_Bot/index .js (it works on js, but Python gets the error described above)

Your current code

from javascript import require, On
mineflayer = require('mineflayer')

bot = mineflayer.createBot({
  'host': 'localhost',
  'port': 59304,
  'username': 'lookAt_Bot'
})

def lookAtNearestPlayer():
    playerEntity = bot.nearestEntity()

    if not playerEntity: 
        return

    pos = playerEntity.position.offset(0, playerEntity.height, 0)
    bot.lookAt(pos)

@On(bot, 'chat')
def chathandle(this, username, message, *args):
    if username == "sffkjsdfsfd" and message == "asdkasdjkadjskajsdj":
        bot.chat('asjdkjasdkasjd')

@On(bot, 'physicsTick')
def handle(*args):
    lookAtNearestPlayer()

Expected behavior

It was expected to see that the bot looked at the player and did not crash after messages in the chat.

Additional context

I attach a screenshot of the minecraft chat and a screenshot of the error and the error text Minecraft chat: https://imgur.com/5gChrTF Error: https://imgur.com/Ww9h3ci C:\Users\root\Desktop>python main.py [JSE] node:internal/process/promises:288 [JSE] triggerUncaughtException(err, true /* fromPromise */); [JSE] ^ [JSE] [JSE] [🐍 Python Error JavaScript attempt to call 'some function' in Python failed: [JSE] > bot.emit('physicsTick') [JSE] at Timeout.doPhysics [as _onTimeout] (C:\Users\root\AppData\Local\Programs\Python\Python39\lib\site-packages\javascript\js\node_modules\mineflayer\lib\plugins\physics.js:65:13) [JSE] at listOnTimeout (node:internal/timers:569:17) [JSE] at process.processTimers (node:internal/timers:512:7) [JSE] [JSE] ... across the bridge ... [JSE] [JSE] > lookAtNearestPlayer() [JSE] at handle (C:\Users\root\Desktop\main.py:26) [JSE] > pos = playerEntity.position.offset(0, playerEntity.height, 0) [JSE] at lookAtNearestPlayer (C:\Users\root\Desktop\main.py:16) [JSE] 🌉 javascript.errors.JavaScriptError: ('offset', "TypeError: Cannot read properties of undefined (reading 'offset')\n at Bridge.call (C:\\Users\\root\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\javascript\\js\\bridge.js:136:35)\n at Bridge.onMessage (C:\\Users\\root\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\javascript\\js\\bridge.js:226:25)\n at Socket.<anonymous> (C:\\Users\\root\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\javascript\\js\\bridge.js:278:18)\n at Socket.emit (node:events:513:28)\n at addChunk (node:internal/streams/readable:324:12)\n at readableAddChunk (node:internal/streams/readable:297:9)\n at Readable.push (node:internal/streams/readable:234:10)\n at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)")] [JSE] [JSE] Node.js v18.15.0

ghost commented 1 year ago

up?

ghost commented 4 weeks ago

up