@minecraft/math 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/api-report/math.api.md +125 -0
- package/dist/minecraft-math.js +378 -0
- package/dist/minecraft-math.js.map +7 -0
- package/lib/general/clamp.js +14 -0
- package/lib/general/clamp.js.map +1 -0
- package/lib/general/index.js +19 -0
- package/lib/general/index.js.map +1 -0
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -0
- package/lib/index.test.js +10 -0
- package/lib/index.test.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types/math-beta.d.ts +327 -0
- package/lib/types/math-public.d.ts +327 -0
- package/lib/types/math.d.ts +327 -0
- package/lib/vector3/coreHelpers.js +230 -0
- package/lib/vector3/coreHelpers.js.map +1 -0
- package/lib/vector3/coreHelpers.test.js +147 -0
- package/lib/vector3/coreHelpers.test.js.map +1 -0
- package/lib/vector3/index.js +20 -0
- package/lib/vector3/index.js.map +1 -0
- package/lib/vector3/vectorWrapper.js +147 -0
- package/lib/vector3/vectorWrapper.js.map +1 -0
- package/lib/vector3/vectorWrapper.test.js +135 -0
- package/lib/vector3/vectorWrapper.test.js.map +1 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Minecraft Math
|
|
2
|
+
|
|
3
|
+
A set of utilities and functions for common math operations. Major pieces are covered below.
|
|
4
|
+
|
|
5
|
+
## Vector3
|
|
6
|
+
|
|
7
|
+
A set of utility functions and a wrapper class for common vector3 operations. Two distinct patterns are supported, a more pure computational approach operating on the Vector3 interface with no mutation, and a separate wrapper object oriented approach following a "builder" pattern. It is mostly preference whether you prefer the more "mutation" heavy pattern or the functional pattern, it depends on the structure of your code. Under the covers, the same helpers are used.
|
|
8
|
+
|
|
9
|
+
### Pure Functional Style
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Vector3, world } from '@minecraft/server';
|
|
13
|
+
import { MinecraftDimensionTypes } from '@minecraft/vanilla-data';
|
|
14
|
+
import { Vector3Utils } from '@minecraft/math';
|
|
15
|
+
|
|
16
|
+
const vectorA: Vector3 = {x: 1, y: 2, z:3};
|
|
17
|
+
const vectorB: Vector3 = {x: 4, y: 5, z:6};
|
|
18
|
+
|
|
19
|
+
const resultAdd = Vector3Utils.add(vectorA, vectorB); // {x:5, y:7, z:9}
|
|
20
|
+
const resultSubtract = Vector3Utils.subtract(vectorA, vectorB); // {x:-3, y:-3, z:-3}
|
|
21
|
+
const resultAdd = Vector3Utils.cross(vectorA, vectorB); // {x:-3, y:6, z:-3}
|
|
22
|
+
|
|
23
|
+
console.log(toString(vectorA)); // Prints out "1, 2, 3"
|
|
24
|
+
|
|
25
|
+
// Use your vectors with any @minecraft/server API
|
|
26
|
+
const = dimension = world.getDimension(MinecraftDimensionTypes.Overworld);
|
|
27
|
+
dimension.spawnParticle("minecraft:colored_flame_particle", resultAdd);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Builder Style
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Vector3, world } from '@minecraft/server';
|
|
34
|
+
import { Vector3Builder } from '@minecraft/math';
|
|
35
|
+
import { MinecraftDimensionTypes } from '@minecraft/vanilla-data';
|
|
36
|
+
|
|
37
|
+
const vectorA: Vector3Builder = new Vector3Builder({x: 1, y: 2, z:3});
|
|
38
|
+
const vectorB: Vector3 = {x: 4, y: 5, z:6};
|
|
39
|
+
const vectorC: Vector3 = {x: 1, y: 3, z:5};
|
|
40
|
+
|
|
41
|
+
// Mutates vectorA directly each time
|
|
42
|
+
vectorA.add(vectorB).subtract(vectorC).cross(vectorB); // Final result {x:4, y:-8, z:4}
|
|
43
|
+
|
|
44
|
+
console.log(vectorA.toString()); // Prints out "4, -8, 4"
|
|
45
|
+
|
|
46
|
+
// Vector3Builder type can directly be used in APIs that accept Vector3
|
|
47
|
+
const dimension = world.getDimension(MinecraftDimensionTypes.Overworld);
|
|
48
|
+
dimension.spawnParticle("minecraft:colored_flame_particle", vectorA);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## How to use @minecraft/math in your project
|
|
52
|
+
|
|
53
|
+
@minecraft/math is published to NPM and follows standard semver semantics. To use it in your project,
|
|
54
|
+
|
|
55
|
+
- Download `@minecraft/math` from NPM by doing `npm install @minecraft/math` within your scripts pack. By using `@minecraft/math`, you will need to do some sort of bundling to merge the library into your packs code. We recommend using [esbuild](https://esbuild.github.io/getting-started/#your-first-bundle) for simplicity.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
## API Report File for "@minecraft/math"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import type { Vector2 } from '@minecraft/server';
|
|
8
|
+
import type { Vector3 } from '@minecraft/server';
|
|
9
|
+
|
|
10
|
+
// @public
|
|
11
|
+
export function clampNumber(val: number, min: number, max: number): number;
|
|
12
|
+
|
|
13
|
+
// @public
|
|
14
|
+
export class Vector2Builder implements Vector2 {
|
|
15
|
+
constructor(vec: Vector2, arg?: never);
|
|
16
|
+
constructor(x: number, y: number);
|
|
17
|
+
// (undocumented)
|
|
18
|
+
toString(options?: {
|
|
19
|
+
decimals?: number;
|
|
20
|
+
delimiter?: string;
|
|
21
|
+
}): string;
|
|
22
|
+
// (undocumented)
|
|
23
|
+
x: number;
|
|
24
|
+
// (undocumented)
|
|
25
|
+
y: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// @public
|
|
29
|
+
export class Vector2Utils {
|
|
30
|
+
static toString(v: Vector2, options?: {
|
|
31
|
+
decimals?: number;
|
|
32
|
+
delimiter?: string;
|
|
33
|
+
}): string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// @public
|
|
37
|
+
export const VECTOR3_BACK: Vector3;
|
|
38
|
+
|
|
39
|
+
// @public
|
|
40
|
+
export const VECTOR3_DOWN: Vector3;
|
|
41
|
+
|
|
42
|
+
// @public
|
|
43
|
+
export const VECTOR3_EAST: Vector3;
|
|
44
|
+
|
|
45
|
+
// @public
|
|
46
|
+
export const VECTOR3_FORWARD: Vector3;
|
|
47
|
+
|
|
48
|
+
// @public
|
|
49
|
+
export const VECTOR3_LEFT: Vector3;
|
|
50
|
+
|
|
51
|
+
// @public
|
|
52
|
+
export const VECTOR3_NORTH: Vector3;
|
|
53
|
+
|
|
54
|
+
// @public
|
|
55
|
+
export const VECTOR3_ONE: Vector3;
|
|
56
|
+
|
|
57
|
+
// @public
|
|
58
|
+
export const VECTOR3_RIGHT: Vector3;
|
|
59
|
+
|
|
60
|
+
// @public
|
|
61
|
+
export const VECTOR3_SOUTH: Vector3;
|
|
62
|
+
|
|
63
|
+
// @public
|
|
64
|
+
export const VECTOR3_UP: Vector3;
|
|
65
|
+
|
|
66
|
+
// @public
|
|
67
|
+
export const VECTOR3_WEST: Vector3;
|
|
68
|
+
|
|
69
|
+
// @public
|
|
70
|
+
export const VECTOR3_ZERO: Vector3;
|
|
71
|
+
|
|
72
|
+
// @public
|
|
73
|
+
export class Vector3Builder implements Vector3 {
|
|
74
|
+
constructor(vec: Vector3, arg?: never, arg2?: never);
|
|
75
|
+
constructor(x: number, y: number, z: number);
|
|
76
|
+
add(v: Vector3): this;
|
|
77
|
+
assign(vec: Vector3): this;
|
|
78
|
+
clamp(limits: {
|
|
79
|
+
min?: Partial<Vector3>;
|
|
80
|
+
max?: Partial<Vector3>;
|
|
81
|
+
}): this;
|
|
82
|
+
cross(vec: Vector3): this;
|
|
83
|
+
dot(vec: Vector3): number;
|
|
84
|
+
equals(v: Vector3): boolean;
|
|
85
|
+
floor(): this;
|
|
86
|
+
magnitude(): number;
|
|
87
|
+
normalize(): this;
|
|
88
|
+
scale(val: number): this;
|
|
89
|
+
subtract(v: Vector3): this;
|
|
90
|
+
toString(options?: {
|
|
91
|
+
decimals?: number;
|
|
92
|
+
delimiter?: string;
|
|
93
|
+
}): string;
|
|
94
|
+
// (undocumented)
|
|
95
|
+
x: number;
|
|
96
|
+
// (undocumented)
|
|
97
|
+
y: number;
|
|
98
|
+
// (undocumented)
|
|
99
|
+
z: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// @public
|
|
103
|
+
export class Vector3Utils {
|
|
104
|
+
static add(v1: Vector3, v2: Vector3): Vector3;
|
|
105
|
+
static clamp(v: Vector3, limits?: {
|
|
106
|
+
min?: Partial<Vector3>;
|
|
107
|
+
max?: Partial<Vector3>;
|
|
108
|
+
}): Vector3;
|
|
109
|
+
static cross(a: Vector3, b: Vector3): Vector3;
|
|
110
|
+
static dot(a: Vector3, b: Vector3): number;
|
|
111
|
+
static equals(v1: Vector3, v2: Vector3): boolean;
|
|
112
|
+
static floor(v: Vector3): Vector3;
|
|
113
|
+
static magnitude(v: Vector3): number;
|
|
114
|
+
static normalize(v: Vector3): Vector3;
|
|
115
|
+
static scale(v1: Vector3, scale: number): Vector3;
|
|
116
|
+
static subtract(v1: Vector3, v2: Vector3): Vector3;
|
|
117
|
+
static toString(v: Vector3, options?: {
|
|
118
|
+
decimals?: number;
|
|
119
|
+
delimiter?: string;
|
|
120
|
+
}): string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// (No @packageDocumentation comment for this package)
|
|
124
|
+
|
|
125
|
+
```
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// lib/general/clamp.js
|
|
7
|
+
var require_clamp = __commonJS({
|
|
8
|
+
"lib/general/clamp.js"(exports) {
|
|
9
|
+
"use strict";
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.clampNumber = void 0;
|
|
12
|
+
function clampNumber(val, min, max) {
|
|
13
|
+
return Math.min(Math.max(val, min), max);
|
|
14
|
+
}
|
|
15
|
+
exports.clampNumber = clampNumber;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// lib/vector3/coreHelpers.js
|
|
20
|
+
var require_coreHelpers = __commonJS({
|
|
21
|
+
"lib/vector3/coreHelpers.js"(exports) {
|
|
22
|
+
"use strict";
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.VECTOR3_SOUTH = exports.VECTOR3_NORTH = exports.VECTOR3_EAST = exports.VECTOR3_WEST = exports.VECTOR3_ZERO = exports.VECTOR3_ONE = exports.VECTOR3_BACK = exports.VECTOR3_FORWARD = exports.VECTOR3_RIGHT = exports.VECTOR3_LEFT = exports.VECTOR3_DOWN = exports.VECTOR3_UP = exports.Vector2Utils = exports.Vector3Utils = void 0;
|
|
25
|
+
var clamp_1 = require_clamp();
|
|
26
|
+
var Vector3Utils = class _Vector3Utils {
|
|
27
|
+
/**
|
|
28
|
+
* equals
|
|
29
|
+
*
|
|
30
|
+
* Check the equality of two vectors
|
|
31
|
+
*/
|
|
32
|
+
static equals(v1, v2) {
|
|
33
|
+
return v1.x === v2.x && v1.y === v2.y && v1.z === v2.z;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* add
|
|
37
|
+
*
|
|
38
|
+
* Add two vectors to produce a new vector
|
|
39
|
+
*/
|
|
40
|
+
static add(v1, v2) {
|
|
41
|
+
return { x: v1.x + v2.x, y: v1.y + v2.y, z: v1.z + v2.z };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* subtract
|
|
45
|
+
*
|
|
46
|
+
* Subtract two vectors to produce a new vector (v1-v2)
|
|
47
|
+
*/
|
|
48
|
+
static subtract(v1, v2) {
|
|
49
|
+
return { x: v1.x - v2.x, y: v1.y - v2.y, z: v1.z - v2.z };
|
|
50
|
+
}
|
|
51
|
+
/** scale
|
|
52
|
+
*
|
|
53
|
+
* Multiple all entries in a vector by a single scalar value producing a new vector
|
|
54
|
+
*/
|
|
55
|
+
static scale(v1, scale) {
|
|
56
|
+
return { x: v1.x * scale, y: v1.y * scale, z: v1.z * scale };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* dot
|
|
60
|
+
*
|
|
61
|
+
* Calculate the dot product of two vectors
|
|
62
|
+
*/
|
|
63
|
+
static dot(a, b) {
|
|
64
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* cross
|
|
68
|
+
*
|
|
69
|
+
* Calculate the cross product of two vectors. Returns a new vector.
|
|
70
|
+
*/
|
|
71
|
+
static cross(a, b) {
|
|
72
|
+
return {
|
|
73
|
+
x: a.y * b.z - a.z * b.y,
|
|
74
|
+
y: a.z * b.x - a.x * b.z,
|
|
75
|
+
z: a.x * b.y - a.y * b.x
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* magnitude
|
|
80
|
+
*
|
|
81
|
+
* The magnitude of a vector
|
|
82
|
+
*/
|
|
83
|
+
static magnitude(v) {
|
|
84
|
+
return Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* normalize
|
|
88
|
+
*
|
|
89
|
+
* Takes a vector 3 and normalizes it to a unit vector
|
|
90
|
+
*/
|
|
91
|
+
static normalize(v) {
|
|
92
|
+
const mag = _Vector3Utils.magnitude(v);
|
|
93
|
+
return { x: v.x / mag, y: v.y / mag, z: v.z / mag };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* floor
|
|
97
|
+
*
|
|
98
|
+
* Floor the components of a vector to produce a new vector
|
|
99
|
+
*/
|
|
100
|
+
static floor(v) {
|
|
101
|
+
return { x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z) };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* toString
|
|
105
|
+
*
|
|
106
|
+
* Create a string representation of a vector3
|
|
107
|
+
*/
|
|
108
|
+
static toString(v, options) {
|
|
109
|
+
const decimals = options?.decimals ?? 2;
|
|
110
|
+
const str = [v.x.toFixed(decimals), v.y.toFixed(decimals), v.z.toFixed(decimals)];
|
|
111
|
+
return str.join(options?.delimiter ?? ", ");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* clamp
|
|
115
|
+
*
|
|
116
|
+
* Clamps the components of a vector to limits to produce a new vector
|
|
117
|
+
*/
|
|
118
|
+
static clamp(v, limits) {
|
|
119
|
+
return {
|
|
120
|
+
x: (0, clamp_1.clampNumber)(v.x, limits?.min?.x ?? Number.MIN_SAFE_INTEGER, limits?.max?.x ?? Number.MAX_SAFE_INTEGER),
|
|
121
|
+
y: (0, clamp_1.clampNumber)(v.y, limits?.min?.y ?? Number.MIN_SAFE_INTEGER, limits?.max?.y ?? Number.MAX_SAFE_INTEGER),
|
|
122
|
+
z: (0, clamp_1.clampNumber)(v.z, limits?.min?.z ?? Number.MIN_SAFE_INTEGER, limits?.max?.z ?? Number.MAX_SAFE_INTEGER)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.Vector3Utils = Vector3Utils;
|
|
127
|
+
var Vector2Utils = class {
|
|
128
|
+
/**
|
|
129
|
+
* toString
|
|
130
|
+
*
|
|
131
|
+
* Create a string representation of a vector2
|
|
132
|
+
*/
|
|
133
|
+
static toString(v, options) {
|
|
134
|
+
const decimals = options?.decimals ?? 2;
|
|
135
|
+
const str = [v.x.toFixed(decimals), v.y.toFixed(decimals)];
|
|
136
|
+
return str.join(options?.delimiter ?? ", ");
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.Vector2Utils = Vector2Utils;
|
|
140
|
+
exports.VECTOR3_UP = { x: 0, y: 1, z: 0 };
|
|
141
|
+
exports.VECTOR3_DOWN = { x: 0, y: -1, z: 0 };
|
|
142
|
+
exports.VECTOR3_LEFT = { x: -1, y: 0, z: 0 };
|
|
143
|
+
exports.VECTOR3_RIGHT = { x: 1, y: 0, z: 0 };
|
|
144
|
+
exports.VECTOR3_FORWARD = { x: 0, y: 0, z: 1 };
|
|
145
|
+
exports.VECTOR3_BACK = { x: 0, y: 0, z: -1 };
|
|
146
|
+
exports.VECTOR3_ONE = { x: 1, y: 1, z: 1 };
|
|
147
|
+
exports.VECTOR3_ZERO = { x: 0, y: 0, z: 0 };
|
|
148
|
+
exports.VECTOR3_WEST = { x: -1, y: 0, z: 0 };
|
|
149
|
+
exports.VECTOR3_EAST = { x: 1, y: 0, z: 0 };
|
|
150
|
+
exports.VECTOR3_NORTH = { x: 0, y: 0, z: 1 };
|
|
151
|
+
exports.VECTOR3_SOUTH = { x: 0, y: 0, z: -1 };
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// lib/vector3/vectorWrapper.js
|
|
156
|
+
var require_vectorWrapper = __commonJS({
|
|
157
|
+
"lib/vector3/vectorWrapper.js"(exports) {
|
|
158
|
+
"use strict";
|
|
159
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
160
|
+
exports.Vector2Builder = exports.Vector3Builder = void 0;
|
|
161
|
+
var coreHelpers_1 = require_coreHelpers();
|
|
162
|
+
var Vector3Builder = class {
|
|
163
|
+
constructor(first, y, z) {
|
|
164
|
+
if (typeof first === "object") {
|
|
165
|
+
this.x = first.x;
|
|
166
|
+
this.y = first.y;
|
|
167
|
+
this.z = first.z;
|
|
168
|
+
} else {
|
|
169
|
+
this.x = first;
|
|
170
|
+
this.y = y ?? 0;
|
|
171
|
+
this.z = z ?? 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Assigns the values of the passed in vector to this vector. Returns itself.
|
|
176
|
+
*/
|
|
177
|
+
assign(vec) {
|
|
178
|
+
this.x = vec.x;
|
|
179
|
+
this.y = vec.y;
|
|
180
|
+
this.z = vec.z;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* equals
|
|
185
|
+
*
|
|
186
|
+
* Check the equality of two vectors
|
|
187
|
+
*/
|
|
188
|
+
equals(v) {
|
|
189
|
+
return coreHelpers_1.Vector3Utils.equals(this, v);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* add
|
|
193
|
+
*
|
|
194
|
+
* Adds the vector v to this, returning itself.
|
|
195
|
+
*/
|
|
196
|
+
add(v) {
|
|
197
|
+
return this.assign(coreHelpers_1.Vector3Utils.add(this, v));
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* subtract
|
|
201
|
+
*
|
|
202
|
+
* Subtracts the vector v from this, returning itself.
|
|
203
|
+
*/
|
|
204
|
+
subtract(v) {
|
|
205
|
+
return this.assign(coreHelpers_1.Vector3Utils.subtract(this, v));
|
|
206
|
+
}
|
|
207
|
+
/** scale
|
|
208
|
+
*
|
|
209
|
+
* Scales this by the passed in value, returning itself.
|
|
210
|
+
*/
|
|
211
|
+
scale(val) {
|
|
212
|
+
return this.assign(coreHelpers_1.Vector3Utils.scale(this, val));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* dot
|
|
216
|
+
*
|
|
217
|
+
* Computes the dot product of this and the passed in vector.
|
|
218
|
+
*/
|
|
219
|
+
dot(vec) {
|
|
220
|
+
return coreHelpers_1.Vector3Utils.dot(this, vec);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* cross
|
|
224
|
+
*
|
|
225
|
+
* Computes the cross product of this and the passed in vector, returning itself.
|
|
226
|
+
*/
|
|
227
|
+
cross(vec) {
|
|
228
|
+
return this.assign(coreHelpers_1.Vector3Utils.cross(this, vec));
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* magnitude
|
|
232
|
+
*
|
|
233
|
+
* The magnitude of the vector
|
|
234
|
+
*/
|
|
235
|
+
magnitude() {
|
|
236
|
+
return coreHelpers_1.Vector3Utils.magnitude(this);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* normalize
|
|
240
|
+
*
|
|
241
|
+
* Normalizes this vector, returning itself.
|
|
242
|
+
*/
|
|
243
|
+
normalize() {
|
|
244
|
+
return this.assign(coreHelpers_1.Vector3Utils.normalize(this));
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* floor
|
|
248
|
+
*
|
|
249
|
+
* Floor the components of a vector to produce a new vector
|
|
250
|
+
*/
|
|
251
|
+
floor() {
|
|
252
|
+
return this.assign(coreHelpers_1.Vector3Utils.floor(this));
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* toString
|
|
256
|
+
*
|
|
257
|
+
* Create a string representation of a vector
|
|
258
|
+
*/
|
|
259
|
+
toString(options) {
|
|
260
|
+
return coreHelpers_1.Vector3Utils.toString(this, options);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* clamp
|
|
264
|
+
*
|
|
265
|
+
* Clamps the components of a vector to limits to produce a new vector
|
|
266
|
+
*/
|
|
267
|
+
clamp(limits) {
|
|
268
|
+
return this.assign(coreHelpers_1.Vector3Utils.clamp(this, limits));
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
exports.Vector3Builder = Vector3Builder;
|
|
272
|
+
var Vector2Builder = class {
|
|
273
|
+
constructor(first, y) {
|
|
274
|
+
if (typeof first === "object") {
|
|
275
|
+
this.x = first.x;
|
|
276
|
+
this.y = first.y;
|
|
277
|
+
} else {
|
|
278
|
+
this.x = first;
|
|
279
|
+
this.y = y ?? 0;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
toString(options) {
|
|
283
|
+
return coreHelpers_1.Vector2Utils.toString(this, options);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
exports.Vector2Builder = Vector2Builder;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// lib/vector3/index.js
|
|
291
|
+
var require_vector3 = __commonJS({
|
|
292
|
+
"lib/vector3/index.js"(exports) {
|
|
293
|
+
"use strict";
|
|
294
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
295
|
+
if (k2 === void 0)
|
|
296
|
+
k2 = k;
|
|
297
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
298
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
299
|
+
desc = { enumerable: true, get: function() {
|
|
300
|
+
return m[k];
|
|
301
|
+
} };
|
|
302
|
+
}
|
|
303
|
+
Object.defineProperty(o, k2, desc);
|
|
304
|
+
} : function(o, m, k, k2) {
|
|
305
|
+
if (k2 === void 0)
|
|
306
|
+
k2 = k;
|
|
307
|
+
o[k2] = m[k];
|
|
308
|
+
});
|
|
309
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
310
|
+
for (var p in m)
|
|
311
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
312
|
+
__createBinding(exports2, m, p);
|
|
313
|
+
};
|
|
314
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
315
|
+
__exportStar(require_coreHelpers(), exports);
|
|
316
|
+
__exportStar(require_vectorWrapper(), exports);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// lib/general/index.js
|
|
321
|
+
var require_general = __commonJS({
|
|
322
|
+
"lib/general/index.js"(exports) {
|
|
323
|
+
"use strict";
|
|
324
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
325
|
+
if (k2 === void 0)
|
|
326
|
+
k2 = k;
|
|
327
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
328
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
329
|
+
desc = { enumerable: true, get: function() {
|
|
330
|
+
return m[k];
|
|
331
|
+
} };
|
|
332
|
+
}
|
|
333
|
+
Object.defineProperty(o, k2, desc);
|
|
334
|
+
} : function(o, m, k, k2) {
|
|
335
|
+
if (k2 === void 0)
|
|
336
|
+
k2 = k;
|
|
337
|
+
o[k2] = m[k];
|
|
338
|
+
});
|
|
339
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
340
|
+
for (var p in m)
|
|
341
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
342
|
+
__createBinding(exports2, m, p);
|
|
343
|
+
};
|
|
344
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
345
|
+
__exportStar(require_clamp(), exports);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// lib/index.js
|
|
350
|
+
var require_lib = __commonJS({
|
|
351
|
+
"lib/index.js"(exports) {
|
|
352
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
353
|
+
if (k2 === void 0)
|
|
354
|
+
k2 = k;
|
|
355
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
356
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
357
|
+
desc = { enumerable: true, get: function() {
|
|
358
|
+
return m[k];
|
|
359
|
+
} };
|
|
360
|
+
}
|
|
361
|
+
Object.defineProperty(o, k2, desc);
|
|
362
|
+
} : function(o, m, k, k2) {
|
|
363
|
+
if (k2 === void 0)
|
|
364
|
+
k2 = k;
|
|
365
|
+
o[k2] = m[k];
|
|
366
|
+
});
|
|
367
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
368
|
+
for (var p in m)
|
|
369
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
370
|
+
__createBinding(exports2, m, p);
|
|
371
|
+
};
|
|
372
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
373
|
+
__exportStar(require_vector3(), exports);
|
|
374
|
+
__exportStar(require_general(), exports);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
export default require_lib();
|
|
378
|
+
//# sourceMappingURL=minecraft-math.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/general/clamp.ts", "../src/vector3/coreHelpers.ts", "../src/vector3/vectorWrapper.ts", "../src/vector3/index.ts", "../src/general/index.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mojang AB. All rights reserved.\n\n/**\n * Clamps the passed in number to the passed in min and max values.\n *\n * @public\n */\nexport function clampNumber(val: number, min: number, max: number): number {\n return Math.min(Math.max(val, min), max);\n}\n", "// Copyright (c) Mojang AB. All rights reserved.\n\nimport type { Vector2, Vector3 } from '@minecraft/server';\nimport { clampNumber } from '../general/clamp';\n\n/**\n * Utilities operating on Vector3 objects. All methods are static and do not modify the input objects.\n *\n * @public\n */\nexport class Vector3Utils {\n /**\n * equals\n *\n * Check the equality of two vectors\n */\n static equals(v1: Vector3, v2: Vector3): boolean {\n return v1.x === v2.x && v1.y === v2.y && v1.z === v2.z;\n }\n\n /**\n * add\n *\n * Add two vectors to produce a new vector\n */\n static add(v1: Vector3, v2: Vector3): Vector3 {\n return { x: v1.x + v2.x, y: v1.y + v2.y, z: v1.z + v2.z };\n }\n\n /**\n * subtract\n *\n * Subtract two vectors to produce a new vector (v1-v2)\n */\n static subtract(v1: Vector3, v2: Vector3): Vector3 {\n return { x: v1.x - v2.x, y: v1.y - v2.y, z: v1.z - v2.z };\n }\n\n /** scale\n *\n * Multiple all entries in a vector by a single scalar value producing a new vector\n */\n static scale(v1: Vector3, scale: number): Vector3 {\n return { x: v1.x * scale, y: v1.y * scale, z: v1.z * scale };\n }\n\n /**\n * dot\n *\n * Calculate the dot product of two vectors\n */\n static dot(a: Vector3, b: Vector3): number {\n return a.x * b.x + a.y * b.y + a.z * b.z;\n }\n\n /**\n * cross\n *\n * Calculate the cross product of two vectors. Returns a new vector.\n */\n static cross(a: Vector3, b: Vector3): Vector3 {\n return {\n x: a.y * b.z - a.z * b.y,\n y: a.z * b.x - a.x * b.z,\n z: a.x * b.y - a.y * b.x,\n };\n }\n\n /**\n * magnitude\n *\n * The magnitude of a vector\n */\n static magnitude(v: Vector3): number {\n return Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2);\n }\n\n /**\n * normalize\n *\n * Takes a vector 3 and normalizes it to a unit vector\n */\n static normalize(v: Vector3): Vector3 {\n const mag = Vector3Utils.magnitude(v);\n return { x: v.x / mag, y: v.y / mag, z: v.z / mag };\n }\n\n /**\n * floor\n *\n * Floor the components of a vector to produce a new vector\n */\n static floor(v: Vector3): Vector3 {\n return { x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z) };\n }\n\n /**\n * toString\n *\n * Create a string representation of a vector3\n */\n static toString(v: Vector3, options?: { decimals?: number; delimiter?: string }): string {\n const decimals = options?.decimals ?? 2;\n const str: string[] = [v.x.toFixed(decimals), v.y.toFixed(decimals), v.z.toFixed(decimals)];\n return str.join(options?.delimiter ?? ', ');\n }\n\n /**\n * clamp\n *\n * Clamps the components of a vector to limits to produce a new vector\n */\n static clamp(\n v: Vector3,\n limits?: {\n min?: Partial<Vector3>;\n max?: Partial<Vector3>;\n },\n ): Vector3 {\n return {\n x: clampNumber(v.x, limits?.min?.x ?? Number.MIN_SAFE_INTEGER, limits?.max?.x ?? Number.MAX_SAFE_INTEGER),\n y: clampNumber(v.y, limits?.min?.y ?? Number.MIN_SAFE_INTEGER, limits?.max?.y ?? Number.MAX_SAFE_INTEGER),\n z: clampNumber(v.z, limits?.min?.z ?? Number.MIN_SAFE_INTEGER, limits?.max?.z ?? Number.MAX_SAFE_INTEGER),\n };\n }\n}\n\n/**\n * Utilities operating on Vector2 objects. All methods are static and do not modify the input objects.\n *\n * @public\n */\nexport class Vector2Utils {\n /**\n * toString\n *\n * Create a string representation of a vector2\n */\n static toString(v: Vector2, options?: { decimals?: number; delimiter?: string }): string {\n const decimals = options?.decimals ?? 2;\n const str: string[] = [v.x.toFixed(decimals), v.y.toFixed(decimals)];\n return str.join(options?.delimiter ?? ', ');\n }\n}\n\n/**\n * up\n *\n * A unit vector representing the world UP direction (0,1,0)\n *\n * @public\n */\nexport const VECTOR3_UP: Vector3 = { x: 0, y: 1, z: 0 };\n/**\n * down\n *\n * A unit vector representing the world DOWN direction (0,-1,0)\n *\n * @public\n */\nexport const VECTOR3_DOWN: Vector3 = { x: 0, y: -1, z: 0 };\n/**\n * left\n *\n * A unit vector representing the world LEFT direction (-1,0,0)\n *\n * @public\n */\nexport const VECTOR3_LEFT: Vector3 = { x: -1, y: 0, z: 0 };\n/**\n * right\n *\n * A unit vector representing the world RIGHT direction (1,0,0)\n *\n * @public\n */\nexport const VECTOR3_RIGHT: Vector3 = { x: 1, y: 0, z: 0 };\n/**\n * forward\n *\n * A unit vector representing the world FORWARD direction (0,0,1)\n *\n * @public\n */\nexport const VECTOR3_FORWARD: Vector3 = { x: 0, y: 0, z: 1 };\n/**\n * back\n *\n * A unit vector representing the world BACK direction (0,0,-1)\n *\n * @public\n */\nexport const VECTOR3_BACK: Vector3 = { x: 0, y: 0, z: -1 };\n/**\n * one\n *\n * A unit vector representing the value of 1 in all directions (1,1,1)\n *\n * @public\n */\nexport const VECTOR3_ONE: Vector3 = { x: 1, y: 1, z: 1 };\n/**\n * zero\n *\n * A unit vector representing the value of 0 in all directions (0,0,0)\n *\n * @public\n */\nexport const VECTOR3_ZERO: Vector3 = { x: 0, y: 0, z: 0 };\n/**\n * west\n *\n * A unit vector representing the world WEST direction (-1,0,0)\n * (same as LEFT)\n *\n * @public\n */\nexport const VECTOR3_WEST: Vector3 = { x: -1, y: 0, z: 0 };\n/**\n * east\n *\n * A unit vector representing the world EAST direction (-1,0,0)\n * (same as RIGHT)\n *\n * @public\n */\nexport const VECTOR3_EAST: Vector3 = { x: 1, y: 0, z: 0 };\n/**\n * north\n *\n * A unit vector representing the world NORTH direction (-1,0,0)\n * (same as FORWARD)\n *\n * @public\n */\nexport const VECTOR3_NORTH: Vector3 = { x: 0, y: 0, z: 1 };\n/**\n * south\n *\n * A unit vector representing the world SOUTH direction (-1,0,0)\n * (same as BACK)\n *\n * @public\n */\nexport const VECTOR3_SOUTH: Vector3 = { x: 0, y: 0, z: -1 };\n", "// Copyright (c) Mojang AB. All rights reserved.\n\nimport type { Vector2, Vector3 } from '@minecraft/server';\nimport { Vector2Utils, Vector3Utils } from './coreHelpers';\n\n/**\n * Vector3 wrapper class which can be used as a Vector3 for APIs on \\@minecraft/server which require a Vector,\n * but also contain additional helper methods. This is an alternative to using the core Vector 3 utility\n * methods directly, for those who prefer a more object-oriented approach. This version of the class is mutable\n * and changes state inline.\n *\n * For an immutable version of the build, use ImmutableVector3Builder.\n *\n * @public\n */\nexport class Vector3Builder implements Vector3 {\n x: number;\n y: number;\n z: number;\n\n constructor(vec: Vector3, arg?: never, arg2?: never);\n constructor(x: number, y: number, z: number);\n constructor(first: number | Vector3, y?: number, z?: number) {\n if (typeof first === 'object') {\n this.x = first.x;\n this.y = first.y;\n this.z = first.z;\n } else {\n this.x = first;\n this.y = y ?? 0;\n this.z = z ?? 0;\n }\n }\n\n /**\n * Assigns the values of the passed in vector to this vector. Returns itself.\n */\n assign(vec: Vector3): this {\n this.x = vec.x;\n this.y = vec.y;\n this.z = vec.z;\n return this;\n }\n\n /**\n * equals\n *\n * Check the equality of two vectors\n */\n equals(v: Vector3): boolean {\n return Vector3Utils.equals(this, v);\n }\n\n /**\n * add\n *\n * Adds the vector v to this, returning itself.\n */\n add(v: Vector3): this {\n return this.assign(Vector3Utils.add(this, v));\n }\n\n /**\n * subtract\n *\n * Subtracts the vector v from this, returning itself.\n */\n subtract(v: Vector3): this {\n return this.assign(Vector3Utils.subtract(this, v));\n }\n\n /** scale\n *\n * Scales this by the passed in value, returning itself.\n */\n scale(val: number): this {\n return this.assign(Vector3Utils.scale(this, val));\n }\n\n /**\n * dot\n *\n * Computes the dot product of this and the passed in vector.\n */\n dot(vec: Vector3): number {\n return Vector3Utils.dot(this, vec);\n }\n\n /**\n * cross\n *\n * Computes the cross product of this and the passed in vector, returning itself.\n */\n cross(vec: Vector3): this {\n return this.assign(Vector3Utils.cross(this, vec));\n }\n\n /**\n * magnitude\n *\n * The magnitude of the vector\n */\n magnitude(): number {\n return Vector3Utils.magnitude(this);\n }\n\n /**\n * normalize\n *\n * Normalizes this vector, returning itself.\n */\n normalize(): this {\n return this.assign(Vector3Utils.normalize(this));\n }\n\n /**\n * floor\n *\n * Floor the components of a vector to produce a new vector\n */\n floor(): this {\n return this.assign(Vector3Utils.floor(this));\n }\n\n /**\n * toString\n *\n * Create a string representation of a vector\n */\n toString(options?: { decimals?: number; delimiter?: string }): string {\n return Vector3Utils.toString(this, options);\n }\n\n /**\n * clamp\n *\n * Clamps the components of a vector to limits to produce a new vector\n */\n clamp(limits: { min?: Partial<Vector3>; max?: Partial<Vector3> }): this {\n return this.assign(Vector3Utils.clamp(this, limits));\n }\n}\n\n/**\n * Vector2 wrapper class which can be used as a Vector2 for APIs on \\@minecraft/server which require a Vector2.\n * @public\n */\nexport class Vector2Builder implements Vector2 {\n x: number;\n y: number;\n\n constructor(vec: Vector2, arg?: never);\n constructor(x: number, y: number);\n constructor(first: number | Vector2, y?: number) {\n if (typeof first === 'object') {\n this.x = first.x;\n this.y = first.y;\n } else {\n this.x = first;\n this.y = y ?? 0;\n }\n }\n\n toString(options?: { decimals?: number; delimiter?: string }): string {\n return Vector2Utils.toString(this, options);\n }\n}\n", "// Copyright (c) Mojang AB. All rights reserved.\n\nexport * from './coreHelpers';\nexport * from './vectorWrapper';\n", "// Copyright (c) Mojang AB. All rights reserved.\n\nexport * from './clamp';\n", "// Copyright (c) Mojang AB. All rights reserved.\n\nexport * from './vector3';\nexport * from './general';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAOA,aAAgB,YAAY,KAAa,KAAa,KAAW;AAC7D,aAAO,KAAK,IAAI,KAAK,IAAI,KAAK,GAAG,GAAG,GAAG;IAC3C;AA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
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Mojang AB. All rights reserved.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.clampNumber = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Clamps the passed in number to the passed in min and max values.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
function clampNumber(val, min, max) {
|
|
11
|
+
return Math.min(Math.max(val, min), max);
|
|
12
|
+
}
|
|
13
|
+
exports.clampNumber = clampNumber;
|
|
14
|
+
//# sourceMappingURL=clamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../src/general/clamp.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAEjD;;;;GAIG;AACH,SAAgB,WAAW,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AAFD,kCAEC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Mojang AB. All rights reserved.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./clamp"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/general/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;;;;;;;;;;;;AAEjD,0CAAwB"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Mojang AB. All rights reserved.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./vector3"), exports);
|
|
19
|
+
__exportStar(require("./general"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;;;;;;;;;;;;AAEjD,4CAA0B;AAC1B,4CAA0B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Mojang AB. All rights reserved.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
(0, vitest_1.describe)('Test', () => {
|
|
6
|
+
(0, vitest_1.it)('should pass', () => {
|
|
7
|
+
(0, vitest_1.expect)(true).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":";AAAA,iDAAiD;;AAEjD,mCAA8C;AAE9C,IAAA,iBAAQ,EAAC,MAAM,EAAE,GAAG,EAAE;IAClB,IAAA,WAAE,EAAC,aAAa,EAAE,GAAG,EAAE;QACnB,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|