@block_factory/lib 0.0.4 → 0.0.6
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 +4 -1
- package/_module/DataTypes.ts +10 -0
- package/_module/Framework/EntityTasks.ts +164 -0
- package/_module/Framework/ItemTasks.ts +157 -0
- package/_module/Framework/PlayerTasks.ts +125 -0
- package/_module/Framework/Threads.ts +72 -0
- package/_module/util/Signal.ts +73 -7
- package/_module/util/Wrapper/IEntity.ts +6 -5
- package/_module/util/Wrapper/IPlayer.ts +10 -4
- package/_types/_module/BlockFactory.d.ts +4 -1
- package/_types/_module/BlockFactory.d.ts.map +1 -1
- package/_types/_module/DataTypes.d.ts +10 -0
- package/_types/_module/DataTypes.d.ts.map +1 -0
- package/_types/_module/Framework/EntityTasks.d.ts +37 -0
- package/_types/_module/Framework/EntityTasks.d.ts.map +1 -0
- package/_types/_module/Framework/ItemTasks.d.ts +59 -0
- package/_types/_module/Framework/ItemTasks.d.ts.map +1 -0
- package/_types/_module/Framework/PlayerTasks.d.ts +28 -0
- package/_types/_module/Framework/PlayerTasks.d.ts.map +1 -0
- package/_types/_module/Framework/Threads.d.ts +22 -0
- package/_types/_module/Framework/Threads.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/Signal.d.ts +63 -4
- package/_types/_module/util/Signal.d.ts.map +1 -1
- package/_types/_module/util/Wrapper/IEntity.d.ts +4 -4
- package/_types/_module/util/Wrapper/IEntity.d.ts.map +1 -1
- package/_types/_module/util/Wrapper/IPlayer.d.ts +4 -3
- package/_types/_module/util/Wrapper/IPlayer.d.ts.map +1 -1
- package/index.js +506 -60
- package/package.json +36 -34
- package/typedoc.json +6 -0
- package/_module/sys/Threads.ts +0 -43
- package/_types/_module/sys/Threads.d.ts +0 -16
- package/_types/_module/sys/Threads.d.ts.map +0 -1
package/index.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2
3
|
var __export = (target, all) => {
|
|
3
4
|
for (var name in all)
|
|
4
5
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
6
|
};
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
8
|
|
|
7
9
|
// _module/BlockFactory.ts
|
|
8
10
|
var BlockFactory_exports = {};
|
|
9
11
|
__export(BlockFactory_exports, {
|
|
10
12
|
Command: () => Command,
|
|
11
13
|
ContainerWrapper: () => ContainerWrapper,
|
|
14
|
+
EntityHandler: () => EntityHandler,
|
|
12
15
|
IEntityWrapper: () => IEntityWrapper,
|
|
13
16
|
IForm: () => IForm,
|
|
14
17
|
IPlayerWrapper: () => IPlayerWrapper,
|
|
18
|
+
ItemHandler: () => ItemHandler,
|
|
15
19
|
MathUtils: () => MathUtils,
|
|
20
|
+
PlayerHandler: () => PlayerHandler,
|
|
16
21
|
RawText: () => RawText,
|
|
17
22
|
RegisterForm: () => RegisterForm,
|
|
18
23
|
Signal: () => Signal,
|
|
19
24
|
System: () => System,
|
|
25
|
+
Thread: () => Thread,
|
|
20
26
|
Vec2: () => Vec2,
|
|
21
|
-
Vec3: () => Vec3
|
|
22
|
-
_THREAD_: () => _THREAD_
|
|
27
|
+
Vec3: () => Vec3
|
|
23
28
|
});
|
|
24
29
|
|
|
25
30
|
// _module/util/Math.ts
|
|
@@ -95,28 +100,80 @@ var MathUtils;
|
|
|
95
100
|
// _module/util/Signal.ts
|
|
96
101
|
var Signal = class {
|
|
97
102
|
constructor() {
|
|
98
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Registered signal listeners.
|
|
105
|
+
*/
|
|
106
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
99
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Number of currently subscribed listeners.
|
|
110
|
+
*/
|
|
100
111
|
get count() {
|
|
101
112
|
return this.listeners.size;
|
|
102
113
|
}
|
|
103
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Subscribes a callback to this signal.
|
|
116
|
+
*
|
|
117
|
+
* The callback will be invoked every time the signal is emitted
|
|
118
|
+
* until it is explicitly unsubscribed or the signal is cleared.
|
|
119
|
+
*
|
|
120
|
+
* @param callback Function invoked on signal emission
|
|
121
|
+
*/
|
|
122
|
+
subscribe(callback) {
|
|
104
123
|
this.listeners.add(callback);
|
|
105
124
|
}
|
|
106
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Unsubscribes a previously registered callback.
|
|
127
|
+
*
|
|
128
|
+
* @param callback Callback to remove
|
|
129
|
+
* @returns `true` if the callback was removed, `false` otherwise
|
|
130
|
+
*/
|
|
131
|
+
unsubscribe(callback) {
|
|
107
132
|
return this.listeners.delete(callback);
|
|
108
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Removes all subscribed listeners from this signal.
|
|
136
|
+
*/
|
|
109
137
|
clear() {
|
|
110
138
|
this.listeners.clear();
|
|
111
139
|
}
|
|
112
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Checks whether a callback is currently subscribed.
|
|
142
|
+
*
|
|
143
|
+
* @param callback Callback to test
|
|
144
|
+
* @returns `true` if the callback is subscribed
|
|
145
|
+
*/
|
|
146
|
+
isSubscribed(callback) {
|
|
113
147
|
return this.listeners.has(callback);
|
|
114
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Emits the signal immediately, invoking all subscribed callbacks.
|
|
151
|
+
*
|
|
152
|
+
* Listener errors are caught and logged to prevent a single failure
|
|
153
|
+
* from interrupting signal propagation.
|
|
154
|
+
*
|
|
155
|
+
* @param data Payload to pass to listeners
|
|
156
|
+
*/
|
|
115
157
|
emit(data) {
|
|
116
|
-
for (const
|
|
117
|
-
|
|
158
|
+
for (const callback of Array.from(this.listeners)) {
|
|
159
|
+
try {
|
|
160
|
+
callback(data);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
console.error("BFLIB: Subscription listener error:", err);
|
|
163
|
+
}
|
|
118
164
|
}
|
|
119
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Emits the signal asynchronously on the microtask queue.
|
|
168
|
+
*
|
|
169
|
+
* Useful for deferring execution to avoid re-entrancy issues
|
|
170
|
+
* or emitting during unsafe execution phases.
|
|
171
|
+
*
|
|
172
|
+
* @param data Payload to pass to listeners
|
|
173
|
+
*/
|
|
174
|
+
emitDeferred(data) {
|
|
175
|
+
queueMicrotask(() => this.emit(data));
|
|
176
|
+
}
|
|
120
177
|
};
|
|
121
178
|
|
|
122
179
|
// _module/util/Vector.ts
|
|
@@ -247,15 +304,15 @@ var _Vec2 = class _Vec2 {
|
|
|
247
304
|
}
|
|
248
305
|
};
|
|
249
306
|
/** Constant zero vector (0, 0) */
|
|
250
|
-
_Vec2
|
|
307
|
+
__publicField(_Vec2, "ZERO", new _Vec2(0, 0));
|
|
251
308
|
/** Up direction (0, 1) */
|
|
252
|
-
_Vec2
|
|
309
|
+
__publicField(_Vec2, "UP", new _Vec2(0, 1));
|
|
253
310
|
/** Down direction (0, -1) */
|
|
254
|
-
_Vec2
|
|
311
|
+
__publicField(_Vec2, "DOWN", new _Vec2(0, -1));
|
|
255
312
|
/** Left direction (-1, 0) */
|
|
256
|
-
_Vec2
|
|
313
|
+
__publicField(_Vec2, "LEFT", new _Vec2(-1, 0));
|
|
257
314
|
/** Right direction (1, 0) */
|
|
258
|
-
_Vec2
|
|
315
|
+
__publicField(_Vec2, "RIGHT", new _Vec2(1, 0));
|
|
259
316
|
var Vec2 = _Vec2;
|
|
260
317
|
var _Vec3 = class _Vec3 {
|
|
261
318
|
/**
|
|
@@ -416,27 +473,27 @@ var _Vec3 = class _Vec3 {
|
|
|
416
473
|
}
|
|
417
474
|
};
|
|
418
475
|
/** Constant zero vector (0, 0, 0) */
|
|
419
|
-
_Vec3
|
|
476
|
+
__publicField(_Vec3, "ZERO", new _Vec3(0, 0, 0));
|
|
420
477
|
/** Up direction (0, 1, 0) */
|
|
421
|
-
_Vec3
|
|
478
|
+
__publicField(_Vec3, "UP", new _Vec3(0, 1, 0));
|
|
422
479
|
/** Down direction (0, -1, 0) */
|
|
423
|
-
_Vec3
|
|
480
|
+
__publicField(_Vec3, "DOWN", new _Vec3(0, -1, 0));
|
|
424
481
|
/** Left direction (-1, 0, 0) */
|
|
425
|
-
_Vec3
|
|
482
|
+
__publicField(_Vec3, "LEFT", new _Vec3(-1, 0, 0));
|
|
426
483
|
/** Right direction (1, 0, 0) */
|
|
427
|
-
_Vec3
|
|
484
|
+
__publicField(_Vec3, "RIGHT", new _Vec3(1, 0, 0));
|
|
428
485
|
/** Forward direction (0, 0, 1) */
|
|
429
|
-
_Vec3
|
|
486
|
+
__publicField(_Vec3, "FORWARD", new _Vec3(0, 0, 1));
|
|
430
487
|
/** Backward direction (0, 0, -1) */
|
|
431
|
-
_Vec3
|
|
488
|
+
__publicField(_Vec3, "BACK", new _Vec3(0, 0, -1));
|
|
432
489
|
/** West direction (-1, 0, 0) */
|
|
433
|
-
_Vec3
|
|
490
|
+
__publicField(_Vec3, "WEST", new _Vec3(-1, 0, 0));
|
|
434
491
|
/** East direction (1, 0, 0) */
|
|
435
|
-
_Vec3
|
|
492
|
+
__publicField(_Vec3, "EAST", new _Vec3(1, 0, 0));
|
|
436
493
|
/** North direction (0, 0, 1) */
|
|
437
|
-
_Vec3
|
|
494
|
+
__publicField(_Vec3, "NORTH", new _Vec3(0, 0, 1));
|
|
438
495
|
/** South direction (0, 0, -1) */
|
|
439
|
-
_Vec3
|
|
496
|
+
__publicField(_Vec3, "SOUTH", new _Vec3(0, 0, -1));
|
|
440
497
|
var Vec3 = _Vec3;
|
|
441
498
|
|
|
442
499
|
// _module/util/RawText.ts
|
|
@@ -482,7 +539,7 @@ var RawText = class {
|
|
|
482
539
|
/**
|
|
483
540
|
* Common formatting and color codes.
|
|
484
541
|
*/
|
|
485
|
-
RawText
|
|
542
|
+
__publicField(RawText, "FORMAT", {
|
|
486
543
|
DarkRed: "\xA74",
|
|
487
544
|
Red: "\xA7c",
|
|
488
545
|
Gold: "\xA76",
|
|
@@ -505,7 +562,7 @@ RawText.FORMAT = {
|
|
|
505
562
|
Italic: "\xA7o",
|
|
506
563
|
Reset: "\xA7r",
|
|
507
564
|
NewLine: "\n"
|
|
508
|
-
};
|
|
565
|
+
});
|
|
509
566
|
|
|
510
567
|
// _module/util/Command.ts
|
|
511
568
|
import {
|
|
@@ -514,6 +571,14 @@ import {
|
|
|
514
571
|
var Command;
|
|
515
572
|
((Command2) => {
|
|
516
573
|
class ICustomCommand {
|
|
574
|
+
constructor() {
|
|
575
|
+
/** Whether cheats must be enabled */
|
|
576
|
+
__publicField(this, "cheatsRequired");
|
|
577
|
+
/** Required command parameters */
|
|
578
|
+
__publicField(this, "mandatoryParameters");
|
|
579
|
+
/** Optional command parameters */
|
|
580
|
+
__publicField(this, "optionalParameters");
|
|
581
|
+
}
|
|
517
582
|
}
|
|
518
583
|
Command2.ICustomCommand = ICustomCommand;
|
|
519
584
|
;
|
|
@@ -581,8 +646,8 @@ var _IForm = class _IForm {
|
|
|
581
646
|
else _IForm.occupiedPlayers.delete(player.id);
|
|
582
647
|
}
|
|
583
648
|
};
|
|
584
|
-
_IForm
|
|
585
|
-
_IForm
|
|
649
|
+
__publicField(_IForm, "occupiedPlayers", /* @__PURE__ */ new Set());
|
|
650
|
+
__publicField(_IForm, "returnText", "Back");
|
|
586
651
|
var IForm = _IForm;
|
|
587
652
|
|
|
588
653
|
// _module/util/Forms/FormAction.ts
|
|
@@ -617,6 +682,7 @@ world2.afterEvents.itemUse.subscribe((event) => {
|
|
|
617
682
|
// _module/util/Wrapper/Container.ts
|
|
618
683
|
var ContainerWrapper = class _ContainerWrapper {
|
|
619
684
|
constructor(source) {
|
|
685
|
+
__publicField(this, "source");
|
|
620
686
|
this.source = source;
|
|
621
687
|
return System.ProxyConstructor(this, source);
|
|
622
688
|
}
|
|
@@ -638,83 +704,107 @@ var ContainerWrapper = class _ContainerWrapper {
|
|
|
638
704
|
};
|
|
639
705
|
|
|
640
706
|
// _module/util/Wrapper/IEntity.ts
|
|
641
|
-
import { EntityInventoryComponent } from "@minecraft/server";
|
|
707
|
+
import { EntityInventoryComponent, system as system2, TicksPerSecond } from "@minecraft/server";
|
|
642
708
|
var IEntityWrapper = class _IEntityWrapper {
|
|
643
709
|
constructor(source) {
|
|
644
|
-
|
|
645
|
-
this.isAlive = false;
|
|
710
|
+
__publicField(this, "source");
|
|
646
711
|
this.source = source;
|
|
647
712
|
return System.ProxyConstructor(this, source);
|
|
648
713
|
}
|
|
649
714
|
static wrap(source) {
|
|
650
715
|
return new _IEntityWrapper(source);
|
|
651
716
|
}
|
|
717
|
+
//======================== Interal ========================
|
|
652
718
|
get inventory() {
|
|
653
719
|
const i = this.source.getComponent(
|
|
654
720
|
EntityInventoryComponent.componentId
|
|
655
721
|
);
|
|
656
722
|
return ContainerWrapper.wrap(i.container);
|
|
657
723
|
}
|
|
658
|
-
|
|
724
|
+
async playAnimationAsync(animation, options) {
|
|
725
|
+
this.source.playAnimation(animation.id, options);
|
|
726
|
+
await system2.waitTicks(animation.length * TicksPerSecond);
|
|
659
727
|
}
|
|
660
728
|
};
|
|
661
729
|
|
|
662
730
|
// _module/util/Wrapper/IPlayer.ts
|
|
663
|
-
import { EntityInventoryComponent as EntityInventoryComponent2 } from "@minecraft/server";
|
|
731
|
+
import { EntityInventoryComponent as EntityInventoryComponent2, system as system3, TicksPerSecond as TicksPerSecond2 } from "@minecraft/server";
|
|
664
732
|
var IPlayerWrapper = class _IPlayerWrapper {
|
|
665
733
|
constructor(source) {
|
|
666
|
-
|
|
667
|
-
this.isAlive = false;
|
|
734
|
+
__publicField(this, "source");
|
|
668
735
|
this.source = source;
|
|
669
736
|
return System.ProxyConstructor(this, source);
|
|
670
737
|
}
|
|
671
738
|
static wrap(player) {
|
|
672
739
|
return new _IPlayerWrapper(player);
|
|
673
740
|
}
|
|
741
|
+
//======================== Interal ========================
|
|
674
742
|
get inventory() {
|
|
675
743
|
const i = this.source.getComponent(
|
|
676
744
|
EntityInventoryComponent2.componentId
|
|
677
745
|
);
|
|
678
746
|
return ContainerWrapper.wrap(i.container);
|
|
679
747
|
}
|
|
680
|
-
|
|
681
|
-
this.source.
|
|
748
|
+
async playSoundAsync(sound, options) {
|
|
749
|
+
this.source.playSound(sound.id, options);
|
|
750
|
+
await system3.waitTicks(sound.length * TicksPerSecond2);
|
|
751
|
+
}
|
|
752
|
+
async playAnimationAsync(animation, options) {
|
|
753
|
+
this.source.playAnimation(animation.id, options);
|
|
754
|
+
await system3.waitTicks(animation.length * TicksPerSecond2);
|
|
682
755
|
}
|
|
683
756
|
};
|
|
684
757
|
|
|
685
|
-
// _module/
|
|
686
|
-
import { system as
|
|
687
|
-
var
|
|
758
|
+
// _module/Framework/Threads.ts
|
|
759
|
+
import { system as system4, TicksPerSecond as TicksPerSecond3 } from "@minecraft/server";
|
|
760
|
+
var SingletonThreadManager = class {
|
|
688
761
|
constructor() {
|
|
689
|
-
this
|
|
690
|
-
this
|
|
691
|
-
this
|
|
692
|
-
this
|
|
693
|
-
this
|
|
694
|
-
this
|
|
762
|
+
__publicField(this, "MAIN", new Signal());
|
|
763
|
+
__publicField(this, "LATE", new Signal());
|
|
764
|
+
__publicField(this, "_mainRate", 0);
|
|
765
|
+
__publicField(this, "_lateRate", TicksPerSecond3);
|
|
766
|
+
__publicField(this, "_MAIN_ID");
|
|
767
|
+
__publicField(this, "_LATE_ID");
|
|
768
|
+
__publicField(this, "_delta", this.createDeltaTimer());
|
|
769
|
+
__publicField(this, "_started", false);
|
|
770
|
+
}
|
|
771
|
+
configure(cfg) {
|
|
772
|
+
if (this._started) throw new Error("BFLIB: _THREAD_ already started; configure before start().");
|
|
773
|
+
if (cfg.mainRate !== void 0) this._mainRate = cfg.mainRate;
|
|
774
|
+
if (cfg.lateRate !== void 0) this._lateRate = cfg.lateRate;
|
|
775
|
+
}
|
|
776
|
+
start() {
|
|
777
|
+
if (this._started) return;
|
|
778
|
+
this._started = true;
|
|
779
|
+
this._MAIN_ID = system4.runInterval(() => {
|
|
695
780
|
if (this.MAIN.count <= 0) return;
|
|
696
781
|
try {
|
|
697
782
|
const delta = this._delta();
|
|
698
783
|
this.MAIN.emit(delta);
|
|
699
|
-
} catch (
|
|
700
|
-
|
|
784
|
+
} catch (e) {
|
|
785
|
+
console.error(`ERROR: _THREAD_.MAIN:${this._MAIN_ID} |`, e);
|
|
701
786
|
}
|
|
702
|
-
}, this.
|
|
703
|
-
this._LATE_ID =
|
|
787
|
+
}, this._mainRate);
|
|
788
|
+
this._LATE_ID = system4.runInterval(() => {
|
|
704
789
|
if (this.LATE.count <= 0) return;
|
|
705
790
|
try {
|
|
706
791
|
this.LATE.emit();
|
|
707
|
-
} catch (
|
|
708
|
-
|
|
792
|
+
} catch (e) {
|
|
793
|
+
console.error(`ERROR: _THREAD_.LATE:${this._LATE_ID} |`, e);
|
|
709
794
|
}
|
|
710
|
-
}, this.
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
|
|
795
|
+
}, this._lateRate);
|
|
796
|
+
}
|
|
797
|
+
stop() {
|
|
798
|
+
if (this._MAIN_ID !== void 0) system4.clearRun(this._MAIN_ID);
|
|
799
|
+
if (this._LATE_ID !== void 0) system4.clearRun(this._LATE_ID);
|
|
800
|
+
this._MAIN_ID = void 0;
|
|
801
|
+
this._LATE_ID = void 0;
|
|
802
|
+
this._started = false;
|
|
803
|
+
this._delta = this.createDeltaTimer();
|
|
714
804
|
}
|
|
715
805
|
createDeltaTimer() {
|
|
716
806
|
let last = Date.now();
|
|
717
|
-
return
|
|
807
|
+
return () => {
|
|
718
808
|
const now = Date.now();
|
|
719
809
|
const delta = (now - last) / 1e3;
|
|
720
810
|
last = now;
|
|
@@ -722,20 +812,376 @@ var Threads = class _Threads {
|
|
|
722
812
|
};
|
|
723
813
|
}
|
|
724
814
|
};
|
|
725
|
-
var
|
|
815
|
+
var Thread = new SingletonThreadManager();
|
|
816
|
+
|
|
817
|
+
// _module/Framework/PlayerTasks.ts
|
|
818
|
+
import { ButtonState, InputButton, world as world3 } from "@minecraft/server";
|
|
819
|
+
var SingletonPlayerHandler = class {
|
|
820
|
+
constructor() {
|
|
821
|
+
__publicField(this, "GLOBAL_MEMORY_ID", "GLB_MEM.PLAYER");
|
|
822
|
+
__publicField(this, "loadEventSignal", world3.afterEvents.worldLoad);
|
|
823
|
+
__publicField(this, "playerSpawnSignal", world3.afterEvents.playerSpawn);
|
|
824
|
+
__publicField(this, "playerLeaveBeforeSignal", world3.beforeEvents.playerLeave);
|
|
825
|
+
__publicField(this, "buttonInputSignal", world3.afterEvents.playerButtonInput);
|
|
826
|
+
__publicField(this, "PR_INDEX", /* @__PURE__ */ new Map());
|
|
827
|
+
__publicField(this, "PR_KEYS", []);
|
|
828
|
+
__publicField(this, "_started", false);
|
|
829
|
+
__publicField(this, "_wired", false);
|
|
830
|
+
__publicField(this, "onWorldLoad", () => {
|
|
831
|
+
this.reloadPlayerMemory();
|
|
832
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
833
|
+
});
|
|
834
|
+
__publicField(this, "onPlayerSpawned", (event) => {
|
|
835
|
+
if (!event) return;
|
|
836
|
+
if (this.hasPlayer(event.player.id)) return;
|
|
837
|
+
this.savePlayerInMemory(event.player);
|
|
838
|
+
});
|
|
839
|
+
__publicField(this, "onPlayerLeaveBefore", (event) => {
|
|
840
|
+
if (!this.hasPlayer(event.player.id)) return;
|
|
841
|
+
this.deletePlayerInMemory(event.player);
|
|
842
|
+
});
|
|
843
|
+
__publicField(this, "onButtonPress", (event) => {
|
|
844
|
+
if (event.button === InputButton.Jump) {
|
|
845
|
+
} else if (event.button === InputButton.Sneak) {
|
|
846
|
+
}
|
|
847
|
+
console.warn(`Player ${event.player.name} pressed button ${InputButton[event.button]}: ${ButtonState[event.newButtonState]}`);
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
start() {
|
|
851
|
+
if (this._started) throw new Error("BFLIB: PlayerHandler already started;");
|
|
852
|
+
this._started = true;
|
|
853
|
+
this.onSystemLoad();
|
|
854
|
+
this.loadEventSignal.subscribe(this.onWorldLoad);
|
|
855
|
+
this.buttonInputSignal.subscribe(this.onButtonPress);
|
|
856
|
+
}
|
|
857
|
+
stop() {
|
|
858
|
+
if (!this._started) return;
|
|
859
|
+
if (this._wired) {
|
|
860
|
+
this.playerSpawnSignal.unsubscribe(this.onPlayerSpawned);
|
|
861
|
+
this.playerLeaveBeforeSignal.unsubscribe(this.onPlayerLeaveBefore);
|
|
862
|
+
this.buttonInputSignal.unsubscribe(this.onButtonPress);
|
|
863
|
+
this._wired = false;
|
|
864
|
+
}
|
|
865
|
+
this._started = false;
|
|
866
|
+
}
|
|
867
|
+
onSystemLoad() {
|
|
868
|
+
this.playerSpawnSignal.subscribe(this.onPlayerSpawned);
|
|
869
|
+
this.playerLeaveBeforeSignal.subscribe(this.onPlayerLeaveBefore);
|
|
870
|
+
this._wired = true;
|
|
871
|
+
}
|
|
872
|
+
hasPlayer(playerId) {
|
|
873
|
+
return this.PR_INDEX.has(playerId);
|
|
874
|
+
}
|
|
875
|
+
/* ------------------------------------------------------------------------ */
|
|
876
|
+
/* Persistence */
|
|
877
|
+
/* ------------------------------------------------------------------------ */
|
|
878
|
+
reloadPlayerMemory() {
|
|
879
|
+
this.PR_INDEX.clear();
|
|
880
|
+
this.PR_KEYS.length = 0;
|
|
881
|
+
const players = world3.getAllPlayers();
|
|
882
|
+
for (const player of players) {
|
|
883
|
+
this.PR_INDEX.set(player.id, player);
|
|
884
|
+
this.PR_KEYS.push(player.id);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
persistKeys() {
|
|
888
|
+
world3.setDynamicProperty(this.GLOBAL_MEMORY_ID, JSON.stringify(this.PR_KEYS));
|
|
889
|
+
}
|
|
890
|
+
savePlayerInMemory(player) {
|
|
891
|
+
if (this.PR_INDEX.has(player.id)) return false;
|
|
892
|
+
this.PR_KEYS.push(player.id);
|
|
893
|
+
this.PR_INDEX.set(player.id, player);
|
|
894
|
+
this.persistKeys();
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
deletePlayerInMemory(player) {
|
|
898
|
+
const existed = this.PR_INDEX.delete(player.id);
|
|
899
|
+
if (!existed) return false;
|
|
900
|
+
const idx = this.PR_KEYS.indexOf(player.id);
|
|
901
|
+
if (idx !== -1) this.PR_KEYS.splice(idx, 1);
|
|
902
|
+
this.persistKeys();
|
|
903
|
+
return true;
|
|
904
|
+
}
|
|
905
|
+
getPlayersInMemory() {
|
|
906
|
+
return Array.from(this.PR_INDEX.values());
|
|
907
|
+
}
|
|
908
|
+
getIPlayersInMemory() {
|
|
909
|
+
return Array.from(this.PR_INDEX.values()).map((player) => IPlayerWrapper.wrap(player));
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
var PlayerHandler = new SingletonPlayerHandler();
|
|
913
|
+
|
|
914
|
+
// _module/Framework/EntityTasks.ts
|
|
915
|
+
import { system as system5, world as world4 } from "@minecraft/server";
|
|
916
|
+
var SingletonEntityHandler = class {
|
|
917
|
+
constructor() {
|
|
918
|
+
__publicField(this, "PACK_ID");
|
|
919
|
+
__publicField(this, "onEntityEmission", new Signal());
|
|
920
|
+
__publicField(this, "GLOBAL_MEMORY_ID", "GLB_MEM.ENTITY");
|
|
921
|
+
__publicField(this, "scriptEventSignal", system5.afterEvents.scriptEventReceive);
|
|
922
|
+
__publicField(this, "loadEventSignal", world4.afterEvents.worldLoad);
|
|
923
|
+
__publicField(this, "spawnEventSignal", world4.afterEvents.entitySpawn);
|
|
924
|
+
__publicField(this, "removeBeforeEventSignal", world4.beforeEvents.entityRemove);
|
|
925
|
+
__publicField(this, "EM_INDEX", /* @__PURE__ */ new Map());
|
|
926
|
+
__publicField(this, "EM_KEYS", []);
|
|
927
|
+
__publicField(this, "SEARCH_TYPES", /* @__PURE__ */ new Set());
|
|
928
|
+
__publicField(this, "_started", false);
|
|
929
|
+
__publicField(this, "_wired", false);
|
|
930
|
+
/* ------------------------------------------------------------------------ */
|
|
931
|
+
/* Event Wiring */
|
|
932
|
+
/* ------------------------------------------------------------------------ */
|
|
933
|
+
__publicField(this, "onWorldLoad", () => {
|
|
934
|
+
this.scriptEventSignal.subscribe(this.processScriptEvents);
|
|
935
|
+
if (this.SEARCH_TYPES.size > 0) {
|
|
936
|
+
this.spawnEventSignal.subscribe(this.onEntitySpawned);
|
|
937
|
+
this.removeBeforeEventSignal.subscribe(this.onEntityRemovedBefore);
|
|
938
|
+
}
|
|
939
|
+
this._wired = true;
|
|
940
|
+
this.reloadEntityMemory();
|
|
941
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
942
|
+
});
|
|
943
|
+
__publicField(this, "processScriptEvents", (event) => {
|
|
944
|
+
if (!event.sourceEntity) return;
|
|
945
|
+
if (event.id !== `${this.PACK_ID}:entity_emitter`) return;
|
|
946
|
+
let parms;
|
|
947
|
+
try {
|
|
948
|
+
parms = JSON.parse(event.message);
|
|
949
|
+
} catch (e) {
|
|
950
|
+
console.error(`BFLIB: entity_emitter JSON parse failed:`, e);
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
this.onEntityEmission.emit({ iEntity: IEntityWrapper.wrap(event.sourceEntity), parms });
|
|
954
|
+
});
|
|
955
|
+
__publicField(this, "onEntitySpawned", (event) => {
|
|
956
|
+
const entity = event.entity;
|
|
957
|
+
if (!this.isValidType(entity.typeId)) return;
|
|
958
|
+
this.saveEntityInMemory(entity);
|
|
959
|
+
});
|
|
960
|
+
__publicField(this, "onEntityRemovedBefore", (event) => {
|
|
961
|
+
const entity = event.removedEntity;
|
|
962
|
+
if (!this.isValidType(entity.typeId)) return;
|
|
963
|
+
this.deleteEntityInMemory(entity);
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
registerEntity(typeId) {
|
|
967
|
+
if (Array.isArray(typeId)) typeId.forEach((t) => this.SEARCH_TYPES.add(t));
|
|
968
|
+
else this.SEARCH_TYPES.add(typeId);
|
|
969
|
+
}
|
|
970
|
+
start(packId) {
|
|
971
|
+
if (this._started) throw new Error("BFLIB: EntityHandler already started;");
|
|
972
|
+
this._started = true;
|
|
973
|
+
this.PACK_ID = packId;
|
|
974
|
+
this.loadEventSignal.subscribe(this.onWorldLoad);
|
|
975
|
+
}
|
|
976
|
+
stop() {
|
|
977
|
+
if (!this._started) return;
|
|
978
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
979
|
+
if (this._wired) {
|
|
980
|
+
this.scriptEventSignal.unsubscribe(this.processScriptEvents);
|
|
981
|
+
this.spawnEventSignal.unsubscribe(this.onEntitySpawned);
|
|
982
|
+
this.removeBeforeEventSignal.unsubscribe(this.onEntityRemovedBefore);
|
|
983
|
+
this._wired = false;
|
|
984
|
+
}
|
|
985
|
+
this._started = false;
|
|
986
|
+
}
|
|
987
|
+
/* ------------------------------------------------------------------------ */
|
|
988
|
+
/* Filters */
|
|
989
|
+
/* ------------------------------------------------------------------------ */
|
|
990
|
+
isValidType(typeId) {
|
|
991
|
+
if (this.PACK_ID && !typeId.startsWith(this.PACK_ID)) return false;
|
|
992
|
+
return this.SEARCH_TYPES.has(typeId);
|
|
993
|
+
}
|
|
994
|
+
/* ------------------------------------------------------------------------ */
|
|
995
|
+
/* Persistence */
|
|
996
|
+
/* ------------------------------------------------------------------------ */
|
|
997
|
+
reloadEntityMemory() {
|
|
998
|
+
this.EM_INDEX.clear();
|
|
999
|
+
this.EM_KEYS.length = 0;
|
|
1000
|
+
const raw = world4.getDynamicProperty(this.GLOBAL_MEMORY_ID);
|
|
1001
|
+
if (!raw) return;
|
|
1002
|
+
let parsed;
|
|
1003
|
+
try {
|
|
1004
|
+
parsed = JSON.parse(raw);
|
|
1005
|
+
} catch (e) {
|
|
1006
|
+
console.error(`BFLIB: Failed to parse ${this.GLOBAL_MEMORY_ID}:`, e);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
for (const id of parsed) {
|
|
1010
|
+
this.EM_KEYS.push(id);
|
|
1011
|
+
const entity = world4.getEntity(id);
|
|
1012
|
+
if (entity) this.EM_INDEX.set(entity.id, entity);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
persistKeys() {
|
|
1016
|
+
world4.setDynamicProperty(this.GLOBAL_MEMORY_ID, JSON.stringify(this.EM_KEYS));
|
|
1017
|
+
}
|
|
1018
|
+
saveEntityInMemory(entity) {
|
|
1019
|
+
if (this.EM_INDEX.has(entity.id)) return false;
|
|
1020
|
+
this.EM_KEYS.push(entity.id);
|
|
1021
|
+
this.EM_INDEX.set(entity.id, entity);
|
|
1022
|
+
this.persistKeys();
|
|
1023
|
+
return true;
|
|
1024
|
+
}
|
|
1025
|
+
deleteEntityInMemory(entity) {
|
|
1026
|
+
const existed = this.EM_INDEX.delete(entity.id);
|
|
1027
|
+
if (!existed) return false;
|
|
1028
|
+
const idx = this.EM_KEYS.indexOf(entity.id);
|
|
1029
|
+
if (idx !== -1) this.EM_KEYS.splice(idx, 1);
|
|
1030
|
+
this.persistKeys();
|
|
1031
|
+
return true;
|
|
1032
|
+
}
|
|
1033
|
+
getEntitiesInMemory() {
|
|
1034
|
+
return Array.from(this.EM_INDEX.values());
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
var EntityHandler = new SingletonEntityHandler();
|
|
1038
|
+
|
|
1039
|
+
// _module/Framework/ItemTasks.ts
|
|
1040
|
+
import { system as system6, world as world5 } from "@minecraft/server";
|
|
1041
|
+
var SingletonItemHandler = class {
|
|
1042
|
+
constructor() {
|
|
1043
|
+
__publicField(this, "PACK_ID");
|
|
1044
|
+
__publicField(this, "whileHoldingItemEvent", new Signal());
|
|
1045
|
+
__publicField(this, "onItemHeldEvent", new Signal());
|
|
1046
|
+
__publicField(this, "onItemUnheldEvent", new Signal());
|
|
1047
|
+
__publicField(this, "onItemUsedEvent", new Signal());
|
|
1048
|
+
__publicField(this, "loadEventSignal", world5.afterEvents.worldLoad);
|
|
1049
|
+
__publicField(this, "useBeforeSignal", world5.beforeEvents.itemUse);
|
|
1050
|
+
__publicField(this, "useAfterSignal", world5.afterEvents.itemUse);
|
|
1051
|
+
__publicField(this, "completeUseSignal", world5.afterEvents.itemCompleteUse);
|
|
1052
|
+
__publicField(this, "releaseUseSignal", world5.afterEvents.itemReleaseUse);
|
|
1053
|
+
__publicField(this, "startUseSignal", world5.afterEvents.itemStartUse);
|
|
1054
|
+
__publicField(this, "startUseOnSignal", world5.afterEvents.itemStartUseOn);
|
|
1055
|
+
__publicField(this, "stopUseSignal", world5.afterEvents.itemStopUse);
|
|
1056
|
+
__publicField(this, "stopUseOnSignal", world5.afterEvents.itemStopUseOn);
|
|
1057
|
+
__publicField(this, "inventoryItemChangeSignal", world5.afterEvents.playerInventoryItemChange);
|
|
1058
|
+
__publicField(this, "hotbarChangeSignal", world5.afterEvents.playerHotbarSelectedSlotChange);
|
|
1059
|
+
__publicField(this, "IM_INDEX", /* @__PURE__ */ new Map());
|
|
1060
|
+
__publicField(this, "HOLD_INDEX", /* @__PURE__ */ new Map());
|
|
1061
|
+
__publicField(this, "_started", false);
|
|
1062
|
+
__publicField(this, "_wired", false);
|
|
1063
|
+
__publicField(this, "onWorldLoad", () => {
|
|
1064
|
+
if (this.IM_INDEX.size > 0) {
|
|
1065
|
+
this.useBeforeSignal.subscribe(this.onUseBefore);
|
|
1066
|
+
this.useAfterSignal.subscribe(this.onUseAfter);
|
|
1067
|
+
this.completeUseSignal.subscribe(this.onCompleteUse);
|
|
1068
|
+
this.releaseUseSignal.subscribe(this.onReleaseUse);
|
|
1069
|
+
this.startUseSignal.subscribe(this.onStartUse);
|
|
1070
|
+
this.startUseOnSignal.subscribe(this.onStartUseOn);
|
|
1071
|
+
this.stopUseSignal.subscribe(this.onStopUse);
|
|
1072
|
+
this.stopUseOnSignal.subscribe(this.onStopUseOn);
|
|
1073
|
+
this.hotbarChangeSignal.subscribe(this.onHotbarChange);
|
|
1074
|
+
this.inventoryItemChangeSignal.subscribe(this.onInventoryItemChange);
|
|
1075
|
+
this._wired = true;
|
|
1076
|
+
}
|
|
1077
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
1078
|
+
});
|
|
1079
|
+
__publicField(this, "onUseBefore", (event) => {
|
|
1080
|
+
const itemStack = event.itemStack;
|
|
1081
|
+
if (!this.isValidType(itemStack.typeId)) return;
|
|
1082
|
+
const i = this.IM_INDEX.get(itemStack.typeId);
|
|
1083
|
+
if (!i || !i.emitOnUse) return;
|
|
1084
|
+
const runId = system6.run(() => {
|
|
1085
|
+
try {
|
|
1086
|
+
this.onItemUsedEvent.emit({ player: event.source, itemStack: event.itemStack });
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
throw new Error(`${error}`);
|
|
1089
|
+
} finally {
|
|
1090
|
+
system6.clearRun(runId);
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
});
|
|
1094
|
+
__publicField(this, "onUseAfter", (_event) => {
|
|
1095
|
+
});
|
|
1096
|
+
__publicField(this, "onCompleteUse", (_event) => {
|
|
1097
|
+
});
|
|
1098
|
+
__publicField(this, "onReleaseUse", (_event) => {
|
|
1099
|
+
});
|
|
1100
|
+
__publicField(this, "onStartUse", (_event) => {
|
|
1101
|
+
});
|
|
1102
|
+
__publicField(this, "onStartUseOn", (_event) => {
|
|
1103
|
+
});
|
|
1104
|
+
__publicField(this, "onStopUse", (_event) => {
|
|
1105
|
+
});
|
|
1106
|
+
__publicField(this, "onStopUseOn", (_event) => {
|
|
1107
|
+
});
|
|
1108
|
+
__publicField(this, "onInventoryItemChange", (_event) => {
|
|
1109
|
+
});
|
|
1110
|
+
__publicField(this, "onHotbarChange", (event) => {
|
|
1111
|
+
const itemStack = event.itemStack;
|
|
1112
|
+
if (this.HOLD_INDEX.has(event.player.id)) this.releaseHold(event.player);
|
|
1113
|
+
if (!itemStack || itemStack && !this.isValidType(itemStack.typeId)) return;
|
|
1114
|
+
this.setNewHold(itemStack, event.player);
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
registerItem(itemRegistration) {
|
|
1118
|
+
if (Array.isArray(itemRegistration)) itemRegistration.forEach((i) => this.IM_INDEX.set(i.typeId, i));
|
|
1119
|
+
else this.IM_INDEX.set(itemRegistration.typeId, itemRegistration);
|
|
1120
|
+
}
|
|
1121
|
+
start(packId) {
|
|
1122
|
+
if (this._started) throw new Error("BFLIB: ItemHandler already started;");
|
|
1123
|
+
this._started = true;
|
|
1124
|
+
this.PACK_ID = packId;
|
|
1125
|
+
this.loadEventSignal.subscribe(this.onWorldLoad);
|
|
1126
|
+
}
|
|
1127
|
+
stop() {
|
|
1128
|
+
if (!this._started) return;
|
|
1129
|
+
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
1130
|
+
if (this._wired) {
|
|
1131
|
+
this.useBeforeSignal.unsubscribe(this.onUseBefore);
|
|
1132
|
+
this.useAfterSignal.unsubscribe(this.onUseAfter);
|
|
1133
|
+
this.completeUseSignal.unsubscribe(this.onCompleteUse);
|
|
1134
|
+
this.releaseUseSignal.unsubscribe(this.onReleaseUse);
|
|
1135
|
+
this.startUseSignal.unsubscribe(this.onStartUse);
|
|
1136
|
+
this.startUseOnSignal.unsubscribe(this.onStartUseOn);
|
|
1137
|
+
this.stopUseSignal.unsubscribe(this.onStopUse);
|
|
1138
|
+
this.stopUseOnSignal.unsubscribe(this.onStopUseOn);
|
|
1139
|
+
this.hotbarChangeSignal.unsubscribe(this.onHotbarChange);
|
|
1140
|
+
this.inventoryItemChangeSignal.unsubscribe(this.onInventoryItemChange);
|
|
1141
|
+
this._wired = false;
|
|
1142
|
+
}
|
|
1143
|
+
this._started = false;
|
|
1144
|
+
}
|
|
1145
|
+
setNewHold(itemStack, player) {
|
|
1146
|
+
this.onItemHeldEvent.emit({ player, itemStack });
|
|
1147
|
+
const i = this.IM_INDEX.get(itemStack.typeId);
|
|
1148
|
+
let instanceId = -1;
|
|
1149
|
+
if (i && i.emitWhileHolding) {
|
|
1150
|
+
instanceId = system6.runInterval(() => {
|
|
1151
|
+
this.whileHoldingItemEvent.emit({ player, itemStack });
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
this.HOLD_INDEX.set(player.id, { instanceId, itemStack });
|
|
1155
|
+
}
|
|
1156
|
+
releaseHold(player) {
|
|
1157
|
+
const holdData = this.HOLD_INDEX.get(player.id);
|
|
1158
|
+
if (!holdData) return;
|
|
1159
|
+
this.onItemUnheldEvent.emit({ player, itemStack: holdData.itemStack });
|
|
1160
|
+
if (holdData.instanceId !== -1) system6.clearRun(holdData.instanceId);
|
|
1161
|
+
this.HOLD_INDEX.delete(player.id);
|
|
1162
|
+
}
|
|
1163
|
+
isValidType(typeId) {
|
|
1164
|
+
if (this.PACK_ID && !typeId.startsWith(this.PACK_ID)) return false;
|
|
1165
|
+
return this.IM_INDEX.has(typeId);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
var ItemHandler = new SingletonItemHandler();
|
|
726
1169
|
export {
|
|
727
1170
|
BlockFactory_exports as BlockFactory,
|
|
728
1171
|
Command,
|
|
729
1172
|
ContainerWrapper,
|
|
1173
|
+
EntityHandler,
|
|
730
1174
|
IEntityWrapper,
|
|
731
1175
|
IForm,
|
|
732
1176
|
IPlayerWrapper,
|
|
1177
|
+
ItemHandler,
|
|
733
1178
|
MathUtils,
|
|
1179
|
+
PlayerHandler,
|
|
734
1180
|
RawText,
|
|
735
1181
|
RegisterForm,
|
|
736
1182
|
Signal,
|
|
737
1183
|
System,
|
|
1184
|
+
Thread,
|
|
738
1185
|
Vec2,
|
|
739
|
-
Vec3
|
|
740
|
-
_THREAD_
|
|
1186
|
+
Vec3
|
|
741
1187
|
};
|