@block_factory/lib 0.0.3 → 0.0.5
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 +22 -0
- package/_module/Framework/EntityTasks.ts +203 -0
- package/_module/Framework/Threads.ts +72 -0
- package/_module/Framework/_INIT.ts +39 -0
- package/_module/Types.ts +10 -0
- package/_module/util/RawText.ts +75 -0
- package/{util → _module/util}/Signal.ts +4 -2
- package/{util → _module/util}/Wrapper/IEntity.ts +6 -5
- package/{util → _module/util}/Wrapper/IPlayer.ts +10 -4
- package/_types/_module/BlockFactory.d.ts +19 -0
- package/_types/_module/BlockFactory.d.ts.map +1 -0
- package/_types/_module/Framework/EntityTasks.d.ts +40 -0
- package/_types/_module/Framework/EntityTasks.d.ts.map +1 -0
- package/{sys → _types/_module/Framework}/Threads.d.ts +10 -4
- package/_types/_module/Framework/Threads.d.ts.map +1 -0
- package/_types/_module/Framework/_INIT.d.ts +19 -0
- package/_types/_module/Framework/_INIT.d.ts.map +1 -0
- package/_types/_module/Types.d.ts +10 -0
- package/_types/_module/Types.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 +12 -0
- package/_types/_module/util/Wrapper/IEntity.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/IPlayer.d.ts +13 -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 +307 -366
- package/index.ts +2 -48
- package/package.json +34 -33
- package/tsconfig.types.json +2 -2
- package/index.d.ts +0 -47
- package/sys/Threads.ts +0 -43
- 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/util/Wrapper/IEntity.d.ts +0 -12
- package/util/Wrapper/IPlayer.d.ts +0 -12
- /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}/System.ts +0 -0
- /package/{util → _module/util}/Vector.ts +0 -0
- /package/{util → _module/util}/Wrapper/Container.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/index.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
3
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
8
|
|
|
5
|
-
//
|
|
9
|
+
// _module/BlockFactory.ts
|
|
10
|
+
var BlockFactory_exports = {};
|
|
11
|
+
__export(BlockFactory_exports, {
|
|
12
|
+
Command: () => Command,
|
|
13
|
+
ContainerWrapper: () => ContainerWrapper,
|
|
14
|
+
IEntityWrapper: () => IEntityWrapper,
|
|
15
|
+
IForm: () => IForm,
|
|
16
|
+
IPlayerWrapper: () => IPlayerWrapper,
|
|
17
|
+
MathUtils: () => MathUtils,
|
|
18
|
+
RawText: () => RawText,
|
|
19
|
+
RegisterForm: () => RegisterForm,
|
|
20
|
+
Signal: () => Signal,
|
|
21
|
+
System: () => System,
|
|
22
|
+
Vec2: () => Vec2,
|
|
23
|
+
Vec3: () => Vec3,
|
|
24
|
+
_EntityHandler_: () => _EntityHandler_,
|
|
25
|
+
_INITIALIZE_BF_FRAMEWORK_: () => _INITIALIZE_BF_FRAMEWORK_,
|
|
26
|
+
_THREAD_: () => _THREAD_,
|
|
27
|
+
onEntityEmission: () => onEntityEmission
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// _module/Framework/_INIT.ts
|
|
31
|
+
var IS_INITIALIZED = false;
|
|
32
|
+
var PACK_ID = void 0;
|
|
33
|
+
function _INITIALIZE_BF_FRAMEWORK_(packId) {
|
|
34
|
+
if (IS_INITIALIZED) throw Error(`CONFLICT WARNING: ${PACK_ID} already initialized.`);
|
|
35
|
+
PACK_ID = packId;
|
|
36
|
+
IS_INITIALIZED = true;
|
|
37
|
+
console.log("Block Factory Framework Loaded");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// _module/util/Math.ts
|
|
6
41
|
var MathUtils;
|
|
7
42
|
((MathUtils2) => {
|
|
8
43
|
function clamp(value, min, max) {
|
|
@@ -72,7 +107,7 @@ var MathUtils;
|
|
|
72
107
|
;
|
|
73
108
|
})(MathUtils || (MathUtils = {}));
|
|
74
109
|
|
|
75
|
-
// util/Signal.ts
|
|
110
|
+
// _module/util/Signal.ts
|
|
76
111
|
var Signal = class {
|
|
77
112
|
constructor() {
|
|
78
113
|
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
@@ -93,13 +128,17 @@ var Signal = class {
|
|
|
93
128
|
return this.listeners.has(callback);
|
|
94
129
|
}
|
|
95
130
|
emit(data) {
|
|
96
|
-
for (const
|
|
97
|
-
|
|
131
|
+
for (const callback of Array.from(this.listeners)) {
|
|
132
|
+
try {
|
|
133
|
+
callback(data);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error("BFLIB: Signal listener error:", err);
|
|
136
|
+
}
|
|
98
137
|
}
|
|
99
138
|
}
|
|
100
139
|
};
|
|
101
140
|
|
|
102
|
-
// util/Vector.ts
|
|
141
|
+
// _module/util/Vector.ts
|
|
103
142
|
var _Vec2 = class _Vec2 {
|
|
104
143
|
/**
|
|
105
144
|
* Creates a new Vec2.
|
|
@@ -419,52 +458,75 @@ __publicField(_Vec3, "NORTH", new _Vec3(0, 0, 1));
|
|
|
419
458
|
__publicField(_Vec3, "SOUTH", new _Vec3(0, 0, -1));
|
|
420
459
|
var Vec3 = _Vec3;
|
|
421
460
|
|
|
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
|
-
|
|
461
|
+
// _module/util/RawText.ts
|
|
462
|
+
var RawText = class {
|
|
463
|
+
/**
|
|
464
|
+
* Creates a simple text component.
|
|
465
|
+
* @param value - The text value.
|
|
466
|
+
* @returns Text component object.
|
|
467
|
+
*/
|
|
468
|
+
static text(value) {
|
|
469
|
+
return { text: value };
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Creates a translation component with optional 'with' parameters.
|
|
473
|
+
* @param key - The translation key.
|
|
474
|
+
* @param params - The optional parameters for translation.
|
|
475
|
+
* @returns Translation component object.
|
|
476
|
+
*/
|
|
477
|
+
static translate(key, ...params) {
|
|
478
|
+
return {
|
|
479
|
+
translate: key,
|
|
480
|
+
with: params.length ? params : void 0
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Creates a score component.
|
|
485
|
+
* @param name - The entity's name whose score is being displayed.
|
|
486
|
+
* @param objective - The name of the score objective.
|
|
487
|
+
* @returns Score component object.
|
|
488
|
+
*/
|
|
489
|
+
static score(name, objective) {
|
|
490
|
+
return { score: { name, objective } };
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Wraps various text components into a rawtext structure.
|
|
494
|
+
* @param rawText - The raw text components.
|
|
495
|
+
* @returns Raw text object.
|
|
496
|
+
*/
|
|
497
|
+
static message(...rawText) {
|
|
498
|
+
return { rawtext: rawText };
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Common formatting and color codes.
|
|
503
|
+
*/
|
|
504
|
+
__publicField(RawText, "FORMAT", {
|
|
505
|
+
DarkRed: "\xA74",
|
|
506
|
+
Red: "\xA7c",
|
|
507
|
+
Gold: "\xA76",
|
|
508
|
+
Yellow: "\xA7e",
|
|
509
|
+
Green: "\xA72",
|
|
510
|
+
Lime: "\xA7a",
|
|
511
|
+
Aqua: "\xA7b",
|
|
512
|
+
Cyan: "\xA73",
|
|
513
|
+
DarkBlue: "\xA71",
|
|
514
|
+
Blue: "\xA79",
|
|
515
|
+
Magenta: "\xA7d",
|
|
516
|
+
Purple: "\xA75",
|
|
517
|
+
White: "\xA7f",
|
|
518
|
+
Gray: "\xA77",
|
|
519
|
+
DarkGray: "\xA78",
|
|
520
|
+
Black: "\xA70",
|
|
521
|
+
Obfuscated: "\xA7k",
|
|
522
|
+
Bold: "\xA7l",
|
|
523
|
+
StrikeThrough: "\xA7m",
|
|
524
|
+
Italic: "\xA7o",
|
|
525
|
+
Reset: "\xA7r",
|
|
526
|
+
NewLine: "\n"
|
|
527
|
+
});
|
|
466
528
|
|
|
467
|
-
// util/Command.ts
|
|
529
|
+
// _module/util/Command.ts
|
|
468
530
|
import {
|
|
469
531
|
system
|
|
470
532
|
} from "@minecraft/server";
|
|
@@ -500,7 +562,7 @@ system.beforeEvents.startup.subscribe(
|
|
|
500
562
|
}
|
|
501
563
|
);
|
|
502
564
|
|
|
503
|
-
// util/System.ts
|
|
565
|
+
// _module/util/System.ts
|
|
504
566
|
var System;
|
|
505
567
|
((System2) => {
|
|
506
568
|
System2.ProxyConstructor = ((_instance, source) => {
|
|
@@ -525,7 +587,7 @@ var System;
|
|
|
525
587
|
});
|
|
526
588
|
})(System || (System = {}));
|
|
527
589
|
|
|
528
|
-
// util/Forms/Form.ts
|
|
590
|
+
// _module/util/Forms/Form.ts
|
|
529
591
|
import { world } from "@minecraft/server";
|
|
530
592
|
import { uiManager } from "@minecraft/server-ui";
|
|
531
593
|
var _IForm = class _IForm {
|
|
@@ -550,267 +612,10 @@ __publicField(_IForm, "occupiedPlayers", /* @__PURE__ */ new Set());
|
|
|
550
612
|
__publicField(_IForm, "returnText", "Back");
|
|
551
613
|
var IForm = _IForm;
|
|
552
614
|
|
|
553
|
-
// util/Forms/FormAction.ts
|
|
615
|
+
// _module/util/Forms/FormAction.ts
|
|
554
616
|
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
|
-
|
|
659
|
-
// util/Forms/FormModal.ts
|
|
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
617
|
|
|
760
|
-
// util/Forms/
|
|
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
|
|
618
|
+
// _module/util/Forms/FormRegistry.ts
|
|
814
619
|
import { Player as Player2, world as world2 } from "@minecraft/server";
|
|
815
620
|
var registeredForms = [];
|
|
816
621
|
function RegisterForm(itemId) {
|
|
@@ -836,7 +641,7 @@ world2.afterEvents.itemUse.subscribe((event) => {
|
|
|
836
641
|
});
|
|
837
642
|
});
|
|
838
643
|
|
|
839
|
-
// util/Wrapper/Container.ts
|
|
644
|
+
// _module/util/Wrapper/Container.ts
|
|
840
645
|
var ContainerWrapper = class _ContainerWrapper {
|
|
841
646
|
constructor(source) {
|
|
842
647
|
__publicField(this, "source");
|
|
@@ -860,88 +665,108 @@ var ContainerWrapper = class _ContainerWrapper {
|
|
|
860
665
|
}
|
|
861
666
|
};
|
|
862
667
|
|
|
863
|
-
// util/Wrapper/IEntity.ts
|
|
864
|
-
import { EntityInventoryComponent } from "@minecraft/server";
|
|
668
|
+
// _module/util/Wrapper/IEntity.ts
|
|
669
|
+
import { EntityInventoryComponent, system as system2, TicksPerSecond } from "@minecraft/server";
|
|
865
670
|
var IEntityWrapper = class _IEntityWrapper {
|
|
866
671
|
constructor(source) {
|
|
867
672
|
__publicField(this, "source");
|
|
868
|
-
//======================== Interal ========================
|
|
869
|
-
__publicField(this, "isAlive", false);
|
|
870
673
|
this.source = source;
|
|
871
674
|
return System.ProxyConstructor(this, source);
|
|
872
675
|
}
|
|
873
676
|
static wrap(source) {
|
|
874
677
|
return new _IEntityWrapper(source);
|
|
875
678
|
}
|
|
679
|
+
//======================== Interal ========================
|
|
876
680
|
get inventory() {
|
|
877
681
|
const i = this.source.getComponent(
|
|
878
682
|
EntityInventoryComponent.componentId
|
|
879
683
|
);
|
|
880
684
|
return ContainerWrapper.wrap(i.container);
|
|
881
685
|
}
|
|
882
|
-
|
|
686
|
+
async playAnimationAsync(animation, options) {
|
|
687
|
+
this.source.playAnimation(animation.id, options);
|
|
688
|
+
await system2.waitTicks(animation.length * TicksPerSecond);
|
|
883
689
|
}
|
|
884
690
|
};
|
|
885
691
|
|
|
886
|
-
// util/Wrapper/IPlayer.ts
|
|
887
|
-
import { EntityInventoryComponent as EntityInventoryComponent2 } from "@minecraft/server";
|
|
692
|
+
// _module/util/Wrapper/IPlayer.ts
|
|
693
|
+
import { EntityInventoryComponent as EntityInventoryComponent2, system as system3, TicksPerSecond as TicksPerSecond2 } from "@minecraft/server";
|
|
888
694
|
var IPlayerWrapper = class _IPlayerWrapper {
|
|
889
695
|
constructor(source) {
|
|
890
696
|
__publicField(this, "source");
|
|
891
|
-
//======================== Interal ========================
|
|
892
|
-
__publicField(this, "isAlive", false);
|
|
893
697
|
this.source = source;
|
|
894
698
|
return System.ProxyConstructor(this, source);
|
|
895
699
|
}
|
|
896
700
|
static wrap(player) {
|
|
897
701
|
return new _IPlayerWrapper(player);
|
|
898
702
|
}
|
|
703
|
+
//======================== Interal ========================
|
|
899
704
|
get inventory() {
|
|
900
705
|
const i = this.source.getComponent(
|
|
901
706
|
EntityInventoryComponent2.componentId
|
|
902
707
|
);
|
|
903
708
|
return ContainerWrapper.wrap(i.container);
|
|
904
709
|
}
|
|
905
|
-
|
|
906
|
-
this.source.
|
|
710
|
+
async playSoundAsync(sound, options) {
|
|
711
|
+
this.source.playSound(sound.id, options);
|
|
712
|
+
await system3.waitTicks(sound.length * TicksPerSecond2);
|
|
713
|
+
}
|
|
714
|
+
async playAnimationAsync(animation, options) {
|
|
715
|
+
this.source.playAnimation(animation.id, options);
|
|
716
|
+
await system3.waitTicks(animation.length * TicksPerSecond2);
|
|
907
717
|
}
|
|
908
718
|
};
|
|
909
719
|
|
|
910
|
-
//
|
|
911
|
-
import { system as
|
|
912
|
-
var Threads = class
|
|
720
|
+
// _module/Framework/Threads.ts
|
|
721
|
+
import { system as system4, TicksPerSecond as TicksPerSecond3 } from "@minecraft/server";
|
|
722
|
+
var Threads = class {
|
|
913
723
|
constructor() {
|
|
914
724
|
__publicField(this, "MAIN", new Signal());
|
|
915
725
|
__publicField(this, "LATE", new Signal());
|
|
916
|
-
__publicField(this, "
|
|
917
|
-
__publicField(this, "
|
|
726
|
+
__publicField(this, "_mainRate", 0);
|
|
727
|
+
__publicField(this, "_lateRate", TicksPerSecond3);
|
|
918
728
|
__publicField(this, "_MAIN_ID");
|
|
919
729
|
__publicField(this, "_LATE_ID");
|
|
920
730
|
__publicField(this, "_delta", this.createDeltaTimer());
|
|
921
|
-
this
|
|
731
|
+
__publicField(this, "_started", false);
|
|
732
|
+
}
|
|
733
|
+
configure(cfg) {
|
|
734
|
+
if (this._started) throw new Error("BFLIB: _THREAD_ already started; configure before start().");
|
|
735
|
+
if (cfg.mainRate !== void 0) this._mainRate = cfg.mainRate;
|
|
736
|
+
if (cfg.lateRate !== void 0) this._lateRate = cfg.lateRate;
|
|
737
|
+
}
|
|
738
|
+
start() {
|
|
739
|
+
if (this._started) return;
|
|
740
|
+
this._started = true;
|
|
741
|
+
this._MAIN_ID = system4.runInterval(() => {
|
|
922
742
|
if (this.MAIN.count <= 0) return;
|
|
923
743
|
try {
|
|
924
744
|
const delta = this._delta();
|
|
925
745
|
this.MAIN.emit(delta);
|
|
926
|
-
} catch (
|
|
927
|
-
|
|
746
|
+
} catch (e) {
|
|
747
|
+
console.error(`ERROR: _THREAD_.MAIN:${this._MAIN_ID} |`, e);
|
|
928
748
|
}
|
|
929
|
-
}, this.
|
|
930
|
-
this._LATE_ID =
|
|
749
|
+
}, this._mainRate);
|
|
750
|
+
this._LATE_ID = system4.runInterval(() => {
|
|
931
751
|
if (this.LATE.count <= 0) return;
|
|
932
752
|
try {
|
|
933
753
|
this.LATE.emit();
|
|
934
|
-
} catch (
|
|
935
|
-
|
|
754
|
+
} catch (e) {
|
|
755
|
+
console.error(`ERROR: _THREAD_.LATE:${this._LATE_ID} |`, e);
|
|
936
756
|
}
|
|
937
|
-
}, this.
|
|
757
|
+
}, this._lateRate);
|
|
938
758
|
}
|
|
939
|
-
|
|
940
|
-
|
|
759
|
+
stop() {
|
|
760
|
+
if (this._MAIN_ID !== void 0) system4.clearRun(this._MAIN_ID);
|
|
761
|
+
if (this._LATE_ID !== void 0) system4.clearRun(this._LATE_ID);
|
|
762
|
+
this._MAIN_ID = void 0;
|
|
763
|
+
this._LATE_ID = void 0;
|
|
764
|
+
this._started = false;
|
|
765
|
+
this._delta = this.createDeltaTimer();
|
|
941
766
|
}
|
|
942
767
|
createDeltaTimer() {
|
|
943
768
|
let last = Date.now();
|
|
944
|
-
return
|
|
769
|
+
return () => {
|
|
945
770
|
const now = Date.now();
|
|
946
771
|
const delta = (now - last) / 1e3;
|
|
947
772
|
last = now;
|
|
@@ -949,38 +774,151 @@ var Threads = class _Threads {
|
|
|
949
774
|
};
|
|
950
775
|
}
|
|
951
776
|
};
|
|
952
|
-
var _THREAD_ = Threads
|
|
953
|
-
_THREAD_.MAIN_INTERVAL_RATE = 10;
|
|
777
|
+
var _THREAD_ = new Threads();
|
|
954
778
|
|
|
955
|
-
//
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
779
|
+
// _module/Framework/EntityTasks.ts
|
|
780
|
+
import {
|
|
781
|
+
system as system5,
|
|
782
|
+
world as world3
|
|
783
|
+
} from "@minecraft/server";
|
|
784
|
+
var onEntityEmission = new Signal();
|
|
785
|
+
var EntityHandler = class {
|
|
786
|
+
constructor() {
|
|
787
|
+
__publicField(this, "PACK_ID");
|
|
788
|
+
__publicField(this, "GLOBAL_MEMORY_ID", "GLB_MEM.ENTITY");
|
|
789
|
+
__publicField(this, "scriptEventSignal", system5.afterEvents.scriptEventReceive);
|
|
790
|
+
__publicField(this, "loadEventSignal", world3.afterEvents.worldLoad);
|
|
791
|
+
__publicField(this, "spawnEventSignal", world3.afterEvents.entitySpawn);
|
|
792
|
+
__publicField(this, "removeAfterEventSignal", world3.afterEvents.entityRemove);
|
|
793
|
+
__publicField(this, "removeBeforeEventSignal", world3.beforeEvents.entityRemove);
|
|
794
|
+
__publicField(this, "EM_INDEX", /* @__PURE__ */ new Map());
|
|
795
|
+
__publicField(this, "EM_KEYS", []);
|
|
796
|
+
__publicField(this, "SEARCH_TYPES", /* @__PURE__ */ new Set());
|
|
797
|
+
__publicField(this, "_started", false);
|
|
798
|
+
__publicField(this, "_wired", false);
|
|
799
|
+
/* ------------------------------------------------------------------------ */
|
|
800
|
+
/* Event Wiring */
|
|
801
|
+
/* ------------------------------------------------------------------------ */
|
|
802
|
+
__publicField(this, "onWorldLoad", (_event) => {
|
|
803
|
+
this.scriptEventSignal.subscribe(this.processScriptEvents);
|
|
804
|
+
if (this.SEARCH_TYPES.size > 0) {
|
|
805
|
+
this.spawnEventSignal.subscribe(this.onEntitySpawned);
|
|
806
|
+
this.removeBeforeEventSignal.subscribe(this.onEntityRemovedBefore);
|
|
807
|
+
this.removeAfterEventSignal.subscribe(this.onEntityRemovedAfter);
|
|
808
|
+
}
|
|
809
|
+
this._wired = true;
|
|
810
|
+
this.reloadEntityMemory();
|
|
811
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
812
|
+
});
|
|
813
|
+
__publicField(this, "processScriptEvents", (event) => {
|
|
814
|
+
if (!event.sourceEntity) return;
|
|
815
|
+
if (event.id !== `${this.PACK_ID}:entity_emitter`) return;
|
|
816
|
+
let parms;
|
|
817
|
+
try {
|
|
818
|
+
parms = JSON.parse(event.message);
|
|
819
|
+
} catch (e) {
|
|
820
|
+
console.error(`BFLIB: entity_emitter JSON parse failed:`, e);
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
onEntityEmission.emit({
|
|
824
|
+
iEntity: IEntityWrapper.wrap(event.sourceEntity),
|
|
825
|
+
parms
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
__publicField(this, "onEntitySpawned", (event) => {
|
|
829
|
+
const entity = event.entity;
|
|
830
|
+
if (!this.isValidType(entity.typeId)) return;
|
|
831
|
+
this.saveEntityInMemory(entity);
|
|
832
|
+
});
|
|
833
|
+
__publicField(this, "onEntityRemovedBefore", (event) => {
|
|
834
|
+
const entity = event.removedEntity;
|
|
835
|
+
if (!this.isValidType(entity.typeId)) return;
|
|
836
|
+
this.deleteEntityInMemory(entity);
|
|
837
|
+
});
|
|
838
|
+
__publicField(this, "onEntityRemovedAfter", (_event) => {
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
configure() {
|
|
842
|
+
if (this._started) throw new Error("BFLIB: EntityHandler already started;");
|
|
843
|
+
}
|
|
844
|
+
registerEntity(typeId) {
|
|
845
|
+
if (Array.isArray(typeId)) typeId.forEach((t) => this.SEARCH_TYPES.add(t));
|
|
846
|
+
else this.SEARCH_TYPES.add(typeId);
|
|
847
|
+
}
|
|
848
|
+
start(packId) {
|
|
849
|
+
if (this._started) return;
|
|
850
|
+
this._started = true;
|
|
851
|
+
this.PACK_ID = packId;
|
|
852
|
+
this.loadEventSignal.subscribe(this.onWorldLoad);
|
|
853
|
+
}
|
|
854
|
+
stop() {
|
|
855
|
+
if (!this._started) return;
|
|
856
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
857
|
+
if (this._wired) {
|
|
858
|
+
this.scriptEventSignal.unsubscribe(this.processScriptEvents);
|
|
859
|
+
this.spawnEventSignal.unsubscribe(this.onEntitySpawned);
|
|
860
|
+
this.removeBeforeEventSignal.unsubscribe(this.onEntityRemovedBefore);
|
|
861
|
+
this.removeAfterEventSignal.unsubscribe(this.onEntityRemovedAfter);
|
|
862
|
+
this._wired = false;
|
|
863
|
+
}
|
|
864
|
+
this._started = false;
|
|
865
|
+
}
|
|
866
|
+
/* ------------------------------------------------------------------------ */
|
|
867
|
+
/* Filters */
|
|
868
|
+
/* ------------------------------------------------------------------------ */
|
|
869
|
+
isValidType(typeId) {
|
|
870
|
+
return this.SEARCH_TYPES.has(typeId);
|
|
871
|
+
}
|
|
872
|
+
/* ------------------------------------------------------------------------ */
|
|
873
|
+
/* Persistence */
|
|
874
|
+
/* ------------------------------------------------------------------------ */
|
|
875
|
+
reloadEntityMemory() {
|
|
876
|
+
this.EM_INDEX.clear();
|
|
877
|
+
this.EM_KEYS.length = 0;
|
|
878
|
+
const raw = world3.getDynamicProperty(this.GLOBAL_MEMORY_ID);
|
|
879
|
+
if (!raw) return;
|
|
880
|
+
let parsed;
|
|
881
|
+
try {
|
|
882
|
+
parsed = JSON.parse(raw);
|
|
883
|
+
} catch (e) {
|
|
884
|
+
console.error(`BFLIB: Failed to parse ${this.GLOBAL_MEMORY_ID}:`, e);
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
for (const id of parsed) {
|
|
888
|
+
this.EM_KEYS.push(id);
|
|
889
|
+
const entity = world3.getEntity(id);
|
|
890
|
+
if (entity) this.EM_INDEX.set(entity.id, entity);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
persistKeys() {
|
|
894
|
+
world3.setDynamicProperty(this.GLOBAL_MEMORY_ID, JSON.stringify(this.EM_KEYS));
|
|
895
|
+
}
|
|
896
|
+
saveEntityInMemory(entity) {
|
|
897
|
+
if (this.EM_INDEX.has(entity.id)) return false;
|
|
898
|
+
this.EM_KEYS.push(entity.id);
|
|
899
|
+
this.EM_INDEX.set(entity.id, entity);
|
|
900
|
+
this.persistKeys();
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
903
|
+
deleteEntityInMemory(entity) {
|
|
904
|
+
const existed = this.EM_INDEX.delete(entity.id);
|
|
905
|
+
if (!existed) return false;
|
|
906
|
+
const idx = this.EM_KEYS.indexOf(entity.id);
|
|
907
|
+
if (idx !== -1) this.EM_KEYS.splice(idx, 1);
|
|
908
|
+
this.persistKeys();
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
getEntitiesInMemory() {
|
|
912
|
+
return Array.from(this.EM_INDEX.values());
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
var _EntityHandler_ = new EntityHandler();
|
|
975
916
|
export {
|
|
976
|
-
BlockFactory,
|
|
917
|
+
BlockFactory_exports as BlockFactory,
|
|
977
918
|
Command,
|
|
978
919
|
ContainerWrapper,
|
|
979
|
-
IActionFormData,
|
|
980
920
|
IEntityWrapper,
|
|
981
921
|
IForm,
|
|
982
|
-
IMessageFormData,
|
|
983
|
-
IModalFormData,
|
|
984
922
|
IPlayerWrapper,
|
|
985
923
|
MathUtils,
|
|
986
924
|
RawText,
|
|
@@ -989,5 +927,8 @@ export {
|
|
|
989
927
|
System,
|
|
990
928
|
Vec2,
|
|
991
929
|
Vec3,
|
|
992
|
-
|
|
930
|
+
_EntityHandler_,
|
|
931
|
+
_INITIALIZE_BF_FRAMEWORK_,
|
|
932
|
+
_THREAD_,
|
|
933
|
+
onEntityEmission
|
|
993
934
|
};
|