@block_factory/lib 0.0.1 → 0.0.3
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/index.d.ts +32 -1
- package/index.js +486 -19
- package/index.ts +33 -1
- package/package.json +3 -2
- package/sys/Threads.d.ts +16 -0
- package/sys/Threads.ts +43 -0
- package/tsconfig.types.json +13 -0
- package/util/Forms/Form.d.ts +16 -0
- package/util/Forms/Form.ts +31 -0
- package/util/Forms/FormAction.d.ts +41 -0
- package/util/Forms/FormAction.ts +196 -0
- package/util/Forms/FormMessage.d.ts +30 -0
- package/util/Forms/FormMessage.ts +87 -0
- package/util/Forms/FormModal.d.ts +57 -0
- package/util/Forms/FormModal.ts +183 -0
- package/util/Forms/FormRegistry.d.ts +26 -0
- package/util/Forms/FormRegistry.ts +43 -0
- package/util/Signal.d.ts +8 -4
- package/util/Signal.ts +16 -58
- package/util/System.d.ts +4 -0
- package/util/System.ts +21 -0
- package/util/Wrapper/Container.d.ts +9 -0
- package/util/Wrapper/Container.ts +34 -0
- package/util/Wrapper/IEntity.d.ts +12 -0
- package/util/Wrapper/IEntity.ts +34 -0
- package/util/Wrapper/IPlayer.d.ts +12 -0
- package/util/Wrapper/IPlayer.ts +34 -0
- package/util/Form.d.ts +0 -75
- package/util/Form.ts +0 -246
package/index.d.ts
CHANGED
|
@@ -3,8 +3,29 @@ import { Signal } from "./util/Signal";
|
|
|
3
3
|
import { Vec2, Vec3 } from "./util/Vector";
|
|
4
4
|
import { RawText } from "./util/RawText";
|
|
5
5
|
import { Command } from "./util/Command";
|
|
6
|
+
import { System } from "./util/System";
|
|
6
7
|
|
|
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, _THREAD_
|
|
28
|
+
}
|
|
8
29
|
|
|
9
30
|
export declare const BlockFactory: {
|
|
10
31
|
MathUtils: typeof MathUtils;
|
|
@@ -13,4 +34,14 @@ export declare const BlockFactory: {
|
|
|
13
34
|
Vec3: typeof Vec3;
|
|
14
35
|
RawText: typeof RawText;
|
|
15
36
|
Command: typeof Command;
|
|
37
|
+
System: typeof System;
|
|
38
|
+
IForm: typeof IForm;
|
|
39
|
+
IActionFormData: typeof IActionFormData;
|
|
40
|
+
IModalFormData: typeof IModalFormData;
|
|
41
|
+
IMessageFormData: typeof IMessageFormData;
|
|
42
|
+
RegisterForm: typeof RegisterForm;
|
|
43
|
+
ContainerWrapper: typeof ContainerWrapper
|
|
44
|
+
IEntityWrapper: typeof IEntityWrapper
|
|
45
|
+
IPlayerWrapper: typeof IPlayerWrapper
|
|
46
|
+
_THREAD_: typeof _THREAD_;
|
|
16
47
|
};
|
package/index.js
CHANGED
|
@@ -77,31 +77,23 @@ var Signal = class {
|
|
|
77
77
|
constructor() {
|
|
78
78
|
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
get count() {
|
|
81
|
+
return this.listeners.size;
|
|
82
|
+
}
|
|
81
83
|
connect(callback) {
|
|
82
84
|
this.listeners.add(callback);
|
|
83
85
|
}
|
|
84
|
-
/** Disconnect a listener */
|
|
85
86
|
disconnect(callback) {
|
|
86
|
-
|
|
87
|
-
this.listeners.delete(callback);
|
|
88
|
-
return true;
|
|
89
|
-
} else {
|
|
90
|
-
this.listeners.clear();
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
87
|
+
return this.listeners.delete(callback);
|
|
93
88
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
this.connect(wrapper);
|
|
89
|
+
clear() {
|
|
90
|
+
this.listeners.clear();
|
|
91
|
+
}
|
|
92
|
+
isConnected(callback) {
|
|
93
|
+
return this.listeners.has(callback);
|
|
101
94
|
}
|
|
102
|
-
/** Emit signal to all listeners */
|
|
103
95
|
emit(data) {
|
|
104
|
-
for (const cb of
|
|
96
|
+
for (const cb of Array.from(this.listeners)) {
|
|
105
97
|
cb(data);
|
|
106
98
|
}
|
|
107
99
|
}
|
|
@@ -480,8 +472,11 @@ var Command;
|
|
|
480
472
|
((Command2) => {
|
|
481
473
|
class ICustomCommand {
|
|
482
474
|
constructor() {
|
|
475
|
+
/** Whether cheats must be enabled */
|
|
483
476
|
__publicField(this, "cheatsRequired");
|
|
477
|
+
/** Required command parameters */
|
|
484
478
|
__publicField(this, "mandatoryParameters");
|
|
479
|
+
/** Optional command parameters */
|
|
485
480
|
__publicField(this, "optionalParameters");
|
|
486
481
|
}
|
|
487
482
|
}
|
|
@@ -505,6 +500,458 @@ system.beforeEvents.startup.subscribe(
|
|
|
505
500
|
}
|
|
506
501
|
);
|
|
507
502
|
|
|
503
|
+
// util/System.ts
|
|
504
|
+
var System;
|
|
505
|
+
((System2) => {
|
|
506
|
+
System2.ProxyConstructor = ((_instance, source) => {
|
|
507
|
+
return new Proxy(_instance, {
|
|
508
|
+
get: (target, prop) => {
|
|
509
|
+
if (prop in target) return target[prop];
|
|
510
|
+
const v = source[prop];
|
|
511
|
+
return typeof v === "function" ? v.bind(source) : v;
|
|
512
|
+
},
|
|
513
|
+
set: (target, prop, value) => {
|
|
514
|
+
if (prop in target) {
|
|
515
|
+
target[prop] = value;
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
source[prop] = value;
|
|
519
|
+
return true;
|
|
520
|
+
},
|
|
521
|
+
has: (target, prop) => prop in target || prop in source,
|
|
522
|
+
ownKeys: () => [...Reflect.ownKeys(source), ...Reflect.ownKeys(_instance)],
|
|
523
|
+
getOwnPropertyDescriptor: (_t, prop) => Object.getOwnPropertyDescriptor(prop in _instance ? _instance : source, prop)
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
})(System || (System = {}));
|
|
527
|
+
|
|
528
|
+
// util/Forms/Form.ts
|
|
529
|
+
import { world } from "@minecraft/server";
|
|
530
|
+
import { uiManager } from "@minecraft/server-ui";
|
|
531
|
+
var _IForm = class _IForm {
|
|
532
|
+
static isOccupied(player) {
|
|
533
|
+
return _IForm.occupiedPlayers.has(player.id);
|
|
534
|
+
}
|
|
535
|
+
static closeForms(player) {
|
|
536
|
+
uiManager.closeAllForms(player);
|
|
537
|
+
}
|
|
538
|
+
static closeOccupiedForms() {
|
|
539
|
+
for (const playerId of _IForm.occupiedPlayers) {
|
|
540
|
+
const player = world.getEntity(playerId);
|
|
541
|
+
if (player) uiManager.closeAllForms(player);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
setOccupied(player, occupied) {
|
|
545
|
+
if (occupied) _IForm.occupiedPlayers.add(player.id);
|
|
546
|
+
else _IForm.occupiedPlayers.delete(player.id);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
__publicField(_IForm, "occupiedPlayers", /* @__PURE__ */ new Set());
|
|
550
|
+
__publicField(_IForm, "returnText", "Back");
|
|
551
|
+
var IForm = _IForm;
|
|
552
|
+
|
|
553
|
+
// util/Forms/FormAction.ts
|
|
554
|
+
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
|
+
|
|
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
|
|
814
|
+
import { Player as Player2, world as world2 } from "@minecraft/server";
|
|
815
|
+
var registeredForms = [];
|
|
816
|
+
function RegisterForm(itemId) {
|
|
817
|
+
return function(formCtor) {
|
|
818
|
+
const i = registeredForms.findIndex((r) => r.itemId === itemId);
|
|
819
|
+
if (i !== -1) registeredForms[i] = { itemId, formCtor };
|
|
820
|
+
else registeredForms.push({ itemId, formCtor });
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
function getFormForItem(itemId) {
|
|
824
|
+
return registeredForms.find((r) => r.itemId === itemId)?.formCtor;
|
|
825
|
+
}
|
|
826
|
+
world2.afterEvents.itemUse.subscribe((event) => {
|
|
827
|
+
const player = event.source;
|
|
828
|
+
if (!(player instanceof Player2)) return;
|
|
829
|
+
const item = event.itemStack;
|
|
830
|
+
if (!item) return;
|
|
831
|
+
const formCtor = getFormForItem(item.typeId);
|
|
832
|
+
if (!formCtor) return;
|
|
833
|
+
const form = new formCtor();
|
|
834
|
+
form.show(player).catch((e) => {
|
|
835
|
+
player.sendMessage(`\xA7cForm error: ${String(e)}`);
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
// util/Wrapper/Container.ts
|
|
840
|
+
var ContainerWrapper = class _ContainerWrapper {
|
|
841
|
+
constructor(source) {
|
|
842
|
+
__publicField(this, "source");
|
|
843
|
+
this.source = source;
|
|
844
|
+
return System.ProxyConstructor(this, source);
|
|
845
|
+
}
|
|
846
|
+
static wrap(source) {
|
|
847
|
+
return new _ContainerWrapper(source);
|
|
848
|
+
}
|
|
849
|
+
//======================== Interal ========================
|
|
850
|
+
reduce(slot, amount = 1) {
|
|
851
|
+
let itemStack = this.source.getItem(slot);
|
|
852
|
+
let currentAmount = itemStack?.amount || 0;
|
|
853
|
+
currentAmount -= amount;
|
|
854
|
+
if (itemStack != void 0 && currentAmount > 0) {
|
|
855
|
+
const newItemStack = itemStack;
|
|
856
|
+
newItemStack.amount = currentAmount;
|
|
857
|
+
itemStack = newItemStack;
|
|
858
|
+
} else itemStack = void 0;
|
|
859
|
+
this.source.setItem(slot, itemStack);
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
// util/Wrapper/IEntity.ts
|
|
864
|
+
import { EntityInventoryComponent } from "@minecraft/server";
|
|
865
|
+
var IEntityWrapper = class _IEntityWrapper {
|
|
866
|
+
constructor(source) {
|
|
867
|
+
__publicField(this, "source");
|
|
868
|
+
//======================== Interal ========================
|
|
869
|
+
__publicField(this, "isAlive", false);
|
|
870
|
+
this.source = source;
|
|
871
|
+
return System.ProxyConstructor(this, source);
|
|
872
|
+
}
|
|
873
|
+
static wrap(source) {
|
|
874
|
+
return new _IEntityWrapper(source);
|
|
875
|
+
}
|
|
876
|
+
get inventory() {
|
|
877
|
+
const i = this.source.getComponent(
|
|
878
|
+
EntityInventoryComponent.componentId
|
|
879
|
+
);
|
|
880
|
+
return ContainerWrapper.wrap(i.container);
|
|
881
|
+
}
|
|
882
|
+
test() {
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
// util/Wrapper/IPlayer.ts
|
|
887
|
+
import { EntityInventoryComponent as EntityInventoryComponent2 } from "@minecraft/server";
|
|
888
|
+
var IPlayerWrapper = class _IPlayerWrapper {
|
|
889
|
+
constructor(source) {
|
|
890
|
+
__publicField(this, "source");
|
|
891
|
+
//======================== Interal ========================
|
|
892
|
+
__publicField(this, "isAlive", false);
|
|
893
|
+
this.source = source;
|
|
894
|
+
return System.ProxyConstructor(this, source);
|
|
895
|
+
}
|
|
896
|
+
static wrap(player) {
|
|
897
|
+
return new _IPlayerWrapper(player);
|
|
898
|
+
}
|
|
899
|
+
get inventory() {
|
|
900
|
+
const i = this.source.getComponent(
|
|
901
|
+
EntityInventoryComponent2.componentId
|
|
902
|
+
);
|
|
903
|
+
return ContainerWrapper.wrap(i.container);
|
|
904
|
+
}
|
|
905
|
+
test() {
|
|
906
|
+
this.source.sendMessage(`${this.source.name} was tested`);
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// sys/Threads.ts
|
|
911
|
+
import { system as system2, TicksPerSecond } from "@minecraft/server";
|
|
912
|
+
var Threads = class _Threads {
|
|
913
|
+
constructor() {
|
|
914
|
+
__publicField(this, "MAIN", new Signal());
|
|
915
|
+
__publicField(this, "LATE", new Signal());
|
|
916
|
+
__publicField(this, "MAIN_INTERVAL_RATE", 0);
|
|
917
|
+
__publicField(this, "LATE_INTERVAL_RATE", TicksPerSecond);
|
|
918
|
+
__publicField(this, "_MAIN_ID");
|
|
919
|
+
__publicField(this, "_LATE_ID");
|
|
920
|
+
__publicField(this, "_delta", this.createDeltaTimer());
|
|
921
|
+
this._MAIN_ID = system2.runInterval(() => {
|
|
922
|
+
if (this.MAIN.count <= 0) return;
|
|
923
|
+
try {
|
|
924
|
+
const delta = this._delta();
|
|
925
|
+
this.MAIN.emit(delta);
|
|
926
|
+
} catch (error) {
|
|
927
|
+
throw Error(`ERROR: _THREAD_.MAIN:${this._MAIN_ID} | ${error}`);
|
|
928
|
+
}
|
|
929
|
+
}, this.MAIN_INTERVAL_RATE);
|
|
930
|
+
this._LATE_ID = system2.runInterval(() => {
|
|
931
|
+
if (this.LATE.count <= 0) return;
|
|
932
|
+
try {
|
|
933
|
+
this.LATE.emit();
|
|
934
|
+
} catch (error) {
|
|
935
|
+
throw Error(`ERROR: _THREAD_.LATE:${this._LATE_ID} | ${error}`);
|
|
936
|
+
}
|
|
937
|
+
}, this.LATE_INTERVAL_RATE);
|
|
938
|
+
}
|
|
939
|
+
static create() {
|
|
940
|
+
return new _Threads();
|
|
941
|
+
}
|
|
942
|
+
createDeltaTimer() {
|
|
943
|
+
let last = Date.now();
|
|
944
|
+
return function nextDelta() {
|
|
945
|
+
const now = Date.now();
|
|
946
|
+
const delta = (now - last) / 1e3;
|
|
947
|
+
last = now;
|
|
948
|
+
return delta;
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
var _THREAD_ = Threads.create();
|
|
953
|
+
_THREAD_.MAIN_INTERVAL_RATE = 10;
|
|
954
|
+
|
|
508
955
|
// index.ts
|
|
509
956
|
var BlockFactory;
|
|
510
957
|
((BlockFactory2) => {
|
|
@@ -514,13 +961,33 @@ var BlockFactory;
|
|
|
514
961
|
Vec3;
|
|
515
962
|
RawText;
|
|
516
963
|
Command;
|
|
964
|
+
System;
|
|
965
|
+
IForm;
|
|
966
|
+
IActionFormData;
|
|
967
|
+
IModalFormData;
|
|
968
|
+
IMessageFormData;
|
|
969
|
+
RegisterForm;
|
|
970
|
+
ContainerWrapper;
|
|
971
|
+
IEntityWrapper;
|
|
972
|
+
IPlayerWrapper;
|
|
973
|
+
_THREAD_;
|
|
517
974
|
})(BlockFactory || (BlockFactory = {}));
|
|
518
975
|
export {
|
|
519
976
|
BlockFactory,
|
|
520
977
|
Command,
|
|
978
|
+
ContainerWrapper,
|
|
979
|
+
IActionFormData,
|
|
980
|
+
IEntityWrapper,
|
|
981
|
+
IForm,
|
|
982
|
+
IMessageFormData,
|
|
983
|
+
IModalFormData,
|
|
984
|
+
IPlayerWrapper,
|
|
521
985
|
MathUtils,
|
|
522
986
|
RawText,
|
|
987
|
+
RegisterForm,
|
|
523
988
|
Signal,
|
|
989
|
+
System,
|
|
524
990
|
Vec2,
|
|
525
|
-
Vec3
|
|
991
|
+
Vec3,
|
|
992
|
+
_THREAD_
|
|
526
993
|
};
|
package/index.ts
CHANGED
|
@@ -3,8 +3,30 @@ import { Signal } from "./util/Signal";
|
|
|
3
3
|
import { Vec2, Vec3 } from "./util/Vector";
|
|
4
4
|
import { RawText } from "./util/RawText";
|
|
5
5
|
import { Command } from "./util/Command";
|
|
6
|
+
import { System } from "./util/System";
|
|
6
7
|
|
|
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
|
+
};
|
|
8
30
|
|
|
9
31
|
export namespace BlockFactory {
|
|
10
32
|
MathUtils;
|
|
@@ -13,4 +35,14 @@ export namespace BlockFactory {
|
|
|
13
35
|
Vec3;
|
|
14
36
|
RawText;
|
|
15
37
|
Command;
|
|
38
|
+
System;
|
|
39
|
+
IForm;
|
|
40
|
+
IActionFormData;
|
|
41
|
+
IModalFormData;
|
|
42
|
+
IMessageFormData;
|
|
43
|
+
RegisterForm;
|
|
44
|
+
ContainerWrapper;
|
|
45
|
+
IEntityWrapper;
|
|
46
|
+
IPlayerWrapper
|
|
47
|
+
_THREAD_;
|
|
16
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@block_factory/lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"description": "Typescript Library for Minecraft Bedrock Edition",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"esbuild": "^0.27.2"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "node esbuild.config.mjs"
|
|
30
|
+
"build": "node esbuild.config.mjs",
|
|
31
|
+
"build:types": "tsc -p tsconfig.types.json"
|
|
31
32
|
}
|
|
32
33
|
}
|
package/sys/Threads.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Signal } from "../util/Signal";
|
|
2
|
+
declare class Threads {
|
|
3
|
+
static create(): Threads;
|
|
4
|
+
readonly MAIN: Signal<number>;
|
|
5
|
+
readonly LATE: Signal<void>;
|
|
6
|
+
MAIN_INTERVAL_RATE: number;
|
|
7
|
+
LATE_INTERVAL_RATE: number;
|
|
8
|
+
private _MAIN_ID;
|
|
9
|
+
private _LATE_ID;
|
|
10
|
+
private _delta;
|
|
11
|
+
private constructor();
|
|
12
|
+
private createDeltaTimer;
|
|
13
|
+
}
|
|
14
|
+
export declare const _THREAD_: Threads;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=Threads.d.ts.map
|