PrismarineJS / mineflayer

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

Python didn't respond in time (100000ms) #2893

Closed EvilGeorgee closed 1 year ago

EvilGeorgee commented 1 year ago

Versions

Detailed description of a problem

My bot is working, but after +- 20 seconds it crashes and i have error: image

This problem not only with this code, i tried a lot of codes, everywhere same problem (it happens even if bot just afk and do nothing)

What did you try yet?

Other codes. Same problem

Your current code

/* from javascript import require, On import time import math import array pvp = require('mineflayer-pvp').plugin mineflayer = require('mineflayer') pathfinder = require('mineflayer-pathfinder') toolPlugin = require('mineflayer-tool').plugin movements = require('mineflayer-pathfinder').Movements GoalNear = require('mineflayer-pathfinder').goals GoalFollow = pathfinder.goals.GoalFollow blockAtCursor = pathfinder.blockAtCursor

bot = mineflayer.createBot({ 'host':'localhost', 'username':'mine', 'version':'1.18', 'port':'49417', })

bot.loadPlugin(pathfinder.pathfinder) mineflayer = require("mineflayer") bot.loadPlugin(toolPlugin) bot.loadPlugin(pvp)

def Fight(): player = input('Which player should i kill?: ') target = bot.players[player] if target == None: print('I cant find this player') Commands() else: bot.pvp.attack(target.entity) Commands()

def Go(): xyzp = input({'XYZ: '}) bot.pathfinder.setGoal(pathfinder.goals.GoalNear()) Commands()

@On(bot, 'spawn') def Commands(*args): mcData = require('minecraft-data')(bot.version) movements = pathfinder.Movements(bot, mcData)

time.sleep(7)

# bot.setControlState('forward', True)
# time.sleep(3.3)
# bot.setControlState('forward', False)
# bot.setControlState('right', True)
# time.sleep(5)
# bot.setControlState('right', False)
# time.sleep(3)
command = input('Command: ')
if 'fight' in command:
    Fight()
    Commands()
elif 'pstop' in command:
     bot.pvp.stop()
     Commands()
elif 'go' in command:
    Go()
else:
    print('I dont understand')
    Commands()

@On(bot, 'rain') def Rain(*args): bot.chat('/weather clear')

@On(bot, 'entityCrouch') def entityCrouch(this, entity, args): nrst = bot.ne /



## Additional context
EvilGeorgee commented 1 year ago

Fixed!!!. You should not write any functions outside @On(Bot, 'spawn') function! Like that:

from javascript import require, On

mineflayer = require('mineflayer')
pathfinder = require('mineflayer-pathfinder')
GoalFollow = pathfinder.goals.GoalFollow

bot = mineflayer.createBot({
'host':'localhost',
'username':'Bot',
'version':'1.18',
})

bot.loadPlugin(pathfinder.pathfinder)

@on(bot, 'spawn') <---- spawn function
def spawn(*args):
        mcData = require('minecraft-data')(bot.version)
        movements = pathfinder.Movements(bot, mcData)

        @On(bot, 'chat')            <----other  function
        def msgHandler(this, user, message, *args):

        @On(bot, 'whisper')        <------------- other  function 
        def whisper(user, message, player):