@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.
Files changed (65) hide show
  1. package/_module/BlockFactory.ts +18 -0
  2. package/_module/sys/Threads.ts +43 -0
  3. package/_module/util/Forms/Form.ts +31 -0
  4. package/{util → _module/util/Forms}/FormAction.ts +15 -26
  5. package/_module/util/Forms/FormMessage.ts +87 -0
  6. package/_module/util/Forms/FormModal.ts +183 -0
  7. package/_module/util/Forms/FormRegistry.ts +43 -0
  8. package/_module/util/RawText.ts +75 -0
  9. package/_module/util/Signal.ts +31 -0
  10. package/_module/util/System.ts +21 -0
  11. package/_module/util/Wrapper/Container.ts +34 -0
  12. package/_module/util/Wrapper/IEntity.ts +34 -0
  13. package/_module/util/Wrapper/IPlayer.ts +34 -0
  14. package/_types/_module/BlockFactory.d.ts +16 -0
  15. package/_types/_module/BlockFactory.d.ts.map +1 -0
  16. package/_types/_module/sys/Threads.d.ts +16 -0
  17. package/_types/_module/sys/Threads.d.ts.map +1 -0
  18. package/_types/_module/util/Command.d.ts +92 -0
  19. package/_types/_module/util/Command.d.ts.map +1 -0
  20. package/_types/_module/util/Forms/Form.d.ts +12 -0
  21. package/_types/_module/util/Forms/Form.d.ts.map +1 -0
  22. package/_types/_module/util/Forms/FormAction.d.ts +73 -0
  23. package/_types/_module/util/Forms/FormAction.d.ts.map +1 -0
  24. package/_types/_module/util/Forms/FormMessage.d.ts +24 -0
  25. package/_types/_module/util/Forms/FormMessage.d.ts.map +1 -0
  26. package/_types/_module/util/Forms/FormModal.d.ts +66 -0
  27. package/_types/_module/util/Forms/FormModal.d.ts.map +1 -0
  28. package/_types/_module/util/Forms/FormRegistry.d.ts +12 -0
  29. package/_types/_module/util/Forms/FormRegistry.d.ts.map +1 -0
  30. package/{util → _types/_module/util}/Math.d.ts +8 -2
  31. package/_types/_module/util/Math.d.ts.map +1 -0
  32. package/_types/_module/util/RawText.d.ts +60 -0
  33. package/_types/_module/util/RawText.d.ts.map +1 -0
  34. package/_types/_module/util/Signal.d.ts +11 -0
  35. package/_types/_module/util/Signal.d.ts.map +1 -0
  36. package/_types/_module/util/System.d.ts +4 -0
  37. package/_types/_module/util/System.d.ts.map +1 -0
  38. package/_types/_module/util/Vector.d.ts +212 -0
  39. package/_types/_module/util/Vector.d.ts.map +1 -0
  40. package/_types/_module/util/Wrapper/Container.d.ts +9 -0
  41. package/_types/_module/util/Wrapper/Container.d.ts.map +1 -0
  42. package/_types/_module/util/Wrapper/IEntity.d.ts +12 -0
  43. package/_types/_module/util/Wrapper/IEntity.d.ts.map +1 -0
  44. package/_types/_module/util/Wrapper/IPlayer.d.ts +12 -0
  45. package/_types/_module/util/Wrapper/IPlayer.d.ts.map +1 -0
  46. package/_types/index.d.ts +3 -0
  47. package/_types/index.d.ts.map +1 -0
  48. package/index.js +303 -215
  49. package/index.ts +2 -21
  50. package/package.json +9 -7
  51. package/tsconfig.types.json +13 -0
  52. package/index.d.ts +0 -20
  53. package/util/Command.d.ts +0 -23
  54. package/util/Form.d.ts +0 -10
  55. package/util/Form.ts +0 -15
  56. package/util/FormAction.d.ts +0 -41
  57. package/util/RawText.d.ts +0 -33
  58. package/util/RawText.ts +0 -76
  59. package/util/Signal.d.ts +0 -9
  60. package/util/Signal.ts +0 -73
  61. package/util/Vector.d.ts +0 -60
  62. package/util/_Form.ts +0 -246
  63. /package/{util → _module/util}/Command.ts +0 -0
  64. /package/{util → _module/util}/Math.ts +0 -0
  65. /package/{util → _module/util}/Vector.ts +0 -0
