@block_factory/lib 0.0.5 → 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.
Files changed (33) hide show
  1. package/_module/BlockFactory.ts +4 -5
  2. package/_module/Framework/EntityTasks.ts +12 -51
  3. package/_module/Framework/ItemTasks.ts +157 -0
  4. package/_module/Framework/PlayerTasks.ts +125 -0
  5. package/_module/Framework/Threads.ts +2 -2
  6. package/_module/util/Signal.ts +71 -7
  7. package/_module/util/Wrapper/IEntity.ts +1 -1
  8. package/_module/util/Wrapper/IPlayer.ts +1 -1
  9. package/_types/_module/BlockFactory.d.ts +4 -4
  10. package/_types/_module/BlockFactory.d.ts.map +1 -1
  11. package/_types/_module/DataTypes.d.ts +10 -0
  12. package/_types/_module/DataTypes.d.ts.map +1 -0
  13. package/_types/_module/Framework/EntityTasks.d.ts +4 -7
  14. package/_types/_module/Framework/EntityTasks.d.ts.map +1 -1
  15. package/_types/_module/Framework/ItemTasks.d.ts +59 -0
  16. package/_types/_module/Framework/ItemTasks.d.ts.map +1 -0
  17. package/_types/_module/Framework/PlayerTasks.d.ts +28 -0
  18. package/_types/_module/Framework/PlayerTasks.d.ts.map +1 -0
  19. package/_types/_module/Framework/Threads.d.ts +2 -2
  20. package/_types/_module/Framework/Threads.d.ts.map +1 -1
  21. package/_types/_module/util/Signal.d.ts +63 -4
  22. package/_types/_module/util/Signal.d.ts.map +1 -1
  23. package/_types/_module/util/Wrapper/IEntity.d.ts +1 -1
  24. package/_types/_module/util/Wrapper/IEntity.d.ts.map +1 -1
  25. package/_types/_module/util/Wrapper/IPlayer.d.ts +1 -1
  26. package/_types/_module/util/Wrapper/IPlayer.d.ts.map +1 -1
  27. package/index.js +306 -53
  28. package/package.json +4 -2
  29. package/typedoc.json +6 -0
  30. package/_module/Framework/_INIT.ts +0 -39
  31. package/_types/_module/Framework/_INIT.d.ts +0 -19
  32. package/_types/_module/Framework/_INIT.d.ts.map +0 -1
  33. /package/_module/{Types.ts → DataTypes.ts} +0 -0
package/index.js CHANGED
@@ -11,32 +11,22 @@ var BlockFactory_exports = {};
11
11
  __export(BlockFactory_exports, {
12
12
  Command: () => Command,
13
13
  ContainerWrapper: () => ContainerWrapper,
14
+ EntityHandler: () => EntityHandler,
14
15
  IEntityWrapper: () => IEntityWrapper,
15
16
  IForm: () => IForm,
16
17
  IPlayerWrapper: () => IPlayerWrapper,
18
+ ItemHandler: () => ItemHandler,
17
19
  MathUtils: () => MathUtils,
20
+ PlayerHandler: () => PlayerHandler,
18
21
  RawText: () => RawText,
19
22
  RegisterForm: () => RegisterForm,
20
23
  Signal: () => Signal,
21
24
  System: () => System,
25
+ Thread: () => Thread,
22
26
  Vec2: () => Vec2,
23
- Vec3: () => Vec3,
24
- _EntityHandler_: () => _EntityHandler_,
25
- _INITIALIZE_BF_FRAMEWORK_: () => _INITIALIZE_BF_FRAMEWORK_,
26
- _THREAD_: () => _THREAD_,
27
- onEntityEmission: () => onEntityEmission
27
+ Vec3: () => Vec3
28
28
  });
29
29
 
30
- // _module/Framework/_INIT.ts
31
- var IS_INITIALIZED = false;
32
- var PACK_ID = void 0;
33
- function _INITIALIZE_BF_FRAMEWORK_(packId) {
34
- if (IS_INITIALIZED) throw Error(`CONFLICT WARNING: ${PACK_ID} already initialized.`);
35
- PACK_ID = packId;
36
- IS_INITIALIZED = true;
37
- console.log("Block Factory Framework Loaded");
38
- }
39
-
40
30
  // _module/util/Math.ts
