@block_factory/lib 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_module/BlockFactory.ts +18 -0
- package/_module/sys/Threads.ts +43 -0
- package/_module/util/Forms/Form.ts +31 -0
- package/{util → _module/util/Forms}/FormAction.ts +15 -26
- package/_module/util/Forms/FormMessage.ts +87 -0
- package/_module/util/Forms/FormModal.ts +183 -0
- package/_module/util/Forms/FormRegistry.ts +43 -0
- package/_module/util/RawText.ts +75 -0
- package/_module/util/Signal.ts +31 -0
- package/_module/util/System.ts +21 -0
- package/_module/util/Wrapper/Container.ts +34 -0
- package/_module/util/Wrapper/IEntity.ts +34 -0
- package/_module/util/Wrapper/IPlayer.ts +34 -0
- package/_types/_module/BlockFactory.d.ts +16 -0
- package/_types/_module/BlockFactory.d.ts.map +1 -0
- package/_types/_module/sys/Threads.d.ts +16 -0
- package/_types/_module/sys/Threads.d.ts.map +1 -0
- package/_types/_module/util/Command.d.ts +92 -0
- package/_types/_module/util/Command.d.ts.map +1 -0
- package/_types/_module/util/Forms/Form.d.ts +12 -0
- 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/_types/_module/util/Forms/FormMessage.d.ts +24 -0
- package/_types/_module/util/Forms/FormMessage.d.ts.map +1 -0
- package/_types/_module/util/Forms/FormModal.d.ts +66 -0
- 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/_types/_module/util/Signal.d.ts +11 -0
- package/_types/_module/util/Signal.d.ts.map +1 -0
- package/_types/_module/util/System.d.ts +4 -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 +9 -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 +12 -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 +303 -215
- package/index.ts +2 -21
- package/package.json +9 -7
- package/tsconfig.types.json +13 -0
- package/index.d.ts +0 -20
- package/util/Command.d.ts +0 -23
- package/util/Form.d.ts +0 -10
- package/util/Form.ts +0 -15
- package/util/FormAction.d.ts +0 -41
- package/util/RawText.d.ts +0 -33
- package/util/RawText.ts +0 -76
- package/util/Signal.d.ts +0 -9
- package/util/Signal.ts +0 -73
- package/util/Vector.d.ts +0 -60
- package/util/_Form.ts +0 -246
- /package/{util → _module/util}/Command.ts +0 -0
- /package/{util → _module/util}/Math.ts +0 -0
- /package/{util → _module/util}/Vector.ts +0 -0
package/index.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// _module/BlockFactory.ts
|
|
8
|
+
var BlockFactory_exports = {};
|
|
9
|
+
__export(BlockFactory_exports, {
|
|
10
|
+
Command: () => Command,
|
|
11
|
+
ContainerWrapper: () => ContainerWrapper,
|
|
12
|
+
IEntityWrapper: () => IEntityWrapper,
|
|
13
|
+
IForm: () => IForm,
|
|
14
|
+
IPlayerWrapper: () => IPlayerWrapper,
|
|
15
|
+
MathUtils: () => MathUtils,
|
|
16
|
+
RawText: () => RawText,
|
|
17
|
+
RegisterForm: () => RegisterForm,
|
|
18
|
+
Signal: () => Signal,
|
|
19
|
+
System: () => System,
|
|
20
|
+
Vec2: () => Vec2,
|
|
21
|
+
Vec3: () => Vec3,
|
|
22
|
+
_THREAD_: () => _THREAD_
|
|
23
|
+
});
|
|
4
24
|
|
|
5
|
-
// util/Math.ts
|
|
25
|
+
// _module/util/Math.ts
|
|
6
26
|
var MathUtils;
|
|
7
27
|
((MathUtils2) => {
|
|
8
28
|
function clamp(value, min, max) {
|
|
@@ -72,42 +92,34 @@ var MathUtils;
|
|
|
72
92
|
;
|
|
73
93
|
})(MathUtils || (MathUtils = {}));
|
|
74
94
|
|
|
75
|
-
// util/Signal.ts
|
|
95
|
+
// _module/util/Signal.ts
|
|
76
96
|
var Signal = class {
|
|
77
97
|
constructor() {
|
|
78
|
-
|
|
98
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
99
|
+
}
|
|
100
|
+
get count() {
|
|
101
|
+
return this.listeners.size;
|
|
79
102
|
}
|
|
80
|
-
/** Connect a listener */
|
|
81
103
|
connect(callback) {
|
|
82
104
|
this.listeners.add(callback);
|
|
83
105
|
}
|
|
84
|
-
/** Disconnect a listener */
|
|
85
106
|
disconnect(callback) {
|
|
86
|
-
|
|
87
|
-
this.listeners.delete(callback);
|
|
88
|
-
return true;
|
|
89
|
-
} else {
|
|
90
|
-
this.listeners.clear();
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
107
|
+
return this.listeners.delete(callback);
|
|
93
108
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
this.connect(wrapper);
|
|
109
|
+
clear() {
|
|
110
|
+
this.listeners.clear();
|
|
111
|
+
}
|
|
112
|
+
isConnected(callback) {
|
|
113
|
+
return this.listeners.has(callback);
|
|
101
114
|
}
|
|
102
|
-
/** Emit signal to all listeners */
|
|
103
115
|
emit(data) {
|
|
104
|
-
for (const cb of
|
|
116
|
+
for (const cb of Array.from(this.listeners)) {
|
|
105
117
|
cb(data);
|
|
106
118
|
}
|
|
107
119
|
}
|
|
108
120
|
};
|
|
109
121
|
|
|
110
|
-
// util/Vector.ts
|
|
122
|
+
// _module/util/Vector.ts
|
|
111
123
|
var _Vec2 = class _Vec2 {
|
|
112
124
|
/**
|
|
113
125
|
* Creates a new Vec2.
|
|
@@ -235,15 +247,15 @@ var _Vec2 = class _Vec2 {
|
|
|
235
247
|
}
|
|
236
248
|
};
|
|
237
249
|
/** Constant zero vector (0, 0) */
|
|
238
|
-
|
|
250
|
+
_Vec2.ZERO = new _Vec2(0, 0);
|
|
239
251
|
/** Up direction (0, 1) */
|
|
240
|
-
|
|
252
|
+
_Vec2.UP = new _Vec2(0, 1);
|
|
241
253
|
/** Down direction (0, -1) */
|
|
242
|
-
|
|
254
|
+
_Vec2.DOWN = new _Vec2(0, -1);
|
|
243
255
|
/** Left direction (-1, 0) */
|
|
244
|
-
|
|
256
|
+
_Vec2.LEFT = new _Vec2(-1, 0);
|
|
245
257
|
/** Right direction (1, 0) */
|
|
246
|
-
|
|
258
|
+
_Vec2.RIGHT = new _Vec2(1, 0);
|
|
247
259
|
var Vec2 = _Vec2;
|
|
248
260
|
var _Vec3 = class _Vec3 {
|
|
249
261
|
/**
|
|
@@ -404,89 +416,104 @@ var _Vec3 = class _Vec3 {
|
|
|
404
416
|
}
|
|
405
417
|
};
|
|
406
418
|
/** Constant zero vector (0, 0, 0) */
|
|
407
|
-
|
|
419
|
+
_Vec3.ZERO = new _Vec3(0, 0, 0);
|
|
408
420
|
/** Up direction (0, 1, 0) */
|
|
409
|
-
|
|
421
|
+
_Vec3.UP = new _Vec3(0, 1, 0);
|
|
410
422
|
/** Down direction (0, -1, 0) */
|
|
411
|
-
|
|
423
|
+
_Vec3.DOWN = new _Vec3(0, -1, 0);
|
|
412
424
|
/** Left direction (-1, 0, 0) */
|
|
413
|
-
|
|
425
|
+
_Vec3.LEFT = new _Vec3(-1, 0, 0);
|
|
414
426
|
/** Right direction (1, 0, 0) */
|
|
415
|
-
|
|
427
|
+
_Vec3.RIGHT = new _Vec3(1, 0, 0);
|
|
416
428
|
/** Forward direction (0, 0, 1) */
|
|
417
|
-
|
|
429
|
+
_Vec3.FORWARD = new _Vec3(0, 0, 1);
|
|
418
430
|
/** Backward direction (0, 0, -1) */
|
|
419
|
-
|
|
431
|
+
_Vec3.BACK = new _Vec3(0, 0, -1);
|
|
420
432
|
/** West direction (-1, 0, 0) */
|
|
421
|
-
|
|
433
|
+
_Vec3.WEST = new _Vec3(-1, 0, 0);
|
|
422
434
|
/** East direction (1, 0, 0) */
|
|
423
|
-
|
|
435
|
+
_Vec3.EAST = new _Vec3(1, 0, 0);
|
|
424
436
|
/** North direction (0, 0, 1) */
|
|
425
|
-
|
|
437
|
+
_Vec3.NORTH = new _Vec3(0, 0, 1);
|
|
426
438
|
/** South direction (0, 0, -1) */
|
|
427
|
-
|
|
439
|
+
_Vec3.SOUTH = new _Vec3(0, 0, -1);
|
|
428
440
|
var Vec3 = _Vec3;
|
|
429
441
|
|
|
430
|
-
// util/RawText.ts
|
|
431
|
-
var RawText
|
|
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
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
442
|
+
// _module/util/RawText.ts
|
|
443
|
+
var RawText = class {
|
|
444
|
+
/**
|
|
445
|
+
* Creates a simple text component.
|
|
446
|
+
* @param value - The text value.
|
|
447
|
+
* @returns Text component object.
|
|
448
|
+
*/
|
|
449
|
+
static text(value) {
|
|
450
|
+
return { text: value };
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Creates a translation component with optional 'with' parameters.
|
|
454
|
+
* @param key - The translation key.
|
|
455
|
+
* @param params - The optional parameters for translation.
|
|
456
|
+
* @returns Translation component object.
|
|
457
|
+
*/
|
|
458
|
+
static translate(key, ...params) {
|
|
459
|
+
return {
|
|
460
|
+
translate: key,
|
|
461
|
+
with: params.length ? params : void 0
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Creates a score component.
|
|
466
|
+
* @param name - The entity's name whose score is being displayed.
|
|
467
|
+
* @param objective - The name of the score objective.
|
|
468
|
+
* @returns Score component object.
|
|
469
|
+
*/
|
|
470
|
+
static score(name, objective) {
|
|
471
|
+
return { score: { name, objective } };
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Wraps various text components into a rawtext structure.
|
|
475
|
+
* @param rawText - The raw text components.
|
|
476
|
+
* @returns Raw text object.
|
|
477
|
+
*/
|
|
478
|
+
static message(...rawText) {
|
|
479
|
+
return { rawtext: rawText };
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Common formatting and color codes.
|
|
484
|
+
*/
|
|
485
|
+
RawText.FORMAT = {
|
|
486
|
+
DarkRed: "\xA74",
|
|
487
|
+
Red: "\xA7c",
|
|
488
|
+
Gold: "\xA76",
|
|
489
|
+
Yellow: "\xA7e",
|
|
490
|
+
Green: "\xA72",
|
|
491
|
+
Lime: "\xA7a",
|
|
492
|
+
Aqua: "\xA7b",
|
|
493
|
+
Cyan: "\xA73",
|
|
494
|
+
DarkBlue: "\xA71",
|
|
495
|
+
Blue: "\xA79",
|
|
496
|
+
Magenta: "\xA7d",
|
|
497
|
+
Purple: "\xA75",
|
|
498
|
+
White: "\xA7f",
|
|
499
|
+
Gray: "\xA77",
|
|
500
|
+
DarkGray: "\xA78",
|
|
501
|
+
Black: "\xA70",
|
|
502
|
+
Obfuscated: "\xA7k",
|
|
503
|
+
Bold: "\xA7l",
|
|
504
|
+
StrikeThrough: "\xA7m",
|
|
505
|
+
Italic: "\xA7o",
|
|
506
|
+
Reset: "\xA7r",
|
|
507
|
+
NewLine: "\n"
|
|
508
|
+
};
|
|
474
509
|
|
|
475
|
-
// util/Command.ts
|
|
510
|
+
// _module/util/Command.ts
|
|
476
511
|
import {
|
|
477
512
|
system
|
|
478
513
|
} from "@minecraft/server";
|
|
479
514
|
var Command;
|
|
480
515
|
((Command2) => {
|
|
481
516
|
class ICustomCommand {
|
|
482
|
-
constructor() {
|
|
483
|
-
/** Whether cheats must be enabled */
|
|
484
|
-
__publicField(this, "cheatsRequired");
|
|
485
|
-
/** Required command parameters */
|
|
486
|
-
__publicField(this, "mandatoryParameters");
|
|
487
|
-
/** Optional command parameters */
|
|
488
|
-
__publicField(this, "optionalParameters");
|
|
489
|
-
}
|
|
490
517
|
}
|
|
491
518
|
Command2.ICustomCommand = ICustomCommand;
|
|
492
519
|
;
|
|
@@ -508,146 +535,207 @@ system.beforeEvents.startup.subscribe(
|
|
|
508
535
|
}
|
|
509
536
|
);
|
|
510
537
|
|
|
511
|
-
// util/
|
|
512
|
-
var
|
|
538
|
+
// _module/util/System.ts
|
|
539
|
+
var System;
|
|
540
|
+
((System2) => {
|
|
541
|
+
System2.ProxyConstructor = ((_instance, source) => {
|
|
542
|
+
return new Proxy(_instance, {
|
|
543
|
+
get: (target, prop) => {
|
|
544
|
+
if (prop in target) return target[prop];
|
|
545
|
+
const v = source[prop];
|
|
546
|
+
return typeof v === "function" ? v.bind(source) : v;
|
|
547
|
+
},
|
|
548
|
+
set: (target, prop, value) => {
|
|
549
|
+
if (prop in target) {
|
|
550
|
+
target[prop] = value;
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
source[prop] = value;
|
|
554
|
+
return true;
|
|
555
|
+
},
|
|
556
|
+
has: (target, prop) => prop in target || prop in source,
|
|
557
|
+
ownKeys: () => [...Reflect.ownKeys(source), ...Reflect.ownKeys(_instance)],
|
|
558
|
+
getOwnPropertyDescriptor: (_t, prop) => Object.getOwnPropertyDescriptor(prop in _instance ? _instance : source, prop)
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
})(System || (System = {}));
|
|
562
|
+
|
|
563
|
+
// _module/util/Forms/Form.ts
|
|
564
|
+
import { world } from "@minecraft/server";
|
|
565
|
+
import { uiManager } from "@minecraft/server-ui";
|
|
566
|
+
var _IForm = class _IForm {
|
|
513
567
|
static isOccupied(player) {
|
|
514
|
-
return
|
|
568
|
+
return _IForm.occupiedPlayers.has(player.id);
|
|
569
|
+
}
|
|
570
|
+
static closeForms(player) {
|
|
571
|
+
uiManager.closeAllForms(player);
|
|
572
|
+
}
|
|
573
|
+
static closeOccupiedForms() {
|
|
574
|
+
for (const playerId of _IForm.occupiedPlayers) {
|
|
575
|
+
const player = world.getEntity(playerId);
|
|
576
|
+
if (player) uiManager.closeAllForms(player);
|
|
577
|
+
}
|
|
515
578
|
}
|
|
516
579
|
setOccupied(player, occupied) {
|
|
517
|
-
if (occupied)
|
|
518
|
-
else
|
|
580
|
+
if (occupied) _IForm.occupiedPlayers.add(player.id);
|
|
581
|
+
else _IForm.occupiedPlayers.delete(player.id);
|
|
519
582
|
}
|
|
520
583
|
};
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
var
|
|
584
|
+
_IForm.occupiedPlayers = /* @__PURE__ */ new Set();
|
|
585
|
+
_IForm.returnText = "Back";
|
|
586
|
+
var IForm = _IForm;
|
|
524
587
|
|
|
525
|
-
// util/FormAction.ts
|
|
588
|
+
// _module/util/Forms/FormAction.ts
|
|
526
589
|
import { ActionFormData } from "@minecraft/server-ui";
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
590
|
+
|
|
591
|
+
// _module/util/Forms/FormRegistry.ts
|
|
592
|
+
import { Player as Player2, world as world2 } from "@minecraft/server";
|
|
593
|
+
var registeredForms = [];
|
|
594
|
+
function RegisterForm(itemId) {
|
|
595
|
+
return function(formCtor) {
|
|
596
|
+
const i = registeredForms.findIndex((r) => r.itemId === itemId);
|
|
597
|
+
if (i !== -1) registeredForms[i] = { itemId, formCtor };
|
|
598
|
+
else registeredForms.push({ itemId, formCtor });
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
function getFormForItem(itemId) {
|
|
602
|
+
return registeredForms.find((r) => r.itemId === itemId)?.formCtor;
|
|
603
|
+
}
|
|
604
|
+
world2.afterEvents.itemUse.subscribe((event) => {
|
|
605
|
+
const player = event.source;
|
|
606
|
+
if (!(player instanceof Player2)) return;
|
|
607
|
+
const item = event.itemStack;
|
|
608
|
+
if (!item) return;
|
|
609
|
+
const formCtor = getFormForItem(item.typeId);
|
|
610
|
+
if (!formCtor) return;
|
|
611
|
+
const form = new formCtor();
|
|
612
|
+
form.show(player).catch((e) => {
|
|
613
|
+
player.sendMessage(`\xA7cForm error: ${String(e)}`);
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
// _module/util/Wrapper/Container.ts
|
|
618
|
+
var ContainerWrapper = class _ContainerWrapper {
|
|
619
|
+
constructor(source) {
|
|
620
|
+
this.source = source;
|
|
621
|
+
return System.ProxyConstructor(this, source);
|
|
622
|
+
}
|
|
623
|
+
static wrap(source) {
|
|
624
|
+
return new _ContainerWrapper(source);
|
|
625
|
+
}
|
|
626
|
+
//======================== Interal ========================
|
|
627
|
+
reduce(slot, amount = 1) {
|
|
628
|
+
let itemStack = this.source.getItem(slot);
|
|
629
|
+
let currentAmount = itemStack?.amount || 0;
|
|
630
|
+
currentAmount -= amount;
|
|
631
|
+
if (itemStack != void 0 && currentAmount > 0) {
|
|
632
|
+
const newItemStack = itemStack;
|
|
633
|
+
newItemStack.amount = currentAmount;
|
|
634
|
+
itemStack = newItemStack;
|
|
635
|
+
} else itemStack = void 0;
|
|
636
|
+
this.source.setItem(slot, itemStack);
|
|
569
637
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// _module/util/Wrapper/IEntity.ts
|
|
641
|
+
import { EntityInventoryComponent } from "@minecraft/server";
|
|
642
|
+
var IEntityWrapper = class _IEntityWrapper {
|
|
643
|
+
constructor(source) {
|
|
644
|
+
//======================== Interal ========================
|
|
645
|
+
this.isAlive = false;
|
|
646
|
+
this.source = source;
|
|
647
|
+
return System.ProxyConstructor(this, source);
|
|
648
|
+
}
|
|
649
|
+
static wrap(source) {
|
|
650
|
+
return new _IEntityWrapper(source);
|
|
651
|
+
}
|
|
652
|
+
get inventory() {
|
|
653
|
+
const i = this.source.getComponent(
|
|
654
|
+
EntityInventoryComponent.componentId
|
|
655
|
+
);
|
|
656
|
+
return ContainerWrapper.wrap(i.container);
|
|
580
657
|
}
|
|
581
|
-
|
|
582
|
-
return await this._showInternal(player, returnStack);
|
|
658
|
+
test() {
|
|
583
659
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// _module/util/Wrapper/IPlayer.ts
|
|
663
|
+
import { EntityInventoryComponent as EntityInventoryComponent2 } from "@minecraft/server";
|
|
664
|
+
var IPlayerWrapper = class _IPlayerWrapper {
|
|
665
|
+
constructor(source) {
|
|
666
|
+
//======================== Interal ========================
|
|
667
|
+
this.isAlive = false;
|
|
668
|
+
this.source = source;
|
|
669
|
+
return System.ProxyConstructor(this, source);
|
|
670
|
+
}
|
|
671
|
+
static wrap(player) {
|
|
672
|
+
return new _IPlayerWrapper(player);
|
|
673
|
+
}
|
|
674
|
+
get inventory() {
|
|
675
|
+
const i = this.source.getComponent(
|
|
676
|
+
EntityInventoryComponent2.componentId
|
|
677
|
+
);
|
|
678
|
+
return ContainerWrapper.wrap(i.container);
|
|
591
679
|
}
|
|
592
|
-
|
|
593
|
-
this.
|
|
594
|
-
this._buttons.clear();
|
|
595
|
-
this._nextButtonIndex = 0;
|
|
596
|
-
this.build(player);
|
|
597
|
-
if (returnStack.length > 0) {
|
|
598
|
-
this.form.button(Form.returnText);
|
|
599
|
-
this._buttons.set(this._nextButtonIndex, {
|
|
600
|
-
id: RETURN_ID,
|
|
601
|
-
subForm: returnStack[returnStack.length - 1],
|
|
602
|
-
allowReturn: true
|
|
603
|
-
});
|
|
604
|
-
this._nextButtonIndex++;
|
|
605
|
-
}
|
|
606
|
-
const response = await this.form.show(player);
|
|
607
|
-
if (response.canceled) {
|
|
608
|
-
const wrapped2 = this._wrapResponse(response, void 0);
|
|
609
|
-
this.onCancel?.(player, wrapped2);
|
|
610
|
-
return wrapped2;
|
|
611
|
-
}
|
|
612
|
-
const meta = response.selection !== void 0 ? this._buttons.get(response.selection) : void 0;
|
|
613
|
-
if (meta?.id === RETURN_ID && meta.subForm) {
|
|
614
|
-
const prevCtor = returnStack[returnStack.length - 1];
|
|
615
|
-
const newStack = returnStack.slice(0, -1);
|
|
616
|
-
const prev = new prevCtor();
|
|
617
|
-
return await prev._showChained(player, newStack);
|
|
618
|
-
}
|
|
619
|
-
const wrapped = this._wrapResponse(response, meta?.id);
|
|
620
|
-
this.onSubmit(player, wrapped);
|
|
621
|
-
if (meta?.subForm) {
|
|
622
|
-
const next = new meta.subForm();
|
|
623
|
-
const allowReturn = meta.allowReturn ?? true;
|
|
624
|
-
const nextStack = allowReturn ? [...returnStack, this.constructor] : [...returnStack];
|
|
625
|
-
return await next._showChained(player, nextStack);
|
|
626
|
-
}
|
|
627
|
-
return wrapped;
|
|
680
|
+
test() {
|
|
681
|
+
this.source.sendMessage(`${this.source.name} was tested`);
|
|
628
682
|
}
|
|
629
683
|
};
|
|
630
684
|
|
|
631
|
-
//
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
685
|
+
// _module/sys/Threads.ts
|
|
686
|
+
import { system as system2, TicksPerSecond } from "@minecraft/server";
|
|
687
|
+
var Threads = class _Threads {
|
|
688
|
+
constructor() {
|
|
689
|
+
this.MAIN = new Signal();
|
|
690
|
+
this.LATE = new Signal();
|
|
691
|
+
this.MAIN_INTERVAL_RATE = 0;
|
|
692
|
+
this.LATE_INTERVAL_RATE = TicksPerSecond;
|
|
693
|
+
this._delta = this.createDeltaTimer();
|
|
694
|
+
this._MAIN_ID = system2.runInterval(() => {
|
|
695
|
+
if (this.MAIN.count <= 0) return;
|
|
696
|
+
try {
|
|
697
|
+
const delta = this._delta();
|
|
698
|
+
this.MAIN.emit(delta);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
throw Error(`ERROR: _THREAD_.MAIN:${this._MAIN_ID} | ${error}`);
|
|
701
|
+
}
|
|
702
|
+
}, this.MAIN_INTERVAL_RATE);
|
|
703
|
+
this._LATE_ID = system2.runInterval(() => {
|
|
704
|
+
if (this.LATE.count <= 0) return;
|
|
705
|
+
try {
|
|
706
|
+
this.LATE.emit();
|
|
707
|
+
} catch (error) {
|
|
708
|
+
throw Error(`ERROR: _THREAD_.LATE:${this._LATE_ID} | ${error}`);
|
|
709
|
+
}
|
|
710
|
+
}, this.LATE_INTERVAL_RATE);
|
|
711
|
+
}
|
|
712
|
+
static create() {
|
|
713
|
+
return new _Threads();
|
|
714
|
+
}
|
|
715
|
+
createDeltaTimer() {
|
|
716
|
+
let last = Date.now();
|
|
717
|
+
return function nextDelta() {
|
|
718
|
+
const now = Date.now();
|
|
719
|
+
const delta = (now - last) / 1e3;
|
|
720
|
+
last = now;
|
|
721
|
+
return delta;
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
var _THREAD_ = Threads.create();
|
|
643
726
|
export {
|
|
644
|
-
BlockFactory,
|
|
727
|
+
BlockFactory_exports as BlockFactory,
|
|
645
728
|
Command,
|
|
646
|
-
|
|
647
|
-
|
|
729
|
+
ContainerWrapper,
|
|
730
|
+
IEntityWrapper,
|
|
731
|
+
IForm,
|
|
732
|
+
IPlayerWrapper,
|
|
648
733
|
MathUtils,
|
|
649
734
|
RawText,
|
|
735
|
+
RegisterForm,
|
|
650
736
|
Signal,
|
|
737
|
+
System,
|
|
651
738
|
Vec2,
|
|
652
|
-
Vec3
|
|
739
|
+
Vec3,
|
|
740
|
+
_THREAD_
|
|
653
741
|
};
|
package/index.ts
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Vec2, Vec3 } from "./util/Vector";
|
|
4
|
-
import { RawText } from "./util/RawText";
|
|
5
|
-
import { Command } from "./util/Command";
|
|
6
|
-
import { Form } from "./util/Form";
|
|
7
|
-
import { ActionFormCtor, IButtonOptions, IActionFormResponse, IActionFormData } from "./util/FormAction";
|
|
8
|
-
|
|
9
|
-
export { MathUtils, Signal, Vec2, Vec3, RawText, Command, Form, ActionFormCtor, IButtonOptions, IActionFormResponse, IActionFormData };
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export namespace BlockFactory {
|
|
13
|
-
MathUtils;
|
|
14
|
-
Signal;
|
|
15
|
-
Vec2;
|
|
16
|
-
Vec3;
|
|
17
|
-
RawText;
|
|
18
|
-
Command;
|
|
19
|
-
Form;
|
|
20
|
-
IActionFormData;
|
|
21
|
-
}
|
|
1
|
+
export * from "./_module/BlockFactory";
|
|
2
|
+
export * as BlockFactory from "./_module/BlockFactory";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@block_factory/lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"description": "Typescript Library for Minecraft Bedrock Edition",
|
|
@@ -17,16 +17,18 @@
|
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/Block-Factory-Studio/bf-
|
|
20
|
+
"url": "https://github.com/Block-Factory-Studio/bf-mcbr-library/issues"
|
|
21
21
|
},
|
|
22
|
-
"homepage": "https://github.com/Block-Factory-Studio/bf-
|
|
22
|
+
"homepage": "https://github.com/Block-Factory-Studio/bf-mcbr-library#readme",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@minecraft/server": "^2.4.0",
|
|
25
|
-
"@minecraft/server-ui": "^2.0.0"
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
"@minecraft/server-ui": "^2.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"esbuild": "^0.25.9"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
|
-
"build": "node esbuild.config.mjs"
|
|
31
|
+
"build": "node esbuild.config.mjs",
|
|
32
|
+
"build:types": "tsc -p tsconfig.types.json"
|
|
31
33
|
}
|
|
32
34
|
}
|