mbler 0.1.1 → 0.1.3-alpha

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/lib/build/base.js +297 -1
  4. package/lib/build/build-g-config.json +11 -11
  5. package/lib/build/getModule.js +182 -1
  6. package/lib/build/index.js +370 -1
  7. package/lib/build/manifest.build.js +103 -1
  8. package/lib/build/mcVersion.js +86 -1
  9. package/lib/build/utils.js +6 -1
  10. package/lib/code-processor/c-handler-export.js +12 -1
  11. package/lib/code-processor/index.js +141 -1
  12. package/lib/code-processor/mtreehandler.js +164 -1
  13. package/lib/commander/index.js +154 -1
  14. package/lib/data/includes.json +12 -12
  15. package/lib/git/clone.js +28 -1
  16. package/lib/git/index.js +12 -1
  17. package/lib/git/pull.js +100 -1
  18. package/lib/lang/__translate.js +93 -1
  19. package/lib/lang/en.js +128 -1
  20. package/lib/lang/index.js +78 -1
  21. package/lib/lang/zh.js +146 -1
  22. package/lib/loger/colors.js +13 -1
  23. package/lib/loger/index.js +136 -1
  24. package/lib/mcx/ast/index.js +11 -1
  25. package/lib/mcx/ast/prop.js +78 -1
  26. package/lib/mcx/ast/tag.js +246 -1
  27. package/lib/mcx/compile-component/lib.js +106 -1
  28. package/lib/mcx/compile-component/types.js +2 -1
  29. package/lib/mcx/compile-component/utils.js +26 -1
  30. package/lib/mcx/compile-mcx/_compile.js +1 -1
  31. package/lib/mcx/compile-mcx/compile.js +34 -1
  32. package/lib/mcx/compile-mcx/context.js +19 -1
  33. package/lib/mcx/compile-mcx/index.js +10 -1
  34. package/lib/mcx/compile-mcx/mcx/index.js +2 -1
  35. package/lib/mcx/compile-mcx/mcx/types.js +2 -1
  36. package/lib/mcx/compile-mcx/template/module.js +42 -1
  37. package/lib/mcx/compile-mcx/types.js +2 -1
  38. package/lib/mcx/compile-mcx/utils.node.js +207 -1
  39. package/lib/mcx/index.js +13 -1
  40. package/lib/mcx/test/index.js +7 -1
  41. package/lib/mcx/test.js +21 -1
  42. package/lib/mcx/types.js +2 -1
  43. package/lib/mcx/utils.js +86 -1
  44. package/lib/module-handler/index.js +482 -1
  45. package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
  46. package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
  47. package/lib/modules/create-game/src/config.js +27 -1
  48. package/lib/modules/create-game/src/constants.js +19 -1
  49. package/lib/modules/create-game/src/createGameModule.js +24 -1
  50. package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
  51. package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
  52. package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
  53. package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
  54. package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
  55. package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
  56. package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
  57. package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
  58. package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
  59. package/lib/modules/create-game/src/gameComponent/index.js +31 -1
  60. package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
  61. package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
  62. package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
  63. package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
  64. package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
  65. package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
  66. package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
  67. package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
  68. package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
  69. package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
  70. package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
  71. package/lib/modules/create-game/src/gameContext.js +6 -1
  72. package/lib/modules/create-game/src/gameEngine.js +139 -1
  73. package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
  74. package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
  75. package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
  76. package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
  77. package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
  78. package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
  79. package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
  80. package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
  81. package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
  82. package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
  83. package/lib/modules/create-game/src/gameEvent/index.js +20 -1
  84. package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
  85. package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
  86. package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
  87. package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
  88. package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
  89. package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
  90. package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
  91. package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
  92. package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
  93. package/lib/modules/create-game/src/gameRegion/index.js +43 -1
  94. package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
  95. package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
  96. package/lib/modules/create-game/src/gameState/gameState.js +169 -1
  97. package/lib/modules/create-game/src/gameState/index.js +7 -1
  98. package/lib/modules/create-game/src/gameState/types.js +35 -1
  99. package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
  100. package/lib/modules/create-game/src/main.js +86 -1
  101. package/lib/modules/create-game/src/system/gameCommand.js +107 -1
  102. package/lib/modules/create-game/src/system/gameManager.js +124 -1
  103. package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
  104. package/lib/modules/create-game/src/utils/GameError.js +31 -1
  105. package/lib/modules/create-game/src/utils/algorithm.js +95 -1
  106. package/lib/modules/create-game/src/utils/chunk.js +63 -1
  107. package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
  108. package/lib/modules/create-game/src/utils/duration.js +25 -1
  109. package/lib/modules/create-game/src/utils/func.js +20 -1
  110. package/lib/modules/create-game/src/utils/index.js +52 -1
  111. package/lib/modules/create-game/src/utils/interfaces.js +2 -1
  112. package/lib/modules/create-game/src/utils/logger.js +47 -1
  113. package/lib/modules/create-game/src/utils/random.js +76 -1
  114. package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
  115. package/lib/modules/create-game/src/utils/vector.js +96 -1
  116. package/lib/modules/gameLib/src/config.js +134 -1
  117. package/lib/modules/gameLib/src/data.js +77 -1
  118. package/lib/modules/gameLib/src/entity.js +256 -1
  119. package/lib/modules/gameLib/src/event.js +285 -1
  120. package/lib/modules/gameLib/src/index.js +20 -1
  121. package/lib/modules/gameLib/src/loger.js +21 -1
  122. package/lib/modules/gameLib/src/ui.js +209 -1
  123. package/lib/modules/gameLib/src/utils.js +122 -1
  124. package/lib/modules/gutils/src/index.js +22 -1
  125. package/lib/runTemp/File.js +54 -1
  126. package/lib/runTemp/index.js +137 -1
  127. package/lib/runTemp/securityFile.js +93 -1
  128. package/lib/start/addPack.js +3 -1
  129. package/lib/start/clean.js +84 -1
  130. package/lib/start/create.js +146 -1
  131. package/lib/start/dev.js +99 -1
  132. package/lib/start/getResConfig.js +3 -1
  133. package/lib/start/incg.js +3 -1
  134. package/lib/start/index.js +207 -1
  135. package/lib/start/init.js +125 -1
  136. package/lib/start/rechce.js +57 -1
  137. package/lib/start/unaddPack.js +3 -1
  138. package/lib/start/unincg.js +67 -1
  139. package/lib/start/version.js +73 -1
  140. package/lib/utils/index.js +298 -1
  141. package/lib/uuid/index.js +27 -1
  142. package/package.json +1 -1
  143. package/test/script-mbler/behavior/scripts/index.js +0 -5
