@block_factory/lib 0.0.3 → 0.0.4
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/_module/BlockFactory.ts +18 -0
- package/_module/util/RawText.ts +75 -0
- package/_types/_module/BlockFactory.d.ts +16 -0
- package/_types/_module/BlockFactory.d.ts.map +1 -0
- package/_types/_module/sys/Threads.d.ts.map +1 -0
- package/_types/_module/util/Command.d.ts +92 -0
- package/_types/_module/util/Command.d.ts.map +1 -0
- package/{util → _types/_module/util}/Forms/Form.d.ts +12 -16
- package/_types/_module/util/Forms/Form.d.ts.map +1 -0
- package/_types/_module/util/Forms/FormAction.d.ts +73 -0
- package/_types/_module/util/Forms/FormAction.d.ts.map +1 -0
- package/{util → _types/_module/util}/Forms/FormMessage.d.ts +24 -30
- package/_types/_module/util/Forms/FormMessage.d.ts.map +1 -0
- package/{util → _types/_module/util}/Forms/FormModal.d.ts +66 -57
- package/_types/_module/util/Forms/FormModal.d.ts.map +1 -0
- package/_types/_module/util/Forms/FormRegistry.d.ts +12 -0
- package/_types/_module/util/Forms/FormRegistry.d.ts.map +1 -0
- package/{util → _types/_module/util}/Math.d.ts +8 -2
- package/_types/_module/util/Math.d.ts.map +1 -0
- package/_types/_module/util/RawText.d.ts +60 -0
- package/_types/_module/util/RawText.d.ts.map +1 -0
- package/{util → _types/_module/util}/Signal.d.ts +3 -5
- package/_types/_module/util/Signal.d.ts.map +1 -0
- package/_types/_module/util/System.d.ts.map +1 -0
- package/_types/_module/util/Vector.d.ts +212 -0
- package/_types/_module/util/Vector.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/Container.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/IEntity.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/IPlayer.d.ts.map +1 -0
- package/_types/index.d.ts +3 -0
- package/_types/index.d.ts.map +1 -0
- package/index.js +128 -380
- package/index.ts +2 -48
- package/package.json +7 -6
- package/tsconfig.types.json +2 -2
- package/index.d.ts +0 -47
- package/util/Command.d.ts +0 -23
- package/util/Forms/FormAction.d.ts +0 -41
- package/util/Forms/FormRegistry.d.ts +0 -26
- package/util/RawText.d.ts +0 -33
- package/util/RawText.ts +0 -76
- package/util/Vector.d.ts +0 -60
- /package/{sys → _module/sys}/Threads.ts +0 -0
- /package/{util → _module/util}/Command.ts +0 -0
- /package/{util → _module/util}/Forms/Form.ts +0 -0
- /package/{util → _module/util}/Forms/FormAction.ts +0 -0
- /package/{util → _module/util}/Forms/FormMessage.ts +0 -0
- /package/{util → _module/util}/Forms/FormModal.ts +0 -0
- /package/{util → _module/util}/Forms/FormRegistry.ts +0 -0
- /package/{util → _module/util}/Math.ts +0 -0
- /package/{util → _module/util}/Signal.ts +0 -0
- /package/{util → _module/util}/System.ts +0 -0
- /package/{util → _module/util}/Vector.ts +0 -0
- /package/{util → _module/util}/Wrapper/Container.ts +0 -0
- /package/{util → _module/util}/Wrapper/IEntity.ts +0 -0
- /package/{util → _module/util}/Wrapper/IPlayer.ts +0 -0
- /package/{sys → _types/_module/sys}/Threads.d.ts +0 -0
- /package/{util → _types/_module/util}/System.d.ts +0 -0
- /package/{util → _types/_module/util}/Wrapper/Container.d.ts +0 -0
- /package/{util → _types/_module/util}/Wrapper/IEntity.d.ts +0 -0
- /package/{util → _types/_module/util}/Wrapper/IPlayer.d.ts +0 -0
package/index.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// _module/BlockFactory.ts
|
|
8
|
+
var BlockFactory_exports = {};
|
|
9
|
+
__export(BlockFactory_exports, {
|
|
10
|
+
Command: () => Command,
|
|
11
|
+
ContainerWrapper: () => ContainerWrapper,
|
|
12
|
+
IEntityWrapper: () => IEntityWrapper,
|
|
13
|
+
IForm: () => IForm,
|
|
14
|
+
IPlayerWrapper: () => IPlayerWrapper,
|
|
15
|
+
MathUtils: () => MathUtils,
|
|
16
|
+
RawText: () => RawText,
|
|
17
|
+
RegisterForm: () => RegisterForm,
|
|
18
|
+
Signal: () => Signal,
|
|
19
|
+
System: () => System,
|
|
20
|
+
Vec2: () => Vec2,
|
|
21
|
+
Vec3: () => Vec3,
|
|
22
|
+
_THREAD_: () => _THREAD_
|
|
23
|
+
});
|
|
4
24
|
|
|
5
|
-
// util/Math.ts
|
|
25
|
+
// _module/util/Math.ts
|
|
6
26
|
var MathUtils;
|
|
7
27
|
((MathUtils2) => {
|
|
8
28
|
function clamp(value, min, max) {
|
|
@@ -72,10 +92,10 @@ var MathUtils;
|
|
|
72
92
|
;
|
|
73
93
|
})(MathUtils || (MathUtils = {}));
|
|
74
94
|
|
|
75
|
-
// util/Signal.ts
|
|
95
|
+
// _module/util/Signal.ts
|
|
76
96
|
var Signal = class {
|
|
77
97
|
constructor() {
|
|
78
|
-
|
|
98
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
79
99
|
}
|
|
80
100
|
get count() {
|
|
81
101
|
return this.listeners.size;
|
|
@@ -99,7 +119,7 @@ var Signal = class {
|
|
|
99
119
|
}
|
|
100
120
|
};
|
|
101
121
|
|
|
102
|
-
// util/Vector.ts
|
|
122
|
+
// _module/util/Vector.ts
|
|
103
123
|
var _Vec2 = class _Vec2 {
|
|
104
124
|
/**
|
|
105
125
|
* Creates a new Vec2.
|
|
@@ -227,15 +247,15 @@ var _Vec2 = class _Vec2 {
|
|
|
227
247
|
}
|
|
228
248
|
};
|
|
229
249
|
/** Constant zero vector (0, 0) */
|
|
230
|
-
|
|
250
|
+
_Vec2.ZERO = new _Vec2(0, 0);
|
|
231
251
|
/** Up direction (0, 1) */
|
|
232
|
-
|
|
252
|
+
_Vec2.UP = new _Vec2(0, 1);
|
|
233
253
|
/** Down direction (0, -1) */
|
|
234
|
-
|
|
254
|
+
_Vec2.DOWN = new _Vec2(0, -1);
|
|
235
255
|
/** Left direction (-1, 0) */
|
|
236
|
-
|
|
256
|
+
_Vec2.LEFT = new _Vec2(-1, 0);
|
|
237
257
|
/** Right direction (1, 0) */
|
|
238
|
-
|
|
258
|
+
_Vec2.RIGHT = new _Vec2(1, 0);
|
|
239
259
|
var Vec2 = _Vec2;
|
|
240
260
|
var _Vec3 = class _Vec3 {
|
|
241
261
|
/**
|
|
@@ -396,89 +416,104 @@ var _Vec3 = class _Vec3 {
|
|
|
396
416
|
}
|
|
397
417
|
};
|
|
398
418
|
/** Constant zero vector (0, 0, 0) */
|
|
399
|
-
|
|
419
|
+
_Vec3.ZERO = new _Vec3(0, 0, 0);
|
|
400
420
|
/** Up direction (0, 1, 0) */
|
|
401
|
-
|
|
421
|
+
_Vec3.UP = new _Vec3(0, 1, 0);
|
|
402
422
|
/** Down direction (0, -1, 0) */
|
|
403
|
-
|
|
423
|
+
_Vec3.DOWN = new _Vec3(0, -1, 0);
|
|
404
424
|
/** Left direction (-1, 0, 0) */
|
|
405
|
-
|
|
425
|
+
_Vec3.LEFT = new _Vec3(-1, 0, 0);
|
|
406
426
|
/** Right direction (1, 0, 0) */
|
|
407
|
-
|
|
427
|
+
_Vec3.RIGHT = new _Vec3(1, 0, 0);
|
|
408
428
|
/** Forward direction (0, 0, 1) */
|
|
409
|
-
|
|
429
|
+
_Vec3.FORWARD = new _Vec3(0, 0, 1);
|
|
410
430
|
/** Backward direction (0, 0, -1) */
|
|
411
|
-
|
|
431
|
+
_Vec3.BACK = new _Vec3(0, 0, -1);
|
|
412
432
|
/** West direction (-1, 0, 0) */
|
|
413
|
-
|
|
433
|
+
_Vec3.WEST = new _Vec3(-1, 0, 0);
|
|
414
434
|
/** East direction (1, 0, 0) */
|
|
415
|
-
|
|
435
|
+
_Vec3.EAST = new _Vec3(1, 0, 0);
|
|
416
436
|
/** North direction (0, 0, 1) */
|
|
417
|
-
|
|
437
|
+
_Vec3.NORTH = new _Vec3(0, 0, 1);
|
|
418
438
|
/** South direction (0, 0, -1) */
|
|
419
|
-
|
|
439
|
+
_Vec3.SOUTH = new _Vec3(0, 0, -1);
|
|
420
440
|
var Vec3 = _Vec3;
|
|
421
441
|
|
|
422
|
-
// util/RawText.ts
|
|
423
|
-
var RawText
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
442
|
+
// _module/util/RawText.ts
|
|
443
|
+
var RawText = class {
|
|
444
|
+
/**
|
|
445
|
+
* Creates a simple text component.
|
|
446
|
+
* @param value - The text value.
|
|
447
|
+
* @returns Text component object.
|
|
448
|
+
*/
|
|
449
|
+
static text(value) {
|
|
450
|
+
return { text: value };
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Creates a translation component with optional 'with' parameters.
|
|
454
|
+
* @param key - The translation key.
|
|
455
|
+
* @param params - The optional parameters for translation.
|
|
456
|
+
* @returns Translation component object.
|
|
457
|
+
*/
|
|
458
|
+
static translate(key, ...params) {
|
|
459
|
+
return {
|
|
460
|
+
translate: key,
|
|
461
|
+
with: params.length ? params : void 0
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Creates a score component.
|
|
466
|
+
* @param name - The entity's name whose score is being displayed.
|
|
467
|
+
* @param objective - The name of the score objective.
|
|
468
|
+
* @returns Score component object.
|
|
469
|
+
*/
|
|
470
|
+
static score(name, objective) {
|
|
471
|
+
return { score: { name, objective } };
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Wraps various text components into a rawtext structure.
|
|
475
|
+
* @param rawText - The raw text components.
|
|
476
|
+
* @returns Raw text object.
|
|
477
|
+
*/
|
|
478
|
+
static message(...rawText) {
|
|
479
|
+
return { rawtext: rawText };
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Common formatting and color codes.
|
|
484
|
+
*/
|
|
485
|
+
RawText.FORMAT = {
|
|
486
|
+
DarkRed: "\xA74",
|
|
487
|
+
Red: "\xA7c",
|
|
488
|
+
Gold: "\xA76",
|
|
489
|
+
Yellow: "\xA7e",
|
|
490
|
+
Green: "\xA72",
|
|
491
|
+
Lime: "\xA7a",
|
|
492
|
+
Aqua: "\xA7b",
|
|
493
|
+
Cyan: "\xA73",
|
|
494
|
+
DarkBlue: "\xA71",
|
|
495
|
+
Blue: "\xA79",
|
|
496
|
+
Magenta: "\xA7d",
|
|
497
|
+
Purple: "\xA75",
|
|
498
|
+
White: "\xA7f",
|
|
499
|
+
Gray: "\xA77",
|
|
500
|
+
DarkGray: "\xA78",
|
|
501
|
+
Black: "\xA70",
|
|
502
|
+
Obfuscated: "\xA7k",
|
|
503
|
+
Bold: "\xA7l",
|
|
504
|
+
StrikeThrough: "\xA7m",
|
|
505
|
+
Italic: "\xA7o",
|
|
506
|
+
Reset: "\xA7r",
|
|
507
|
+
NewLine: "\n"
|
|
508
|
+
};
|
|
466
509
|
|
|
467
|
-
// util/Command.ts
|
|
510
|
+
// _module/util/Command.ts
|
|
468
511
|
import {
|
|
469
512
|
system
|
|
470
513
|
} from "@minecraft/server";
|
|
471
514
|
var Command;
|
|
472
515
|
((Command2) => {
|
|
473
516
|
class ICustomCommand {
|
|
474
|
-
constructor() {
|
|
475
|
-
/** Whether cheats must be enabled */
|
|
476
|
-
__publicField(this, "cheatsRequired");
|
|
477
|
-
/** Required command parameters */
|
|
478
|
-
__publicField(this, "mandatoryParameters");
|
|
479
|
-
/** Optional command parameters */
|
|
480
|
-
__publicField(this, "optionalParameters");
|
|
481
|
-
}
|
|
482
517
|
}
|
|
483
518
|
Command2.ICustomCommand = ICustomCommand;
|
|
484
519
|
;
|
|
@@ -500,7 +535,7 @@ system.beforeEvents.startup.subscribe(
|
|
|
500
535
|
}
|
|
501
536
|
);
|
|
502
537
|
|
|
503
|
-
// util/System.ts
|
|
538
|
+
// _module/util/System.ts
|
|
504
539
|
var System;
|
|
505
540
|
((System2) => {
|
|
506
541
|
System2.ProxyConstructor = ((_instance, source) => {
|
|
@@ -525,7 +560,7 @@ var System;
|
|
|
525
560
|
});
|
|
526
561
|
})(System || (System = {}));
|
|
527
562
|
|
|
528
|
-
// util/Forms/Form.ts
|
|
563
|
+
// _module/util/Forms/Form.ts
|
|
529
564
|
import { world } from "@minecraft/server";
|
|
530
565
|
import { uiManager } from "@minecraft/server-ui";
|
|
531
566
|
var _IForm = class _IForm {
|
|
@@ -546,271 +581,14 @@ var _IForm = class _IForm {
|
|
|
546
581
|
else _IForm.occupiedPlayers.delete(player.id);
|
|
547
582
|
}
|
|
548
583
|
};
|
|
549
|
-
|
|
550
|
-
|
|
584
|
+
_IForm.occupiedPlayers = /* @__PURE__ */ new Set();
|
|
585
|
+
_IForm.returnText = "Back";
|
|
551
586
|
var IForm = _IForm;
|
|
552
587
|
|
|
553
|
-
// util/Forms/FormAction.ts
|
|
588
|
+
// _module/util/Forms/FormAction.ts
|
|
554
589
|
import { ActionFormData } from "@minecraft/server-ui";
|
|
555
|
-
var RETURN_ID = "d7213196-4cb6-4199-a40b-22fbf2d944ef";
|
|
556
|
-
var IActionFormData = class extends IForm {
|
|
557
|
-
constructor() {
|
|
558
|
-
super(...arguments);
|
|
559
|
-
__publicField(this, "form", new ActionFormData());
|
|
560
|
-
__publicField(this, "_buttons", /* @__PURE__ */ new Map());
|
|
561
|
-
__publicField(this, "_nextButtonIndex", 0);
|
|
562
|
-
__publicField(this, "_id", "untitled");
|
|
563
|
-
}
|
|
564
|
-
title(titleText) {
|
|
565
|
-
this.form.title(titleText);
|
|
566
|
-
this._id = typeof titleText === "string" ? titleText : JSON.stringify(titleText);
|
|
567
|
-
return this;
|
|
568
|
-
}
|
|
569
|
-
body(bodyText) {
|
|
570
|
-
this.form.body(bodyText);
|
|
571
|
-
return this;
|
|
572
|
-
}
|
|
573
|
-
divider() {
|
|
574
|
-
this.form.divider();
|
|
575
|
-
return this;
|
|
576
|
-
}
|
|
577
|
-
header(text) {
|
|
578
|
-
this.form.header(text);
|
|
579
|
-
return this;
|
|
580
|
-
}
|
|
581
|
-
label(text) {
|
|
582
|
-
this.form.label(text);
|
|
583
|
-
return this;
|
|
584
|
-
}
|
|
585
|
-
button(text, options = {}) {
|
|
586
|
-
if (options.iconPath) this.form.button(text, options.iconPath);
|
|
587
|
-
else this.form.button(text);
|
|
588
|
-
const id = options.id ?? this._nextButtonIndex;
|
|
589
|
-
const allowReturn = options.allowReturn ?? true;
|
|
590
|
-
this._buttons.set(this._nextButtonIndex, {
|
|
591
|
-
id,
|
|
592
|
-
subForm: options.subForm,
|
|
593
|
-
allowReturn
|
|
594
|
-
});
|
|
595
|
-
this._nextButtonIndex++;
|
|
596
|
-
return this;
|
|
597
|
-
}
|
|
598
|
-
async show(player) {
|
|
599
|
-
if (IForm.isOccupied(player)) {
|
|
600
|
-
throw new Error(`Player ${player.id} is already occupied by form: ${this._id}`);
|
|
601
|
-
}
|
|
602
|
-
this.setOccupied(player, true);
|
|
603
|
-
try {
|
|
604
|
-
return await this._showInternal(player, []);
|
|
605
|
-
} finally {
|
|
606
|
-
this.setOccupied(player, false);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
async _showChained(player, returnStack) {
|
|
610
|
-
return await this._showInternal(player, returnStack);
|
|
611
|
-
}
|
|
612
|
-
_wrapResponse(response, id) {
|
|
613
|
-
return {
|
|
614
|
-
canceled: response.canceled,
|
|
615
|
-
cancelationReason: response.cancelationReason,
|
|
616
|
-
selection: response.selection,
|
|
617
|
-
id
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
async _showInternal(player, returnStack) {
|
|
621
|
-
this.form = new ActionFormData();
|
|
622
|
-
this._buttons.clear();
|
|
623
|
-
this._nextButtonIndex = 0;
|
|
624
|
-
this.build(player);
|
|
625
|
-
if (returnStack.length > 0) {
|
|
626
|
-
this.form.button(IForm.returnText);
|
|
627
|
-
this._buttons.set(this._nextButtonIndex, {
|
|
628
|
-
id: RETURN_ID,
|
|
629
|
-
subForm: returnStack[returnStack.length - 1],
|
|
630
|
-
allowReturn: true
|
|
631
|
-
});
|
|
632
|
-
this._nextButtonIndex++;
|
|
633
|
-
}
|
|
634
|
-
const response = await this.form.show(player);
|
|
635
|
-
if (response.canceled) {
|
|
636
|
-
const wrapped2 = this._wrapResponse(response, void 0);
|
|
637
|
-
this.onCancel?.(player, wrapped2);
|
|
638
|
-
return wrapped2;
|
|
639
|
-
}
|
|
640
|
-
const meta = response.selection !== void 0 ? this._buttons.get(response.selection) : void 0;
|
|
641
|
-
if (meta?.id === RETURN_ID && meta.subForm) {
|
|
642
|
-
const prevCtor = returnStack[returnStack.length - 1];
|
|
643
|
-
const newStack = returnStack.slice(0, -1);
|
|
644
|
-
const prev = new prevCtor();
|
|
645
|
-
return await prev._showChained(player, newStack);
|
|
646
|
-
}
|
|
647
|
-
const wrapped = this._wrapResponse(response, meta?.id);
|
|
648
|
-
this.onSubmit(player, wrapped);
|
|
649
|
-
if (meta?.subForm) {
|
|
650
|
-
const next = new meta.subForm();
|
|
651
|
-
const allowReturn = meta.allowReturn ?? true;
|
|
652
|
-
const nextStack = allowReturn ? [...returnStack, this.constructor] : [...returnStack];
|
|
653
|
-
return await next._showChained(player, nextStack);
|
|
654
|
-
}
|
|
655
|
-
return wrapped;
|
|
656
|
-
}
|
|
657
|
-
};
|
|
658
590
|
|
|
659
|
-
// util/Forms/
|
|
660
|
-
import {
|
|
661
|
-
ModalFormData
|
|
662
|
-
} from "@minecraft/server-ui";
|
|
663
|
-
var IModalFormData = class extends IForm {
|
|
664
|
-
constructor() {
|
|
665
|
-
super(...arguments);
|
|
666
|
-
__publicField(this, "form", new ModalFormData());
|
|
667
|
-
__publicField(this, "_id", "untitled");
|
|
668
|
-
__publicField(this, "_widgetMeta", []);
|
|
669
|
-
}
|
|
670
|
-
title(titleText) {
|
|
671
|
-
this.form.title(titleText);
|
|
672
|
-
this._id = typeof titleText === "string" ? titleText : JSON.stringify(titleText);
|
|
673
|
-
return this;
|
|
674
|
-
}
|
|
675
|
-
divider() {
|
|
676
|
-
this.form.divider();
|
|
677
|
-
return this;
|
|
678
|
-
}
|
|
679
|
-
header(text) {
|
|
680
|
-
this.form.header(text);
|
|
681
|
-
return this;
|
|
682
|
-
}
|
|
683
|
-
label(text) {
|
|
684
|
-
this.form.label(text);
|
|
685
|
-
return this;
|
|
686
|
-
}
|
|
687
|
-
textField(label, options) {
|
|
688
|
-
const opts = { defaultValue: options.defaultValue };
|
|
689
|
-
this.form.textField(label, options.placeholder, opts);
|
|
690
|
-
this._widgetMeta.push({ type: "textField", id: options.id });
|
|
691
|
-
return this;
|
|
692
|
-
}
|
|
693
|
-
dropdown(label, options) {
|
|
694
|
-
const opts = { defaultValueIndex: options.defaultValueIndex };
|
|
695
|
-
this.form.dropdown(label, options.choices, opts);
|
|
696
|
-
this._widgetMeta.push({ type: "dropdown", id: options.id });
|
|
697
|
-
return this;
|
|
698
|
-
}
|
|
699
|
-
slider(label, options) {
|
|
700
|
-
const opts = {
|
|
701
|
-
defaultValue: options.defaultValue,
|
|
702
|
-
valueStep: options.step
|
|
703
|
-
};
|
|
704
|
-
this.form.slider(label, options.min, options.max, opts);
|
|
705
|
-
this._widgetMeta.push({ type: "slider", id: options.id });
|
|
706
|
-
return this;
|
|
707
|
-
}
|
|
708
|
-
toggle(label, options) {
|
|
709
|
-
const opts = { defaultValue: options.defaultValue };
|
|
710
|
-
this.form.toggle(label, opts);
|
|
711
|
-
this._widgetMeta.push({ type: "toggle", id: options.id });
|
|
712
|
-
return this;
|
|
713
|
-
}
|
|
714
|
-
async show(player) {
|
|
715
|
-
if (IForm.isOccupied(player)) {
|
|
716
|
-
throw new Error(`Player ${player.id} is already occupied by form: ${this._id}`);
|
|
717
|
-
}
|
|
718
|
-
this.setOccupied(player, true);
|
|
719
|
-
try {
|
|
720
|
-
return await this._showInternal(player);
|
|
721
|
-
} finally {
|
|
722
|
-
this.setOccupied(player, false);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
_wrapResponse(res, values) {
|
|
726
|
-
return {
|
|
727
|
-
canceled: res.canceled,
|
|
728
|
-
cancelationReason: res.cancelationReason,
|
|
729
|
-
formValues: res.formValues,
|
|
730
|
-
widget: values
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
_mapValues(formValues) {
|
|
734
|
-
if (!formValues) return void 0;
|
|
735
|
-
const out = /* @__PURE__ */ new Map();
|
|
736
|
-
for (let i = 0; i < formValues.length; i++) {
|
|
737
|
-
const meta = this._widgetMeta[i];
|
|
738
|
-
if (!meta) continue;
|
|
739
|
-
out.set(meta.id, formValues[i]);
|
|
740
|
-
}
|
|
741
|
-
return out;
|
|
742
|
-
}
|
|
743
|
-
async _showInternal(player) {
|
|
744
|
-
this.form = new ModalFormData();
|
|
745
|
-
this._widgetMeta = [];
|
|
746
|
-
this.build(player);
|
|
747
|
-
const res = await this.form.show(player);
|
|
748
|
-
if (res.canceled) {
|
|
749
|
-
const wrapped2 = this._wrapResponse(res);
|
|
750
|
-
this.onCancel?.(player, wrapped2);
|
|
751
|
-
return wrapped2;
|
|
752
|
-
}
|
|
753
|
-
const values = this._mapValues(res.formValues);
|
|
754
|
-
const wrapped = this._wrapResponse(res, values);
|
|
755
|
-
this.onSubmit(player, wrapped);
|
|
756
|
-
return wrapped;
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
// util/Forms/FormMessage.ts
|
|
761
|
-
import {
|
|
762
|
-
MessageFormData
|
|
763
|
-
} from "@minecraft/server-ui";
|
|
764
|
-
var IMessageFormData = class extends IForm {
|
|
765
|
-
constructor() {
|
|
766
|
-
super(...arguments);
|
|
767
|
-
__publicField(this, "form", new MessageFormData());
|
|
768
|
-
__publicField(this, "_id", "untitled");
|
|
769
|
-
}
|
|
770
|
-
title(titleText) {
|
|
771
|
-
this.form.title(titleText);
|
|
772
|
-
this._id = typeof titleText === "string" ? titleText : JSON.stringify(titleText);
|
|
773
|
-
return this;
|
|
774
|
-
}
|
|
775
|
-
body(bodyText) {
|
|
776
|
-
this.form.body(bodyText);
|
|
777
|
-
return this;
|
|
778
|
-
}
|
|
779
|
-
button0(text, id = 0) {
|
|
780
|
-
this.form.button1(text);
|
|
781
|
-
return this;
|
|
782
|
-
}
|
|
783
|
-
button1(text, id = 1) {
|
|
784
|
-
this.form.button2(text);
|
|
785
|
-
return this;
|
|
786
|
-
}
|
|
787
|
-
async show(player) {
|
|
788
|
-
if (IForm.isOccupied(player)) {
|
|
789
|
-
throw new Error(
|
|
790
|
-
`Player ${player.id} is already occupied by form: ${this._id}`
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
this.setOccupied(player, true);
|
|
794
|
-
try {
|
|
795
|
-
return await this._showInternal(player);
|
|
796
|
-
} finally {
|
|
797
|
-
this.setOccupied(player, false);
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
async _showInternal(player) {
|
|
801
|
-
this.form = new MessageFormData();
|
|
802
|
-
this.build(player);
|
|
803
|
-
const res = await this.form.show(player);
|
|
804
|
-
if (res.canceled || res.selection === void 0) {
|
|
805
|
-
this.onCancel?.(player, res);
|
|
806
|
-
return res;
|
|
807
|
-
}
|
|
808
|
-
this.onSubmit(player, res);
|
|
809
|
-
return res;
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
|
|
813
|
-
// util/Forms/FormRegistry.ts
|
|
591
|
+
// _module/util/Forms/FormRegistry.ts
|
|
814
592
|
import { Player as Player2, world as world2 } from "@minecraft/server";
|
|
815
593
|
var registeredForms = [];
|
|
816
594
|
function RegisterForm(itemId) {
|
|
@@ -836,10 +614,9 @@ world2.afterEvents.itemUse.subscribe((event) => {
|
|
|
836
614
|
});
|
|
837
615
|
});
|
|
838
616
|
|
|
839
|
-
// util/Wrapper/Container.ts
|
|
617
|
+
// _module/util/Wrapper/Container.ts
|
|
840
618
|
var ContainerWrapper = class _ContainerWrapper {
|
|
841
619
|
constructor(source) {
|
|
842
|
-
__publicField(this, "source");
|
|
843
620
|
this.source = source;
|
|
844
621
|
return System.ProxyConstructor(this, source);
|
|
845
622
|
}
|
|
@@ -860,13 +637,12 @@ var ContainerWrapper = class _ContainerWrapper {
|
|
|
860
637
|
}
|
|
861
638
|
};
|
|
862
639
|
|
|
863
|
-
// util/Wrapper/IEntity.ts
|
|
640
|
+
// _module/util/Wrapper/IEntity.ts
|
|
864
641
|
import { EntityInventoryComponent } from "@minecraft/server";
|
|
865
642
|
var IEntityWrapper = class _IEntityWrapper {
|
|
866
643
|
constructor(source) {
|
|
867
|
-
__publicField(this, "source");
|
|
868
644
|
//======================== Interal ========================
|
|
869
|
-
|
|
645
|
+
this.isAlive = false;
|
|
870
646
|
this.source = source;
|
|
871
647
|
return System.ProxyConstructor(this, source);
|
|
872
648
|
}
|
|
@@ -883,13 +659,12 @@ var IEntityWrapper = class _IEntityWrapper {
|
|
|
883
659
|
}
|
|
884
660
|
};
|
|
885
661
|
|
|
886
|
-
// util/Wrapper/IPlayer.ts
|
|
662
|
+
// _module/util/Wrapper/IPlayer.ts
|
|
887
663
|
import { EntityInventoryComponent as EntityInventoryComponent2 } from "@minecraft/server";
|
|
888
664
|
var IPlayerWrapper = class _IPlayerWrapper {
|
|
889
665
|
constructor(source) {
|
|
890
|
-
__publicField(this, "source");
|
|
891
666
|
//======================== Interal ========================
|
|
892
|
-
|
|
667
|
+
this.isAlive = false;
|
|
893
668
|
this.source = source;
|
|
894
669
|
return System.ProxyConstructor(this, source);
|
|
895
670
|
}
|
|
@@ -907,17 +682,15 @@ var IPlayerWrapper = class _IPlayerWrapper {
|
|
|
907
682
|
}
|
|
908
683
|
};
|
|
909
684
|
|
|
910
|
-
// sys/Threads.ts
|
|
685
|
+
// _module/sys/Threads.ts
|
|
911
686
|
import { system as system2, TicksPerSecond } from "@minecraft/server";
|
|
912
687
|
var Threads = class _Threads {
|
|
913
688
|
constructor() {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
__publicField(this, "_LATE_ID");
|
|
920
|
-
__publicField(this, "_delta", this.createDeltaTimer());
|
|
689
|
+
this.MAIN = new Signal();
|
|
690
|
+
this.LATE = new Signal();
|
|
691
|
+
this.MAIN_INTERVAL_RATE = 0;
|
|
692
|
+
this.LATE_INTERVAL_RATE = TicksPerSecond;
|
|
693
|
+
this._delta = this.createDeltaTimer();
|
|
921
694
|
this._MAIN_ID = system2.runInterval(() => {
|
|
922
695
|
if (this.MAIN.count <= 0) return;
|
|
923
696
|
try {
|
|
@@ -950,37 +723,12 @@ var Threads = class _Threads {
|
|
|
950
723
|
}
|
|
951
724
|
};
|
|
952
725
|
var _THREAD_ = Threads.create();
|
|
953
|
-
_THREAD_.MAIN_INTERVAL_RATE = 10;
|
|
954
|
-
|
|
955
|
-
// index.ts
|
|
956
|
-
var BlockFactory;
|
|
957
|
-
((BlockFactory2) => {
|
|
958
|
-
MathUtils;
|
|
959
|
-
Signal;
|
|
960
|
-
Vec2;
|
|
961
|
-
Vec3;
|
|
962
|
-
RawText;
|
|
963
|
-
Command;
|
|
964
|
-
System;
|
|
965
|
-
IForm;
|
|
966
|
-
IActionFormData;
|
|
967
|
-
IModalFormData;
|
|
968
|
-
IMessageFormData;
|
|
969
|
-
RegisterForm;
|
|
970
|
-
ContainerWrapper;
|
|
971
|
-
IEntityWrapper;
|
|
972
|
-
IPlayerWrapper;
|
|
973
|
-
_THREAD_;
|
|
974
|
-
})(BlockFactory || (BlockFactory = {}));
|
|
975
726
|
export {
|
|
976
|
-
BlockFactory,
|
|
727
|
+
BlockFactory_exports as BlockFactory,
|
|
977
728
|
Command,
|
|
978
729
|
ContainerWrapper,
|
|
979
|
-
IActionFormData,
|
|
980
730
|
IEntityWrapper,
|
|
981
731
|
IForm,
|
|
982
|
-
IMessageFormData,
|
|
983
|
-
IModalFormData,
|
|
984
732
|
IPlayerWrapper,
|
|
985
733
|
MathUtils,
|
|
986
734
|
RawText,
|
package/index.ts
CHANGED
|
@@ -1,48 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Vec2, Vec3 } from "./util/Vector";
|
|
4
|
-
import { RawText } from "./util/RawText";
|
|
5
|
-
import { Command } from "./util/Command";
|
|
6
|
-
import { System } from "./util/System";
|
|
7
|
-
|
|
8
|
-
import { IForm, IFormValue } from "./util/Forms/Form";
|
|
9
|
-
import { ActionFormCtor, IButtonOptions, IActionFormResponse, IActionFormData } from "./util/Forms/FormAction";
|
|
10
|
-
import { IModalFormResponse, ITextFieldOptions, IDropdownOptions, ISliderOptions, IToggleOptions, IModalFormData } from "./util/Forms/FormModal";
|
|
11
|
-
import { IMessageFormData, IMessageFormResponse } from "./util/Forms/FormMessage";
|
|
12
|
-
import { IFormRegistration, RegisterForm } from "./util/Forms/FormRegistry";
|
|
13
|
-
|
|
14
|
-
import { Inventory, ContainerWrapper } from "./util/Wrapper/Container";
|
|
15
|
-
import { IEntity, IEntityWrapper } from "./util/Wrapper/IEntity";
|
|
16
|
-
import { IPlayer, IPlayerWrapper } from "./util/Wrapper/IPlayer";
|
|
17
|
-
|
|
18
|
-
import { _THREAD_ } from "./sys/Threads";
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
MathUtils, Signal, Vec2, Vec3, RawText, Command, System,
|
|
22
|
-
IForm, IFormValue,
|
|
23
|
-
ActionFormCtor, IButtonOptions, IActionFormResponse, IActionFormData,
|
|
24
|
-
IModalFormResponse, ITextFieldOptions, IDropdownOptions, ISliderOptions, IToggleOptions, IModalFormData,
|
|
25
|
-
IMessageFormData, IMessageFormResponse,
|
|
26
|
-
IFormRegistration, RegisterForm,
|
|
27
|
-
Inventory, ContainerWrapper, IEntity, IEntityWrapper, IPlayer, IPlayerWrapper,
|
|
28
|
-
_THREAD_
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export namespace BlockFactory {
|
|
32
|
-
MathUtils;
|
|
33
|
-
Signal;
|
|
34
|
-
Vec2;
|
|
35
|
-
Vec3;
|
|
36
|
-
RawText;
|
|
37
|
-
Command;
|
|
38
|
-
System;
|
|
39
|
-
IForm;
|
|
40
|
-
IActionFormData;
|
|
41
|
-
IModalFormData;
|
|
42
|
-
IMessageFormData;
|
|
43
|
-
RegisterForm;
|
|
44
|
-
ContainerWrapper;
|
|
45
|
-
IEntityWrapper;
|
|
46
|
-
IPlayerWrapper
|
|
47
|
-
_THREAD_;
|
|
48
|
-
}
|
|
1
|
+
export * from "./_module/BlockFactory";
|
|
2
|
+
export * as BlockFactory from "./_module/BlockFactory";
|