@nxg-org/mineflayer-tracker
Version:
Provides functionality for more accurate entity and projectile tracking.
145 lines (144 loc) • 6.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdvancedPlayerControls = exports.PlayerControls = exports.ControlStateHandler = void 0;
;
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
class ControlStateHandler {
constructor(forward, back, left, right, jump, sprint, sneak) {
this.forward = forward;
this.back = back;
this.left = left;
this.right = right;
this.jump = jump;
this.sprint = sprint;
this.sneak = sneak;
}
static DEFAULT() {
return new ControlStateHandler(false, false, false, false, false, false, false);
}
static COPY_BOT(bot) {
return new ControlStateHandler(bot.controlState.forward, bot.controlState.back, bot.controlState.left, bot.controlState.right, bot.controlState.jump, bot.controlState.sprint, bot.controlState.sneak);
}
static COPY_STATE(state) {
return new ControlStateHandler(state.controlState.forward, state.controlState.back, state.controlState.left, state.controlState.right, state.controlState.jump, state.controlState.sprint, state.controlState.sneak);
}
set(state, wanted) {
this[state] = wanted;
return this;
}
get(state) {
return this[state];
}
clear(state) {
this[state] = false;
return this;
}
clone() {
return new ControlStateHandler(this.forward, this.back, this.left, this.right, this.jump, this.sprint, this.sneak);
}
equals(other) {
return this.forward == other.forward &&
this.back == other.back &&
this.left == other.left &&
this.right == other.right &&
this.jump == other.jump &&
this.sprint == other.sprint &&
this.sneak == other.sneak;
}
applyControls(bot) {
for (const move of this) {
bot.setControlState(move[0], move[1]);
}
}
*[Symbol.iterator]() {
yield ["forward", this.forward];
yield ["back", this.back];
yield ["left", this.left];
yield ["right", this.right];
yield ["jump", this.jump];
yield ["sprint", this.sprint];
yield ["sneak", this.sneak];
}
}
exports.ControlStateHandler = ControlStateHandler;
class PlayerControls extends ControlStateHandler {
constructor(forward, back, left, right, jump, sprint, sneak, leftClick, rightClick, yaw, pitch, force = false) {
super(forward, back, left, right, jump, sprint, sneak);
this.leftClick = leftClick;
this.rightClick = rightClick;
this.yaw = yaw;
this.pitch = pitch;
this.force = force;
this.leftClick = leftClick;
this.rightClick = rightClick;
}
static DEFAULT() {
return new PlayerControls(false, false, false, false, false, false, false, false, false, NaN, NaN);
}
static LOOK(yaw, pitch, force) {
return new PlayerControls(false, false, false, false, false, false, false, false, false, yaw, pitch, force);
}
static LOOKAT(pos, force) {
const info = mineflayer_util_plugin_1.MathUtils.dirToYawAndPitch(pos);
return new PlayerControls(false, false, false, false, false, false, false, false, false, info.yaw, info.pitch, force);
}
static COPY_BOT(bot) {
return new PlayerControls(bot.controlState.forward, bot.controlState.back, bot.controlState.left, bot.controlState.right, bot.controlState.jump, bot.controlState.sprint, bot.controlState.sneak, bot.util.entity.isMainHandActive(), bot.util.entity.isOffHandActive(), bot.entity.yaw, bot.entity.pitch, false);
}
static COPY_STATE(state) {
return new PlayerControls(state.controlState.forward, state.controlState.back, state.controlState.left, state.controlState.right, state.controlState.jump, state.controlState.sprint, state.controlState.sneak, state.isUsingMainHand, state.isUsingOffHand, state.yaw, state.pitch, false);
}
clone() {
return new PlayerControls(this.forward, this.back, this.left, this.right, this.jump, this.sprint, this.sneak, this.leftClick, this.rightClick, this.yaw, this.pitch, this.force);
}
setRot(dir) {
const tmp = mineflayer_util_plugin_1.MathUtils.dirToYawAndPitch(dir);
this.yaw = tmp.yaw;
this.pitch = tmp.pitch;
}
setRotRaw(yaw, pitch) {
this.yaw = yaw;
this.pitch = pitch;
}
*movements() {
yield this.forward;
yield this.back;
yield this.left;
yield this.right;
yield this.jump;
yield this.sprint;
yield this.sneak;
}
*linkedMovements() {
yield ["forward", this.forward];
yield ["back", this.back];
yield ["left", this.left];
yield ["right", this.right];
yield ["jump", this.jump];
yield ["sprint", this.sprint];
yield ["sneak", this.sneak];
}
}
exports.PlayerControls = PlayerControls;
class AdvancedPlayerControls extends PlayerControls {
constructor(forward, back, left, right, jump, sprint, sneak, leftClick, rightClick, yaw, pitch, force = false) {
super(forward, back, left, right, jump, sprint, sneak, leftClick, rightClick, yaw, pitch, force);
this.isGrounded = true;
this.faceBackwards = 0; //4
this.mlg = 0;
this.bucketTimer = 0;
this.bucketTarget = { x: 0, y: 0, z: 0 };
this.lastTimer = 0; //-10
}
static DEFAULT() {
return new AdvancedPlayerControls(false, false, false, false, false, false, false, false, false, NaN, NaN);
}
static LOOK(yaw, pitch) {
return new AdvancedPlayerControls(false, false, false, false, false, false, false, false, false, NaN, NaN);
}
static LOOKAT(pos) {
const info = mineflayer_util_plugin_1.MathUtils.dirToYawAndPitch(pos);
return new AdvancedPlayerControls(false, false, false, false, false, false, false, false, false, info.yaw, info.pitch);
}
}
exports.AdvancedPlayerControls = AdvancedPlayerControls;