@nxg-org/mineflayer-util-plugin 1.0.0 → 1.0.1

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.
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RaycastIterator = exports.BlockFace = void 0;
4
- const vec3_1 = require("vec3");
5
- var BlockFace;
6
- (function (BlockFace) {
7
- BlockFace[BlockFace["UNKNOWN"] = -999] = "UNKNOWN";
8
- BlockFace[BlockFace["BOTTOM"] = 0] = "BOTTOM";
9
- BlockFace[BlockFace["TOP"] = 1] = "TOP";
10
- BlockFace[BlockFace["NORTH"] = 2] = "NORTH";
11
- BlockFace[BlockFace["SOUTH"] = 3] = "SOUTH";
12
- BlockFace[BlockFace["WEST"] = 4] = "WEST";
13
- BlockFace[BlockFace["EAST"] = 5] = "EAST";
14
- })(BlockFace = exports.BlockFace || (exports.BlockFace = {}));
15
- class RaycastIterator {
16
- constructor(pos, dir, maxDistance) {
17
- this.block = {
18
- x: Math.floor(pos.x),
19
- y: Math.floor(pos.y),
20
- z: Math.floor(pos.z),
21
- face: BlockFace.UNKNOWN,
22
- };
23
- this.blockVec = new vec3_1.Vec3(Math.floor(pos.x), Math.floor(pos.y), Math.floor(pos.z));
24
- this.pos = pos;
25
- this.dir = dir;
26
- this.invDirX = dir.x === 0 ? Number.MAX_VALUE : 1 / dir.x;
27
- this.invDirY = dir.y === 0 ? Number.MAX_VALUE : 1 / dir.y;
28
- this.invDirZ = dir.z === 0 ? Number.MAX_VALUE : 1 / dir.z;
29
- this.stepX = Math.sign(dir.x);
30
- this.stepY = Math.sign(dir.y);
31
- this.stepZ = Math.sign(dir.z);
32
- this.tDeltaX = dir.x === 0 ? Number.MAX_VALUE : Math.abs(1 / dir.x);
33
- this.tDeltaY = dir.y === 0 ? Number.MAX_VALUE : Math.abs(1 / dir.y);
34
- this.tDeltaZ = dir.z === 0 ? Number.MAX_VALUE : Math.abs(1 / dir.z);
35
- this.tMaxX = dir.x === 0 ? Number.MAX_VALUE : Math.abs((this.block.x + (dir.x > 0 ? 1 : 0) - pos.x) / dir.x);
36
- this.tMaxY = dir.y === 0 ? Number.MAX_VALUE : Math.abs((this.block.y + (dir.y > 0 ? 1 : 0) - pos.y) / dir.y);
37
- this.tMaxZ = dir.z === 0 ? Number.MAX_VALUE : Math.abs((this.block.z + (dir.z > 0 ? 1 : 0) - pos.z) / dir.z);
38
- this.maxDistance = maxDistance;
39
- }
40
- // Returns null if none of the shapes is intersected, otherwise returns intersect pos and face
41
- // shapes are translated by offset
42
- //[x0: number,y0: number,z0: number,x1:number,y1:number,z1:number][]
43
- intersect(shapes, offset) {
44
- // Shapes is an array of shapes, each in the form of: [x0, y0, z0, x1, y1, z1]
45
- let t = Number.MAX_VALUE;
46
- let f = BlockFace.UNKNOWN;
47
- const p = this.pos.minus(offset);
48
- for (const shape of shapes) {
49
- let tmin = (shape[this.invDirX > 0 ? 0 : 3] - p.x) * this.invDirX;
50
- let tmax = (shape[this.invDirX > 0 ? 3 : 0] - p.x) * this.invDirX;
51
- const tymin = (shape[this.invDirY > 0 ? 1 : 4] - p.y) * this.invDirY;
52
- const tymax = (shape[this.invDirY > 0 ? 4 : 1] - p.y) * this.invDirY;
53
- let face = this.stepX > 0 ? BlockFace.WEST : BlockFace.EAST;
54
- if (tmin > tymax || tymin > tmax)
55
- continue;
56
- if (tymin > tmin) {
57
- tmin = tymin;
58
- face = this.stepY > 0 ? BlockFace.BOTTOM : BlockFace.TOP;
59
- }
60
- if (tymax < tmax)
61
- tmax = tymax;
62
- const tzmin = (shape[this.invDirZ > 0 ? 2 : 5] - p.z) * this.invDirZ;
63
- const tzmax = (shape[this.invDirZ > 0 ? 5 : 2] - p.z) * this.invDirZ;
64
- if (tmin > tzmax || tzmin > tmax)
65
- continue;
66
- if (tzmin > tmin) {
67
- tmin = tzmin;
68
- face = this.stepZ > 0 ? BlockFace.NORTH : BlockFace.SOUTH;
69
- }
70
- if (tzmax < tmax)
71
- tmax = tzmax;
72
- if (tmin < t) {
73
- t = tmin;
74
- f = face;
75
- }
76
- }
77
- if (t === Number.MAX_VALUE)
78
- return null;
79
- return { pos: this.pos.plus(this.dir.scaled(t)), face: f };
80
- }
81
- next() {
82
- if (Math.min(Math.min(this.tMaxX, this.tMaxY), this.tMaxZ) > this.maxDistance) {
83
- return null;
84
- }
85
- if (this.tMaxX < this.tMaxY) {
86
- if (this.tMaxX < this.tMaxZ) {
87
- this.block.x += this.stepX;
88
- this.tMaxX += this.tDeltaX;
89
- this.block.face = this.stepX > 0 ? BlockFace.WEST : BlockFace.EAST;
90
- }
91
- else {
92
- this.block.z += this.stepZ;
93
- this.tMaxZ += this.tDeltaZ;
94
- this.block.face = this.stepZ > 0 ? BlockFace.NORTH : BlockFace.SOUTH;
95
- }
96
- }
97
- else {
98
- if (this.tMaxY < this.tMaxZ) {
99
- this.block.y += this.stepY;
100
- this.tMaxY += this.tDeltaY;
101
- this.block.face = this.stepY > 0 ? BlockFace.BOTTOM : BlockFace.TOP;
102
- }
103
- else {
104
- this.block.z += this.stepZ;
105
- this.tMaxZ += this.tDeltaZ;
106
- this.block.face = this.stepZ > 0 ? BlockFace.NORTH : BlockFace.SOUTH;
107
- }
108
- }
109
- if (isNaN(this.block.x) || isNaN(this.block.y) || isNaN(this.block.z))
110
- return null;
111
- return this.block;
112
- }
113
- }
114
- exports.RaycastIterator = RaycastIterator;