darthfett / mineflayer-blockfinder Goto Github PK
View Code? Open in Web Editor NEWmineflayer plugin which gives bots a function to find the nearest block
mineflayer plugin which gives bots a function to find the nearest block
This is after I updated the script for mineflayer 2.0.0
C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.js:246
bot.findBlock = findBlock;
^
TypeError: Cannot set property 'findBlock' of undefined
at inject (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index
.js:246:23)
at Object. (C:\Program Files\nodejs\reddit.js:6:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
I am trying to use blockfinder to find a chest and have the bot stand on it but it gives me this error:
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
AssertionError [ERR_ASSERTION]: undefined != null
at optionsWithDefaults (C:\Users\blake\Desktop\Friend PRO\node_modules\mineflayer-blockfinder\index.js:234:20)
at EventEmitter.findBlock (C:\Users\blake\Desktop\Friend PRO\node_modules\mineflayer-blockfinder\index.js:262:23)
at putItemsIntoChest (C:\Users\blake\Desktop\Friend PRO\bot.js:81:23)
at EventEmitter.<anonymous> (C:\Users\blake\Desktop\Friend PRO\bot.js:58:9)
at EventEmitter.emit (node:events:538:35)
at EventEmitter.<anonymous> (C:\Users\blake\Desktop\Friend PRO\node_modules\mineflayer\lib\plugins\chat.js:85:13)
at EventEmitter.emit (node:events:526:28)
at Client.<anonymous> (C:\Users\blake\Desktop\Friend PRO\node_modules\mineflayer\lib\plugins\chat.js:130:9)
at Client.emit (node:events:526:28)
at Client.<anonymous> (C:\Users\blake\Desktop\Friend PRO\node_modules\minecraft-protocol\src\client\chat.js:244:14) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: undefined,
expected: null,
operator: '!='
}
copy + paste code
update mineflayer
update mineflayer-blockfinder
rewrite entirety of code
const mineflayer = require('mineflayer');
const blockFinderPlugin = require('mineflayer-blockfinder')(mineflayer);
const pathfinder = require('mineflayer-pathfinder').pathfinder
const Movements = require('mineflayer-pathfinder').Movements
const { GoalNear } = require('mineflayer-pathfinder').goals
const { GoalFollow } = require('mineflayer-pathfinder').goals;
const { GoalBlock } = require('mineflayer-pathfinder').goals
var canFollow = false
const settings = {
host: 'localhost',
port: '61757',
username: 'Friend_PRO',
version: '1.19.2'
}
const bot = mineflayer.createBot(settings)
bot.loadPlugin(pathfinder);
bot.loadPlugin(blockFinderPlugin);
bot.once('spawn', async () => {
const defaultMove = new Movements(bot)
bot.on('chat', async function(username, message) {
if (username != 'firewry') return
const target = bot.players[username] ? bot.players[username].entity : null
if (message === ';come') {
if (!target) {
await bot.waitForTicks(20)
bot.chat('I don\'t see you. where are you?')
return
}
const p = target.position
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalNear(p.x, p.y, p.z, 1))
}
})
})
bot.on('chat', async function(username, message) {
if (username != 'firewry') return
if (message == ';follow'){
canFollow = true
followPlayer(username)
}
if (message == ';stop'){
canFollow = false
bot.pathfinder.setGoal(null);
}
if (message == ';items'){
putItemsIntoChest()
}
})
async function followPlayer(username){
if (canFollow){
const playerToFollow = bot.players[username];
const mcData = require('minecraft-data')(bot.version);
const movements = new Movements(bot, mcData);
movements.scafoldingBlocks = []
bot.pathfinder.setMovements(movements)
bot.pathfinder.setGoal(new GoalFollow(playerToFollow.entity, 2), true)
}
}
async function putItemsIntoChest(){
const mcData = require('minecraft-data')(bot.version)
const movements = new Movements(bot, mcData)
movements.scafoldingBlocks = []
bot.pathfinder.setMovements(movements)
const chest = bot.findBlock({
matching: 54,
maxDistance: 32
})
if(!chest){
bot.chat("I cant find a chest")
return
}
const x = chest.position.x
const y = chest.position.y + 1
const z = chest.position.z
const goal = new GoalBlock(x, y, z)
bot.pathfinder.setGoal(goal)
}
The bot go and stand on the chest
N/A
Refactor this module to make re-use of the logic between findBlock and findBlockSync. See this issue on helperbot.
I think it's just an error that I made, or setGoal
really doesn't work on the goal_reached
event.
Here's my code:
const { pathfinder, goals, Movements } = require('mineflayer-pathfinder');
const blockfinder = require('mineflayer-blockfinder')(mineflayer);
const bot = mineflayer.createBot({ host: 'xxx', port: 'xxx', username: 'woodfetcher' });
bot.loadPlugin(pathfinder);
bot.loadPlugin(blockfinder);
let player;
bot.once('spawn', () => {
const mcData = require('minecraft-data')(bot.version);
const defaultMovements = new Movements(bot, mcData);
bot.on('chat', (username, message) => {
player = bot.players[username].entity;
if (message === 'fetch wood') {
bot.findBlock({
point: bot.entity.position,
matching: 17,
maxDistance: 256,
count: 1
}, (err, blocks) => {
if (err) return console.error(err);
if (blocks.length >= 1) {
bot.chat('Fetching wood!');
const pos = blocks[0].position;
bot.pathfinder.setMovements(defaultMovements);
bot.pathfinder.setGoal(new goals.GoalBlock(pos.x, pos.y, pos.z));
}
});
}
});
bot.on('goal_reached', () => {
bot.chat('Got wood!');
if (player) {
bot.pathfinder.setMovements(defaultMovements);
bot.pathfinder.setGoal(new goals.GoalFollow(player, 2));
}
});
});
I don't know what changed but I'm getting this running https://github.com/Darthfett/mineflayer-blockfinder/blob/master/examples/diamondFinder.js now (with the last commit from mineflayer)
(I noticed this because I'm using this plugin in https://github.com/rom1504/rbot)
Using the following code:
case '!findportal':
try {
bot.findBlock({
point: bot.entity.postition,
matching: 181,
maxDistance: 256,
count: 1,
}, function(err, blocks) {
if (err) {
return console.log(err)
}
if (blocks.length) {
pos = blocks[0].position
bot.chat("I found a portal at " + pos + ". Going there now...")
bot.navigate.to(pos)
return;
} else {
bot.chat("Portal not found.")
return;
}
});
} catch(err) {
console.log(err)
}
break
Gives me:
C: <jvyden420> !findportal
assert.js:42
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: undefined != null
at optionsWithDefaults (/home/jvyden/jvybotmc/node_modules/mineflayer-blockfinder/index.js:234:20)
at Bot.findBlockSync (/home/jvyden/jvybotmc/node_modules/mineflayer-blockfinder/index.js:248:23)
at Bot.<anonymous> (/home/jvyden/jvybotmc/main.js:66:13)
at emitMany (events.js:147:13)
at Bot.emit (events.js:224:7)
at checkForChatPatterns (/home/jvyden/jvybotmc/node_modules/mineflayer/lib/plugins/chat.js:44:80)
at Client.bot._client.on (/home/jvyden/jvybotmc/node_modules/mineflayer/lib/plugins/chat.js:56:5)
at emitTwo (events.js:126:13)
at Client.emit (events.js:214:7)
at FullPacketParser.deserializer.on (/home/jvyden/jvybotmc/node_modules/minecraft-protocol/src/client.js:82:12)
What am I doing wrong?
Greetings,
I just installed this plugin and after debugging my project I noticed that its implementation is always ignored in favor of the one in mineflayer.
Here's some code snippets:
My project's code:
var bot = mineflayer.createBot({
...
});
// Install the plugin - method override is done here
blockFinderPlugin(bot);
// Sample usage
bot.once('spawn', function() {
bot.findBlock(...) // the original findBlock is called instead of the plugin`s
});
The injection function blockFinderPlugin
is successfully called and the override code also succeeds:
function findBlockSync(options) {
...
}
function findBlock(options, callback) {
...
}
bot.findBlock = findBlock;
bot.findBlockSync = findBlockSync;
Yet the original function is always called instead. I don't know if the issue belongs here or at themain repo, so apologies if this isn't meant for here.
Cheers
Minecraft version 1.16.1
Hello, I found this example of chest opening and withdrawing items. https://github.com/PrismarineJS/mineflayer/blob/1abfe102766175b27fa39cb6cf587da6fc9a2d9a/examples/chest.js
But I couldn't find a chest.
So I found this plugin and tried the usage example.
I lowered the maxDistance, otherwise, it crashes. I placed a diamond ore next to the player, and it didn't find a single block.
It just returns an empty array
If there's no way to fix this. Is there a way to open a chest at given coords? (constructing a Block)
Many blocks found when the count > 1 are duplicates, although not all of them.
Does this mean that the search algorithm is iterating over some blocks multiple times?
Woops, wrong repository. Ignore me, I'm stupid.
There is clearly diamond ore like 60 blocks underground.
It doesn't work.
I'm using the example
point: bot.entity.position,
matching: 56,
maxDistance: 256,
count: 1,
bot.findBlock({
point: bot.entity.position,
matching: [54, 57],
maxDistance: 256,
count: 7,
}
if the block are more the bug will be not caused but if there are not much block then the count the bot will crash without error
If I specify mineflayer-blockfinder 0.0.5 in my package.json and run npm install, the saved files are not the latest version. (MAX_CPU_SPIN = 100, not 10)
I have to manually link this repository's latest commit to get the correct version.
------ TheTechPony: find 56
C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.js:279
var cpuSpinTime = new Date() - lastTick;
^
RangeError: Maximum call stack size exceeded
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:279:46)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
at next (C:\Program Files\nodejs\node_modules\mineflayer-blockfinder\index.j
s:287:21)
instead of an array of item/block enums.
My script can't find any wood block with ID 17 or 4 ... Can you help me ?
The new blockfinder algorithm now takes 4 minutes to check 64 blocks in all directions from the player (This is 128^3 blocks).
The new algorithm actually checks all these blocks, unlike the old algorithm, which only worked sometimes.
I think its the same issue as #19
I've set the ID to bedrock (7)... but for some reason it seems like it can never find anything. No bedrock, no grassblocks, nothing.
What was the fix @moom0o that eventually helped you out? Or anyone else knows what is going on?
const mineflayer = require('mineflayer')
var blockFinderPlugin = require('mineflayer-blockfinder')(mineflayer);
const fs = require('fs')
function createBot () {
const bot = mineflayer.createBot({
host: '192.168.137.1',
port: 25565,
username: 'MAIL',
password: 'PASSWORD',
auth: 'microsoft'
})
bot.loadPlugin(blockFinderPlugin);
//
// blockFinderPlugin(bot);
bot.on('spawn', function() {
console.log("[BOT] - Spawned")
bot.findBlock({
point: bot.entity.position,
matching: 7, //90 = portal, 49 = obsidian, 1 = stone, 7 = bedrock
maxDistance: 16,
count: 1,
}, function(err, blocks) {
console.log("[BOT] - findBLocks function started")
if (err) {
bot.chat('Error trying to find Bedrock: ' + err);
setTimeout(kill, 5100)
}
console.log(blocks)
if (blocks.length) {
return bot.chat('I found a Bedrock block at ' + blocks[0].position + '.');
} else {
bot.chat("I couldn't find any Bedrock within 256.");
setTimeout(kill, 5100)
}
});
});
bot.on('error', (err) => {
console.log(err)
process.exit(1)
})
// setInterval(kill, 5100)
function kill () {
bot.chat("/kill")
}
}
createBot()
as you can see above, the console.log(blocks)
gives an empty console
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.