UNPKG

@nxg-org/mineflayer-util-plugin

Version:

mineflayer utils for NextGEN mineflayer plugins.

52 lines (51 loc) 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InterceptFunctions = void 0; const vec3_1 = require("vec3"); const iterators_1 = require("./iterators"); class InterceptFunctions { constructor(bot) { this.bot = bot; } //Old ver grabs range between the two + direction from... from to... to. //calls raycast. check(from, to) { //old code: const range = from.distanceTo(to); const direction = to.minus(from).normalize(); if (isNaN(range)) return { block: null, iterations: [] }; return this.raycast(from, direction, range); } raycast(from, direction, range) { const iterations = []; const iter = new iterators_1.RaycastIterator(from, direction, range); let pos = iter.next(); while (pos) { iterations.push(pos); const position = new vec3_1.Vec3(pos.x, pos.y, pos.z); const block = this.bot.blockAt(position); if (block) { const intersect = iter.intersect(block.shapes, position); if (intersect) { return { block, iterations, intersect: intersect, }; } } pos = iter.next(); if ((iterations.length >= 1000 && iterations.length % 1000 === 0)) { // console.trace("too much"); console.log(from, direction, range, iterations, block, position, pos); } // console.log(range, iterations.length); } return { block: null, iterations, }; } } exports.InterceptFunctions = InterceptFunctions;