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,48 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EntityInteractionBlocker=void 0;const server_1=require("@minecraft/server"),main_js_1=require("../../main.js");class EntityInteractionBlocker extends main_js_1.GameComponent{onAttach(){if(!this.options)return;const{groupSet:e,entityIds:t,entityComponentTypes:n,showMessage:r=!0,message:s}=this.options;this.subscribe(server_1.world.beforeEvents.playerInteractWithEntity,o=>{const{player:i,target:c}=o;if(console.log(c.typeId),e.findById(i.id)&&(!(t&&t.length>0)||t.includes(c.typeId))){if(n&&n.length>0){if(!n.some(e=>{try{return!!c.getComponent(e)}catch{return!1}}))return}o.cancel=!0,r&&server_1.system.run(()=>i.onScreenDisplay.setActionBar(s??"§c你无法与该实体交互!"))}})}}exports.EntityInteractionBlocker=EntityInteractionBlocker;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityInteractionBlocker = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const main_js_1 = require("../../main.js");
6
+ /**
7
+ * 通用实体交互阻止组件
8
+ */
9
+ class EntityInteractionBlocker extends main_js_1.GameComponent {
10
+ onAttach() {
11
+ if (!this.options)
12
+ return;
13
+ const { groupSet, entityIds, entityComponentTypes, showMessage = true, message, } = this.options;
14
+ this.subscribe(server_1.world.beforeEvents.playerInteractWithEntity, (t) => {
15
+ const { player, target } = t;
16
+ console.log(target.typeId);
17
+ // 1️⃣ 不在限制组内 -> 放行
18
+ if (!groupSet.findById(player.id))
19
+ return;
20
+ // 2️⃣ 若有实体类型限制,且当前实体不在其中 -> 放行
21
+ if (entityIds &&
22
+ entityIds.length > 0 &&
23
+ !entityIds.includes(target.typeId)) {
24
+ return;
25
+ }
26
+ // 3️⃣ 若指定组件类型数组,且实体不含任意一个组件 -> 放行
27
+ if (entityComponentTypes && entityComponentTypes.length > 0) {
28
+ const hasComponent = entityComponentTypes.some((type) => {
29
+ try {
30
+ return !!target.getComponent(type);
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ });
36
+ if (!hasComponent)
37
+ return;
38
+ }
39
+ // 4️⃣ 阻止交互
40
+ t.cancel = true;
41
+ // 5️⃣ 提示
42
+ if (showMessage) {
43
+ server_1.system.run(() => player.onScreenDisplay.setActionBar(message ?? "§c你无法与该实体交互!"));
44
+ }
45
+ });
46
+ }
47
+ }
48
+ exports.EntityInteractionBlocker = EntityInteractionBlocker;
@@ -1 +1,48 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlayerHealthIndicator=void 0;const server_1=require("@minecraft/server"),main_js_1=require("../../main.js"),index_js_1=require("../index.js");class PlayerHealthIndicator extends index_js_1.GameComponent{obj;onAttach(){this.options&&this.subscribe(main_js_1.Game.events.interval,()=>this.refresh(),this.options.refreshInterval)}onDetach(){this.obj?.isValid&&server_1.world.scoreboard.removeObjective(this.obj)}getObj(){return this.obj&&this.obj.isValid||(this.obj=server_1.world.scoreboard.getObjective(this.options.scoreBoardName)??server_1.world.scoreboard.addObjective(this.options.scoreBoardName,this.options.displayName)),this.obj}show(){const e=this.getObj();server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.BelowName,{objective:e})}refresh(){const e=this.getObj();server_1.world.getAllPlayers().forEach(r=>{if(!r)return;const t=r.getComponent(server_1.EntityComponentTypes.Health);if(!t)return;const s=t.currentValue;e.setScore(r,s)})}}exports.PlayerHealthIndicator=PlayerHealthIndicator;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerHealthIndicator = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const main_js_1 = require("../../main.js");
6
+ const index_js_1 = require("../index.js");
7
+ class PlayerHealthIndicator extends index_js_1.GameComponent {
8
+ obj;
9
+ onAttach() {
10
+ if (!this.options)
11
+ return;
12
+ this.subscribe(main_js_1.Game.events.interval, () => this.refresh(), this.options.refreshInterval);
13
+ }
14
+ onDetach() {
15
+ if (this.obj?.isValid) {
16
+ server_1.world.scoreboard.removeObjective(this.obj);
17
+ }
18
+ }
19
+ getObj() {
20
+ if (this.obj && this.obj.isValid)
21
+ return this.obj;
22
+ this.obj =
23
+ server_1.world.scoreboard.getObjective(this.options.scoreBoardName) ??
24
+ server_1.world.scoreboard.addObjective(this.options.scoreBoardName, this.options.displayName);
25
+ return this.obj;
26
+ }
27
+ /**展示 */
28
+ show() {
29
+ const obj = this.getObj();
30
+ server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.BelowName, {
31
+ objective: obj,
32
+ });
33
+ }
34
+ /**刷新计分板 */
35
+ refresh() {
36
+ const obj = this.getObj();
37
+ server_1.world.getAllPlayers().forEach((p) => {
38
+ if (!p)
39
+ return;
40
+ const comp = p.getComponent(server_1.EntityComponentTypes.Health);
41
+ if (!comp)
42
+ return;
43
+ const cur = comp.currentValue;
44
+ obj.setScore(p, cur);
45
+ });
46
+ }
47
+ }
48
+ exports.PlayerHealthIndicator = PlayerHealthIndicator;
@@ -1 +1,22 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlayerRegionMonitor=void 0;const main_js_1=require("../../main.js"),gameComponent_js_1=require("../gameComponent.js");class PlayerRegionMonitor extends gameComponent_js_1.GameComponent{onAttach(){this.options&&this.subscribe(main_js_1.Game.events.interval,()=>this.detectOutOfRegionPlayers(),this.options.interval)}detectOutOfRegionPlayers(){const e=this.options.region;this.options.groups.forEach(o=>{e.isInside(o.player.location)||this.options.onLeave(o)})}}exports.PlayerRegionMonitor=PlayerRegionMonitor;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerRegionMonitor = void 0;
4
+ const main_js_1 = require("../../main.js");
5
+ const gameComponent_js_1 = require("../gameComponent.js");
6
+ /**玩家区域监测 */
7
+ class PlayerRegionMonitor extends gameComponent_js_1.GameComponent {
8
+ onAttach() {
9
+ if (!this.options)
10
+ return;
11
+ this.subscribe(main_js_1.Game.events.interval, () => this.detectOutOfRegionPlayers(), this.options.interval);
12
+ }
13
+ detectOutOfRegionPlayers() {
14
+ const region = this.options.region;
15
+ this.options.groups.forEach((p) => {
16
+ if (!region.isInside(p.player.location)) {
17
+ this.options.onLeave(p);
18
+ }
19
+ });
20
+ }
21
+ }
22
+ exports.PlayerRegionMonitor = PlayerRegionMonitor;
@@ -1 +1,59 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RespawnComponent=void 0;const server_1=require("@minecraft/server"),vanila_data_js_1=require("../../utils/vanila-data.js"),index_js_1=require("../index.js");class RespawnComponent extends index_js_1.GameComponent{onAttach(){if(!this.options)return;const{onDie:e,autoBroadcast:t,buildNameFunc:n,groupSet:s,onSpawn:i,buildMsg:r}=this.options;this.subscribe(server_1.world.afterEvents.entityDie,i=>{const a=i.deadEntity;if(a.typeId!==vanila_data_js_1.EntityTypeIds.Player)return;const o=s.findById(a.id);if(!o)return;const{player:d,group:p}=o;if(e?.(d,p,i.damageSource.damagingEntity),t&&n){const e=n(d,p),t=this.getKillerName(i.damageSource.damagingEntity);let a;a=r?r(e,t,d):t?`${e} §r 被 ${t} §r 杀死了`:`${e} §r 死了`,s.sendMessage(a)}}),i&&this.subscribe(server_1.world.afterEvents.playerSpawn,e=>{const t=s.findById(e.player.id);t?.player&&i(t.player,t.group)})}getKillerName(e){if(!e||e.typeId!==vanila_data_js_1.EntityTypeIds.Player)return;const t=this.options.groupSet.findById(e.id);return t&&this.options.buildNameFunc?this.options.buildNameFunc(t.player,t.group):void 0}}exports.RespawnComponent=RespawnComponent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RespawnComponent = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const vanila_data_js_1 = require("../../utils/vanila-data.js");
6
+ const index_js_1 = require("../index.js");
7
+ class RespawnComponent extends index_js_1.GameComponent {
8
+ onAttach() {
9
+ if (!this.options)
10
+ return;
11
+ const { onDie, autoBroadcast, buildNameFunc, groupSet, onSpawn, buildMsg, } = this.options;
12
+ this.subscribe(server_1.world.afterEvents.entityDie, (event) => {
13
+ const deadEntity = event.deadEntity;
14
+ if (deadEntity.typeId !== vanila_data_js_1.EntityTypeIds.Player)
15
+ return;
16
+ const result = groupSet.findById(deadEntity.id);
17
+ if (!result)
18
+ return;
19
+ const { player, group } = result;
20
+ // 执行自定义逻辑
21
+ onDie?.(player, group, event.damageSource.damagingEntity);
22
+ // 自动广播消息
23
+ if (autoBroadcast && buildNameFunc) {
24
+ const playerName = buildNameFunc(player, group);
25
+ const killerName = this.getKillerName(event.damageSource.damagingEntity);
26
+ let message;
27
+ if (buildMsg) {
28
+ message = buildMsg(playerName, killerName, player);
29
+ }
30
+ else {
31
+ message = killerName
32
+ ? `${playerName} §r 被 ${killerName} §r 杀死了`
33
+ : `${playerName} §r 死了`;
34
+ }
35
+ groupSet.sendMessage(message);
36
+ }
37
+ });
38
+ if (onSpawn) {
39
+ this.subscribe(server_1.world.afterEvents.playerSpawn, (t) => {
40
+ const ans = groupSet.findById(t.player.id);
41
+ if (ans?.player) {
42
+ onSpawn(ans.player, ans.group);
43
+ }
44
+ });
45
+ }
46
+ }
47
+ getKillerName(source) {
48
+ if (!source || source.typeId !== vanila_data_js_1.EntityTypeIds.Player)
49
+ return undefined;
50
+ const result = this.options.groupSet.findById(source.id);
51
+ if (!result)
52
+ return undefined;
53
+ if (this.options.buildNameFunc) {
54
+ return this.options.buildNameFunc(result.player, result.group);
55
+ }
56
+ return undefined;
57
+ }
58
+ }
59
+ exports.RespawnComponent = RespawnComponent;
@@ -1 +1,69 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SpawnPointProtector=void 0;const server_1=require("@minecraft/server"),main_js_1=require("../../main.js"),index_js_1=require("../../utils/index.js"),gameComponent_js_1=require("../gameComponent.js");class SpawnPointProtector extends gameComponent_js_1.GameComponent{onAttach(){const e=this.options;if(!e)return;(e.autoSetSpawnPoint??1)&&this.setPlayerSpawnPoints();const t=e.protectInterval??new index_js_1.Duration(10);this.subscribe(main_js_1.Game.events.interval,()=>{e.autoSetSpawnPoint&&this.setPlayerSpawnPoints(),this.protectSpawnAreas()},t);const o=index_js_1.Vector3Utils.below(e.spawnPoint);this.subscribe(server_1.world.beforeEvents.playerInteractWithBlock,e=>{index_js_1.Vector3Utils.isEqual(e.block.location,o)&&(e.cancel=!0)})}setPlayerSpawnPoints(){const{playerGroup:e,spawnPoint:t,dimension:o}=this.options;e.forEach(e=>{e.player.setSpawnPoint({dimension:o,...t})})}teleportAllToSpawn(){const{playerGroup:e,spawnPoint:t,dimension:o}=this.options;e.forEach(e=>{e.player.teleport(t,{dimension:o})})}protectSpawnAreas(){const{spawnPoint:e,dimension:t,protectRadius:o}=this.options;if(e&&t)try{const n=o??{x:1,y:1,z:1},s=index_js_1.Vector3Utils.add(e,n),i=index_js_1.Vector3Utils.subtract(e,{x:n.x,y:0,z:n.z});t.fillBlocks(new server_1.BlockVolume(s,i),"air"),t.setBlockType(index_js_1.Vector3Utils.below(e),"bedrock")}catch(e){}}}exports.SpawnPointProtector=SpawnPointProtector;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpawnPointProtector = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const main_js_1 = require("../../main.js");
6
+ const index_js_1 = require("../../utils/index.js");
7
+ const gameComponent_js_1 = require("../gameComponent.js");
8
+ class SpawnPointProtector extends gameComponent_js_1.GameComponent {
9
+ onAttach() {
10
+ const options = this.options;
11
+ if (!options)
12
+ return;
13
+ // 初始设置玩家重生点
14
+ if (options.autoSetSpawnPoint ?? true) {
15
+ this.setPlayerSpawnPoints();
16
+ }
17
+ // 循环设置重生点 & 保护区域
18
+ const interval = options.protectInterval ?? new index_js_1.Duration(10);
19
+ this.subscribe(main_js_1.Game.events.interval, () => {
20
+ if (options.autoSetSpawnPoint) {
21
+ this.setPlayerSpawnPoints();
22
+ }
23
+ this.protectSpawnAreas();
24
+ }, interval);
25
+ // 出生点保护:拦截方块交互
26
+ const protectedBlock = index_js_1.Vector3Utils.below(options.spawnPoint);
27
+ this.subscribe(server_1.world.beforeEvents.playerInteractWithBlock, (t) => {
28
+ if (index_js_1.Vector3Utils.isEqual(t.block.location, protectedBlock)) {
29
+ t.cancel = true;
30
+ }
31
+ });
32
+ }
33
+ /** 设置玩家重生点 */
34
+ setPlayerSpawnPoints() {
35
+ const { playerGroup, spawnPoint, dimension } = this.options;
36
+ playerGroup.forEach((p) => {
37
+ p.player.setSpawnPoint({
38
+ dimension,
39
+ ...spawnPoint,
40
+ });
41
+ });
42
+ }
43
+ /** 传送所有玩家到出生点 */
44
+ teleportAllToSpawn() {
45
+ const { playerGroup, spawnPoint, dimension } = this.options;
46
+ playerGroup.forEach((p) => {
47
+ p.player.teleport(spawnPoint, { dimension });
48
+ });
49
+ }
50
+ /** 循环保护出生点区域 */
51
+ protectSpawnAreas() {
52
+ const { spawnPoint, dimension, protectRadius } = this.options;
53
+ if (!spawnPoint || !dimension)
54
+ return;
55
+ try {
56
+ const radius = protectRadius ?? { x: 1, y: 1, z: 1 };
57
+ const max = index_js_1.Vector3Utils.add(spawnPoint, radius);
58
+ const min = index_js_1.Vector3Utils.subtract(spawnPoint, {
59
+ x: radius.x,
60
+ y: 0,
61
+ z: radius.z,
62
+ });
63
+ dimension.fillBlocks(new server_1.BlockVolume(max, min), "air");
64
+ dimension.setBlockType(index_js_1.Vector3Utils.below(spawnPoint), "bedrock");
65
+ }
66
+ catch (err) { }
67
+ }
68
+ }
69
+ exports.SpawnPointProtector = SpawnPointProtector;
@@ -1 +1,53 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RegionProtector=void 0;const server_1=require("@minecraft/server"),gameComponent_js_1=require("../gameComponent.js");class RegionProtector extends gameComponent_js_1.GameComponent{onAttach(){this.options&&((this.options.blockBreakInside||this.options.blockBreakOutside)&&this.subscribe(server_1.world.beforeEvents.playerBreakBlock,o=>{this.options?.groupSet&&!this.options.groupSet.has(o.player.id)||this.handleBreak(o)}),(this.options.blockInteractOutside||this.options.blockInteractInside)&&this.subscribe(server_1.world.beforeEvents.playerInteractWithBlock,o=>{this.options?.groupSet&&!this.options.groupSet.has(o.player.id)||this.handleInteract(o)}))}handleBreak(o){(this.options.blockBreakInside&&this.options.region.isBlockInside(o.block.location)||this.options.blockBreakOutside&&!this.options.region.isBlockInside(o.block.location))&&(o.cancel=!0)}handleInteract(o){(this.options.blockInteractInside&&this.options.region.isBlockInside(o.block.location)||this.options.blockInteractOutside&&!this.options.region.isBlockInside(o.block.location))&&(o.cancel=!0)}}exports.RegionProtector=RegionProtector;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegionProtector = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const gameComponent_js_1 = require("../gameComponent.js");
6
+ class RegionProtector extends gameComponent_js_1.GameComponent {
7
+ onAttach() {
8
+ if (!this.options)
9
+ return;
10
+ // 处理破坏方块
11
+ if (this.options.blockBreakInside || this.options.blockBreakOutside) {
12
+ this.subscribe(server_1.world.beforeEvents.playerBreakBlock, (t) => {
13
+ if (this.options?.groupSet &&
14
+ !this.options.groupSet.has(t.player.id)) {
15
+ return;
16
+ }
17
+ this.handleBreak(t);
18
+ });
19
+ }
20
+ // 处理方块交互
21
+ if (this.options.blockInteractOutside ||
22
+ this.options.blockInteractInside) {
23
+ this.subscribe(server_1.world.beforeEvents.playerInteractWithBlock, (t) => {
24
+ if (this.options?.groupSet &&
25
+ !this.options.groupSet.has(t.player.id)) {
26
+ return;
27
+ }
28
+ this.handleInteract(t);
29
+ });
30
+ }
31
+ }
32
+ handleBreak(t) {
33
+ if (this.options.blockBreakInside &&
34
+ this.options.region.isBlockInside(t.block.location)) {
35
+ t.cancel = true;
36
+ }
37
+ else if (this.options.blockBreakOutside &&
38
+ !this.options.region.isBlockInside(t.block.location)) {
39
+ t.cancel = true;
40
+ }
41
+ }
42
+ handleInteract(t) {
43
+ if (this.options.blockInteractInside &&
44
+ this.options.region.isBlockInside(t.block.location)) {
45
+ t.cancel = true;
46
+ }
47
+ else if (this.options.blockInteractOutside &&
48
+ !this.options.region.isBlockInside(t.block.location)) {
49
+ t.cancel = true;
50
+ }
51
+ }
52
+ }
53
+ exports.RegionProtector = RegionProtector;
@@ -1 +1,71 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RegionTeamChooser=void 0;const regionEvents_js_1=require("../../gameEvent/events/regionEvents.js"),main_js_1=require("../../main.js"),gameComponent_js_1=require("../gameComponent.js"),server_1=require("@minecraft/server");class RegionTeamChooser extends gameComponent_js_1.GameComponent{onAttach(){this.options&&this.options.config.forEach(e=>{this.subscribe(main_js_1.Game.events.region,n=>this.handleRegionEvent(n,e),e.region)})}handleRegionEvent(e,n){const o=this.state.playerManager.get(e.player);if(o.isValid)switch(e.type){case regionEvents_js_1.RegionEventType.Enter:this.handlePlayerEnter(o,n);break;case regionEvents_js_1.RegionEventType.Leave:this.handlePlayerLeave(o,n)}else e.player.isValid&&e.player.sendMessage("暂时无法进入队伍")}handlePlayerEnter(e,n){if((this.options.allowSpectator??1)&&e.player?.getGameMode()==server_1.GameMode.Spectator)return;const o=n.team,t=o.has(e);n.onEnter&&n.onEnter(e),this.options?.config.forEach(n=>{n.team!==o&&n.team.delete(e)}),o.add(e),n.onJoin&&!t&&n.onJoin(e)}handlePlayerLeave(e,n){(this.options?.removeOnLeave??!1)&&n.team.delete(e)}onDetach(){super.onDetach(),this.options&&this.options.config.forEach(e=>e.team.clearInvalid())}}exports.RegionTeamChooser=RegionTeamChooser;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegionTeamChooser = void 0;
4
+ const regionEvents_js_1 = require("../../gameEvent/events/regionEvents.js");
5
+ const main_js_1 = require("../../main.js");
6
+ const gameComponent_js_1 = require("../gameComponent.js");
7
+ const server_1 = require("@minecraft/server");
8
+ /**区域队伍选择器 */
9
+ class RegionTeamChooser extends gameComponent_js_1.GameComponent {
10
+ onAttach() {
11
+ if (!this.options)
12
+ return;
13
+ this.options.config.forEach((data) => {
14
+ this.subscribe(main_js_1.Game.events.region, (event) => this.handleRegionEvent(event, data), data.region);
15
+ });
16
+ }
17
+ handleRegionEvent(event, data) {
18
+ const gamePlayer = this.state.playerManager.get(event.player);
19
+ if (!gamePlayer.isValid) {
20
+ if (event.player.isValid) {
21
+ event.player.sendMessage("暂时无法进入队伍");
22
+ }
23
+ return;
24
+ }
25
+ switch (event.type) {
26
+ case regionEvents_js_1.RegionEventType.Enter:
27
+ this.handlePlayerEnter(gamePlayer, data);
28
+ break;
29
+ case regionEvents_js_1.RegionEventType.Leave:
30
+ this.handlePlayerLeave(gamePlayer, data);
31
+ break;
32
+ }
33
+ }
34
+ handlePlayerEnter(gamePlayer, configData) {
35
+ //不允许旁观者直接返回
36
+ if ((this.options.allowSpectator ?? true) &&
37
+ gamePlayer.player?.getGameMode() == server_1.GameMode.Spectator) {
38
+ return;
39
+ }
40
+ const newTeam = configData.team;
41
+ const alreadyInTeam = newTeam.has(gamePlayer);
42
+ if (configData.onEnter) {
43
+ configData.onEnter(gamePlayer);
44
+ }
45
+ //从所有队伍清除目标玩家
46
+ this.options?.config.forEach((d) => {
47
+ if (d.team !== newTeam) {
48
+ d.team.delete(gamePlayer);
49
+ }
50
+ });
51
+ //添加到新队伍
52
+ newTeam.add(gamePlayer);
53
+ //执行回调
54
+ if (configData.onJoin && !alreadyInTeam) {
55
+ configData.onJoin(gamePlayer);
56
+ }
57
+ }
58
+ handlePlayerLeave(gamePlayer, configData) {
59
+ const shouldRemoveOnLeave = this.options?.removeOnLeave ?? false;
60
+ if (shouldRemoveOnLeave) {
61
+ configData.team.delete(gamePlayer);
62
+ }
63
+ }
64
+ onDetach() {
65
+ super.onDetach();
66
+ if (this.options) {
67
+ this.options.config.forEach((t) => t.team.clearInvalid());
68
+ }
69
+ }
70
+ }
71
+ exports.RegionTeamChooser = RegionTeamChooser;
@@ -1 +1,20 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RegionTeamCleaner=void 0;const regionEvents_js_1=require("../../gameEvent/events/regionEvents.js"),main_js_1=require("../../main.js"),gameComponent_js_1=require("../gameComponent.js");class RegionTeamCleaner extends gameComponent_js_1.GameComponent{onAttach(){this.options&&this.subscribe(main_js_1.Game.events.region,e=>{e.type==regionEvents_js_1.RegionEventType.Leave&&(this.options?.teams.forEach(n=>n.delete(e.player)),this.options?.onClean?.(e.player))},this.options.region)}}exports.RegionTeamCleaner=RegionTeamCleaner;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegionTeamCleaner = void 0;
4
+ const regionEvents_js_1 = require("../../gameEvent/events/regionEvents.js");
5
+ const main_js_1 = require("../../main.js");
6
+ const gameComponent_js_1 = require("../gameComponent.js");
7
+ /**玩家离开指定区域时将他从team移除 */
8
+ class RegionTeamCleaner extends gameComponent_js_1.GameComponent {
9
+ onAttach() {
10
+ if (!this.options)
11
+ return;
12
+ this.subscribe(main_js_1.Game.events.region, (t) => {
13
+ if (t.type == regionEvents_js_1.RegionEventType.Leave) {
14
+ this.options?.teams.forEach((team) => team.delete(t.player));
15
+ this.options?.onClean?.(t.player);
16
+ }
17
+ }, this.options.region);
18
+ }
19
+ }
20
+ exports.RegionTeamCleaner = RegionTeamCleaner;
@@ -1 +1,77 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InfoScoreboard=void 0;const server_1=require("@minecraft/server"),gameComponent_js_1=require("../gameComponent.js");class InfoScoreboard extends gameComponent_js_1.GameComponent{objective;initCode=48;getObj(){if(this.objective&&this.objective.isValid)return this.objective;const e=this.options.scoreBoardName;return this.objective=server_1.world.scoreboard.getObjective(e)??server_1.world.scoreboard.addObjective(e,this.options.displayName),this.objective}onAttach(){if(!this.options)throw new Error("无options");this.options.showOnAttach&&this.show()}onDetach(){this.objective?.isValid&&server_1.world.scoreboard.removeObjective(this.objective)}show(){this.options&&server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar,{objective:this.getObj()})}updateLines(e){if(!this.options)return;const o=this.getObj(),t=server_1.world.scoreboard.getObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar)?.objective.id==o.id;if(server_1.world.scoreboard.removeObjective(o),!t)return;this.show();let r=this.initCode;for(let o=0;o<e.length;o++)""===e[o]&&(e[o]="§"+String.fromCodePoint(r++)),e[o]=" ".repeat(this.options.paddingLeft??0)+e[o];const s=this.options?.header,i=this.options?.footer;s&&e.unshift(...s()),i&&e.push(...i());const n=this.getObj();for(let o=0;o<e.length;o++)n.setScore(e[o],e.length-o-1)}}exports.InfoScoreboard=InfoScoreboard;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfoScoreboard = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const gameComponent_js_1 = require("../gameComponent.js");
6
+ /**信息侧边栏 */
7
+ class InfoScoreboard extends gameComponent_js_1.GameComponent {
8
+ objective;
9
+ initCode = 48;
10
+ getObj() {
11
+ if (this.objective && this.objective.isValid)
12
+ return this.objective;
13
+ const name = this.options.scoreBoardName;
14
+ this.objective =
15
+ server_1.world.scoreboard.getObjective(name) ??
16
+ server_1.world.scoreboard.addObjective(name, this.options.displayName);
17
+ return this.objective;
18
+ }
19
+ onAttach() {
20
+ if (!this.options) {
21
+ throw new Error("无options");
22
+ }
23
+ if (this.options.showOnAttach) {
24
+ this.show();
25
+ }
26
+ }
27
+ onDetach() {
28
+ if (this.objective?.isValid) {
29
+ server_1.world.scoreboard.removeObjective(this.objective);
30
+ }
31
+ }
32
+ /**手动显示计分板 */
33
+ show() {
34
+ if (!this.options)
35
+ return;
36
+ server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar, {
37
+ objective: this.getObj(),
38
+ });
39
+ }
40
+ /**更新计分板内容 */
41
+ updateLines(lines) {
42
+ if (!this.options)
43
+ return;
44
+ const sb = this.getObj();
45
+ const isDisplay = server_1.world.scoreboard.getObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar)
46
+ ?.objective.id == sb.id;
47
+ server_1.world.scoreboard.removeObjective(sb);
48
+ //如果不在显示则直接返回
49
+ if (!isDisplay) {
50
+ return;
51
+ }
52
+ this.show();
53
+ //预处理
54
+ let blankCode = this.initCode;
55
+ for (let i = 0; i < lines.length; i++) {
56
+ if (lines[i] === "") {
57
+ lines[i] = "§" + String.fromCodePoint(blankCode++);
58
+ }
59
+ lines[i] = " ".repeat(this.options.paddingLeft ?? 0) + lines[i];
60
+ }
61
+ //加上header和footer
62
+ const header = this.options?.header;
63
+ const footer = this.options?.footer;
64
+ if (header) {
65
+ lines.unshift(...header());
66
+ }
67
+ if (footer) {
68
+ lines.push(...footer());
69
+ }
70
+ const sb1 = this.getObj();
71
+ //设置
72
+ for (let i = 0; i < lines.length; i++) {
73
+ sb1.setScore(lines[i], lines.length - i - 1);
74
+ }
75
+ }
76
+ }
77
+ exports.InfoScoreboard = InfoScoreboard;
@@ -1 +1,83 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TeamScoreBoard=void 0;const server_1=require("@minecraft/server"),gameComponent_js_1=require("../gameComponent.js");class TeamScoreBoard extends gameComponent_js_1.GameComponent{obj;lastRefresh=0;onAttach(){this.options&&this.reset()}getObj(){return this.obj&&this.obj.isValid||(this.obj=server_1.world.scoreboard.getObjective(this.options.scoreboardName)??server_1.world.scoreboard.addObjective(this.options.scoreboardName,this.options.displayName)),this.obj}reset(){const e=this.getObj(),r=server_1.world.scoreboard.getObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar)?.objective.id==e.id;server_1.world.scoreboard.removeObjective(e),r&&this.show()}show(){this.options&&server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar,{objective:this.getObj()})}refreshScoreBoard(){if(!this.options)return;if(this.lastRefresh==server_1.system.currentTick)return;this.reset();const e=[],r=this.options.teams;for(const t of r){let r=t.team.getAll();t.teamFilter&&(r=r.filter(t.teamFilter)),t.teamSort&&r.sort(t.teamSort),r.forEach(r=>{if(!t.showInvalid&&!r.isValid)return;const s=t.buildName?t.buildName(r):(t.prefix??"")+r.name;e.push(s)})}const t=this.getObj();for(let r=0;r<e.length;r++)t.setScore(e[r],r);this.lastRefresh=server_1.system.currentTick}onDetach(){this.obj?.isValid&&server_1.world.scoreboard.removeObjective(this.obj)}}exports.TeamScoreBoard=TeamScoreBoard;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TeamScoreBoard = void 0;
4
+ const server_1 = require("@minecraft/server");
5
+ const gameComponent_js_1 = require("../gameComponent.js");
6
+ class TeamScoreBoard extends gameComponent_js_1.GameComponent {
7
+ obj;
8
+ lastRefresh = 0;
9
+ onAttach() {
10
+ if (!this.options)
11
+ return;
12
+ this.reset();
13
+ }
14
+ getObj() {
15
+ if (this.obj && this.obj.isValid)
16
+ return this.obj;
17
+ this.obj =
18
+ server_1.world.scoreboard.getObjective(this.options.scoreboardName) ??
19
+ server_1.world.scoreboard.addObjective(this.options.scoreboardName, this.options.displayName);
20
+ return this.obj;
21
+ }
22
+ reset() {
23
+ const obj = this.getObj();
24
+ const isDisplay = server_1.world.scoreboard.getObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar)
25
+ ?.objective.id == obj.id;
26
+ server_1.world.scoreboard.removeObjective(obj);
27
+ if (isDisplay) {
28
+ this.show();
29
+ }
30
+ }
31
+ /**显示 */
32
+ show() {
33
+ if (!this.options)
34
+ return;
35
+ server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar, {
36
+ objective: this.getObj(),
37
+ });
38
+ }
39
+ /**刷新选队计分板 */
40
+ refreshScoreBoard() {
41
+ if (!this.options)
42
+ return;
43
+ if (this.lastRefresh == server_1.system.currentTick)
44
+ return;
45
+ //清空计分板
46
+ this.reset();
47
+ //构建计分项
48
+ const scores = [];
49
+ const teams = this.options.teams;
50
+ for (const team of teams) {
51
+ let sortedTeam = team.team.getAll();
52
+ //过滤
53
+ if (team.teamFilter) {
54
+ sortedTeam = sortedTeam.filter(team.teamFilter);
55
+ }
56
+ //排序
57
+ if (team.teamSort) {
58
+ sortedTeam.sort(team.teamSort);
59
+ }
60
+ sortedTeam.forEach((p) => {
61
+ if (!(team.showInvalid ?? false) && !p.isValid) {
62
+ return;
63
+ }
64
+ const text = team.buildName
65
+ ? team.buildName(p)
66
+ : (team.prefix ?? "") + p.name;
67
+ scores.push(text);
68
+ });
69
+ }
70
+ //设置积分项
71
+ const obj = this.getObj();
72
+ for (let i = 0; i < scores.length; i++) {
73
+ obj.setScore(scores[i], i);
74
+ }
75
+ this.lastRefresh = server_1.system.currentTick;
76
+ }
77
+ onDetach() {
78
+ if (this.obj?.isValid) {
79
+ server_1.world.scoreboard.removeObjective(this.obj);
80
+ }
81
+ }
82
+ }
83
+ exports.TeamScoreBoard = TeamScoreBoard;
@@ -1 +1,6 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GameContext=void 0;class GameContext{}exports.GameContext=GameContext;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GameContext = void 0;
4
+ class GameContext {
5
+ }
6
+ exports.GameContext = GameContext;