[enhanced-vec3] init

This commit is contained in:
方而静 2023-11-03 11:50:43 +08:00
parent 57c602e443
commit 12b5295db6
Signed by: szTom
GPG Key ID: 072D999D60C6473C
5 changed files with 173 additions and 0 deletions

31
enhanced-vec3/index.d.ts vendored Normal file
View File

@ -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;
}
}

128
enhanced-vec3/index.mjs Normal file
View File

@ -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;
};

View File

@ -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"
}
}

View File

@ -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() {

View File

@ -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": {