PrismarineJS / mineflayer

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

deprecated event (physicTick) Error #3417

Open nicolio03 opened 4 months ago

nicolio03 commented 4 months ago

Detailed description of a problem

I am having trouble loading the code I have written due to an error saying : [JSE] Mineflayer detected that you are using a deprecated event (physicTick)! Please use this event (physicsTick) instead. I am using python so this might be the issue but I am fairly new to programing so I have no clue on how to begin troubleshooting farther than the code I write.

Your current code

''' from javascript import require, On, Once from threading import Thread from time import sleep

mineflayer = require('mineflayer') pathfinder = require('mineflayer-pathfinder') pvp = require('mineflayer-pvp').plugin Entity = require("prismarine-entity")('1.8.9') global movements

def main():

bot = mineflayer.createBot ({
    'host': 'localhost',
    'username': 'Bot',
    'auth': 'offline',
    'port': 25565,
    'version': '1.12',
    'password' : 'nicole11'
})    

bot.loadPlugin(pathfinder.pathfinder)
bot.loadPlugin(pvp)

global enemy

def needFood(bot):
    health = bot.health
    if health <= 10:
        bot.setQuickBarSlot(1)
        bot.consume()
    bot.setQuickBarSlot(0)
    bot.attack(bot.nearestEntity(),swing=True)

@Once (bot,'spawn')
def handleMsg(*args):    

    movements = pathfinder.Movements(bot)
    bot.chat("/give iron_sword")
    bot.chat("/give bread 64")
    bot.setQuickBarSlot(0)

    t1 = Thread(target = bot.needFood)
    t1.setDaemon(True)
    t1.start()

    @On (bot,'chat')
    def handleMsg(this, sender, message, *args):

        if 'fight' in message:

            @On (bot, 'physicsTick')
            def handleMsg (*args):
                entity = bot.nearestEntity()
                if entity.type == 'mob':
                    if entity.position.distanceTo(bot.entity.position) < 20:
                        enemy = entity
                        bot.pvp.attack(enemy)

            @On (bot,('entityDead',enemy))
            def handleMsg(*args):
                bot.pvp.attack(bot.nearestEntity(),swing=False)
                bot.chat('HAHA loser...')

            @On (bot,('entityMoved',enemy))
            def handleMsg(*args):
                pos= enemy.position
                bot.pathfinder.setMovements(movements)
                bot.pathfinder.setGoal(pathfinder.goals.GoalNear(pos.x,pos.y,pos.z,1))

if name == 'main': main() '''

Expected behavior

I am simply trying to get a bot to fight the closest entity.

BF5258 commented 1 month ago

It's just a warning. It is safe to ignore. The problem is in mineflayer-pvp not mineflayer. Here is a patch file if the warning is really that annoying: mineflayer-pvp+1.3.2.patch

diff --git a/node_modules/mineflayer-pvp/lib/PVP.js b/node_modules/mineflayer-pvp/lib/PVP.js
index 758c2b3..7c7220e 100644
--- a/node_modules/mineflayer-pvp/lib/PVP.js
+++ b/node_modules/mineflayer-pvp/lib/PVP.js
@@ -48,7 +48,7 @@ class PVP {
         this.meleeAttackRate = new TimingSolver_1.MaxDamageOffset();
         this.bot = bot;
         this.movements = new mineflayer_pathfinder_1.Movements(bot, require('minecraft-data')(bot.version));
-        this.bot.on('physicTick', () => this.update());
+        this.bot.on('physicsTick', () => this.update());
         this.bot.on('entityGone', e => { if (e === this.target)
             this.stop(); });
     }

Though I don't know how to use javascript with python.