PrismarineJS / mineflayer

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

bot get kicked for flying #671

Closed yunfan closed 4 years ago

yunfan commented 6 years ago

hi i am testing my bot on an BungeeCord MC server, which's version is 1.12 and all the other works, the bot receive message, and type login info and got respawn. but then after login->respawn, the bot got kicked for the server thoughts it was flying

i was wondering if some attribute in physics.js were too optimistic?

yunfan commented 6 years ago

here is the reg.js, use node reg.js username passwd to register a account on that server

var mineflayer = require('mineflayer');
var idx = 0;

var bot = mineflayer.createBot({
    host: "180.97.81.195", // optional
    port: 25565,       // optional
    username: process.argv[2], // email and password are required only for
    version: "1.12.2",
    colorsEnabled: false,
});

/** **/
bot.on('message', (msg) => {
    idx += 1;

    let tips = msg.extra ? msg.extra.map((m) => m.text).join('\n') : msg.text ;

    if(tips != undefined || tips != ''){
        if(tips.includes('请先注册账号')){
            bot.chat('/reg '+process.argv[3]+' '+process.argv[3]);
        }else{
            console.log(idx);
            console.log(tips);
        }
    }else{
            console.log(idx);
            console.log(msg);
    }
/** **
/** **/
});
/** **/

/** **
bot.on('chat', function(username, message) {
  if (username === bot.username) return;
    console.log(username);
    console.log(message);
    //bot.chat(message);
});
/** **/
yunfan commented 6 years ago

and here is the app.js, use node app.js username passwd to run it

var mineflayer = require('mineflayer');
//const navigatePlugin = require('mineflayer-navigate')(mineflayer);

var idx = 0;

var bot = mineflayer.createBot({
    host: "180.97.81.195", // optional
    port: 25565,       // optional
    username: process.argv[2], // email and password are required only for
    version: "1.12.2",
    colorsEnabled: false,
    keepAlive: true,
    checkTimeoutInterval: 10*1000,
});

bot.STATE = 'PRELOGIN'
bot.physics.gravity = 1;

//navigatePlugin(bot);

/** **/
bot.on('message', (msg) => {
    idx += 1;

    let tips = msg.extra ? msg.extra.map((m) => m.text).join('\n') : msg.text ;

    if(tips != undefined || tips != ''){
        if(bot.STATE=='PRELOGIN' && tips.includes('需要登录')){
            bot.chat('/l '+process.argv[3])
        }else if(bot.STATE=='PRELOGIN' && tips.includes('登录成功'))
            bot.STATE = 'AUTHED'
        else{
        }
            console.log(idx);
            console.log(tips);
            console.log(msg)
    }else{
       console.log(idx);
       console.log(msg);
    }
/** **
/** **/
});

/** **/

bot.on('actionBar', (msg) => { idx+=1; console.log({idx: idx, type: 'actionBar', msg: msg}); });
bot.on('login', (msg) => { idx+=1; console.log({idx: idx, type: 'login', msg: msg}); });
bot.on('spawn', (msg) => { idx+=1; console.log({idx: idx, type: 'spawn', msg: msg, bot: bot}); });
bot._client.on('position', (msg) => { idx+=1; console.log({idx: idx, type: 'position', msg: msg, position: bot.entity.position}); })
bot.on('respawn', (msg) => { idx+=1; console.log({idx: idx, type: 'respawn', msg: msg, bot: bot}); });
bot.on('game', (msg) => { idx+=1; console.log({idx: idx, type: 'game', msg: msg}); });
bot.on('title', (msg) => { idx+=1; console.log({idx: idx, type: 'title', msg: msg}); });
bot.on('rain', (msg) => { idx+=1; console.log({idx: idx, type: 'rain', msg: msg}); });
bot.on('time', (msg) => { idx+=1; console.log({idx: idx, type: 'time', msg: msg}); });
bot.on('end', (msg) => { idx+=1; console.log({idx: idx, type: 'end', msg: msg}); });
bot.on('kicked', (msg) => { idx+=1; console.log({idx: idx, type: 'kicked', msg: msg}); });
bot.on('spawnReset', (msg) => { idx+=1; console.log({idx: idx, type: 'spawnReset', msg: msg}); });
bot.on('death', (msg) => { idx+=1; console.log({idx: idx, type: 'death', msg: msg}); });
bot.on('health', (msg) => { idx+=1; console.log({idx: idx, type: 'health', msg: msg}); });

/** **/
bot.on('chat', function(username, message) {
  idx += 1;

  if (username === bot.username) return;
  console.log({idx: idx, type: 'chat', username: username, message: message});
});
/** **/
yunfan commented 6 years ago

i have to say that document need some improvement that i am now using logging everything to learn it

rom1504 commented 6 years ago

Does your server have no cheat plus plugin enabled ? If so, refer yourself to the corresponding issues. Yes physics.js might need some tweaking to work on these non vanilla servers.

On Tue, May 29, 2018, 17:45 yunfan notifications@github.com wrote:

i have to say that document need some improvement that i am now using logging everything to learn it

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/671#issuecomment-392826745, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_uUeOIK3G6SV4f5yBHxoR4Lm7qW1ks5t3W0WgaJpZM4URvt4 .

yunfan commented 6 years ago

yes i am sure that server had some anti cheat plugin.

yunfan commented 6 years ago

i tried pyCraft, and found it works, it looks like caused by the handle of teleconfirm package you see in such servers, they usually has some customized auth plugin, which spawn unauthened player to
a place and after authed, the server will teleport player to another place or world, and this is where my bot got kicked.

lluiscab commented 6 years ago

This seems to be caused because the physics stop as soon as the bot receives a respawn packet (see here) and don't get started again until a position packet is received from the server (see here).

This could simply be fixed by adding a new restartPhysics method which restarts the doPhysicsTimer interval

rom1504 commented 6 years ago

@lluiscab yes that makes sense, @yunfan could you try it on your server, make sure it works and then make a PR for this ?

yunfan commented 6 years ago

sorry the server i mentioned has been shutdown right now, will wait for its reopen and try that

tntpower10 commented 4 years ago

I found a way to fix this, you just have to put this bot.physics.gravity = 27; in your code after the bot spawns so in the end your code should look like this:

bot.on('spawn', function() {
        bot.physics.gravity = 27;
        //Your code here
}

You can change the 27 to a higher number if you want the bot to move less when being hit for example but 27 is the vanilla value and if you want to use the navigate plugin you should just put it on 27.

yunfan commented 4 years ago

@tntpower10 thanks, i havnt play this game for a year, your reply made me really want to retry again :D