41
31
  var MathUtils;
42
32
  ((MathUtils2) => {
@@ -110,32 +100,80 @@ var MathUtils;
110
100
  // _module/util/Signal.ts
111
101
  var Signal = class {
112
102
  constructor() {
103
+ /**
104
+ * Registered signal listeners.
105
+ */
113
106
  __publicField(this, "listeners", /* @__PURE__ */ new Set());
114
107
  }
108
+ /**
109
+ * Number of currently subscribed listeners.
110
+ */
115
111
  get count() {
116
112
  return this.listeners.size;
117
113
  }
118
- connect(callback) {
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) {
119
123
  this.listeners.add(callback);
120
124
  }
121
- disconnect(callback) {
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) {
122
132
  return this.listeners.delete(callback);
123
133
  }
134
+ /**
135
+ * Removes all subscribed listeners from this signal.
136
+ */
124
137
  clear() {
125
138
  this.listeners.clear();
126
139
  }
127
- isConnected(callback) {
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) {
128
147
  return this.listeners.has(callback);
129
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
+ */
130
157
  emit(data) {
131
158
  for (const callback of Array.from(this.listeners)) {
132
159
  try {
133
160
  callback(data);
134
161
  } catch (err) {
135
- console.error("BFLIB: Signal listener error:", err);
162
+ console.error("BFLIB: Subscription listener error:", err);
136
163
  }
137
164
  }
138
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
+ }
139
177
  };
140
178
 
141
179
  // _module/util/Vector.ts
@@ -719,7 +757,7 @@ var IPlayerWrapper = class _IPlayerWrapper {
719
757
 
720
758
  // _module/Framework/Threads.ts
721
759
  import { system as system4, TicksPerSecond as TicksPerSecond3 } from "@minecraft/server";
722
- var Threads = class {
760
+ var SingletonThreadManager = class {
723
761
  constructor() {
724
762
  __publicField(this, "MAIN", new Signal());
725
763
  __publicField(this, "LATE", new Signal());
@@ -774,23 +812,116 @@ var Threads = class {
774
812
  };
775
813
  }
776
814
  };
777
- var _THREAD_ = new Threads();
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();
778
913
 
779
914
  // _module/Framework/EntityTasks.ts
780
- import {
781
- system as system5,
782
- world as world3
783
- } from "@minecraft/server";
784
- var onEntityEmission = new Signal();
785
- var EntityHandler = class {
915
+ import { system as system5, world as world4 } from "@minecraft/server";
916
+ var SingletonEntityHandler = class {
786
917
  constructor() {
787
918
  __publicField(this, "PACK_ID");
919
+ __publicField(this, "onEntityEmission", new Signal());
788
920
  __publicField(this, "GLOBAL_MEMORY_ID", "GLB_MEM.ENTITY");
789
921
  __publicField(this, "scriptEventSignal", system5.afterEvents.scriptEventReceive);
790
- __publicField(this, "loadEventSignal", world3.afterEvents.worldLoad);
791
- __publicField(this, "spawnEventSignal", world3.afterEvents.entitySpawn);
792
- __publicField(this, "removeAfterEventSignal", world3.afterEvents.entityRemove);
793
- __publicField(this, "removeBeforeEventSignal", world3.beforeEvents.entityRemove);
922
+ __publicField(this, "loadEventSignal", world4.afterEvents.worldLoad);
923
+ __publicField(this, "spawnEventSignal", world4.afterEvents.entitySpawn);
924
+ __publicField(this, "removeBeforeEventSignal", world4.beforeEvents.entityRemove);
794
925
  __publicField(this, "EM_INDEX", /* @__PURE__ */ new Map());
795
926
  __publicField(this, "EM_KEYS", []);
796
927
  __publicField(this, "SEARCH_TYPES", /* @__PURE__ */ new Set());
@@ -799,12 +930,11 @@ var EntityHandler = class {
799
930
  /* ------------------------------------------------------------------------ */
800
931
  /* Event Wiring */
801
932
  /* ------------------------------------------------------------------------ */
802
- __publicField(this, "onWorldLoad", (_event) => {
933
+ __publicField(this, "onWorldLoad", () => {
803
934
  this.scriptEventSignal.subscribe(this.processScriptEvents);
804
935
  if (this.SEARCH_TYPES.size > 0) {
805
936
  this.spawnEventSignal.subscribe(this.onEntitySpawned);
806
937
  this.removeBeforeEventSignal.subscribe(this.onEntityRemovedBefore);
807
- this.removeAfterEventSignal.subscribe(this.onEntityRemovedAfter);
808
938
  }
809
939
  this._wired = true;
810
940
  this.reloadEntityMemory();
@@ -820,10 +950,7 @@ var EntityHandler = class {
820
950
  console.error(`BFLIB: entity_emitter JSON parse failed:`, e);
821
951
  return;
822
952
  }
823
- onEntityEmission.emit({
824
- iEntity: IEntityWrapper.wrap(event.sourceEntity),
825
- parms
826
- });
953
+ this.onEntityEmission.emit({ iEntity: IEntityWrapper.wrap(event.sourceEntity), parms });
827
954
  });
828
955
  __publicField(this, "onEntitySpawned", (event) => {
829
956
  const entity = event.entity;
@@ -835,18 +962,13 @@ var EntityHandler = class {
835
962
  if (!this.isValidType(entity.typeId)) return;
836
963
  this.deleteEntityInMemory(entity);
837
964
  });
838
- __publicField(this, "onEntityRemovedAfter", (_event) => {
839
- });
840
- }
841
- configure() {
842
- if (this._started) throw new Error("BFLIB: EntityHandler already started;");
843
965
  }
844
966
  registerEntity(typeId) {
845
967
  if (Array.isArray(typeId)) typeId.forEach((t) => this.SEARCH_TYPES.add(t));
846
968
  else this.SEARCH_TYPES.add(typeId);
847
969
  }
848
970
  start(packId) {
849
- if (this._started) return;
971
+ if (this._started) throw new Error("BFLIB: EntityHandler already started;");
850
972
  this._started = true;
851
973
  this.PACK_ID = packId;
852
974
  this.loadEventSignal.subscribe(this.onWorldLoad);
@@ -858,7 +980,6 @@ var EntityHandler = class {
858
980
  this.scriptEventSignal.unsubscribe(this.processScriptEvents);
859
981
  this.spawnEventSignal.unsubscribe(this.onEntitySpawned);
860
982
  this.removeBeforeEventSignal.unsubscribe(this.onEntityRemovedBefore);
861
- this.removeAfterEventSignal.unsubscribe(this.onEntityRemovedAfter);
862
983
  this._wired = false;
863
984
  }
864
985
  this._started = false;
@@ -867,6 +988,7 @@ var EntityHandler = class {
867
988
  /* Filters */
868
989
  /* ------------------------------------------------------------------------ */
869
990
  isValidType(typeId) {
991
+ if (this.PACK_ID && !typeId.startsWith(this.PACK_ID)) return false;
870
992
  return this.SEARCH_TYPES.has(typeId);
871
993
  }
872
994
  /* ------------------------------------------------------------------------ */
@@ -875,7 +997,7 @@ var EntityHandler = class {
875
997
  reloadEntityMemory() {
876
998
  this.EM_INDEX.clear();
877
999
  this.EM_KEYS.length = 0;
878
- const raw = world3.getDynamicProperty(this.GLOBAL_MEMORY_ID);
1000
+ const raw = world4.getDynamicProperty(this.GLOBAL_MEMORY_ID);
879
1001
  if (!raw) return;
880
1002
  let parsed;
881
1003
  try {
@@ -886,12 +1008,12 @@ var EntityHandler = class {
886
1008
  }
887
1009
  for (const id of parsed) {
888
1010
  this.EM_KEYS.push(id);
889
- const entity = world3.getEntity(id);
1011
+ const entity = world4.getEntity(id);
890
1012
  if (entity) this.EM_INDEX.set(entity.id, entity);
891
1013
  }
892
1014
  }
893
1015
  persistKeys() {
894
- world3.setDynamicProperty(this.GLOBAL_MEMORY_ID, JSON.stringify(this.EM_KEYS));
1016
+ world4.setDynamicProperty(this.GLOBAL_MEMORY_ID, JSON.stringify(this.EM_KEYS));
895
1017
  }
896
1018
  saveEntityInMemory(entity) {
897
1019
  if (this.EM_INDEX.has(entity.id)) return false;
@@ -912,23 +1034,154 @@ var EntityHandler = class {
912
1034
  return Array.from(this.EM_INDEX.values());
913
1035
  }
914
1036
  };
915
- var _EntityHandler_ = new EntityHandler();
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();
916
1169
  export {
917
1170
  BlockFactory_exports as BlockFactory,
918
1171
  Command,
919
1172
  ContainerWrapper,
1173
+ EntityHandler,
920
1174
  IEntityWrapper,
921
1175
  IForm,
922
1176
  IPlayerWrapper,
1177
+ ItemHandler,
923
1178
  MathUtils,
1179
+ PlayerHandler,
924
1180
  RawText,
925
1181
  RegisterForm,
926
1182
  Signal,
927
1183
  System,
1184
+ Thread,
928
1185
  Vec2,
929
- Vec3,
930
- _EntityHandler_,
931
- _INITIALIZE_BF_FRAMEWORK_,
932
- _THREAD_,
933
- onEntityEmission
1186
+ Vec3
934
1187
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@block_factory/lib",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "description": "Typescript Library for Minecraft Bedrock Edition",
@@ -25,7 +25,9 @@
25
25
  "@minecraft/server-ui": "^2.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "esbuild": "^0.25.9"
28
+ "esbuild": "^0.25.9",
29
+ "typedoc": "^0.28.16",
30
+ "typedoc-plugin-markdown": "^4.9.0"
29
31
  },
30
32
  "scripts": {
31
33
  "build": "node esbuild.config.mjs",
package/typedoc.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "entryPoints": ["./index.ts"],
3
+ "out": "docs",
4
+ "plugin": ["typedoc-plugin-markdown"],
5
+ "readme": "none"
6
+ }
@@ -1,39 +0,0 @@
1
- let IS_INITIALIZED: boolean = false
2
- let PACK_ID: string | undefined = undefined
3
-
4
- /* -------------------------------------------------------------------------- */
5
- /* Public API */
6
- /* -------------------------------------------------------------------------- */
7
-
8
- /**
9
- * Initializes the Block Factory framework.
10
- *
11
- * This **must be called exactly once** before using any backend systems
12
- * such as threads, entity tasks, or event routing.
13
- *
14
- * @param packId - Unique identifier for the active pack instance.
15
- *
16
- * @throws Error if the framework has already been initialized.
17
- *
18
- * @example
19
- * ```ts
20
- * _INITIALIZE_BF_FRAMEWORK_("bf:utility_tools");
21
- * ```
22
- */
23
- export function _INITIALIZE_BF_FRAMEWORK_(packId: string): void {
24
- if (IS_INITIALIZED) throw Error(`CONFLICT WARNING: ${PACK_ID} already initialized.`);
25
- PACK_ID = packId; IS_INITIALIZED = true;
26
- console.log("Block Factory Framework Loaded");
27
- }
28
-
29
- /* -------------------------------------------------------------------------- */
30
- /* Internal API */
31
- /* -------------------------------------------------------------------------- */
32
-
33
- export function getPackId(): string | undefined {
34
- return PACK_ID;
35
- }
36
-
37
- export function isInitalized(): boolean {
38
- return IS_INITIALIZED;
39
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Initializes the Block Factory framework.
3
- *
4
- * This **must be called exactly once** before using any backend systems
5
- * such as threads, entity tasks, or event routing.
6
- *
7
- * @param packId - Unique identifier for the active pack instance.
8
- *
9
- * @throws Error if the framework has already been initialized.
10
- *
11
- * @example
12
- * ```ts
13
- * _INITIALIZE_BF_FRAMEWORK_("bf:utility_tools");
14
- * ```
15
- */
16
- export declare function _INITIALIZE_BF_FRAMEWORK_(packId: string): void;
17
- export declare function getPackId(): string | undefined;
18
- export declare function isInitalized(): boolean;
19
- //# sourceMappingURL=_INIT.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_INIT.d.ts","sourceRoot":"","sources":["../../../_module/Framework/_INIT.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAI9D;AAMD,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED,wBAAgB,YAAY,IAAI,OAAO,CAEtC"}
File without changes