Загрузка...

Issues with Node.js and MineFlayer

Thread in Node.js created by renameduser_3131873 Jun 15, 2023. 418 views

  1. renameduser_3131873
    renameduser_3131873 Topic starter Jun 15, 2023 0 Apr 4, 2020
    Здравствуйте все! тут нашел интерестный скрипт на ноде и хочу его возрадить но хз как xD, ChatGPT отказываеться с этим работать вот сам код

    JS
    const mineflayer = require('mineflayer');
    const pvp = require('mineflayer-pvp');
    const { pathfinder, Movements, goals } = require('mineflayer-pathfinder');
    const armorManager = require('mineflayer-armor-manager');
    const autoeat = require('mineflayer-auto-eat');
    const collectBlock = require('mineflayer-collectblock');

    const bot = mineflayer.createBot({
    host: 'Myheart12.aternos.me',
    port: 27153,
    username: 'vakaaa',
    });

    bot.loadPlugin(pvp);
    bot.loadPlugin(armorManager);
    bot.loadPlugin(pathfinder);
    bot.loadPlugin(autoeat);
    bot.loadPlugin(collectBlock);

    bot.once('spawn', () => {
    bot.autoEat.options = {
    priority: 'foodPoints',
    startAt: 10,
    bannedFood: []
    };
    });

    bot.on('playerCollect', (collector, itemDrop) => {
    if (collector !== bot.entity) return;

    setTimeout(() => {
    const sword = bot.inventory.items().find(item => item.name.includes('sword'));
    if (sword) bot.equip(sword, 'hand');
    }, 150);
    });

    bot.on('playerCollect', (collector, itemDrop) => {
    if (collector !== bot.entity) return;

    setTimeout(() => {
    const shield = bot.inventory.items().find(item => item.name.includes('shield'));
    if (shield) bot.equip(shield, 'off-hand');
    }, 250);
    });

    let guardPos = null;

    function guardArea(pos) {
    guardPos = pos.clone();

    if (!bot.pvp.target) {
    moveToGuardPos();
    }
    }

    function stopGuarding() {
    guardPos = null;
    bot.pvp.stop();
    bot.pathfinder.setGoal(null);
    }

    function moveToGuardPos() {
    const mcData = require('minecraft-data')(bot.version);
    const movements = new Movements(bot, mcData);
    bot.pathfinder.setMovements(movements);
    const goal = new goals.GoalBlock(guardPos.x, guardPos.y, guardPos.z);
    bot.pathfinder.setGoal(goal);
    }

    bot.on('stoppedAttacking', () => {
    if (guardPos) {
    moveToGuardPos();
    }
    });

    bot.on('physicTick', () => {
    if (bot.pvp.target) return;
    if (bot.pathfinder.isMoving()) return;

    const entity = bot.nearestEntity();
    if (entity) bot.lookAt(entity.position.offset(0, entity.height, 0));
    });

    bot.on('physicTick', () => {
    if (!guardPos) return;

    const filter = e => e.type === 'mob' && e.position.distanceTo(bot.entity.position) < 16 &&
    e.mobType !== 'Armor Stand';

    const entity = bot.nearestEntity(filter);
    if (entity) {
    bot.pvp.attack(entity);
    }
    });

    bot.on('chat', (username, message) => {
    if (username === 'Vaka') {
    const args = message.split(' ');
    if (args[0] === 'Собери') {
    const mcData = require('minecraft-data')(bot.version);
    const blockType = mcData.blocksByName[args[1]];
    if (!blockType) {
    bot.chat("Не знаю такого блока.");
    return;
    }

    const block = bot.findBlock({
    matching: blockType.id,
    maxDistance: 64
    });

    if (!block) {
    bot.chat("Не вижу таких поблизости.");
    return;
    }

    bot.chat('Собираю ближний ' + blockType.name);
    bot.collectBlock.collect(block, err => {
    if (err) bot.chat(err.message);
    });
    }

    if (message === 'охраняй') {
    const player = bot.players[username];

    if (!player) {
    bot.chat("Не могу тебя найти.");
    return;
    }

    bot.chat('Буду защищать эту локацию.');
    guardArea(player.entity.position);
    }

    if (message.indexOf('пиши ') !== -1) {
    const replacement = "пиши ";
    const toReplace = "";
    let str = message.replace(replacement, toReplace);
    bot.chat(str);
    }

    if (message.indexOf('ходи ') !== -1) {
    const replacement = "ходи ";
    const toReplace = "";
    let str = message.replace(replacement, toReplace);
    const player = bot.players[str];

    if (!player) {
    bot.chat("Не могу найти.");
    return;
    }

    const goal = new GoalFollow(player.entity, 1);
    bot.pathfinder.setGoal(goal, true);
    }

    if (message.indexOf('дерись ') !== -1) {
    const replacement = "дерись ";
    const toReplace = "";
    let str = message.replace(replacement, toReplace);
    const player = bot.players[str];

    if (!player) {
    bot.chat("Не могу тебя найти.");
    return;
    }

    bot.chat('Готовлюсь к битве!');
    bot.pvp.attack(player.entity);
    }

    if (message === 'стоп') {
    bot.chat('Больше не охраняю.');
    stopGuarding();
    }

    if (message === 'выкинь') {
    function tossNext() {
    if (bot.inventory.items().length === 0) return;
    const item = bot.inventory.items()[0];
    bot.tossStack(item, tossNext);
    }
    tossNext();
    }
    }
    });

    Ну, а тут сама ошибка при запуске :finger_up:

    node:assert:399
    throw err;
    ^

    AssertionError [ERR_ASSERTION]: plugin needs to be a function
    at EventEmitter.loadPlugin (C:\Users\Стас\node_modules\mineflayer\lib\plugin_loader.js:16:12)
    at Object.<anonymous> (C:\Users\Стас\main.js:14:5)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
    generatedMessage: false,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
    }

    Node.js v20.3.0
     
  2. eqshka
    eqshka Jun 22, 2023 11 Nov 14, 2018
    Скинь ошибку полностью
     
  3. Tw1x_Team
    Tw1x_Team Oct 21, 2023 Banned 0 Dec 29, 2022
    жалуется на то что == а не ===
     
Loading...
Top