script-box-mc 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nano191225
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # ScriptBoxMC
2
+
3
+ ScriptAPI addon template generated by scriptup.
4
+
5
+ ## Local library structure
6
+
7
+ - package/main.ts: local package source
8
+ - src/main.ts: sample usage that imports from ScriptBoxMC
9
+
10
+ ## Setup
11
+
12
+ ```bash
13
+ npm install
14
+ ```
15
+
16
+ ## Publish
17
+
18
+ ### First publish (manual)
19
+
20
+ 1. Update `name` and `version` in package.json (current import alias: `ScriptBoxMC`).
21
+ 2. Build and publish:
22
+
23
+ ```bash
24
+ npm run build
25
+ npm publish --access public
26
+ ```
27
+
28
+ ### Subsequent publishes (automated via GitHub Actions)
29
+
30
+ > [!TIP]
31
+ > Using [npm Trusted Publishers](https://docs.npmjs.com/trusted-publishers#configuring-trusted-publishing) removes the need to manage `NPM_TOKEN` in GitHub secrets.
32
+
33
+ 1. On [npmjs.com](https://www.npmjs.com), open your package → **Settings** → **Trusted Publishers**.
34
+ 2. Add a trusted publisher:
35
+ - **GitHub Actions** as the provider
36
+ - Organization or user: Enter your GitHub username or organization name
37
+ - Repository: Enter the repository name where the package is located
38
+ - Workflow filename: `publish.yml`
39
+ - Environment name: Keep empty
40
+
41
+ 3. Once configured, **delete** the `NPM_TOKEN` secret from GitHub repository settings (not needed anymore).
42
+
43
+ 4. Bump `version` in package.json, then create a GitHub release → **.github/workflows/publish.yml** runs automatically.
package/dist/main.d.ts ADDED
@@ -0,0 +1,228 @@
1
+ import { Entity as Entity$1, ItemLockMode, ItemStack as ItemStack$1, Player as Player$1, RGB, RawMessage, ScoreboardIdentity, ScoreboardObjective, Vector3 } from "@minecraft/server";
2
+ import { ActionFormResponse, FormCancelationReason, MessageFormResponse, ModalFormResponse } from "@minecraft/server-ui";
3
+
4
+ //#region package/define/entity.d.ts
5
+ declare module "@minecraft/server" {
6
+ interface Entity {
7
+ isPlayer(): this is Player;
8
+ isEntity(): this is Entity;
9
+ isBlock(): this is Block;
10
+ readonly container?: Container;
11
+ health: number;
12
+ }
13
+ }
14
+ //#endregion
15
+ //#region package/define/player.d.ts
16
+ declare module "@minecraft/server" {
17
+ interface Player {
18
+ kick(reason?: string): boolean;
19
+ closeAllForms(): void;
20
+ isRiding: boolean;
21
+ joinedAt: number;
22
+ equip: {
23
+ getHead(): ItemStack | undefined;
24
+ getChest(): ItemStack | undefined;
25
+ getLegs(): ItemStack | undefined;
26
+ getFeet(): ItemStack | undefined;
27
+ getMainHand(): ItemStack | undefined;
28
+ getOffHand(): ItemStack | undefined;
29
+ };
30
+ }
31
+ }
32
+ //#endregion
33
+ //#region package/define/block.d.ts
34
+ declare module "@minecraft/server" {
35
+ interface Block {
36
+ isPlayer(): this is Player;
37
+ isEntity(): this is Entity;
38
+ isBlock(): this is Block;
39
+ }
40
+ }
41
+ //#endregion
42
+ //#region package/define/item.d.ts
43
+ declare module "@minecraft/server" {
44
+ interface ItemStack {
45
+ enchantment: {
46
+ getEnchant(enchantmentType: EnchantmentType | string): Enchantment | undefined;
47
+ getAllEnchants(): Enchantment[] | undefined;
48
+ addEnchant(enchantmentType: EnchantmentType | string, level: number): void;
49
+ canAddEnchant(enchantmentType: EnchantmentType | string, level: number): boolean | undefined;
50
+ removeEnchant(enchantmentType: EnchantmentType | string): void;
51
+ removeAllEnchants(): void;
52
+ hasEnchant: (enchantmentType: EnchantmentType | string) => boolean | undefined;
53
+ };
54
+ }
55
+ }
56
+ //#endregion
57
+ //#region package/form/action.d.ts
58
+ type ActionElementCallback = (player: Player$1, index: number) => void;
59
+ interface ActionFormConfig {
60
+ back: {
61
+ text: RawMessage | string;
62
+ iconPath?: string;
63
+ };
64
+ close: {
65
+ enabled: boolean;
66
+ text: RawMessage | string;
67
+ iconPath?: string;
68
+ };
69
+ }
70
+ declare class ActionFormBox {
71
+ private form;
72
+ private callbacks;
73
+ private backCallback?;
74
+ private cancelledCallback?;
75
+ static config: ActionFormConfig;
76
+ constructor(title?: string);
77
+ title(text: RawMessage | string): ActionFormBox;
78
+ body(text: RawMessage | string): ActionFormBox;
79
+ button(text: RawMessage | string, callback?: ActionElementCallback): ActionFormBox;
80
+ button(text: RawMessage | string, iconPath: string, callback?: ActionElementCallback): ActionFormBox;
81
+ back(callback: ActionElementCallback): ActionFormBox;
82
+ cancel(callback: (cancelationReason?: FormCancelationReason) => void): ActionFormBox;
83
+ label(text: RawMessage | string): ActionFormBox;
84
+ divider(): ActionFormBox;
85
+ show(player: Player$1): Promise<ActionFormResponse>;
86
+ }
87
+ //#endregion
88
+ //#region package/form/message.d.ts
89
+ declare class MessageFormBox {
90
+ private form;
91
+ private upperCallback;
92
+ private lowerCallback;
93
+ private cancelCallback;
94
+ constructor(title?: RawMessage | string);
95
+ title(titleText: RawMessage | string): MessageFormBox;
96
+ body(bodyText: RawMessage | string): MessageFormBox;
97
+ upperButton(text: RawMessage | string, callback: (player: Player$1) => void): MessageFormBox;
98
+ lowerButton(text: RawMessage | string, callback: (player: Player$1) => void): MessageFormBox;
99
+ cancel(callback: (player: Player$1, cancelationReason?: FormCancelationReason) => void): MessageFormBox;
100
+ show(player: Player$1): Promise<MessageFormResponse>;
101
+ }
102
+ //#endregion
103
+ //#region package/form/modal.d.ts
104
+ interface DropdownOptions {
105
+ label: RawMessage | string;
106
+ options: (RawMessage | string)[];
107
+ defaultValueIndex?: number;
108
+ tooltip?: RawMessage | string;
109
+ callback?: ModalElementCallback<number>;
110
+ }
111
+ interface SliderOptions {
112
+ label: RawMessage | string;
113
+ minimumValue: number;
114
+ maximumValue: number;
115
+ valueStep: number;
116
+ defaultValue?: number;
117
+ tooltip?: RawMessage | string;
118
+ callback?: ModalElementCallback<number>;
119
+ }
120
+ interface TextFieldOptions {
121
+ label: RawMessage | string;
122
+ placeholder?: RawMessage | string;
123
+ defaultValue?: string;
124
+ tooltip?: RawMessage | string;
125
+ callback?: ModalElementCallback<string>;
126
+ }
127
+ interface ToggleOptions {
128
+ label: RawMessage | string;
129
+ defaultValue?: boolean;
130
+ tooltip?: RawMessage | string;
131
+ callback?: ModalElementCallback<boolean>;
132
+ }
133
+ type ModalElementCallback<T> = ({
134
+ player,
135
+ response,
136
+ responses
137
+ }: {
138
+ player: Player$1;
139
+ response: T;
140
+ responses: (string | number | boolean | undefined)[];
141
+ }) => void;
142
+ declare class ModalFormBox {
143
+ private form;
144
+ private callbacks;
145
+ private cancelCallback;
146
+ cancel(callback: (player: Player$1, reason?: FormCancelationReason) => void): ModalFormBox;
147
+ divider(): ModalFormBox;
148
+ dropdown({
149
+ label,
150
+ options,
151
+ defaultValueIndex,
152
+ tooltip,
153
+ callback
154
+ }: DropdownOptions): ModalFormBox;
155
+ header(text: RawMessage | string): ModalFormBox;
156
+ label(text: RawMessage | string): ModalFormBox;
157
+ show(player: Player$1): Promise<ModalFormResponse>;
158
+ slider({
159
+ label,
160
+ minimumValue,
161
+ maximumValue,
162
+ valueStep,
163
+ defaultValue,
164
+ tooltip,
165
+ callback
166
+ }: SliderOptions): ModalFormBox;
167
+ submitButton(submitButtonText: RawMessage | string): ModalFormBox;
168
+ textField({
169
+ label,
170
+ placeholder,
171
+ defaultValue,
172
+ tooltip,
173
+ callback
174
+ }: TextFieldOptions): ModalFormBox;
175
+ title(text: RawMessage | string): ModalFormBox;
176
+ toggle({
177
+ label,
178
+ defaultValue,
179
+ tooltip,
180
+ callback
181
+ }: ToggleOptions): ModalFormBox;
182
+ }
183
+ //#endregion
184
+ //#region package/utils/item.d.ts
185
+ declare namespace ItemStackUtils {
186
+ export function toJSON(item: ItemStack$1): ItemStackJSON;
187
+ export function fromJSON(json: ItemStackJSON): ItemStack$1;
188
+ export function minimizeJSON(json: ItemStackJSON): ItemStackJSON;
189
+ interface ItemStackJSON {
190
+ typeId: string;
191
+ amount: number;
192
+ keepOnDeath?: boolean;
193
+ lockMode?: keyof typeof ItemLockMode;
194
+ nameTag?: string;
195
+ dynamicProperties?: Record<string, boolean | number | string | Vector3 | undefined>;
196
+ canDestroy?: string[];
197
+ canPlaceOn?: string[];
198
+ lore?: string[];
199
+ components?: {
200
+ durability?: {
201
+ damage?: number;
202
+ };
203
+ dyeable?: {
204
+ color?: RGB;
205
+ };
206
+ enchantable?: {
207
+ enchantments?: {
208
+ level: number;
209
+ type: string;
210
+ }[];
211
+ };
212
+ };
213
+ }
214
+ export {};
215
+ }
216
+ //#endregion
217
+ //#region package/utils/scoreboard.d.ts
218
+ declare namespace ScoreboardUtils {
219
+ function addObjective(id: string, display?: string): ScoreboardObjective;
220
+ function getObjective(id: string): ScoreboardObjective;
221
+ function deleteObjective(id: string): boolean;
222
+ function getScore(target: ScoreboardIdentity | Entity$1 | string, objective: string): number | undefined;
223
+ function addScore(target: ScoreboardIdentity | Entity$1 | string, objective: string, value: number): number;
224
+ function setScore(target: ScoreboardIdentity | Entity$1 | string, objective: string, value: number): void;
225
+ function resetScore(target: ScoreboardIdentity | Entity$1 | string, objective: string): boolean;
226
+ }
227
+ //#endregion
228
+ export { ActionFormBox, ItemStackUtils, MessageFormBox, ModalFormBox, ScoreboardUtils };
package/dist/main.js ADDED
@@ -0,0 +1,474 @@
1
+ import { Block, EnchantmentTypes, Entity, EquipmentSlot, ItemLockMode, ItemStack, Player, world } from "@minecraft/server";
2
+ import { ActionFormData, MessageFormData, ModalFormData, uiManager } from "@minecraft/server-ui";
3
+ //#region package/define/entity.ts
4
+ Object.defineProperties(Entity.prototype, {
5
+ isPlayer: {
6
+ value: function() {
7
+ return this instanceof Player;
8
+ },
9
+ configurable: true
10
+ },
11
+ isEntity: {
12
+ value: function() {
13
+ return this instanceof Entity;
14
+ },
15
+ configurable: true
16
+ },
17
+ isBlock: {
18
+ value: function() {
19
+ return this instanceof Block;
20
+ },
21
+ configurable: true
22
+ },
23
+ container: {
24
+ get: function() {
25
+ return this.getComponent("minecraft:inventory")?.container;
26
+ },
27
+ configurable: true
28
+ },
29
+ health: {
30
+ set: function(v) {
31
+ this.getComponent("minecraft:health")?.setCurrentValue(v);
32
+ },
33
+ get: function() {
34
+ return this.getComponent("minecraft:health")?.currentValue;
35
+ },
36
+ configurable: true
37
+ }
38
+ });
39
+ //#endregion
40
+ //#region package/define/player.ts
41
+ Object.defineProperties(Player.prototype, {
42
+ kick: {
43
+ value: function(reason) {
44
+ return this.runCommand(`kick ${JSON.stringify(this.name)} ${reason ?? ""}`).successCount > 0;
45
+ },
46
+ configurable: true
47
+ },
48
+ closeAllForms: {
49
+ value: function() {
50
+ uiManager.closeAllForms(this);
51
+ },
52
+ configurable: true
53
+ },
54
+ isRiding: {
55
+ get: function() {
56
+ return this.getComponent("minecraft:riding")?.entityRidingOn !== void 0;
57
+ },
58
+ configurable: true
59
+ },
60
+ joinedAt: {
61
+ get: function() {
62
+ return this.getDynamicProperty("box@joinedAt");
63
+ },
64
+ configurable: true
65
+ },
66
+ equip: {
67
+ get: function() {
68
+ const com = this.getComponent("equippable");
69
+ return {
70
+ getHead: () => com?.getEquipment(EquipmentSlot.Head),
71
+ getChest: () => com?.getEquipment(EquipmentSlot.Chest),
72
+ getLegs: () => com?.getEquipment(EquipmentSlot.Legs),
73
+ getFeet: () => com?.getEquipment(EquipmentSlot.Feet),
74
+ getMainHand: () => com?.getEquipment(EquipmentSlot.Mainhand),
75
+ getOffHand: () => com?.getEquipment(EquipmentSlot.Offhand)
76
+ };
77
+ },
78
+ configurable: true
79
+ }
80
+ });
81
+ world.afterEvents.playerSpawn.subscribe((ev) => {
82
+ const { player, initialSpawn } = ev;
83
+ if (initialSpawn) player.setDynamicProperty("box@joinedAt", Date.now());
84
+ });
85
+ //#endregion
86
+ //#region package/define/block.ts
87
+ Object.defineProperties(Block.prototype, {
88
+ isPlayer: {
89
+ value: function() {
90
+ return this instanceof Player;
91
+ },
92
+ configurable: true
93
+ },
94
+ isEntity: {
95
+ value: function() {
96
+ return this instanceof Entity;
97
+ },
98
+ configurable: true
99
+ },
100
+ isBlock: {
101
+ value: function() {
102
+ return this instanceof Block;
103
+ },
104
+ configurable: true
105
+ }
106
+ });
107
+ //#endregion
108
+ //#region package/define/item.ts
109
+ Object.defineProperties(ItemStack.prototype, { enchantment: {
110
+ get: function() {
111
+ const com = this.getComponent("enchantable");
112
+ const getEnchantmentType = (enchantmentType) => {
113
+ if (typeof enchantmentType === "string") {
114
+ if (EnchantmentTypes.get(enchantmentType) === void 0) throw new Error(`Invalid enchantment type: ${enchantmentType}`);
115
+ enchantmentType = EnchantmentTypes.get(enchantmentType);
116
+ }
117
+ return enchantmentType;
118
+ };
119
+ return {
120
+ getEnchant: function(enchantmentType) {
121
+ return com?.getEnchantment(enchantmentType);
122
+ },
123
+ getAllEnchants: function() {
124
+ return com?.getEnchantments();
125
+ },
126
+ addEnchant: function(enchantmentType, level) {
127
+ com?.addEnchantment({
128
+ type: getEnchantmentType(enchantmentType),
129
+ level
130
+ });
131
+ },
132
+ canAddEnchant: function(enchantmentType, level) {
133
+ return com?.canAddEnchantment({
134
+ type: getEnchantmentType(enchantmentType),
135
+ level
136
+ });
137
+ },
138
+ removeEnchant: function(enchantmentType) {
139
+ com?.removeEnchantment(getEnchantmentType(enchantmentType));
140
+ },
141
+ removeAllEnchants: function() {
142
+ com?.removeAllEnchantments();
143
+ },
144
+ hasEnchant: function(enchantmentType) {
145
+ return com?.hasEnchantment(getEnchantmentType(enchantmentType));
146
+ }
147
+ };
148
+ },
149
+ configurable: true
150
+ } });
151
+ //#endregion
152
+ //#region package/form/action.ts
153
+ var ActionFormBox = class ActionFormBox {
154
+ static {
155
+ this.config = {
156
+ back: {
157
+ text: "Back",
158
+ iconPath: "textures/ui/arrowLeft.png"
159
+ },
160
+ close: {
161
+ enabled: true,
162
+ text: "Close",
163
+ iconPath: "textures/ui/redX1.png"
164
+ }
165
+ };
166
+ }
167
+ constructor(title) {
168
+ this.callbacks = [];
169
+ this.form = new ActionFormData();
170
+ if (title) this.form.title(title);
171
+ }
172
+ title(text) {
173
+ this.form.title(text);
174
+ return this;
175
+ }
176
+ body(text) {
177
+ this.form.body(text);
178
+ return this;
179
+ }
180
+ button(text, value1, value2) {
181
+ let iconPath;
182
+ let callback;
183
+ if (typeof value1 === "string") [iconPath, callback] = [value1, value2];
184
+ else callback = value1;
185
+ this.form.button(text, iconPath);
186
+ if (callback) this.callbacks.push(callback);
187
+ return this;
188
+ }
189
+ back(callback) {
190
+ this.backCallback = callback;
191
+ return this;
192
+ }
193
+ cancel(callback) {
194
+ this.cancelledCallback = callback;
195
+ return this;
196
+ }
197
+ label(text) {
198
+ this.form.label(text);
199
+ return this;
200
+ }
201
+ divider() {
202
+ this.form.divider();
203
+ return this;
204
+ }
205
+ async show(player) {
206
+ if (this.backCallback) this.form.button(ActionFormBox.config.back.text, ActionFormBox.config.back.iconPath);
207
+ if (ActionFormBox.config.close.enabled) this.form.button(ActionFormBox.config.close.text, ActionFormBox.config.close.iconPath);
208
+ const response = await this.form.show(player);
209
+ if (response.canceled) {
210
+ if (this.cancelledCallback) this.cancelledCallback(response.cancelationReason);
211
+ return response;
212
+ }
213
+ if (response.selection === void 0) throw new Error("response.selection is undefined");
214
+ if (response.selection === this.callbacks.length) {
215
+ if (this.backCallback) this.backCallback(player, response.selection);
216
+ return response;
217
+ }
218
+ const callback = this.callbacks[response.selection];
219
+ if (callback) callback(player, response.selection);
220
+ return response;
221
+ }
222
+ };
223
+ //#endregion
224
+ //#region package/form/message.ts
225
+ var MessageFormBox = class {
226
+ constructor(title) {
227
+ this.form = new MessageFormData();
228
+ if (title !== void 0) this.form.title(title);
229
+ }
230
+ title(titleText) {
231
+ this.form.title(titleText);
232
+ return this;
233
+ }
234
+ body(bodyText) {
235
+ this.form.body(bodyText);
236
+ return this;
237
+ }
238
+ upperButton(text, callback) {
239
+ this.form.button1(text);
240
+ this.lowerCallback = callback;
241
+ return this;
242
+ }
243
+ lowerButton(text, callback) {
244
+ this.form.button2(text);
245
+ this.upperCallback = callback;
246
+ return this;
247
+ }
248
+ cancel(callback) {
249
+ this.cancelCallback = callback;
250
+ return this;
251
+ }
252
+ async show(player) {
253
+ const response = await this.form.show(player);
254
+ if (response.canceled) {
255
+ if (this.cancelCallback) this.cancelCallback(player, response.cancelationReason);
256
+ return response;
257
+ }
258
+ if (response.selection === 1) {
259
+ if (this.upperCallback) this.upperCallback(player);
260
+ } else if (response.selection === 0) {
261
+ if (this.lowerCallback) this.lowerCallback(player);
262
+ }
263
+ return response;
264
+ }
265
+ };
266
+ //#endregion
267
+ //#region package/form/modal.ts
268
+ var ModalFormBox = class {
269
+ constructor() {
270
+ this.form = new ModalFormData();
271
+ this.callbacks = [];
272
+ }
273
+ cancel(callback) {
274
+ this.cancelCallback = callback;
275
+ return this;
276
+ }
277
+ divider() {
278
+ this.form.divider();
279
+ this.callbacks.push(() => {});
280
+ return this;
281
+ }
282
+ dropdown({ label, options, defaultValueIndex, tooltip, callback }) {
283
+ this.form.dropdown(label, options, {
284
+ defaultValueIndex,
285
+ tooltip
286
+ });
287
+ this.callbacks.push(callback ?? (() => {}));
288
+ return this;
289
+ }
290
+ header(text) {
291
+ this.form.header(text);
292
+ this.callbacks.push(() => {});
293
+ return this;
294
+ }
295
+ label(text) {
296
+ this.form.label(text);
297
+ this.callbacks.push(() => {});
298
+ return this;
299
+ }
300
+ async show(player) {
301
+ const response = await this.form.show(player);
302
+ if (response.canceled) {
303
+ if (this.cancelCallback) this.cancelCallback(player, response.cancelationReason);
304
+ return response;
305
+ }
306
+ for (const i in this.callbacks) if (response.formValues?.length) this.callbacks[i]({
307
+ player,
308
+ response: response.formValues[i],
309
+ responses: response.formValues
310
+ });
311
+ return response;
312
+ }
313
+ slider({ label, minimumValue, maximumValue, valueStep, defaultValue, tooltip, callback }) {
314
+ this.form.slider(label, minimumValue, maximumValue, {
315
+ valueStep,
316
+ defaultValue,
317
+ tooltip
318
+ });
319
+ this.callbacks.push(callback ?? (() => {}));
320
+ return this;
321
+ }
322
+ submitButton(submitButtonText) {
323
+ this.form.submitButton(submitButtonText);
324
+ return this;
325
+ }
326
+ textField({ label, placeholder, defaultValue, tooltip, callback }) {
327
+ this.form.textField(label, placeholder ?? "", {
328
+ defaultValue,
329
+ tooltip
330
+ });
331
+ this.callbacks.push(callback ?? (() => {}));
332
+ return this;
333
+ }
334
+ title(text) {
335
+ this.form.title(text);
336
+ return this;
337
+ }
338
+ toggle({ label, defaultValue, tooltip, callback }) {
339
+ this.form.toggle(label, {
340
+ defaultValue,
341
+ tooltip
342
+ });
343
+ this.callbacks.push(callback ?? (() => {}));
344
+ return this;
345
+ }
346
+ };
347
+ //#endregion
348
+ //#region package/utils/item.ts
349
+ let ItemStackUtils;
350
+ (function(_ItemStackUtils) {
351
+ function toJSON(item) {
352
+ const dynamicProperties = item.getDynamicPropertyIds().map((key) => {
353
+ return [key, item.getDynamicProperty(key)];
354
+ });
355
+ const enchantments = item.getComponent("enchantable")?.getEnchantments().map((enchantment) => {
356
+ return {
357
+ level: enchantment.level,
358
+ type: enchantment.type.id
359
+ };
360
+ });
361
+ return {
362
+ typeId: item.typeId,
363
+ amount: item.amount,
364
+ keepOnDeath: item.keepOnDeath,
365
+ lockMode: item.lockMode,
366
+ nameTag: item.nameTag,
367
+ dynamicProperties: Object.fromEntries(dynamicProperties),
368
+ canDestroy: item.getCanDestroy(),
369
+ canPlaceOn: item.getCanPlaceOn(),
370
+ lore: item.getLore(),
371
+ components: {
372
+ durability: { damage: item.getComponent("durability")?.damage },
373
+ dyeable: { color: item.getComponent("dyeable")?.color },
374
+ enchantable: { enchantments }
375
+ }
376
+ };
377
+ }
378
+ _ItemStackUtils.toJSON = toJSON;
379
+ function fromJSON(json) {
380
+ const item = new ItemStack(json.typeId, json.amount);
381
+ item.keepOnDeath = json.keepOnDeath ?? false;
382
+ item.lockMode = json.lockMode ?? ItemLockMode.none;
383
+ item.nameTag = json.nameTag;
384
+ for (const [key, value] of Object.entries(json.dynamicProperties ?? {})) item.setDynamicProperty(key, value);
385
+ item.setCanDestroy(json.canDestroy ?? []);
386
+ item.setCanPlaceOn(json.canPlaceOn ?? []);
387
+ item.setLore(json.lore ?? []);
388
+ if (json.components) {
389
+ if (json.components.durability) {
390
+ const com = item.getComponent("durability");
391
+ if (com) com.damage = json.components.durability.damage ?? 0;
392
+ }
393
+ if (json.components.dyeable) {
394
+ const com = item.getComponent("dyeable");
395
+ if (com) com.color = json.components.dyeable.color ?? com.defaultColor;
396
+ }
397
+ if (json.components.enchantable) {
398
+ const com = item.getComponent("enchantable");
399
+ if (com) for (const enchantment of json.components.enchantable.enchantments ?? []) {
400
+ const enchantmentType = EnchantmentTypes.get(enchantment.type);
401
+ if (!enchantmentType) throw new Error(`Invalid enchantment type: ${enchantment.type}`);
402
+ com.addEnchantment({
403
+ type: enchantmentType,
404
+ level: enchantment.level
405
+ });
406
+ }
407
+ }
408
+ }
409
+ return item;
410
+ }
411
+ _ItemStackUtils.fromJSON = fromJSON;
412
+ function minimizeJSON(json) {
413
+ json.components = Object.fromEntries(Object.entries(json.components ?? {}).filter(([key, value]) => {
414
+ if (key === "durability" && "damage" in value && (value.damage === 0 || value.damage === void 0)) return false;
415
+ if (key === "dyeable" && "color" in value && value.color === void 0) return false;
416
+ if (key === "enchantable" && "enchantments" in value && value.enchantments?.length === 0) return false;
417
+ return true;
418
+ }));
419
+ json = Object.fromEntries(Object.entries(json).filter(([key, value]) => {
420
+ if (key === "keepOnDeath" && value === false) return false;
421
+ if (key === "lockMode" && value === ItemLockMode.none) return false;
422
+ if (key === "nameTag" && value === void 0) return false;
423
+ if (key === "canDestroy" && value.length === 0) return false;
424
+ if (key === "canPlaceOn" && value.length === 0) return false;
425
+ if (key === "lore" && value.length === 0) return false;
426
+ if (key === "dynamicProperties") return Object.values(value).some((v) => v !== void 0 && v !== null);
427
+ if (key === "components") return Object.values(value).some((v) => v !== void 0 && v !== null && Object.values(v).filter(Boolean).length > 0);
428
+ return value !== void 0 && value !== null;
429
+ }));
430
+ return json;
431
+ }
432
+ _ItemStackUtils.minimizeJSON = minimizeJSON;
433
+ })(ItemStackUtils || (ItemStackUtils = {}));
434
+ //#endregion
435
+ //#region package/utils/scoreboard.ts
436
+ let ScoreboardUtils;
437
+ (function(_ScoreboardUtils) {
438
+ function addObjective(id, display) {
439
+ return world.scoreboard.addObjective(id, display);
440
+ }
441
+ _ScoreboardUtils.addObjective = addObjective;
442
+ function getObjective(id) {
443
+ const object = world.scoreboard.getObjective(id);
444
+ if (!object) return addObjective(id);
445
+ return object;
446
+ }
447
+ _ScoreboardUtils.getObjective = getObjective;
448
+ function deleteObjective(id) {
449
+ return world.scoreboard.removeObjective(id);
450
+ }
451
+ _ScoreboardUtils.deleteObjective = deleteObjective;
452
+ function getScore(target, objective) {
453
+ try {
454
+ return getObjective(objective).getScore(target);
455
+ } catch {
456
+ return;
457
+ }
458
+ }
459
+ _ScoreboardUtils.getScore = getScore;
460
+ function addScore(target, objective, value) {
461
+ return getObjective(objective).addScore(target, value);
462
+ }
463
+ _ScoreboardUtils.addScore = addScore;
464
+ function setScore(target, objective, value) {
465
+ return getObjective(objective).setScore(target, value);
466
+ }
467
+ _ScoreboardUtils.setScore = setScore;
468
+ function resetScore(target, objective) {
469
+ return getObjective(objective).removeParticipant(target);
470
+ }
471
+ _ScoreboardUtils.resetScore = resetScore;
472
+ })(ScoreboardUtils || (ScoreboardUtils = {}));
473
+ //#endregion
474
+ export { ActionFormBox, ItemStackUtils, MessageFormBox, ModalFormBox, ScoreboardUtils };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "script-box-mc",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/main.d.ts",
8
+ "default": "./dist/main.js"
9
+ }
10
+ },
11
+ "main": "./dist/main.js",
12
+ "types": "./dist/main.d.ts",
13
+ "prepublishOnly": "scriptup build --release && node .github/workflows/ensure-dts-export.js",
14
+ "repository": "https://github.com/Unknown-Creators-Team/ScriptBoxMC",
15
+ "dependencies": {
16
+ "@minecraft/server": "2.6.0-beta.1.26.3-stable",
17
+ "@minecraft/server-ui": "2.1.0-beta.1.26.3-stable"
18
+ },
19
+ "devDependencies": {
20
+ "@bedrock-apis/env-types": "^1.0.0-beta.6",
21
+ "mc-chalk": "^1.0.2",
22
+ "@nano191225/scriptup": "^1.3.2",
23
+ "tsdown": "^0.21.2",
24
+ "typescript": "^5.9.3"
25
+ },
26
+ "keywords": [
27
+ "minecraft",
28
+ "minecraft-bedrock",
29
+ "minecraft-script-api",
30
+ "scriptapi"
31
+ ],
32
+ "files": [
33
+ "dist",
34
+ "LICENSE",
35
+ "README.md"
36
+ ],
37
+ "scripts": {
38
+ "build": "scriptup build --release",
39
+ "watch": "scriptup build --watch"
40
+ }
41
+ }