package/index.js CHANGED
@@ -1,8 +1,28 @@
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;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
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
- __publicField(this, "listeners", /* @__PURE__ */ new Set());
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
- if (callback) {
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
- /** Connect a listener that runs only once */
95
- once(callback) {
96
- const wrapper = (data) => {
97
- this.disconnect(wrapper);
98
- callback(data);
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 [...this.listeners]) {
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
- __publicField(_Vec2, "ZERO", new _Vec2(0, 0));
250
+ _Vec2.ZERO = new _Vec2(0, 0);
239
251
  /** Up direction (0, 1) */
240
- __publicField(_Vec2, "UP", new _Vec2(0, 1));
252
+ _Vec2.UP = new _Vec2(0, 1);
241
253
  /** Down direction (0, -1) */
242
- __publicField(_Vec2, "DOWN", new _Vec2(0, -1));
254
+ _Vec2.DOWN = new _Vec2(0, -1);
243
255
  /** Left direction (-1, 0) */
244
- __publicField(_Vec2, "LEFT", new _Vec2(-1, 0));
256
+ _Vec2.LEFT = new _Vec2(-1, 0);
245
257
  /** Right direction (1, 0) */
246
- __publicField(_Vec2, "RIGHT", new _Vec2(1, 0));
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
- __publicField(_Vec3, "ZERO", new _Vec3(0, 0, 0));
419
+ _Vec3.ZERO = new _Vec3(0, 0, 0);
408
420
  /** Up direction (0, 1, 0) */
409
- __publicField(_Vec3, "UP", new _Vec3(0, 1, 0));
421
+ _Vec3.UP = new _Vec3(0, 1, 0);
410
422
  /** Down direction (0, -1, 0) */
411
- __publicField(_Vec3, "DOWN", new _Vec3(0, -1, 0));
423
+ _Vec3.DOWN = new _Vec3(0, -1, 0);
412
424
  /** Left direction (-1, 0, 0) */
413
- __publicField(_Vec3, "LEFT", new _Vec3(-1, 0, 0));
425
+ _Vec3.LEFT = new _Vec3(-1, 0, 0);
414
426
  /** Right direction (1, 0, 0) */
415
- __publicField(_Vec3, "RIGHT", new _Vec3(1, 0, 0));
427
+ _Vec3.RIGHT = new _Vec3(1, 0, 0);
416
428
  /** Forward direction (0, 0, 1) */
417
- __publicField(_Vec3, "FORWARD", new _Vec3(0, 0, 1));
429
+ _Vec3.FORWARD = new _Vec3(0, 0, 1);
418
430
  /** Backward direction (0, 0, -1) */
419
- __publicField(_Vec3, "BACK", new _Vec3(0, 0, -1));
431
+ _Vec3.BACK = new _Vec3(0, 0, -1);
420
432
  /** West direction (-1, 0, 0) */
421
- __publicField(_Vec3, "WEST", new _Vec3(-1, 0, 0));
433
+ _Vec3.WEST = new _Vec3(-1, 0, 0);
422
434
  /** East direction (1, 0, 0) */
423
- __publicField(_Vec3, "EAST", new _Vec3(1, 0, 0));
435
+ _Vec3.EAST = new _Vec3(1, 0, 0);
424
436
  /** North direction (0, 0, 1) */
425
- __publicField(_Vec3, "NORTH", new _Vec3(0, 0, 1));
437
+ _Vec3.NORTH = new _Vec3(0, 0, 1);
426
438
  /** South direction (0, 0, -1) */
427
- __publicField(_Vec3, "SOUTH", new _Vec3(0, 0, -1));
439
+ _Vec3.SOUTH = new _Vec3(0, 0, -1);
428
440
  var Vec3 = _Vec3;
429
441
 
430
- // util/RawText.ts
431
- var RawText;
432
- ((RawText2) => {
433
- RawText2.TEXT = (value) => ({
434
- text: value
435
- });
436
- RawText2.TRANSLATE = (key, ...params) => ({
437
- translate: key,
438
- with: params.length ? params : void 0
439
- });
440
- RawText2.SCORE = (name, objective) => ({
441
- score: {
442
- name,
443
- objective
444
- }
445
- });
446
- RawText2.MESSAGE = (...rawText) => ({
447
- rawtext: rawText
448
- });
449
- RawText2.FORMAT = {
450
- DarkRed: (0, RawText2.TEXT)("\xA74"),
451
- Red: (0, RawText2.TEXT)("\xA7c"),
452
- Gold: (0, RawText2.TEXT)("\xA76"),
453
- Yellow: (0, RawText2.TEXT)("\xA7e"),
454
- Green: (0, RawText2.TEXT)("\xA72"),
455
- Lime: (0, RawText2.TEXT)("\xA7a"),
456
- Aqua: (0, RawText2.TEXT)("\xA7b"),
457
- Cyan: (0, RawText2.TEXT)("\xA73"),
458
- DarkBlue: (0, RawText2.TEXT)("\xA71"),
459
- Blue: (0, RawText2.TEXT)("\xA79"),
460
- Magenta: (0, RawText2.TEXT)("\xA7d"),
461
- Purple: (0, RawText2.TEXT)("\xA75"),
462
- White: (0, RawText2.TEXT)("\xA7f"),
463
- Gray: (0, RawText2.TEXT)("\xA77"),
464
- DarkGray: (0, RawText2.TEXT)("\xA78"),
465
- Black: (0, RawText2.TEXT)("\xA70"),
466
- Obfuscated: (0, RawText2.TEXT)("\xA7k"),
467
- Bold: (0, RawText2.TEXT)("\xA7l"),
468
- StrikeThrough: (0, RawText2.TEXT)("\xA7m"),
469
- Italic: (0, RawText2.TEXT)("\xA7o"),
470
- Reset: (0, RawText2.TEXT)("\xA7r"),
471
- NewLine: (0, RawText2.TEXT)("\n")
472
- };
473
- })(RawText || (RawText = {}));
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/Form.ts
512
- var _Form = class _Form {
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 _Form.occupiedPlayers.has(player.id);
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) _Form.occupiedPlayers.add(player.id);
518
- else _Form.occupiedPlayers.delete(player.id);
580
+ if (occupied) _IForm.occupiedPlayers.add(player.id);
581
+ else _IForm.occupiedPlayers.delete(player.id);
519
582
  }
520
583
  };
521
- __publicField(_Form, "occupiedPlayers", /* @__PURE__ */ new Set());
522
- __publicField(_Form, "returnText", "Back");
523
- var Form = _Form;
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
- var RETURN_ID = "d7213196-4cb6-4199-a40b-22fbf2d944ef";
528
- var IActionFormData = class extends Form {
529
- constructor() {
530
- super(...arguments);
531
- __publicField(this, "form", new ActionFormData());
532
- __publicField(this, "_buttons", /* @__PURE__ */ new Map());
533
- __publicField(this, "_nextButtonIndex", 0);
534
- __publicField(this, "_id", "untitled");
535
- }
536
- title(titleText) {
537
- this.form.title(titleText);
538
- this._id = typeof titleText === "string" ? titleText : JSON.stringify(titleText);
539
- return this;
540
- }
541
- body(bodyText) {
542
- this.form.body(bodyText);
543
- return this;
544
- }
545
- divider() {
546
- this.form.divider();
547
- return this;
548
- }
549
- header(text) {
550
- this.form.header(text);
551
- return this;
552
- }
553
- label(text) {
554
- this.form.label(text);
555
- return this;
556
- }
557
- button(text, options = {}) {
558
- if (options.iconPath) this.form.button(text, options.iconPath);
559
- else this.form.button(text);
560
- const id = options.id ?? this._nextButtonIndex;
561
- const allowReturn = options.allowReturn ?? true;
562
- this._buttons.set(this._nextButtonIndex, {
563
- id,
564
- subForm: options.subForm,
565
- allowReturn
566
- });
567
- this._nextButtonIndex++;
568
- return this;
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
- async show(player) {
571
- if (Form.isOccupied(player)) {
572
- throw new Error(`Player ${player.id} is already occupied by form: ${this._id}`);
573
- }
574
- this.setOccupied(player, true);
575
- try {
576
- return await this._showInternal(player, []);
577
- } finally {
578
- this.setOccupied(player, false);
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
- async _showChained(player, returnStack) {
582
- return await this._showInternal(player, returnStack);
658
+ test() {
583
659
  }
584
- _wrapResponse(response, id) {
585
- return {
586
- canceled: response.canceled,
587
- cancelationReason: response.cancelationReason,
588
- selection: response.selection,
589
- id
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
- async _showInternal(player, returnStack) {
593
- this.form = new ActionFormData();
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
- // index.ts
632
- var BlockFactory;
633
- ((BlockFactory2) => {
634
- MathUtils;
635
- Signal;
636
- Vec2;
637
- Vec3;
638
- RawText;
639
- Command;
640
- Form;
641
- IActionFormData;
642
- })(BlockFactory || (BlockFactory = {}));
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
- Form,
647
- IActionFormData,
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
- import { MathUtils } from "./util/Math";
2
- import { Signal } from "./util/Signal";
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.2",
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-lib/issues"
20
+ "url": "https://github.com/Block-Factory-Studio/bf-mcbr-library/issues"
21
21
  },
22
- "homepage": "https://github.com/Block-Factory-Studio/bf-lib#readme",
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
- "all": "^0.0.0",
27
- "esbuild": "^0.27.2"
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
  }