From 12b5295db63dc68e848b704bd37b9c4c9ceff431 Mon Sep 17 00:00:00 2001 From: szdytom Date: Fri, 3 Nov 2023 11:50:43 +0800 Subject: [PATCH] [enhanced-vec3] init --- enhanced-vec3/index.d.ts | 31 +++++++++ enhanced-vec3/index.mjs | 128 +++++++++++++++++++++++++++++++++++++ enhanced-vec3/package.json | 12 ++++ index.mjs | 1 + package.json | 1 + 5 files changed, 173 insertions(+) create mode 100644 enhanced-vec3/index.d.ts create mode 100644 enhanced-vec3/index.mjs create mode 100644 enhanced-vec3/package.json diff --git a/enhanced-vec3/index.d.ts b/enhanced-vec3/index.d.ts new file mode 100644 index 0000000..cb4500d --- /dev/null +++ b/enhanced-vec3/index.d.ts @@ -0,0 +1,31 @@ +import { Vec3 } from 'vec3'; + +declare module 'vec3' { + export interface Vec3 { + setXZ(x: number, z: number): Vec3; + setXY(x: number, y: number): Vec3; + setYZ(y: number, z: number): Vec3; + updateXZ(other: Vec3): Vec3; + xzNorm(): number; + dotXZ(other: Vec3): number; + crossXZ(other: Vec3): number; + offsetXZ(x: number, z: number): Vec3; + centralizeXZ(): Vec3; + updateXY(other: Vec3): Vec3; + updateYZ(other: Vec3): Vec3; + xyNorm(): number; + yzNorm(): number; + dotXY(other: Vec3): number; + dotYZ(other: Vec3): number; + crossXY(other: Vec3): number; + crossYZ(other: Vec3): number; + offsetXY(x: number, y: number): Vec3; + offsetYZ(y: number, z: number): Vec3; + centralizeXY(): Vec3; + centralizeYZ(): Vec3; + centralize(): Vec3; + xzNormSquared(): number; + xyNormSquared(): number; + yzNormSquared(): number; + } +} diff --git a/enhanced-vec3/index.mjs b/enhanced-vec3/index.mjs new file mode 100644 index 0000000..8dc1168 --- /dev/null +++ b/enhanced-vec3/index.mjs @@ -0,0 +1,128 @@ +import { Vec3 } from 'vec3'; + +Vec3.prototype.setXZ = function setXZ(x, z) { + this.x = x; + this.z = z; + return this; +}; + +Vec3.prototype.setXY = function setXY(x, y) { + this.x = x; + this.y = y; + return this; +}; + +Vec3.prototype.setYZ = function setYZ(y, z) { + this.y = y; + this.z = z; + return this; +}; + +Vec3.prototype.updateXZ = function updateXZ(other) { + this.x = other.x; + this.z = other.z; + return this; +}; + +Vec3.prototype.xzNorm = function xzNorm() { + return Math.sqrt((this.x * this.x) + (this.z * this.z)); +}; + +Vec3.prototype.dotXZ = function dotXZ(other) { + return (this.x * other.x) + (this.y * other.y); +}; + +Vec3.prototype.crossXZ = function crossXZ(other) { + return (this.x * other.z) - (this.z * other.x); +}; + +Vec3.prototype.offsetXZ = function offsetXZ(x, z) { + this.x += x; + this.z += z; + return this; +}; + +Vec3.prototype.centralizeXZ = function centralizeXZ() { + this.x = Math.floor(this.x) + .5; + this.z = Math.floor(this.z) + .5; + return this; +}; + +Vec3.prototype.updateXY = function updateXY(other) { + this.x = other.x; + this.y = other.y; + return this; +}; + +Vec3.prototype.updateYZ = function updateYZ(other) { + this.y = other.y; + this.z = other.z; + return this; +}; + +Vec3.prototype.xyNorm = function xyNorm() { + return Math.sqrt((this.x * this.x) + (this.y * this.y)); +}; + +Vec3.prototype.yzNorm = function yzNorm() { + return Math.sqrt((this.y * this.y) + (this.z * this.z)); +}; + +Vec3.prototype.dotXY = function dotXY(other) { + return (this.x * other.x) + (this.y * other.y); +}; + +Vec3.prototype.dotYZ = function dotYZ(other) { + return (this.y * other.y) + (this.z * other.z); +}; + +Vec3.prototype.crossXY = function crossXY(other) { + return (this.x * other.y) - (this.y * other.x); +}; + +Vec3.prototype.crossYZ = function crossYZ(other) { + return (this.y * other.z) - (this.z * other.y); +}; + +Vec3.prototype.offsetXY = function offsetXY(x, y) { + this.x += x; + this.y += y; + return this; +}; + +Vec3.prototype.offsetYZ = function offsetYZ(y, z) { + this.y += y; + this.z += z; + return this; +}; + +Vec3.prototype.centralizeXY = function centralizeXY() { + this.x = Math.floor(this.x) + .5; + this.y = Math.floor(this.y) + .5; + return this; +}; + +Vec3.prototype.centralizeYZ = function centralizeYZ() { + this.y = Math.floor(this.y) + .5; + this.z = Math.floor(this.z) + .5; + return this; +}; + +Vec3.prototype.centralize = function centralize() { + this.x = Math.floor(this.x) + .5; + this.y = Math.floor(this.y) + .5; + this.z = Math.floor(this.z) + .5; + return this; +}; + +Vec3.prototype.xzNormSquared = function xzNormSquared() { + return this.x * this.x + this.z * this.z; +}; + +Vec3.prototype.xyNormSquared = function xyNormSquared() { + return this.x * this.x + this.y * this.y; +}; + +Vec3.prototype.yzNormSquared = function yzNormSquared() { + return this.y * this.y + this.z * this.z; +}; diff --git a/enhanced-vec3/package.json b/enhanced-vec3/package.json new file mode 100644 index 0000000..b666b15 --- /dev/null +++ b/enhanced-vec3/package.json @@ -0,0 +1,12 @@ +{ + "name": "enhanced-vec3", + "description": "More methods for vec3", + "type": "module", + "main": "index.mjs", + "types": "index.d.ts", + "dependencies": { + "debug": "^4.3.4", + "vec3": "^0.1.8", + "compass-utils": "file:../../utils" + } +} diff --git a/index.mjs b/index.mjs index ddf4cff..5bfc86c 100644 --- a/index.mjs +++ b/index.mjs @@ -3,6 +3,7 @@ import mineflayer from 'mineflayer'; import yargs from 'yargs'; import { asyncSleep, parseLogin, waitEvent } from 'compass-utils'; import repl from 'node:repl'; +import 'enhanced-vec3'; import debug from 'debug'; async function main() { diff --git a/package.json b/package.json index 48cfa34..0fc1225 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "mineflayer-control": "file:plugin/control", "mineflayer-event-promise": "file:plugin/event-promise", "mineflayer-fly-control": "file:plugin/fly-control", + "enhanced-vec3": "file:enhanced-vec3", "yargs": "^17.7.2" }, "engines": {