PrismarineJS / mineflayer-collectblock

A simple utility plugin for Mineflayer that add a higher level API for collecting blocks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read properties of undefined (reading 'targets')

murilopereirame opened this issue · comments

The latest version of plugin throws

TypeError: Cannot read properties of undefined (reading 'targets')
    at /Users/mo0p3/Documents/Projetos/MineBot/node_modules/mineflayer-collectblock/lib/CollectBlock.js:191:31
    at Generator.next (<anonymous>)
    at /Users/mo0p3/Documents/Projetos/MineBot/node_modules/mineflayer-collectblock/lib/CollectBlock.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/mo0p3/Documents/Projetos/MineBot/node_modules/mineflayer-collectblock/lib/CollectBlock.js:4:12)
    at collect (/Users/mo0p3/Documents/Projetos/MineBot/node_modules/mineflayer-collectblock/lib/CollectBlock.js:178:16)
    at collectCallbackified (node:util:304:5)
    at CollectBlock.<anonymous> (/Users/mo0p3/Documents/Projetos/MineBot/node_modules/mineflayer-collectblock/lib/CollectBlock.js:185:61)
    at Generator.next (<anonymous>)
    at /Users/mo0p3/Documents/Projetos/MineBot/node_modules/mineflayer-collectblock/lib/CollectBlock.js:8:71

Script

/**
 * A quick and easy implementation of the collect block plugin. (Requires mineflayer-pathfinder and mineflayer-collectblock)
 */
const mineflayer = require("mineflayer");
const pathfinder = require("mineflayer-pathfinder").pathfinder;
const collectBlock = require("mineflayer-collectblock").plugin;

const bot = mineflayer.createBot({
  host: "localhost",
  username: "TheMinner",
});

// Load pathfinder and collect block plugins
bot.loadPlugin(pathfinder);
bot.loadPlugin(collectBlock);

// Load mc data
let mcData;

const digIron = async () => {
  const block = bot.findBlock({
    matching: mcData.blocksByName.iron_ore.id,
    maxDistance: 64,
  });
  try {
    await bot.collectBlock.collect(
      block,
      {
        append: true,
        ignoreNoPath: true,
        chestLocations: [],
        itemFilter: (item) => true,
      },
      (err) => {
        if (!err) {
          console.log("New dig!");
          digIron();
        } else console.log("CALLBACK=>", err);
      }
    );
  } catch (err) {
    console.log(err);
  }
};

bot.once("spawn", () => {
  mcData = require("minecraft-data")(bot.version);
  digIron();
});