Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'targets') #93

Open
murilopereirame opened this issue May 5, 2022 · 0 comments
Open

Cannot read properties of undefined (reading 'targets') #93

murilopereirame opened this issue May 5, 2022 · 0 comments

Comments

@murilopereirame
Copy link

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();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant