UNPKG

@nxg-org/mineflayer-util-plugin

Version:

mineflayer utils for NextGEN mineflayer plugins.

42 lines (41 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AABBUtils = void 0; const aabb_1 = require("../calcs/aabb"); var AABBUtils; (function (AABBUtils) { function getBlockAABB(block, height = 1) { const { x, y, z } = block.position; return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1); } AABBUtils.getBlockAABB = getBlockAABB; function getBlockPosAABB(block, height = 1) { const { x, y, z } = block.floored(); return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1); } AABBUtils.getBlockPosAABB = getBlockPosAABB; function getEntityAABB(entity) { switch (entity.type) { case "player": return getEntityAABBRaw({ position: entity.position, height: entity.height + 0.18, width: entity.width }); case "mob": default: //TODO: Implement better AABBs. However, this may just be correct. return getEntityAABBRaw({ position: entity.position, height: entity.height, width: entity.width }); } } AABBUtils.getEntityAABB = getEntityAABB; function getPlayerAABB(entity) { const hw = entity.width ? entity.width / 2 : 0.3; return new aabb_1.AABB(-hw, 0, -hw, hw, entity.height ? entity.height + 0.18 : 1.8, hw).translateVec(entity.position); } AABBUtils.getPlayerAABB = getPlayerAABB; function getPlayerAABBRaw(position, height = 1.8) { return new aabb_1.AABB(-0.3, 0, -0.3, 0.3, height, 0.3).translateVec(position); } AABBUtils.getPlayerAABBRaw = getPlayerAABBRaw; function getEntityAABBRaw(entity) { const hw = entity.width ? entity.width / 2 : entity.height / 2; return new aabb_1.AABB(-hw, 0, -hw, hw, entity.height, hw).translateVec(entity.position); } AABBUtils.getEntityAABBRaw = getEntityAABBRaw; })(AABBUtils = exports.AABBUtils || (exports.AABBUtils = {}));