@nxg-org/mineflayer-util-plugin 1.8.4 → 1.9.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,111 +1,111 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PredictiveWorld = void 0;
4
- const vec3_1 = require("vec3");
5
- const iterators_1 = require("../calcs/iterators");
6
- const static_1 = require("../static");
7
- /**
8
- * A class dedicated to predictive logic.
9
- *
10
- * Currently, this class can predict explosion damages of crystals using a custom world.
11
- */
12
- class PredictiveWorld {
13
- constructor(bot) {
14
- this.blocks = {};
15
- this.originalWorld = bot.world;
16
- }
17
- raycast(from, direction, range, matcher = null) {
18
- const iter = new iterators_1.RaycastIterator(from, direction, range);
19
- let pos = iter.next();
20
- while (pos) {
21
- const position = new vec3_1.Vec3(pos.x, pos.y, pos.z);
22
- const block = this.getBlock(position);
23
- if (block && (!matcher || matcher(block))) {
24
- const intersect = iter.intersect(block.shapes, position);
25
- if (intersect) {
26
- //@ts-expect-error 2
27
- block.face = intersect.face;
28
- //@ts-expect-error
29
- block.intersect = intersect.pos;
30
- return block;
31
- }
32
- }
33
- pos = iter.next();
34
- }
35
- return null;
36
- }
37
- /**
38
- * this works
39
- * @param {Block} block
40
- */
41
- setBlock(pos, block) {
42
- var _a;
43
- var _b, _c;
44
- (_a = (_b = this.blocks)[_c = pos.toString()]) !== null && _a !== void 0 ? _a : (_b[_c] = block);
45
- }
46
- /**
47
- * @param {Overwrites} blocks Blocks indexed by position.toString()
48
- */
49
- setBlocks(blocks) {
50
- for (const index in blocks)
51
- this.blocks[index] = blocks[index];
52
- }
53
- /**
54
- * @param {Vec3} pos
55
- * @returns {Block | null} Block at position.
56
- */
57
- getBlock(pos) {
58
- var _a;
59
- const pblock = this.blocks[pos.toString()];
60
- if (pblock !== undefined && pblock !== null)
61
- return pblock;
62
- return (_a = this.originalWorld.getBlock(pos)) !== null && _a !== void 0 ? _a : null;
63
- }
64
- removeBlock(pos, force) {
65
- if (force) {
66
- delete this.blocks[pos.toString()];
67
- }
68
- else {
69
- const realBlock = this.originalWorld.getBlock(pos);
70
- if (realBlock)
71
- this.blocks[pos.toString()] = realBlock;
72
- else
73
- delete this.blocks[pos.toString()];
74
- }
75
- }
76
- removeBlocks(positions, force) {
77
- positions.forEach((pos) => this.removeBlock(pos, force));
78
- }
79
- /**
80
- * @param playerPos Position of effected entity.
81
- * @param explosionPos Position of explosion origin.
82
- * @param block bot.block
83
- * @returns List of affected blocks that potentially protect the entity.
84
- */
85
- getExplosionAffectedBlocks(entityBB, explosionPos) {
86
- let blocks = {};
87
- const { x: xWidth, y: yWidth, z: zWidth } = entityBB.heightAndWidths();
88
- const dx = 1 / (xWidth * 2 + 1);
89
- const dy = 1 / (yWidth * 2 + 1);
90
- const dz = 1 / (zWidth * 2 + 1);
91
- const d3 = (1 - Math.floor(1 / dx) * dx) / 2;
92
- const d4 = (1 - Math.floor(1 / dz) * dz) / 2;
93
- const pos = new vec3_1.Vec3(0, 0, 0);
94
- for (pos.y = entityBB.minY; pos.y <= entityBB.maxY; pos.y += yWidth * dy) {
95
- for (pos.x = entityBB.minX + d3; pos.x <= entityBB.maxX; pos.x += xWidth * dx) {
96
- for (pos.z = entityBB.minZ + d4; pos.z <= entityBB.maxZ; pos.z += zWidth * dz) {
97
- const dir = pos.minus(explosionPos);
98
- const range = dir.norm();
99
- const potentialBlock = this.raycast(explosionPos, dir.normalize(), range);
100
- if (potentialBlock !== null)
101
- blocks[potentialBlock.position.toString()] = potentialBlock;
102
- }
103
- }
104
- }
105
- return blocks;
106
- }
107
- loadProtectiveBlocks(playerPos, explosionPos) {
108
- this.setBlocks(this.getExplosionAffectedBlocks(static_1.AABBUtils.getPlayerAABBRaw(playerPos), explosionPos));
109
- }
110
- }
111
- exports.PredictiveWorld = PredictiveWorld;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PredictiveWorld = void 0;
4
+ const vec3_1 = require("vec3");
5
+ const iterators_1 = require("../calcs/iterators");
6
+ const static_1 = require("../static");
7
+ /**
8
+ * A class dedicated to predictive logic.
9
+ *
10
+ * Currently, this class can predict explosion damages of crystals using a custom world.
11
+ */
12
+ class PredictiveWorld {
13
+ constructor(bot) {
14
+ this.blocks = {};
15
+ this.originalWorld = bot.world;
16
+ }
17
+ raycast(from, direction, range, matcher = null) {
18
+ const iter = new iterators_1.RaycastIterator(from, direction, range);
19
+ let pos = iter.next();
20
+ while (pos) {
21
+ const position = new vec3_1.Vec3(pos.x, pos.y, pos.z);
22
+ const block = this.getBlock(position);
23
+ if (block && (!matcher || matcher(block))) {
24
+ const intersect = iter.intersect(block.shapes, position);
25
+ if (intersect) {
26
+ //@ts-expect-error 2
27
+ block.face = intersect.face;
28
+ //@ts-expect-error
29
+ block.intersect = intersect.pos;
30
+ return block;
31
+ }
32
+ }
33
+ pos = iter.next();
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * this works
39
+ * @param {Block} block
40
+ */
41
+ setBlock(pos, block) {
42
+ var _a;
43
+ var _b, _c;
44
+ (_a = (_b = this.blocks)[_c = pos.toString()]) !== null && _a !== void 0 ? _a : (_b[_c] = block);
45
+ }
46
+ /**
47
+ * @param {Overwrites} blocks Blocks indexed by position.toString()
48
+ */
49
+ setBlocks(blocks) {
50
+ for (const index in blocks)
51
+ this.blocks[index] = blocks[index];
52
+ }
53
+ /**
54
+ * @param {Vec3} pos
55
+ * @returns {Block | null} Block at position.
56
+ */
57
+ getBlock(pos) {
58
+ var _a;
59
+ const pblock = this.blocks[pos.toString()];
60
+ if (pblock !== undefined && pblock !== null)
61
+ return pblock;
62
+ return (_a = this.originalWorld.getBlock(pos)) !== null && _a !== void 0 ? _a : null;
63
+ }
64
+ removeBlock(pos, force) {
65
+ if (force) {
66
+ delete this.blocks[pos.toString()];
67
+ }
68
+ else {
69
+ const realBlock = this.originalWorld.getBlock(pos);
70
+ if (realBlock)
71
+ this.blocks[pos.toString()] = realBlock;
72
+ else
73
+ delete this.blocks[pos.toString()];
74
+ }
75
+ }
76
+ removeBlocks(positions, force) {
77
+ positions.forEach((pos) => this.removeBlock(pos, force));
78
+ }
79
+ /**
80
+ * @param playerPos Position of effected entity.
81
+ * @param explosionPos Position of explosion origin.
82
+ * @param block bot.block
83
+ * @returns List of affected blocks that potentially protect the entity.
84
+ */
85
+ getExplosionAffectedBlocks(entityBB, explosionPos) {
86
+ let blocks = {};
87
+ const { x: xWidth, y: yWidth, z: zWidth } = entityBB.heightAndWidths();
88
+ const dx = 1 / (xWidth * 2 + 1);
89
+ const dy = 1 / (yWidth * 2 + 1);
90
+ const dz = 1 / (zWidth * 2 + 1);
91
+ const d3 = (1 - Math.floor(1 / dx) * dx) / 2;
92
+ const d4 = (1 - Math.floor(1 / dz) * dz) / 2;
93
+ const pos = new vec3_1.Vec3(0, 0, 0);
94
+ for (pos.y = entityBB.minY; pos.y <= entityBB.maxY; pos.y += yWidth * dy) {
95
+ for (pos.x = entityBB.minX + d3; pos.x <= entityBB.maxX; pos.x += xWidth * dx) {
96
+ for (pos.z = entityBB.minZ + d4; pos.z <= entityBB.maxZ; pos.z += zWidth * dz) {
97
+ const dir = pos.minus(explosionPos);
98
+ const range = dir.norm();
99
+ const potentialBlock = this.raycast(explosionPos, dir.normalize(), range);
100
+ if (potentialBlock !== null)
101
+ blocks[potentialBlock.position.toString()] = potentialBlock;
102
+ }
103
+ }
104
+ }
105
+ return blocks;
106
+ }
107
+ loadProtectiveBlocks(playerPos, explosionPos) {
108
+ this.setBlocks(this.getExplosionAffectedBlocks(static_1.AABBUtils.getPlayerAABBRaw(playerPos), explosionPos));
109
+ }
110
+ }
111
+ exports.PredictiveWorld = PredictiveWorld;
package/package.json CHANGED
@@ -1,29 +1,31 @@
1
1
  {
2
- "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.8.4",
4
- "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
- "keywords": [
6
- "mineflayer",
7
- "mineflayer-util"
8
- ],
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/nxg-org/mineflayer-util-plugin.git"
12
- },
13
- "license": "GPL-3.0",
14
- "author": "generel_schwerz",
15
- "main": "lib/index.js",
16
- "types": "lib/index.d.ts",
17
- "scripts": {
18
- "build": "npx tsc",
19
- "prepublish": "npm run build",
20
- "test": "ts-node examples/example.ts"
21
- },
22
- "dependencies": {},
23
- "devDependencies": {
24
- "@types/node": "^17.0.4",
25
- "mineflayer": "^4.17.0",
26
- "typescript": "^4.5.2",
27
- "vec3": "^0.1.7"
28
- }
29
- }
2
+ "name": "@nxg-org/mineflayer-util-plugin",
3
+ "version": "1.9.1",
4
+ "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
+ "keywords": [
6
+ "mineflayer",
7
+ "mineflayer-util"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/nxg-org/mineflayer-util-plugin.git"
12
+ },
13
+ "license": "GPL-3.0",
14
+ "author": "generel_schwerz",
15
+ "main": "lib/index.js",
16
+ "types": "lib/index.d.ts",
17
+ "devDependencies": {
18
+ "@types/node": "^17.0.4",
19
+ "mineflayer": "^4.17.0",
20
+ "prismarine-block": "^1.23.0",
21
+ "prismarine-entity": "^2.6.0",
22
+ "prismarine-item": "^1.18.0",
23
+ "typescript": "^4.5.2",
24
+ "vec3": "^0.1.7"
25
+ },
26
+ "scripts": {
27
+ "build": "npx tsc",
28
+ "prepublish": "npm run build",
29
+ "test": "ts-node examples/example.ts"
30
+ }
31
+ }