@@ -1 +1,139 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GameEngine=void 0;const playerManager_js_1=require("./gamePlayer/playerManager.js"),main_js_1=require("./main.js"),GameError_js_1=require("./utils/GameError.js"),logger_js_1=require("./utils/logger.js");class GameEngine{stateStack=[];logger;context;playerManager;key;_isActive=!1;get isDaemon(){return!1}get isActive(){return this._isActive}get groupBuilder(){return this.playerManager.groupBuilder}constructor(t,e,s){this.playerManager=new playerManager_js_1.GamePlayerManager(t,e,this.isDaemon),this.key=e,this.context=this.buildContext(s??{}),this.logger=new logger_js_1.Logger(this.constructor.name),this._isActive=!0}pushState(t,e){if(!this.isActive)return this;this.logger.debug(`Pushing state: ${t.name}`);const s=new t(this,e);return this.stateStack.push(s),s.onEnter(),this}popState(){const t=this.stateStack.pop();t&&this.removeState(t)}resetState(t,e){this.logger.debug(`Setting root state to: ${t.name}`),this.clearStateStack(),this.pushState(t,e)}replaceFrom(t,e,s){this.logger.debug(`Replacing from ${t.constructor.name} with ${e.name}`);const a=this.stateStack.indexOf(t);if(-1===a)throw this.logger.error(`无法找到要替换的状态实例:${t.constructor.name}`),new GameError_js_1.GameEngineError("State to replace not found in stack.");for(;this.stateStack.length>a;){const t=this.stateStack.pop();this.removeState(t)}this.pushState(e,s)}clearStateStack(){for(;this.stateStack.length>0;)this.popState()}removeState(t){this.logger.debug(`Removing state: ${t.constructor.name}`),t._onExit()}getNextState(t){const e=this.stateStack.findIndex(e=>e===t);if(-1!=e&&this.stateStack.length>e+1)return this.stateStack[e+1]}getLastState(t){const e=this.stateStack.findIndex(e=>e===t);if(e>0)return this.stateStack[e-1]}getState(t){const e=this.stateStack.find(e=>e.constructor==t);if(e)return e}deleteState(t){const e=this.stateStack.findIndex(e=>e.constructor==t);if(-1!=e){const[t]=this.stateStack.splice(e,1);this.removeState(t)}}stats(t=!1){let e;const s=this.stateStack.map(t=>t.constructor.name),a=`§ePlayers§r: §a${this.playerManager.validSize}§r / §7${this.playerManager.size}`;if(t){const t=this.stateStack.map(t=>t.stats());e=s.length>0?`§eStates§r(${s.length}): \n ${t.join("\n ")}`:"§eStates§r: §7<empty>"}else e=s.length>0?`§eStates§r(${s.length}): §b${s.join(" §7| §b")}`:"§eStates§r: §7<empty>";return["",a,e].join("\n ")}stopGame(){main_js_1.Game.manager.stopGameByKey(this.key)}onDispose(){this.logger?.debug("dispose"),this.playerManager.dispose(),this._isActive=!1,this.clearStateStack()}}exports.GameEngine=GameEngine;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GameEngine = void 0;
4
+ const playerManager_js_1 = require("./gamePlayer/playerManager.js");
5
+ const main_js_1 = require("./main.js");
6
+ const GameError_js_1 = require("./utils/GameError.js");
7
+ const logger_js_1 = require("./utils/logger.js");
8
+ class GameEngine {
9
+ stateStack = [];
10
+ logger;
11
+ context;
12
+ playerManager;
13
+ key;
14
+ _isActive = false;
15
+ /**是否是常驻游戏(常驻游戏不会被game end结束) */
16
+ get isDaemon() {
17
+ return false;
18
+ }
19
+ get isActive() {
20
+ return this._isActive;
21
+ }
22
+ /**玩家组构建器 */
23
+ get groupBuilder() {
24
+ return this.playerManager.groupBuilder;
25
+ }
26
+ constructor(playerClass, key, config) {
27
+ this.playerManager = new playerManager_js_1.GamePlayerManager(playerClass, key, this.isDaemon);
28
+ this.key = key;
29
+ this.context = this.buildContext(config ?? {});
30
+ this.logger = new logger_js_1.Logger(this.constructor.name);
31
+ this._isActive = true;
32
+ }
33
+ /** 在栈顶添加一个新的子状态 */
34
+ pushState(stateType, config) {
35
+ if (!this.isActive)
36
+ return this;
37
+ this.logger.debug(`Pushing state: ${stateType.name}`);
38
+ const stateInstance = new stateType(this, config);
39
+ this.stateStack.push(stateInstance);
40
+ stateInstance.onEnter();
41
+ return this;
42
+ }
43
+ /** 移除栈顶的状态,返回到父状态 */
44
+ popState() {
45
+ const topState = this.stateStack.pop();
46
+ if (topState) {
47
+ this.removeState(topState);
48
+ }
49
+ }
50
+ /** 清空所有状态,并设置一个新的根状态 */
51
+ resetState(stateType, config) {
52
+ this.logger.debug(`Setting root state to: ${stateType.name}`);
53
+ this.clearStateStack();
54
+ this.pushState(stateType, config);
55
+ }
56
+ /** 从指定的状态实例开始替换状态分支。*/
57
+ replaceFrom(stateToReplace, newStateType, config) {
58
+ this.logger.debug(`Replacing from ${stateToReplace.constructor.name} with ${newStateType.name}`);
59
+ const index = this.stateStack.indexOf(stateToReplace);
60
+ if (index === -1) {
61
+ this.logger.error(`无法找到要替换的状态实例:${stateToReplace.constructor.name}`);
62
+ throw new GameError_js_1.GameEngineError("State to replace not found in stack.");
63
+ }
64
+ // 清理后续所有状态
65
+ while (this.stateStack.length > index) {
66
+ const removed = this.stateStack.pop();
67
+ this.removeState(removed);
68
+ }
69
+ this.pushState(newStateType, config);
70
+ }
71
+ clearStateStack() {
72
+ while (this.stateStack.length > 0) {
73
+ this.popState();
74
+ }
75
+ }
76
+ removeState(state) {
77
+ this.logger.debug(`Removing state: ${state.constructor.name}`);
78
+ state._onExit();
79
+ }
80
+ /**获取下一个state */
81
+ getNextState(state) {
82
+ const index = this.stateStack.findIndex((s) => s === state);
83
+ if (index != -1 && this.stateStack.length > index + 1) {
84
+ return this.stateStack[index + 1];
85
+ }
86
+ }
87
+ /**获取上一个state */
88
+ getLastState(state) {
89
+ const index = this.stateStack.findIndex((s) => s === state);
90
+ if (index > 0) {
91
+ return this.stateStack[index - 1];
92
+ }
93
+ }
94
+ /**获取指定state */
95
+ getState(stateType) {
96
+ const state = this.stateStack.find((s) => s.constructor == stateType);
97
+ if (state) {
98
+ return state;
99
+ }
100
+ }
101
+ /**删除指定state */
102
+ deleteState(stateType) {
103
+ const idx = this.stateStack.findIndex((s) => s.constructor == stateType);
104
+ if (idx != -1) {
105
+ const [removed] = this.stateStack.splice(idx, 1);
106
+ this.removeState(removed);
107
+ }
108
+ }
109
+ /**显示engine信息 */
110
+ stats(detail = false) {
111
+ let stateLine;
112
+ const stateNames = this.stateStack.map((s) => s.constructor.name);
113
+ const playersLine = `§ePlayers§r: §a${this.playerManager.validSize}§r / §7${this.playerManager.size}`;
114
+ if (detail) {
115
+ const stateStats = this.stateStack.map((s) => s.stats());
116
+ stateLine =
117
+ stateNames.length > 0
118
+ ? `§eStates§r(${stateNames.length}): \n ${stateStats.join("\n ")}`
119
+ : `§eStates§r: §7<empty>`;
120
+ }
121
+ else {
122
+ stateLine =
123
+ stateNames.length > 0
124
+ ? `§eStates§r(${stateNames.length}): §b${stateNames.join(" §7| §b")}`
125
+ : `§eStates§r: §7<empty>`;
126
+ }
127
+ return ["", playersLine, stateLine].join("\n ");
128
+ }
129
+ stopGame() {
130
+ main_js_1.Game.manager.stopGameByKey(this.key);
131
+ }
132
+ onDispose() {
133
+ this.logger?.debug("dispose");
134
+ this.playerManager.dispose();
135
+ this._isActive = false;
136
+ this.clearStateStack();
137
+ }
138
+ }
139
+ exports.GameEngine = GameEngine;
@@ -1 +1,108 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventSubscription=exports.EventManager=void 0;const subscription_js_1=require("./subscription.js");class EventManager{subscriptionMap=new Map;isActive=!0;subscribe(s,t,...i){if(!this.isActive)return;const[n,e]=i,r=this.subscriptionMap.get(s)??[];this.subscriptionMap.set(s,r);const o=void 0!==e?t.subscribe(n,e):t.subscribe(n),c="function"==typeof o?new subscription_js_1.GameEventSubscription(t,n):o,u=new EventSubscription(t,s,c);return r.push(u),u}unsubscribe(s){const t=asInternal(s),i=this.subscriptionMap.get(t.subscriber);if(!i)return;const n=i.indexOf(s);-1!==n&&i.splice(n,1),t.subscription.unsubscribe(),0===i.length&&this.subscriptionMap.delete(t.subscriber)}unsubscribeByEvent(s){this.subscriptionMap.forEach((t,i)=>{for(const i of t){const t=asInternal(i);t.event===s&&t.subscription.unsubscribe()}const n=t.filter(t=>asInternal(t).event!==s);n.length>0?this.subscriptionMap.set(i,n):this.subscriptionMap.delete(i)})}unsubscribeBySubscriber(s){const t=this.subscriptionMap.get(s);if(t){for(const s of t)asInternal(s).subscription.unsubscribe();this.subscriptionMap.delete(s)}}dispose(){for(const s of this.subscriptionMap.values())for(const t of s)asInternal(t).subscription.unsubscribe();this.subscriptionMap.clear(),this.isActive=!1}debug(){console.log("=== EventManager Debug ==="),console.log("Total subscribers:",this.subscriptionMap.size),this.subscriptionMap.forEach((s,t)=>{console.log("Subscriber:",t.name),console.log(" Total subscriptions:",s.length);for(const t of s){const s=asInternal(t);console.log(" → Event:",s.event.constructor.name)}}),console.log("==========================")}}exports.EventManager=EventManager;class EventSubscription{event;subscriber;subscription;constructor(s,t,i){this.event=s,this.subscriber=t,this.subscription=i}}function asInternal(s){return s}exports.EventSubscription=EventSubscription;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventSubscription = exports.EventManager = void 0;
4
+ const subscription_js_1 = require("./subscription.js");
5
+ class EventManager {
6
+ subscriptionMap = new Map();
7
+ isActive = true;
8
+ /**订阅事件 */
9
+ subscribe(subscriber, event, ...args) {
10
+ if (!this.isActive)
11
+ return;
12
+ const [callback, options] = args;
13
+ const list = this.subscriptionMap.get(subscriber) ?? [];
14
+ this.subscriptionMap.set(subscriber, list);
15
+ // 订阅事件
16
+ const result = options !== undefined
17
+ ? event.subscribe(callback, options)
18
+ : event.subscribe(callback);
19
+ const subscription = typeof result === "function"
20
+ ? new subscription_js_1.GameEventSubscription(event, callback)
21
+ : result;
22
+ const record = new EventSubscription(event, subscriber, subscription);
23
+ list.push(record);
24
+ return record;
25
+ }
26
+ /**取消订阅 */
27
+ unsubscribe(subscription) {
28
+ const subData = asInternal(subscription);
29
+ const list = this.subscriptionMap.get(subData.subscriber);
30
+ if (!list)
31
+ return;
32
+ //寻找,删除列表项
33
+ const idx = list.indexOf(subscription);
34
+ if (idx !== -1) {
35
+ list.splice(idx, 1);
36
+ }
37
+ //取消订阅
38
+ subData.subscription.unsubscribe();
39
+ //清理
40
+ if (list.length === 0) {
41
+ this.subscriptionMap.delete(subData.subscriber);
42
+ }
43
+ }
44
+ unsubscribeByEvent(event) {
45
+ this.subscriptionMap.forEach((list, subscriber) => {
46
+ for (const subscription of list) {
47
+ const sub = asInternal(subscription);
48
+ if (sub.event === event) {
49
+ sub.subscription.unsubscribe();
50
+ }
51
+ }
52
+ const filtered = list.filter((sub) => asInternal(sub).event !== event);
53
+ if (filtered.length > 0) {
54
+ this.subscriptionMap.set(subscriber, filtered);
55
+ }
56
+ else {
57
+ this.subscriptionMap.delete(subscriber);
58
+ }
59
+ });
60
+ }
61
+ /**取消订阅指定object的所有事件 */
62
+ unsubscribeBySubscriber(subscriber) {
63
+ const list = this.subscriptionMap.get(subscriber);
64
+ if (!list)
65
+ return;
66
+ for (const sub of list) {
67
+ asInternal(sub).subscription.unsubscribe();
68
+ }
69
+ this.subscriptionMap.delete(subscriber);
70
+ }
71
+ dispose() {
72
+ for (const list of this.subscriptionMap.values()) {
73
+ for (const sub of list) {
74
+ asInternal(sub).subscription.unsubscribe();
75
+ }
76
+ }
77
+ this.subscriptionMap.clear();
78
+ this.isActive = false;
79
+ }
80
+ debug() {
81
+ console.log("=== EventManager Debug ===");
82
+ console.log("Total subscribers:", this.subscriptionMap.size);
83
+ this.subscriptionMap.forEach((list, subscriber) => {
84
+ console.log("Subscriber:", subscriber.name);
85
+ console.log(" Total subscriptions:", list.length);
86
+ for (const sub of list) {
87
+ const internal = asInternal(sub);
88
+ console.log(" → Event:", internal.event.constructor.name);
89
+ }
90
+ });
91
+ console.log("==========================");
92
+ }
93
+ }
94
+ exports.EventManager = EventManager;
95
+ class EventSubscription {
96
+ event;
97
+ subscriber;
98
+ subscription;
99
+ constructor(event, subscriber, subscription) {
100
+ this.event = event;
101
+ this.subscriber = subscriber;
102
+ this.subscription = subscription;
103
+ }
104
+ }
105
+ exports.EventSubscription = EventSubscription;
106
+ function asInternal(sub) {
107
+ return sub;
108
+ }
@@ -1 +1,28 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BasicCustomEventSignal=void 0;const logger_js_1=require("../utils/logger.js");class BasicCustomEventSignal{set=new Set;logger=new logger_js_1.Logger(this.constructor.name);unsubscribe(s){this.set.has(s)&&this.set.delete(s)}publish(s){const e=[...this.set];for(const t of e)try{this.runCallback(t,s)}catch(s){this.logger.error("Callback error:",s)}}}exports.BasicCustomEventSignal=BasicCustomEventSignal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicCustomEventSignal = void 0;
4
+ const logger_js_1 = require("../utils/logger.js");
5
+ /**自定义事件 */
6
+ class BasicCustomEventSignal {
7
+ set = new Set();
8
+ logger = new logger_js_1.Logger(this.constructor.name);
9
+ // 取消订阅
10
+ unsubscribe(item) {
11
+ if (this.set.has(item)) {
12
+ this.set.delete(item);
13
+ }
14
+ }
15
+ // 发布事件,执行所有回调
16
+ publish(data) {
17
+ const callbacksCopy = [...this.set];
18
+ for (const cb of callbacksCopy) {
19
+ try {
20
+ this.runCallback(cb, data);
21
+ }
22
+ catch (e) {
23
+ this.logger.error("Callback error:", e);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ exports.BasicCustomEventSignal = BasicCustomEventSignal;
@@ -1 +1,41 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ButtonPushEventSignal=void 0;const server_1=require("@minecraft/server"),vector_js_1=require("../../utils/vector.js"),mapEventSignal_js_1=require("../mapEventSignal.js");class ButtonPushEventSignal extends mapEventSignal_js_1.BaseMapEventSignal{buildKey(e){const r=vector_js_1.Vector3Utils.fromArray(e.loc);return`${e.dimensionId}-${r.x}-${r.y}-${r.z}`}buildData(e,r){return{callback:e,players:r.players,sourceType:r.sourceType}}extractKey(e){const r=e.block.location;return`${e.dimension.id}-${r.x}-${r.y}-${r.z}`}filter(e,r){return(!e.sourceType||r.source.typeId===e.sourceType)&&!(r.source instanceof server_1.Player&&e.players&&!e.players.getById(r.source.id))}subscribeNative(e){return server_1.world.afterEvents.buttonPush.subscribe(e),e}unsubscribeNative(e){server_1.world.afterEvents.buttonPush.unsubscribe(e)}}exports.ButtonPushEventSignal=ButtonPushEventSignal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ButtonPushEventSignal = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const vector_js_1 = require("../../utils/vector.js");
6
+ const mapEventSignal_js_1 = require("../mapEventSignal.js");
7
+ class ButtonPushEventSignal extends mapEventSignal_js_1.BaseMapEventSignal {
8
+ buildKey(options) {
9
+ const loc = vector_js_1.Vector3Utils.fromArray(options.loc);
10
+ return `${options.dimensionId}-${loc.x}-${loc.y}-${loc.z}`;
11
+ }
12
+ buildData(callback, options) {
13
+ return {
14
+ callback,
15
+ players: options.players,
16
+ sourceType: options.sourceType,
17
+ };
18
+ }
19
+ extractKey(event) {
20
+ const loc = event.block.location;
21
+ return `${event.dimension.id}-${loc.x}-${loc.y}-${loc.z}`;
22
+ }
23
+ filter(data, event) {
24
+ if (data.sourceType && event.source.typeId !== data.sourceType)
25
+ return false;
26
+ if (event.source instanceof server_1.Player &&
27
+ data.players &&
28
+ !data.players.getById(event.source.id)) {
29
+ return false;
30
+ }
31
+ return true;
32
+ }
33
+ subscribeNative(cb) {
34
+ server_1.world.afterEvents.buttonPush.subscribe(cb);
35
+ return cb;
36
+ }
37
+ unsubscribeNative(cb) {
38
+ server_1.world.afterEvents.buttonPush.unsubscribe(cb);
39
+ }
40
+ }
41
+ exports.ButtonPushEventSignal = ButtonPushEventSignal;
@@ -1 +1,77 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlayerItemInSlotEventSignal=void 0;const server_1=require("@minecraft/server"),index_js_1=require("../../utils/index.js");class PlayerItemInSlotEventSignal{intervalEvent;tickSub=null;map=new Map;logger=new index_js_1.Logger(this.constructor.name);constructor(t){this.intervalEvent=t}subscribe(t,e){this.tickSub||(this.tickSub=this.intervalEvent.subscribe(this.tick.bind(this)));const s={...e,callback:t};let i=this.map.get(e.slot);return i||(i=new Set,this.map.set(e.slot,i)),i.add(s),this.wrapUnsubscribe(s)}wrapUnsubscribe(t){return{unsubscribe:()=>{const e=this.map.get(t.slot);e&&(e.delete(t),0==e.size&&this.map.delete(t.slot),this.cleanUp())}}}cleanUp(){0==this.map.size&&this.tickSub&&(this.tickSub?.unsubscribe(),this.tickSub=null)}tick(){for(let t of server_1.world.getAllPlayers()){if(!t||!t.isValid)continue;const e=t.getComponent(server_1.EntityComponentTypes.Equippable);if(e)for(const[s,i]of this.map.entries()){const r=e.getEquipment(s);if(r)for(const e of i)if(r.typeId===e.itemId&&(!e.group||e.group.has(t)))try{e.callback({item:r,player:t})}catch(t){this.logger.error("回调执行错误",t)}}}}}exports.PlayerItemInSlotEventSignal=PlayerItemInSlotEventSignal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerItemInSlotEventSignal = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const index_js_1 = require("../../utils/index.js");
6
+ /**当玩家指定槽位出现指定物品时触发 */
7
+ class PlayerItemInSlotEventSignal {
8
+ intervalEvent;
9
+ tickSub = null;
10
+ map = new Map();
11
+ logger = new index_js_1.Logger(this.constructor.name);
12
+ constructor(intervalEvent) {
13
+ this.intervalEvent = intervalEvent;
14
+ }
15
+ subscribe(callback, options) {
16
+ if (!this.tickSub) {
17
+ this.tickSub = this.intervalEvent.subscribe(this.tick.bind(this));
18
+ }
19
+ const data = {
20
+ ...options,
21
+ callback: callback,
22
+ };
23
+ let slot = this.map.get(options.slot);
24
+ if (!slot) {
25
+ slot = new Set();
26
+ this.map.set(options.slot, slot);
27
+ }
28
+ slot.add(data);
29
+ return this.wrapUnsubscribe(data);
30
+ }
31
+ wrapUnsubscribe(data) {
32
+ return {
33
+ unsubscribe: () => {
34
+ const slot = this.map.get(data.slot);
35
+ if (!slot)
36
+ return;
37
+ slot.delete(data);
38
+ if (slot.size == 0) {
39
+ this.map.delete(data.slot);
40
+ }
41
+ this.cleanUp();
42
+ },
43
+ };
44
+ }
45
+ cleanUp() {
46
+ if (this.map.size == 0 && this.tickSub) {
47
+ this.tickSub?.unsubscribe();
48
+ this.tickSub = null;
49
+ }
50
+ }
51
+ tick() {
52
+ for (let player of server_1.world.getAllPlayers()) {
53
+ if (!player || !player.isValid)
54
+ continue;
55
+ const equipComponent = player.getComponent(server_1.EntityComponentTypes.Equippable);
56
+ if (!equipComponent)
57
+ continue;
58
+ for (const [equip, list] of this.map.entries()) {
59
+ const item = equipComponent.getEquipment(equip);
60
+ if (!item)
61
+ continue;
62
+ for (const data of list) {
63
+ if (item.typeId === data.itemId &&
64
+ (!data.group || data.group.has(player))) {
65
+ try {
66
+ data.callback({ item, player });
67
+ }
68
+ catch (err) {
69
+ this.logger.error("回调执行错误", err);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ exports.PlayerItemInSlotEventSignal = PlayerItemInSlotEventSignal;
@@ -1 +1,51 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IntervalEventSignal=void 0;const server_1=require("@minecraft/server"),index_js_1=require("../../utils/index.js");class IntervalEventSignal{intervalId=null;items=new Set;logger=new index_js_1.Logger(this.constructor.name);subscribe(t,e){this.intervalId||this.start();const r={callback:t,interval:e?.ticks??0,tickCount:e?.ticks??1};return this.items.add(r),{unsubscribe:()=>this.items.delete(r)}}start(){this.intervalId=server_1.system.runInterval(()=>this.tick())}tick(){for(const t of this.items)if(t.tickCount--,t.tickCount<=0){try{t.callback()}catch(t){this.logger.error("Interval callback error:",t)}t.tickCount=t.interval}}dispose(){null!==this.intervalId&&(this.items.clear(),server_1.system.clearRun(this.intervalId))}}exports.IntervalEventSignal=IntervalEventSignal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntervalEventSignal = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const index_js_1 = require("../../utils/index.js");
6
+ /** 间隔时间事件 */
7
+ class IntervalEventSignal {
8
+ intervalId = null;
9
+ items = new Set();
10
+ logger = new index_js_1.Logger(this.constructor.name);
11
+ subscribe(callback, interval) {
12
+ //启动interval
13
+ if (!this.intervalId)
14
+ this.start();
15
+ //添加到set
16
+ const data = {
17
+ callback: callback,
18
+ interval: interval?.ticks ?? 0,
19
+ tickCount: interval?.ticks ?? 1,
20
+ };
21
+ this.items.add(data);
22
+ //返回取消订阅方法
23
+ return {
24
+ unsubscribe: () => this.items.delete(data),
25
+ };
26
+ }
27
+ start() {
28
+ this.intervalId = server_1.system.runInterval(() => this.tick());
29
+ }
30
+ tick() {
31
+ for (const item of this.items) {
32
+ item.tickCount--;
33
+ if (item.tickCount <= 0) {
34
+ try {
35
+ item.callback();
36
+ }
37
+ catch (e) {
38
+ this.logger.error("Interval callback error:", e);
39
+ }
40
+ item.tickCount = item.interval;
41
+ }
42
+ }
43
+ }
44
+ dispose() {
45
+ if (this.intervalId !== null) {
46
+ this.items.clear();
47
+ server_1.system.clearRun(this.intervalId);
48
+ }
49
+ }
50
+ }
51
+ exports.IntervalEventSignal = IntervalEventSignal;
@@ -1 +1,36 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ItemUseEventSignal=void 0;const server_1=require("@minecraft/server"),mapEventSignal_js_1=require("../mapEventSignal.js");class ItemUseEventSignal extends mapEventSignal_js_1.BaseMapEventSignal{buildKey(e){return e.itemId}buildData(e,r){return{callback:e,itemId:r.itemId,players:r.players}}extractKey(e){return e.itemStack.typeId??null}filter(e,r){return!(r.source instanceof server_1.Player&&e.players&&!e.players.getById(r.source.id))}subscribeNative(e){return server_1.world.afterEvents.itemUse.subscribe(e),e}unsubscribeNative(e){server_1.world.afterEvents.itemUse.unsubscribe(e)}}exports.ItemUseEventSignal=ItemUseEventSignal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ItemUseEventSignal = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const mapEventSignal_js_1 = require("../mapEventSignal.js");
6
+ class ItemUseEventSignal extends mapEventSignal_js_1.BaseMapEventSignal {
7
+ buildKey(options) {
8
+ return options.itemId;
9
+ }
10
+ buildData(callback, options) {
11
+ return {
12
+ callback,
13
+ itemId: options.itemId,
14
+ players: options.players,
15
+ };
16
+ }
17
+ extractKey(event) {
18
+ return event.itemStack.typeId ?? null;
19
+ }
20
+ filter(data, event) {
21
+ if (event.source instanceof server_1.Player &&
22
+ data.players &&
23
+ !data.players.getById(event.source.id)) {
24
+ return false;
25
+ }
26
+ return true;
27
+ }
28
+ subscribeNative(cb) {
29
+ server_1.world.afterEvents.itemUse.subscribe(cb);
30
+ return cb;
31
+ }
32
+ unsubscribeNative(cb) {
33
+ server_1.world.afterEvents.itemUse.unsubscribe(cb);
34
+ }
35
+ }
36
+ exports.ItemUseEventSignal = ItemUseEventSignal;
@@ -1 +1,106 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlayerOnBlockEventSignal=void 0;const server_1=require("@minecraft/server"),index_js_1=require("../../utils/index.js");class PlayerOnBlockEventSignal{tickEvent;blockMap=new Map;globalSubs=new Set;logger=new index_js_1.Logger(this.constructor.name);static BELOW_OFFSET={x:0,y:.02,z:0};subscription=null;constructor(e){this.tickEvent=e}subscribe(e,t){this.subscription||(this.subscription=this.tickEvent.subscribe(this.tick.bind(this)));const s=t?.typeIds,i={group:t?.group,callback:e,typeIds:s};if(!s||0===s.length)return this.globalSubs.add(i),this.wrapUnsubscribe(()=>this.globalSubs.delete(i));if(1===s.length){const e=s[0],t=this.blockMap.get(e)??new Set;return t.add(i),this.blockMap.set(e,t),this.wrapUnsubscribe(()=>{const t=this.blockMap.get(e);t&&(t.delete(i),0===t.size&&this.blockMap.delete(e))})}return this.globalSubs.add(i),this.wrapUnsubscribe(()=>this.globalSubs.delete(i))}wrapUnsubscribe(e){return{unsubscribe:()=>{e(),0===this.blockMap.size&&0===this.globalSubs.size&&this.cleanUp()}}}cleanUp(){this.subscription?.unsubscribe(),this.subscription=null}tick(){for(const e of server_1.world.getAllPlayers()){if(null==e||!e.isValid)continue;if(e.location.y<e.dimension.heightRange.min||e.location.y>e.dimension.heightRange.max)continue;const t=e.dimension.getBlock(index_js_1.Vector3Utils.subtract(e.location,PlayerOnBlockEventSignal.BELOW_OFFSET));if(!t)continue;for(const s of this.globalSubs)if((!s.group||s.group.getById(e.id))&&(!s.typeIds||s.typeIds.includes(t.typeId)))try{s.callback({player:e,block:t})}catch(e){this.logger.error("回调执行错误",e)}const s=this.blockMap.get(t.typeId);if(s)for(const i of s)if(!i.group||i.group.getById(e.id))try{i.callback({player:e,block:t})}catch(e){this.logger.error("回调执行错误",e)}}}}exports.PlayerOnBlockEventSignal=PlayerOnBlockEventSignal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerOnBlockEventSignal = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const index_js_1 = require("../../utils/index.js");
6
+ class PlayerOnBlockEventSignal {
7
+ tickEvent;
8
+ blockMap = new Map();
9
+ globalSubs = new Set();
10
+ logger = new index_js_1.Logger(this.constructor.name);
11
+ static BELOW_OFFSET = { x: 0, y: 0.02, z: 0 };
12
+ subscription = null;
13
+ constructor(tickEvent) {
14
+ this.tickEvent = tickEvent;
15
+ }
16
+ subscribe(callback, options) {
17
+ if (!this.subscription) {
18
+ this.subscription = this.tickEvent.subscribe(this.tick.bind(this));
19
+ }
20
+ const typeIds = options?.typeIds;
21
+ const data = {
22
+ group: options?.group,
23
+ callback,
24
+ typeIds,
25
+ };
26
+ // 1) 没传 typeIds → 全局订阅
27
+ if (!typeIds || typeIds.length === 0) {
28
+ this.globalSubs.add(data);
29
+ return this.wrapUnsubscribe(() => this.globalSubs.delete(data));
30
+ }
31
+ // 2) 传了 1 个 typeId → 用 map 存储
32
+ if (typeIds.length === 1) {
33
+ const typeId = typeIds[0];
34
+ const set = this.blockMap.get(typeId) ?? new Set();
35
+ set.add(data);
36
+ this.blockMap.set(typeId, set);
37
+ return this.wrapUnsubscribe(() => {
38
+ const list = this.blockMap.get(typeId);
39
+ if (list) {
40
+ list.delete(data);
41
+ if (list.size === 0) {
42
+ this.blockMap.delete(typeId);
43
+ }
44
+ }
45
+ });
46
+ }
47
+ // 3) 多个 typeId → 放到 globalSubs,tick 时筛选
48
+ this.globalSubs.add(data);
49
+ return this.wrapUnsubscribe(() => this.globalSubs.delete(data));
50
+ }
51
+ wrapUnsubscribe(remove) {
52
+ return {
53
+ unsubscribe: () => {
54
+ remove();
55
+ if (this.blockMap.size === 0 && this.globalSubs.size === 0) {
56
+ this.cleanUp();
57
+ }
58
+ },
59
+ };
60
+ }
61
+ cleanUp() {
62
+ this.subscription?.unsubscribe();
63
+ this.subscription = null;
64
+ }
65
+ tick() {
66
+ for (const p of server_1.world.getAllPlayers()) {
67
+ if (p == undefined || !p.isValid)
68
+ continue;
69
+ //如果超过高度范围,跳过
70
+ if (p.location.y < p.dimension.heightRange.min ||
71
+ p.location.y > p.dimension.heightRange.max)
72
+ continue;
73
+ const block = p.dimension.getBlock(index_js_1.Vector3Utils.subtract(p.location, PlayerOnBlockEventSignal.BELOW_OFFSET));
74
+ if (!block)
75
+ continue;
76
+ // 1) 全局订阅(含多 typeId 的订阅)
77
+ for (const data of this.globalSubs) {
78
+ if (data.group && !data.group.getById(p.id))
79
+ continue;
80
+ if (data.typeIds && !data.typeIds.includes(block.typeId))
81
+ continue;
82
+ try {
83
+ data.callback({ player: p, block });
84
+ }
85
+ catch (e) {
86
+ this.logger.error("回调执行错误", e);
87
+ }
88
+ }
89
+ // 2) 精确 typeId 的订阅
90
+ const list = this.blockMap.get(block.typeId);
91
+ if (list) {
92
+ for (const data of list) {
93
+ if (data.group && !data.group.getById(p.id))
94
+ continue;
95
+ try {
96
+ data.callback({ player: p, block });
97
+ }
98
+ catch (e) {
99
+ this.logger.error("回调执行错误", e);
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ exports.PlayerOnBlockEventSignal = PlayerOnBlockEventSignal;