UNPKG

mineflayer-utils

Version:

A collection of small utility classes, functions, and events which work nicely with Mineflayer.

23 lines (22 loc) 825 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNearestEntity = void 0; function getNearestEntity(bot, filter, count) { if (filter === void 0) { filter = function () { return true; }; } if (count === void 0) { count = 1; } var entities = []; for (var entityName in bot.entities) { var entity = bot.entities[entityName]; if (entity === bot.entity) continue; if (!filter(entity)) continue; entities.push(entity); } var pos = bot.entity.position; entities.sort(function (a, b) { return a.position.distanceSquared(pos) - b.position.distanceSquared(pos); }); if (entities.length > count) entities = entities.splice(0, count); return entities; } exports.getNearestEntity = getNearestEntity;