@starktma/minecraft-utils 1.0.1 → 1.2.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/LICENSE +674 -674
- package/README.md +0 -0
- package/dist/database/constants.d.ts.map +1 -0
- package/dist/database/database.d.ts.map +1 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/interfaces.d.ts.map +1 -0
- package/dist/math/index.d.ts.map +1 -1
- package/dist/minecraft/index.d.ts.map +1 -1
- package/dist/player-event/constants.d.ts.map +1 -0
- package/dist/player-event/index.d.ts.map +1 -0
- package/package.json +44 -36
- package/src/database/constants.ts +1 -0
- package/src/database/database.ts +271 -0
- package/src/database/index.ts +4 -0
- package/src/database/interfaces.ts +6 -0
- package/src/math/index.ts +132 -129
- package/src/minecraft/index.ts +207 -62
- package/src/player-event/constants.ts +1 -0
- package/src/player-event/index.ts +194 -0
- package/tsconfig.json +22 -22
package/src/math/index.ts
CHANGED
|
@@ -1,129 +1,132 @@
|
|
|
1
|
-
import { Vector3 } from "@minecraft/server";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Converts an angle in degrees to radians.
|
|
5
|
-
*
|
|
6
|
-
* @param degrees - The angle in degrees to be converted.
|
|
7
|
-
* @returns The angle in radians.
|
|
8
|
-
*/
|
|
9
|
-
export function toRadians(degrees: number): number {
|
|
10
|
-
return degrees * (Math.PI / 180);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Converts an angle in radians to degrees.
|
|
15
|
-
*
|
|
16
|
-
* @param radians - The angle in radians to be converted.
|
|
17
|
-
* @returns The angle in degrees.
|
|
18
|
-
*/
|
|
19
|
-
export function calculateDistance(position1: Vector3, position2: Vector3): number {
|
|
20
|
-
return Math.sqrt(
|
|
21
|
-
Math.
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Converts an angle in radians to degrees.
|
|
27
|
-
*
|
|
28
|
-
* @param radians - The angle in radians to be converted.
|
|
29
|
-
* @returns The angle in degrees.
|
|
30
|
-
*/
|
|
31
|
-
export function toDegrees(radians: number): number {
|
|
32
|
-
return radians * (180 / Math.PI);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Converts a hex color string to an RGBA object.
|
|
37
|
-
*
|
|
38
|
-
* @param hex - The hex color string, which can be in the formats #RGB, #RGBA, #RRGGBB, or #RRGGBBAA.
|
|
39
|
-
* @returns An object containing the red, green, blue, and alpha components as numbers between 0 and 1.
|
|
40
|
-
* @throws Error if the hex string is invalid.
|
|
41
|
-
*/
|
|
42
|
-
export function hexToRgba(hex: string
|
|
43
|
-
if (!/^#([a-fA-F0-9]{4}|[a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(hex)) {
|
|
44
|
-
throw new Error("Invalid hex color");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let normalized = hex.slice(1);
|
|
48
|
-
if (normalized.length === 3 || normalized.length === 4) {
|
|
49
|
-
normalized = normalized
|
|
50
|
-
.split("")
|
|
51
|
-
.map((c) => c + c)
|
|
52
|
-
.join("");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const red = parseInt(normalized.substring(0, 2), 16) / 255;
|
|
56
|
-
const green = parseInt(normalized.substring(2, 4), 16) / 255;
|
|
57
|
-
const blue = parseInt(normalized.substring(4, 6), 16) / 255;
|
|
58
|
-
const alpha = (normalized.length === 8 ? parseInt(normalized.substring(6, 8), 16) : 255) / 255;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* @
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* @
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
1
|
+
import { RGB, RGBA, Vector3 } from "@minecraft/server";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts an angle in degrees to radians.
|
|
5
|
+
*
|
|
6
|
+
* @param degrees - The angle in degrees to be converted.
|
|
7
|
+
* @returns The angle in radians.
|
|
8
|
+
*/
|
|
9
|
+
export function toRadians(degrees: number): number {
|
|
10
|
+
return degrees * (Math.PI / 180);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Converts an angle in radians to degrees.
|
|
15
|
+
*
|
|
16
|
+
* @param radians - The angle in radians to be converted.
|
|
17
|
+
* @returns The angle in degrees.
|
|
18
|
+
*/
|
|
19
|
+
export function calculateDistance(position1: Vector3, position2: Vector3): number {
|
|
20
|
+
return Math.sqrt(
|
|
21
|
+
Math.pow(position1.x - position2.x, 2) + Math.pow(position1.y - position2.y, 2) + Math.pow(position1.z - position2.z, 2)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Converts an angle in radians to degrees.
|
|
27
|
+
*
|
|
28
|
+
* @param radians - The angle in radians to be converted.
|
|
29
|
+
* @returns The angle in degrees.
|
|
30
|
+
*/
|
|
31
|
+
export function toDegrees(radians: number): number {
|
|
32
|
+
return radians * (180 / Math.PI);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Converts a hex color string to an RGBA object.
|
|
37
|
+
*
|
|
38
|
+
* @param hex - The hex color string, which can be in the formats #RGB, #RGBA, #RRGGBB, or #RRGGBBAA.
|
|
39
|
+
* @returns An object containing the red, green, blue, and alpha components as numbers between 0 and 1.
|
|
40
|
+
* @throws Error if the hex string is invalid.
|
|
41
|
+
*/
|
|
42
|
+
export function hexToRgba(hex: string, stripAlpha: boolean = false): RGB | RGBA {
|
|
43
|
+
if (!/^#([a-fA-F0-9]{4}|[a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(hex)) {
|
|
44
|
+
throw new Error("Invalid hex color");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let normalized = hex.slice(1);
|
|
48
|
+
if (normalized.length === 3 || normalized.length === 4) {
|
|
49
|
+
normalized = normalized
|
|
50
|
+
.split("")
|
|
51
|
+
.map((c) => c + c)
|
|
52
|
+
.join("");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const red = parseInt(normalized.substring(0, 2), 16) / 255;
|
|
56
|
+
const green = parseInt(normalized.substring(2, 4), 16) / 255;
|
|
57
|
+
const blue = parseInt(normalized.substring(4, 6), 16) / 255;
|
|
58
|
+
const alpha = (normalized.length === 8 ? parseInt(normalized.substring(6, 8), 16) : 255) / 255;
|
|
59
|
+
|
|
60
|
+
if (stripAlpha) {
|
|
61
|
+
return { red, green, blue };
|
|
62
|
+
}
|
|
63
|
+
return { red, green, blue, alpha };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Clamps a value between a minimum and maximum range.
|
|
68
|
+
*
|
|
69
|
+
* @param value - The value to be clamped.
|
|
70
|
+
* @param min - The minimum value of the range.
|
|
71
|
+
* @param max - The maximum value of the range.
|
|
72
|
+
* @returns The clamped value, which will be between `min` and `max`.
|
|
73
|
+
*/
|
|
74
|
+
export function clamp(value: number, min: number, max: number): number {
|
|
75
|
+
return Math.max(min, Math.min(max, value));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Converts an angle in degrees to its signed equivalent in the range [-180, 180].
|
|
80
|
+
*
|
|
81
|
+
* @param angle - The angle in degrees to be converted.
|
|
82
|
+
* @returns The signed angle in degrees, normalized to the range [-180, 180].
|
|
83
|
+
*/
|
|
84
|
+
export function toSigned(angle: number): number {
|
|
85
|
+
const wrapped = ((angle % 360) + 360) % 360;
|
|
86
|
+
return wrapped > 180 ? wrapped - 360 : wrapped;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Converts an angle in degrees to its unsigned equivalent in the range [0, 360].
|
|
91
|
+
*
|
|
92
|
+
* @param angle - The angle in degrees to be converted.
|
|
93
|
+
* @returns The unsigned angle in degrees, normalized to the range [0, 360].
|
|
94
|
+
*/
|
|
95
|
+
export function toUnsigned(angle: number): number {
|
|
96
|
+
return ((angle % 360) + 360) % 360;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Calculates the shortest signed arc between two angles in degrees.
|
|
101
|
+
*
|
|
102
|
+
* @param from - The starting angle in degrees.
|
|
103
|
+
* @param to - The target angle in degrees.
|
|
104
|
+
* @returns The shortest arc in degrees from `from` to `to`.
|
|
105
|
+
*/
|
|
106
|
+
export function shortestArc(from: number, to: number): number {
|
|
107
|
+
return -toSigned((to - from + 360) % 360);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Checks if two positions are equal within a specified tolerance.
|
|
112
|
+
*
|
|
113
|
+
* @param a - The first position.
|
|
114
|
+
* @param b - The second position.
|
|
115
|
+
* @param tolerance - The tolerance for comparison (default is 0.5).
|
|
116
|
+
* @returns `true` if the positions are equal within the tolerance, otherwise `false`.
|
|
117
|
+
*/
|
|
118
|
+
export function positionsEqual(a: Vector3, b: Vector3, tolerance: number = 0.5): boolean {
|
|
119
|
+
return Math.abs(a.x - b.x) < tolerance && Math.abs(a.y - b.y) < tolerance && Math.abs(a.z - b.z) < tolerance;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Checks if a value is within a specified range.
|
|
124
|
+
*
|
|
125
|
+
* @param value - The value to check.
|
|
126
|
+
* @param min - The minimum value of the range.
|
|
127
|
+
* @param max - The maximum value of the range.
|
|
128
|
+
* @returns `true` if the value is within the range [min, max], otherwise `false`.
|
|
129
|
+
*/
|
|
130
|
+
export function inRange(value: number, min: number, max: number): boolean {
|
|
131
|
+
return value >= min && value <= max;
|
|
132
|
+
}
|
package/src/minecraft/index.ts
CHANGED
|
@@ -1,62 +1,207 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
import {
|
|
2
|
+
Player,
|
|
3
|
+
Entity,
|
|
4
|
+
Block,
|
|
5
|
+
Vector3,
|
|
6
|
+
world,
|
|
7
|
+
StructureRotation,
|
|
8
|
+
Vector2,
|
|
9
|
+
BlockInventoryComponent,
|
|
10
|
+
BlockPermutation,
|
|
11
|
+
EntityEquippableComponent,
|
|
12
|
+
EntityInventoryComponent,
|
|
13
|
+
EquipmentSlot,
|
|
14
|
+
ItemStack,
|
|
15
|
+
} from "@minecraft/server";
|
|
16
|
+
import { calculateDistance, toRadians, toUnsigned } from "../math";
|
|
17
|
+
|
|
18
|
+
export function getBlocksInASphere(centerBlock: Block | Entity, radius: number, innerRadius?: number) {
|
|
19
|
+
if (centerBlock) {
|
|
20
|
+
if (centerBlock instanceof Block && !centerBlock.isValid) return [];
|
|
21
|
+
let center = centerBlock.location;
|
|
22
|
+
let blocks: Block[] = [];
|
|
23
|
+
for (let x = center.x - radius; x < center.x + radius; x++) {
|
|
24
|
+
for (let y = center.y - radius; y < center.y + radius; y++) {
|
|
25
|
+
for (let z = center.z - radius; z < center.z + radius; z++) {
|
|
26
|
+
try {
|
|
27
|
+
let block = centerBlock.dimension.getBlock({ x: x, y: y, z: z });
|
|
28
|
+
if (
|
|
29
|
+
block &&
|
|
30
|
+
block.isValid &&
|
|
31
|
+
!block.isAir &&
|
|
32
|
+
!block.permutation.matches("minecraft:bedrock") &&
|
|
33
|
+
!block.permutation.matches("minecraft:barrier") &&
|
|
34
|
+
calculateDistance(center, block.location) <= radius &&
|
|
35
|
+
(!innerRadius || calculateDistance(center, block.location) >= innerRadius)
|
|
36
|
+
) {
|
|
37
|
+
blocks.push(block);
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return blocks;
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function displayActionbar(player: Player | undefined, ...message: any) {
|
|
49
|
+
const text = message.join(" ");
|
|
50
|
+
let target;
|
|
51
|
+
let selector;
|
|
52
|
+
target = player && player.isValid ? player : world.getDimension("overworld");
|
|
53
|
+
selector = player ? `@s` : `@a`;
|
|
54
|
+
target.runCommand(`title ${selector} actionbar ${JSON.stringify(text)}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Snaps an angle to the nearest grid size.
|
|
59
|
+
*
|
|
60
|
+
* @param angle - The angle in degrees to be snapped.
|
|
61
|
+
* @returns The snapped unsigned angle in degrees.
|
|
62
|
+
*/
|
|
63
|
+
export function snapYawToGrid(angle: number): number {
|
|
64
|
+
const gridSize = 90;
|
|
65
|
+
return Math.round(toUnsigned(angle) / gridSize) * gridSize;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Snaps a vector to the nearest integer coordinates.
|
|
70
|
+
*
|
|
71
|
+
* @param v - The vector to be snapped.
|
|
72
|
+
* @returns A new vector with each component rounded to the nearest integer.
|
|
73
|
+
*/
|
|
74
|
+
export function snapLocationToGrid(location: Vector3, yaw: Vector2, gridSize: number = 1): Vector3 {
|
|
75
|
+
const snappedYaw = snapYawToGrid(yaw.y);
|
|
76
|
+
const dx = Math.round(Math.sin(snappedYaw));
|
|
77
|
+
const dz = Math.round(Math.cos(snappedYaw));
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
x: Math.floor(location.x / gridSize) * gridSize,
|
|
81
|
+
y: Math.floor(location.y / gridSize) * gridSize,
|
|
82
|
+
z: Math.floor(location.z / gridSize) * gridSize,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function getStructureRotationEnum(angle: number, saveYaw?: number): StructureRotation {
|
|
87
|
+
const EPS = 1e-4;
|
|
88
|
+
const diff = snapYawToGrid(angle) - snapYawToGrid(saveYaw ?? 0);
|
|
89
|
+
if (Math.abs(diff - 90) < EPS) return StructureRotation.Rotate90;
|
|
90
|
+
if (Math.abs(diff - 180) < EPS) return StructureRotation.Rotate180;
|
|
91
|
+
if (Math.abs(diff - 270) < EPS) return StructureRotation.Rotate270;
|
|
92
|
+
return StructureRotation.None;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getRelativeMovementDirection(player: Player, round: boolean): Vector3 {
|
|
96
|
+
const playerYaw = toRadians(player.getRotation().y);
|
|
97
|
+
const { sin, cos } = { sin: Math.sin(playerYaw), cos: Math.cos(playerYaw) };
|
|
98
|
+
|
|
99
|
+
const playerMovement = player.inputInfo.getMovementVector();
|
|
100
|
+
|
|
101
|
+
const dx = -sin * playerMovement.y + cos * playerMovement.x;
|
|
102
|
+
const dz = cos * playerMovement.y + sin * playerMovement.x;
|
|
103
|
+
|
|
104
|
+
if (round) {
|
|
105
|
+
return { x: Math.round(dx), y: 0, z: Math.round(dz) };
|
|
106
|
+
}
|
|
107
|
+
return { x: dx, y: 0, z: dz };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function restoreInventory(entity: Entity, id: string) {
|
|
111
|
+
const blockLocation = entity.dimension.getBlockFromRay(entity.location, { x: 0, y: -1, z: 0 })!.block.location;
|
|
112
|
+
blockLocation.y++;
|
|
113
|
+
const blockLocation2 = { ...blockLocation, y: blockLocation.y + 1 };
|
|
114
|
+
|
|
115
|
+
const savedStructure = world.structureManager.get(id);
|
|
116
|
+
if (savedStructure) world.structureManager.place(savedStructure, entity.dimension, blockLocation);
|
|
117
|
+
world.structureManager.delete(id);
|
|
118
|
+
|
|
119
|
+
const block = entity.dimension.getBlock(blockLocation)!;
|
|
120
|
+
const block2 = entity.dimension.getBlock(blockLocation2)!;
|
|
121
|
+
|
|
122
|
+
const equipment = entity.getComponent(EntityEquippableComponent.componentId) as EntityEquippableComponent;
|
|
123
|
+
const invComponent = entity.getComponent(EntityInventoryComponent.componentId) as EntityInventoryComponent;
|
|
124
|
+
const blockInventory = block.getComponent(BlockInventoryComponent.componentId) as BlockInventoryComponent;
|
|
125
|
+
const blockInventory2 = block2.getComponent(BlockInventoryComponent.componentId) as BlockInventoryComponent;
|
|
126
|
+
|
|
127
|
+
const slots = Object.values(EquipmentSlot);
|
|
128
|
+
slots.forEach((slot) => {
|
|
129
|
+
equipment.setEquipment(slot, blockInventory.container!.getItem(slots.indexOf(slot))!);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
Array(41)
|
|
133
|
+
.fill(0)
|
|
134
|
+
.forEach((_, i) => {
|
|
135
|
+
if (i < invComponent.container!.size) {
|
|
136
|
+
if (i < 9) {
|
|
137
|
+
// First chest: starts filling from slot 5
|
|
138
|
+
blockInventory.container!.moveItem(i + 5, i, invComponent.container!);
|
|
139
|
+
} else {
|
|
140
|
+
// Second chest: adjusts index for 0-26 range starting from slot 0
|
|
141
|
+
blockInventory2.container!.moveItem(i - 9, i, invComponent.container!);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
blockInventory.container!.clearAll();
|
|
147
|
+
blockInventory2.container!.clearAll();
|
|
148
|
+
block.setPermutation(BlockPermutation.resolve("minecraft:air"));
|
|
149
|
+
block2.setPermutation(BlockPermutation.resolve("minecraft:air"));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function saveInventory(entity: Entity, id: string, clearAll: boolean = false): number {
|
|
153
|
+
const blockLocation = entity.dimension.getTopmostBlock(entity.location)!.location;
|
|
154
|
+
blockLocation.y++;
|
|
155
|
+
const blockLocation2 = { ...blockLocation, y: blockLocation.y + 1 };
|
|
156
|
+
|
|
157
|
+
const block = entity.dimension.getBlock(blockLocation)!;
|
|
158
|
+
const block2 = entity.dimension.getBlock(blockLocation2)!;
|
|
159
|
+
|
|
160
|
+
block.setPermutation(BlockPermutation.resolve("minecraft:chest"));
|
|
161
|
+
block2.setPermutation(BlockPermutation.resolve("minecraft:chest"));
|
|
162
|
+
|
|
163
|
+
const equipment = entity.getComponent(EntityEquippableComponent.componentId) as EntityEquippableComponent;
|
|
164
|
+
const invComponent = entity.getComponent(EntityInventoryComponent.componentId) as EntityInventoryComponent;
|
|
165
|
+
const blockInventory = block.getComponent(BlockInventoryComponent.componentId) as BlockInventoryComponent;
|
|
166
|
+
const blockInventory2 = block2.getComponent(BlockInventoryComponent.componentId) as BlockInventoryComponent;
|
|
167
|
+
|
|
168
|
+
const itemCount = invComponent.container!.size - invComponent.container!.emptySlotsCount;
|
|
169
|
+
|
|
170
|
+
Object.values(EquipmentSlot).forEach((slot) => {
|
|
171
|
+
if (clearAll) {
|
|
172
|
+
equipment.setEquipment(slot);
|
|
173
|
+
}
|
|
174
|
+
blockInventory.container!.addItem(equipment.getEquipment(slot) ?? new ItemStack("minecraft:air", 1));
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (clearAll) {
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
Array(41)
|
|
181
|
+
.fill(0)
|
|
182
|
+
.forEach((_, i) => {
|
|
183
|
+
if (i < invComponent.container!.size) {
|
|
184
|
+
if (i < 9) {
|
|
185
|
+
// First chest: starts filling from slot 5
|
|
186
|
+
invComponent.container!.moveItem(i, 5 + i, blockInventory.container!);
|
|
187
|
+
} else {
|
|
188
|
+
// Second chest: adjusts index for 0-26 range starting from slot 0
|
|
189
|
+
invComponent.container!.moveItem(i, i - 9, blockInventory2.container!);
|
|
190
|
+
}
|
|
191
|
+
if (clearAll) {
|
|
192
|
+
invComponent.container!.setItem(i);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
world.structureManager.delete(id);
|
|
198
|
+
world.structureManager.createFromWorld(id, entity.dimension, blockLocation, blockLocation2);
|
|
199
|
+
|
|
200
|
+
blockInventory.container!.clearAll();
|
|
201
|
+
blockInventory2.container!.clearAll();
|
|
202
|
+
|
|
203
|
+
block.setPermutation(BlockPermutation.resolve("minecraft:air"));
|
|
204
|
+
block2.setPermutation(BlockPermutation.resolve("minecraft:air"));
|
|
205
|
+
|
|
206
|
+
return itemCount;
|
|
207
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const NAMESPACE = 'player-event';
|