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.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/lib/build/base.js +297 -1
- package/lib/build/build-g-config.json +11 -11
- package/lib/build/getModule.js +182 -1
- package/lib/build/index.js +370 -1
- package/lib/build/manifest.build.js +103 -1
- package/lib/build/mcVersion.js +86 -1
- package/lib/build/utils.js +6 -1
- package/lib/code-processor/c-handler-export.js +12 -1
- package/lib/code-processor/index.js +141 -1
- package/lib/code-processor/mtreehandler.js +164 -1
- package/lib/commander/index.js +154 -1
- package/lib/data/includes.json +12 -12
- package/lib/git/clone.js +28 -1
- package/lib/git/index.js +12 -1
- package/lib/git/pull.js +100 -1
- package/lib/lang/__translate.js +93 -1
- package/lib/lang/en.js +128 -1
- package/lib/lang/index.js +78 -1
- package/lib/lang/zh.js +146 -1
- package/lib/loger/colors.js +13 -1
- package/lib/loger/index.js +136 -1
- package/lib/mcx/ast/index.js +11 -1
- package/lib/mcx/ast/prop.js +78 -1
- package/lib/mcx/ast/tag.js +246 -1
- package/lib/mcx/compile-component/lib.js +106 -1
- package/lib/mcx/compile-component/types.js +2 -1
- package/lib/mcx/compile-component/utils.js +26 -1
- package/lib/mcx/compile-mcx/_compile.js +1 -1
- package/lib/mcx/compile-mcx/compile.js +34 -1
- package/lib/mcx/compile-mcx/context.js +19 -1
- package/lib/mcx/compile-mcx/index.js +10 -1
- package/lib/mcx/compile-mcx/mcx/index.js +2 -1
- package/lib/mcx/compile-mcx/mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/template/module.js +42 -1
- package/lib/mcx/compile-mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/utils.node.js +207 -1
- package/lib/mcx/index.js +13 -1
- package/lib/mcx/test/index.js +7 -1
- package/lib/mcx/test.js +21 -1
- package/lib/mcx/types.js +2 -1
- package/lib/mcx/utils.js +86 -1
- package/lib/module-handler/index.js +482 -1
- package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
- package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
- package/lib/modules/create-game/src/config.js +27 -1
- package/lib/modules/create-game/src/constants.js +19 -1
- package/lib/modules/create-game/src/createGameModule.js +24 -1
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
- package/lib/modules/create-game/src/gameComponent/index.js +31 -1
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
- package/lib/modules/create-game/src/gameContext.js +6 -1
- package/lib/modules/create-game/src/gameEngine.js +139 -1
- package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
- package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
- package/lib/modules/create-game/src/gameEvent/index.js +20 -1
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
- package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
- package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
- package/lib/modules/create-game/src/gameRegion/index.js +43 -1
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
- package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
- package/lib/modules/create-game/src/gameState/gameState.js +169 -1
- package/lib/modules/create-game/src/gameState/index.js +7 -1
- package/lib/modules/create-game/src/gameState/types.js +35 -1
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
- package/lib/modules/create-game/src/main.js +86 -1
- package/lib/modules/create-game/src/system/gameCommand.js +107 -1
- package/lib/modules/create-game/src/system/gameManager.js +124 -1
- package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
- package/lib/modules/create-game/src/utils/GameError.js +31 -1
- package/lib/modules/create-game/src/utils/algorithm.js +95 -1
- package/lib/modules/create-game/src/utils/chunk.js +63 -1
- package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
- package/lib/modules/create-game/src/utils/duration.js +25 -1
- package/lib/modules/create-game/src/utils/func.js +20 -1
- package/lib/modules/create-game/src/utils/index.js +52 -1
- package/lib/modules/create-game/src/utils/interfaces.js +2 -1
- package/lib/modules/create-game/src/utils/logger.js +47 -1
- package/lib/modules/create-game/src/utils/random.js +76 -1
- package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
- package/lib/modules/create-game/src/utils/vector.js +96 -1
- package/lib/modules/gameLib/src/config.js +134 -1
- package/lib/modules/gameLib/src/data.js +77 -1
- package/lib/modules/gameLib/src/entity.js +256 -1
- package/lib/modules/gameLib/src/event.js +285 -1
- package/lib/modules/gameLib/src/index.js +20 -1
- package/lib/modules/gameLib/src/loger.js +21 -1
- package/lib/modules/gameLib/src/ui.js +209 -1
- package/lib/modules/gameLib/src/utils.js +122 -1
- package/lib/modules/gutils/src/index.js +22 -1
- package/lib/runTemp/File.js +54 -1
- package/lib/runTemp/index.js +137 -1
- package/lib/runTemp/securityFile.js +93 -1
- package/lib/start/addPack.js +3 -1
- package/lib/start/clean.js +84 -1
- package/lib/start/create.js +146 -1
- package/lib/start/dev.js +99 -1
- package/lib/start/getResConfig.js +3 -1
- package/lib/start/incg.js +3 -1
- package/lib/start/index.js +207 -1
- package/lib/start/init.js +125 -1
- package/lib/start/rechce.js +57 -1
- package/lib/start/unaddPack.js +3 -1
- package/lib/start/unincg.js +67 -1
- package/lib/start/version.js +73 -1
- package/lib/utils/index.js +298 -1
- package/lib/uuid/index.js +27 -1
- package/package.json +1 -1
- package/test/script-mbler/behavior/scripts/index.js +0 -5
|
@@ -1 +1,145 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayerGroup = void 0;
|
|
4
|
+
const GameError_js_1 = require("../utils/GameError.js");
|
|
5
|
+
class PlayerGroupError extends GameError_js_1.GameError {
|
|
6
|
+
constructor(mes, options) {
|
|
7
|
+
super(mes, options);
|
|
8
|
+
this.name = this.constructor.name;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**玩家组 */
|
|
12
|
+
class PlayerGroup {
|
|
13
|
+
players;
|
|
14
|
+
playerConstructor;
|
|
15
|
+
data;
|
|
16
|
+
constructor(playerClass, players, data) {
|
|
17
|
+
this.playerConstructor = playerClass;
|
|
18
|
+
if (players != undefined &&
|
|
19
|
+
players.some((p) => !(p instanceof playerClass))) {
|
|
20
|
+
throw new PlayerGroupError(`players必须全为:${playerClass.name}`);
|
|
21
|
+
}
|
|
22
|
+
this.data = data;
|
|
23
|
+
this.players = players ?? [];
|
|
24
|
+
}
|
|
25
|
+
/** 组中玩家数量(包含下线玩家) */
|
|
26
|
+
get size() {
|
|
27
|
+
return this.players.length;
|
|
28
|
+
}
|
|
29
|
+
/** 组中玩家数量(不包含下线玩家) */
|
|
30
|
+
get validSize() {
|
|
31
|
+
return this.players.filter((p) => p.isValid).length;
|
|
32
|
+
}
|
|
33
|
+
/** 根据 id 查找玩家 */
|
|
34
|
+
getById(id) {
|
|
35
|
+
return this.players.find((p) => p.id == id);
|
|
36
|
+
}
|
|
37
|
+
/** 是否包含玩家 */
|
|
38
|
+
has(player) {
|
|
39
|
+
return this.players.findIndex((p) => p.id == player.id) != -1;
|
|
40
|
+
}
|
|
41
|
+
add(player) {
|
|
42
|
+
if (!(player instanceof this.playerConstructor)) {
|
|
43
|
+
throw new PlayerGroupError(`添加的player必须是${this.playerConstructor.name}`);
|
|
44
|
+
}
|
|
45
|
+
if (!this.has(player)) {
|
|
46
|
+
this.players.push(player);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
delete(player) {
|
|
51
|
+
const index = this.players.findIndex((p) => p.id == player.id);
|
|
52
|
+
if (index != -1) {
|
|
53
|
+
this.players.splice(index, 1);
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
removeWhere(func) {
|
|
58
|
+
const removed = [];
|
|
59
|
+
this.players = this.players.filter((p) => {
|
|
60
|
+
if (func(p)) {
|
|
61
|
+
removed.push(p);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
return removed;
|
|
67
|
+
}
|
|
68
|
+
/**获取组中全部玩家的拷贝 */
|
|
69
|
+
getAll() {
|
|
70
|
+
return this.players.slice();
|
|
71
|
+
}
|
|
72
|
+
/** 获取所有原生 Player 对象 */
|
|
73
|
+
getAllPlayers() {
|
|
74
|
+
return this.players.map((p) => p.player).filter((p) => p != undefined);
|
|
75
|
+
}
|
|
76
|
+
/**对所有有效玩家执行操作 */
|
|
77
|
+
forEach(func) {
|
|
78
|
+
try {
|
|
79
|
+
this.players.filter((p) => p.isValid).forEach(func);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
console.error(err, err instanceof Error ? err.stack : "");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**组内所有玩家执行命令 */
|
|
86
|
+
runCommand(commandString) {
|
|
87
|
+
this.forEach((p) => p.runCommand(commandString));
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**向组内所有玩家发送消息 */
|
|
91
|
+
sendMessage(mes) {
|
|
92
|
+
this.forEach((p) => p.sendMessage(mes));
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**向组内所有玩家显示标题 */
|
|
96
|
+
title(title, subtitle, options) {
|
|
97
|
+
this.forEach((p) => p.title(title, subtitle, options));
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
actionbar(text) {
|
|
101
|
+
this.forEach((p) => p.actionbar(text));
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**向组内所有玩家播放音效 */
|
|
105
|
+
playSound(soundId, soundOptions) {
|
|
106
|
+
this.forEach((p) => p.player?.playSound(soundId, soundOptions));
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
map(func) {
|
|
110
|
+
return this.players.map(func);
|
|
111
|
+
}
|
|
112
|
+
/**获取随机在线玩家 */
|
|
113
|
+
random() {
|
|
114
|
+
const validPlayers = this.players.filter((p) => p.isValid);
|
|
115
|
+
if (validPlayers.length === 0)
|
|
116
|
+
return undefined;
|
|
117
|
+
const index = Math.floor(Math.random() * validPlayers.length);
|
|
118
|
+
return validPlayers[index];
|
|
119
|
+
}
|
|
120
|
+
filter(func) {
|
|
121
|
+
return this.players.filter(func);
|
|
122
|
+
}
|
|
123
|
+
/** 清空组 */
|
|
124
|
+
clear() {
|
|
125
|
+
this.players = [];
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
/**清除无效玩家 */
|
|
129
|
+
clearInvalid() {
|
|
130
|
+
this.players = this.players.filter((p) => p.isValid);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/** 克隆一份新的 PlayerGroup */
|
|
134
|
+
clone() {
|
|
135
|
+
return new PlayerGroup(this.playerConstructor, this.players);
|
|
136
|
+
}
|
|
137
|
+
/** 查找符合条件的玩家 */
|
|
138
|
+
find(predicate) {
|
|
139
|
+
return this.players.find(predicate);
|
|
140
|
+
}
|
|
141
|
+
findIndex(predicate) {
|
|
142
|
+
return this.players.findIndex(predicate);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.PlayerGroup = PlayerGroup;
|
|
@@ -1 +1,57 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GamePlayerManager = void 0;
|
|
4
|
+
const main_js_1 = require("../main.js");
|
|
5
|
+
const groupBuilder_js_1 = require("./groupBuilder.js");
|
|
6
|
+
/**游戏玩家管理器 */
|
|
7
|
+
class GamePlayerManager {
|
|
8
|
+
gameKey;
|
|
9
|
+
isDaemon;
|
|
10
|
+
players = new Map();
|
|
11
|
+
playerConstructor;
|
|
12
|
+
/**玩家组构建器 */
|
|
13
|
+
groupBuilder;
|
|
14
|
+
constructor(playerConstructor, gameKey, isDaemon) {
|
|
15
|
+
this.gameKey = gameKey;
|
|
16
|
+
this.isDaemon = isDaemon;
|
|
17
|
+
this.playerConstructor = playerConstructor;
|
|
18
|
+
this.groupBuilder = new groupBuilder_js_1.PlayerGroupBuilder(this);
|
|
19
|
+
}
|
|
20
|
+
/**获取游戏玩家(若玩家已分配,返回无效玩家) */
|
|
21
|
+
get(p) {
|
|
22
|
+
//创建
|
|
23
|
+
let gamePlayer = this.players.get(p.id);
|
|
24
|
+
//若未创建或已失效,则重新创建并尝试分配
|
|
25
|
+
if (!gamePlayer || !gamePlayer.isActive) {
|
|
26
|
+
gamePlayer = new this.playerConstructor(p);
|
|
27
|
+
this.players.set(p.id, gamePlayer);
|
|
28
|
+
//申请分配玩家
|
|
29
|
+
if (!this.isDaemon) {
|
|
30
|
+
const ans = main_js_1.Game.playerManager.allocatePlayerToGame(p.id, this.gameKey);
|
|
31
|
+
gamePlayer.isActive = ans;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return gamePlayer;
|
|
35
|
+
}
|
|
36
|
+
getAll() {
|
|
37
|
+
return Array.from(this.players.values());
|
|
38
|
+
}
|
|
39
|
+
/**让玩家失活 */
|
|
40
|
+
deactivate(p) {
|
|
41
|
+
let gamePlayer = this.players.get(p.id);
|
|
42
|
+
if (gamePlayer) {
|
|
43
|
+
gamePlayer.isActive = false; //强制修改活动状态
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
get size() {
|
|
47
|
+
return this.players.size;
|
|
48
|
+
}
|
|
49
|
+
get validSize() {
|
|
50
|
+
return Array.from(this.players.values()).filter((p) => p.isValid)
|
|
51
|
+
.length;
|
|
52
|
+
}
|
|
53
|
+
dispose() {
|
|
54
|
+
main_js_1.Game.playerManager.releaseAllPlayerFromGame(this.gameKey);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.GamePlayerManager = GamePlayerManager;
|
|
@@ -1 +1,229 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlaneRegion = exports.CylinderRegion = exports.SphereRegion = exports.CubeRegion = exports.GameRegion = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const vector_js_1 = require("../utils/vector.js");
|
|
6
|
+
/**游戏区域 */
|
|
7
|
+
class GameRegion {
|
|
8
|
+
dimensionId;
|
|
9
|
+
constructor(dimId) {
|
|
10
|
+
this.dimensionId = dimId;
|
|
11
|
+
}
|
|
12
|
+
/**获取区域内的玩家 */
|
|
13
|
+
getPlayersInRegion() {
|
|
14
|
+
const result = [];
|
|
15
|
+
const players = server_1.world.getAllPlayers();
|
|
16
|
+
for (const player of players) {
|
|
17
|
+
if (player == undefined)
|
|
18
|
+
continue;
|
|
19
|
+
if (player.dimension.id == this.dimensionId &&
|
|
20
|
+
this.isInside(player.location)) {
|
|
21
|
+
result.push(player);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**获取区域内实体 */
|
|
27
|
+
getEntitesInRegion(options) {
|
|
28
|
+
return server_1.world
|
|
29
|
+
.getDimension(this.dimensionId)
|
|
30
|
+
.getEntities({ ...this.getEntityQueryOption(), ...options })
|
|
31
|
+
.filter((e) => e != undefined);
|
|
32
|
+
}
|
|
33
|
+
/** 在区域内的玩家执行命令 */
|
|
34
|
+
runCommandOnPlayers(commandString) {
|
|
35
|
+
this.getPlayersInRegion().forEach((p) => p.runCommand(commandString));
|
|
36
|
+
}
|
|
37
|
+
/**对每个玩家执行操作 */
|
|
38
|
+
forEachPlayer(callbackfn) {
|
|
39
|
+
this.getPlayersInRegion().forEach(callbackfn);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.GameRegion = GameRegion;
|
|
43
|
+
/**立方体区域 */
|
|
44
|
+
class CubeRegion extends GameRegion {
|
|
45
|
+
pos1;
|
|
46
|
+
pos2;
|
|
47
|
+
constructor(dimId, pos1, pos2) {
|
|
48
|
+
super(dimId);
|
|
49
|
+
this.pos1 = pos1;
|
|
50
|
+
this.pos2 = pos2;
|
|
51
|
+
}
|
|
52
|
+
getEntityQueryOption() {
|
|
53
|
+
return {
|
|
54
|
+
location: this.pos1,
|
|
55
|
+
volume: vector_js_1.Vector3Utils.subtract(this.pos2, this.pos1),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**判断是否在区域内 */
|
|
59
|
+
isInside(loc) {
|
|
60
|
+
const EPSILON = 0.00001;
|
|
61
|
+
const minX = Math.min(this.pos1.x, this.pos2.x);
|
|
62
|
+
const maxX = Math.max(this.pos1.x, this.pos2.x) + 1;
|
|
63
|
+
const minY = Math.min(this.pos1.y, this.pos2.y);
|
|
64
|
+
const maxY = Math.max(this.pos1.y, this.pos2.y) + 0.99;
|
|
65
|
+
const minZ = Math.min(this.pos1.z, this.pos2.z);
|
|
66
|
+
const maxZ = Math.max(this.pos1.z, this.pos2.z) + 1;
|
|
67
|
+
const inX = loc.x + EPSILON >= minX && loc.x - EPSILON <= maxX;
|
|
68
|
+
const inY = loc.y + EPSILON >= minY && loc.y - EPSILON <= maxY;
|
|
69
|
+
const inZ = loc.z + EPSILON >= minZ && loc.z - EPSILON <= maxZ;
|
|
70
|
+
return inX && inY && inZ;
|
|
71
|
+
}
|
|
72
|
+
/**判断方块是否在区域内 */
|
|
73
|
+
isBlockInside(loc) {
|
|
74
|
+
const minX = Math.min(this.pos1.x, this.pos2.x);
|
|
75
|
+
const maxX = Math.max(this.pos1.x, this.pos2.x);
|
|
76
|
+
const minY = Math.min(this.pos1.y, this.pos2.y);
|
|
77
|
+
const maxY = Math.max(this.pos1.y, this.pos2.y);
|
|
78
|
+
const minZ = Math.min(this.pos1.z, this.pos2.z);
|
|
79
|
+
const maxZ = Math.max(this.pos1.z, this.pos2.z);
|
|
80
|
+
const inX = loc.x >= minX && loc.x <= maxX;
|
|
81
|
+
const inY = loc.y >= minY && loc.y <= maxY;
|
|
82
|
+
const inZ = loc.z >= minZ && loc.z <= maxZ;
|
|
83
|
+
return inX && inY && inZ;
|
|
84
|
+
}
|
|
85
|
+
/**转换为BlockVolume */
|
|
86
|
+
toVolume() {
|
|
87
|
+
return new server_1.BlockVolume(this.pos1, this.pos2);
|
|
88
|
+
}
|
|
89
|
+
/**获取大小 */
|
|
90
|
+
getCapacity() {
|
|
91
|
+
const dif = vector_js_1.Vector3Utils.add(vector_js_1.Vector3Utils.subtract(this.getMax(), this.getMin()), { x: 1, y: 1, z: 1 });
|
|
92
|
+
return Math.abs(dif.x * dif.y * dif.z);
|
|
93
|
+
}
|
|
94
|
+
/**获取范围 */
|
|
95
|
+
getBounds() {
|
|
96
|
+
return {
|
|
97
|
+
x1: this.pos1.x,
|
|
98
|
+
x2: this.pos2.x,
|
|
99
|
+
y1: this.pos1.y,
|
|
100
|
+
y2: this.pos2.y,
|
|
101
|
+
z1: this.pos1.z,
|
|
102
|
+
z2: this.pos2.z,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**向外扩张区域 */
|
|
106
|
+
outSet(distance) {
|
|
107
|
+
const minX = Math.min(this.pos1.x, this.pos2.x) - distance.x;
|
|
108
|
+
const maxX = Math.max(this.pos1.x, this.pos2.x) + distance.x;
|
|
109
|
+
const minY = Math.min(this.pos1.y, this.pos2.y) - distance.y;
|
|
110
|
+
const maxY = Math.max(this.pos1.y, this.pos2.y) + distance.y;
|
|
111
|
+
const minZ = Math.min(this.pos1.z, this.pos2.z) - distance.z;
|
|
112
|
+
const maxZ = Math.max(this.pos1.z, this.pos2.z) + distance.z;
|
|
113
|
+
return new CubeRegion(this.dimensionId, { x: minX, y: minY, z: minZ }, { x: maxX, y: maxY, z: maxZ });
|
|
114
|
+
}
|
|
115
|
+
/**向内收缩区域(若收缩后无体积则返回 undefined) */
|
|
116
|
+
inSet(distance) {
|
|
117
|
+
const minX = Math.min(this.pos1.x, this.pos2.x) + distance.x;
|
|
118
|
+
const maxX = Math.max(this.pos1.x, this.pos2.x) - distance.x;
|
|
119
|
+
const minY = Math.min(this.pos1.y, this.pos2.y) + distance.y;
|
|
120
|
+
const maxY = Math.max(this.pos1.y, this.pos2.y) - distance.y;
|
|
121
|
+
const minZ = Math.min(this.pos1.z, this.pos2.z) + distance.z;
|
|
122
|
+
const maxZ = Math.max(this.pos1.z, this.pos2.z) - distance.z;
|
|
123
|
+
// 若某个维度缩没了
|
|
124
|
+
if (minX >= maxX || minY >= maxY || minZ >= maxZ) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return new CubeRegion(this.dimensionId, { x: minX, y: minY, z: minZ }, { x: maxX, y: maxY, z: maxZ });
|
|
128
|
+
}
|
|
129
|
+
/**获取区域最大点坐标 */
|
|
130
|
+
getMax() {
|
|
131
|
+
return {
|
|
132
|
+
x: Math.max(this.pos1.x, this.pos2.x),
|
|
133
|
+
y: Math.max(this.pos1.y, this.pos2.y),
|
|
134
|
+
z: Math.max(this.pos1.z, this.pos2.z),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**获取区域最小点坐标 */
|
|
138
|
+
getMin() {
|
|
139
|
+
return {
|
|
140
|
+
x: Math.min(this.pos1.x, this.pos2.x),
|
|
141
|
+
y: Math.min(this.pos1.y, this.pos2.y),
|
|
142
|
+
z: Math.min(this.pos1.z, this.pos2.z),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.CubeRegion = CubeRegion;
|
|
147
|
+
/**球形区域 */
|
|
148
|
+
class SphereRegion extends GameRegion {
|
|
149
|
+
center;
|
|
150
|
+
r;
|
|
151
|
+
rm;
|
|
152
|
+
constructor(dimId, center, r, rm) {
|
|
153
|
+
super(dimId);
|
|
154
|
+
this.center = center;
|
|
155
|
+
this.r = r;
|
|
156
|
+
this.rm = rm;
|
|
157
|
+
}
|
|
158
|
+
getEntityQueryOption() {
|
|
159
|
+
return {
|
|
160
|
+
location: this.center,
|
|
161
|
+
maxDistance: this.r,
|
|
162
|
+
minDistance: this.rm,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
isInside(loc) {
|
|
166
|
+
const distance = vector_js_1.Vector3Utils.squaredDistance(this.center, loc);
|
|
167
|
+
return distance <= this.r * this.r;
|
|
168
|
+
}
|
|
169
|
+
isBlockInside(loc) {
|
|
170
|
+
return this.isInside(loc);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.SphereRegion = SphereRegion;
|
|
174
|
+
class CylinderRegion extends GameRegion {
|
|
175
|
+
getEntityQueryOption() {
|
|
176
|
+
throw new Error("Method not implemented.");
|
|
177
|
+
}
|
|
178
|
+
isInside(loc) {
|
|
179
|
+
throw new Error("Method not implemented.");
|
|
180
|
+
}
|
|
181
|
+
isBlockInside(loc) {
|
|
182
|
+
return this.isInside(loc);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.CylinderRegion = CylinderRegion;
|
|
186
|
+
/**平面区域 */
|
|
187
|
+
class PlaneRegion extends GameRegion {
|
|
188
|
+
pos1;
|
|
189
|
+
pos2;
|
|
190
|
+
constructor(dimId, pos1, pos2) {
|
|
191
|
+
super(dimId);
|
|
192
|
+
this.pos1 = pos1;
|
|
193
|
+
this.pos2 = pos2;
|
|
194
|
+
}
|
|
195
|
+
getEntityQueryOption() {
|
|
196
|
+
return {
|
|
197
|
+
location: {
|
|
198
|
+
x: this.pos1.x,
|
|
199
|
+
y: -1000,
|
|
200
|
+
z: this.pos1.y,
|
|
201
|
+
},
|
|
202
|
+
volume: {
|
|
203
|
+
x: this.pos2.x - this.pos1.x,
|
|
204
|
+
z: this.pos2.y - this.pos1.y,
|
|
205
|
+
y: 2000,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
isInside(loc) {
|
|
210
|
+
const EPSILON = 0.00001;
|
|
211
|
+
const minX = Math.min(this.pos1.x, this.pos2.x);
|
|
212
|
+
const maxX = Math.max(this.pos1.x, this.pos2.x) + 1;
|
|
213
|
+
const minY = Math.min(this.pos1.y, this.pos2.y);
|
|
214
|
+
const maxY = Math.max(this.pos1.y, this.pos2.y) + 1;
|
|
215
|
+
const inX = loc.x + EPSILON >= minX && loc.x - EPSILON <= maxX;
|
|
216
|
+
const inY = loc.y + EPSILON >= minY && loc.y - EPSILON <= maxY;
|
|
217
|
+
return inX && inY;
|
|
218
|
+
}
|
|
219
|
+
isBlockInside(loc) {
|
|
220
|
+
const minX = Math.min(this.pos1.x, this.pos2.x);
|
|
221
|
+
const maxX = Math.max(this.pos1.x, this.pos2.x);
|
|
222
|
+
const minY = Math.min(this.pos1.y, this.pos2.y);
|
|
223
|
+
const maxY = Math.max(this.pos1.y, this.pos2.y);
|
|
224
|
+
const inX = loc.x >= minX && loc.x <= maxX;
|
|
225
|
+
const inY = loc.y >= minY && loc.y <= maxY;
|
|
226
|
+
return inX && inY;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.PlaneRegion = PlaneRegion;
|
|
@@ -1 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.regionHelper = exports.Region = void 0;
|
|
40
|
+
exports.Region = __importStar(require("./gameRegion.js"));
|
|
41
|
+
var regionHelper_js_1 = require("./regionHelper.js");
|
|
42
|
+
Object.defineProperty(exports, "regionHelper", { enumerable: true, get: function () { return regionHelper_js_1.regionHelper; } });
|
|
43
|
+
__exportStar(require("./gameRegion.js"), exports);
|
|
@@ -1 +1,79 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.regionHelper = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const gameRegion_js_1 = require("./gameRegion.js");
|
|
6
|
+
/**游戏区域 */
|
|
7
|
+
class RegionHelper {
|
|
8
|
+
/**填充方块,需自己保证区块已加载 */
|
|
9
|
+
fillGenerator(region, block, batchSize = 32767) {
|
|
10
|
+
const splited = this.splitCubeRegion(region, batchSize);
|
|
11
|
+
return this.fillGen(splited, block);
|
|
12
|
+
}
|
|
13
|
+
*fillGen(regions, block) {
|
|
14
|
+
if (regions.length == 0)
|
|
15
|
+
return;
|
|
16
|
+
const dim = server_1.world.getDimension(regions[0].dimensionId);
|
|
17
|
+
const blockType = server_1.BlockTypes.get(block);
|
|
18
|
+
if (!blockType)
|
|
19
|
+
return;
|
|
20
|
+
for (let region of regions) {
|
|
21
|
+
dim.fillBlocks(region.toVolume(), blockType);
|
|
22
|
+
yield;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**分割Region,保证每块小于32767 */
|
|
26
|
+
splitCubeRegion(initialRegion, batchSize = 32767) {
|
|
27
|
+
const MAX_CAPACITY = 32767;
|
|
28
|
+
if (batchSize > MAX_CAPACITY)
|
|
29
|
+
batchSize = MAX_CAPACITY;
|
|
30
|
+
const queue = [initialRegion];
|
|
31
|
+
const result = [];
|
|
32
|
+
while (queue.length > 0) {
|
|
33
|
+
// 使用 ! 断言确保 region 存在,因为 queue.length > 0
|
|
34
|
+
const region = queue.shift();
|
|
35
|
+
if (region.getCapacity() <= batchSize) {
|
|
36
|
+
result.push(region);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const { x1, y1, z1, x2, y2, z2 } = region.getBounds();
|
|
40
|
+
const sizes = {
|
|
41
|
+
x: x2 - x1 + 1,
|
|
42
|
+
y: y2 - y1 + 1,
|
|
43
|
+
z: z2 - z1 + 1,
|
|
44
|
+
};
|
|
45
|
+
// 1. 【优化】选择最长的、且可以被分割的轴
|
|
46
|
+
let axisToSplit = null;
|
|
47
|
+
let maxDim = 1; // 尺寸为1的轴不能被分割
|
|
48
|
+
// 遍历所有轴,找到尺寸大于1的最长轴
|
|
49
|
+
for (const axis of ["x", "y", "z"]) {
|
|
50
|
+
if (sizes[axis] > maxDim) {
|
|
51
|
+
maxDim = sizes[axis];
|
|
52
|
+
axisToSplit = axis;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// 如果没有找到可以分割的轴(即所有轴的尺寸都为1)
|
|
56
|
+
if (axisToSplit === null) {
|
|
57
|
+
// 此时无法再分割,即使容量超标也只能强制保留
|
|
58
|
+
result.push(region);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// 2. 【优化】简化分割逻辑,避免使用 switch
|
|
62
|
+
const startCoords = { x: x1, y: y1, z: z1 };
|
|
63
|
+
const endCoords = { x: x2, y: y2, z: z2 };
|
|
64
|
+
// 计算分割点
|
|
65
|
+
const mid = startCoords[axisToSplit] + Math.floor(sizes[axisToSplit] / 2);
|
|
66
|
+
// 创建第一个子区域的终点坐标
|
|
67
|
+
const firstRegionEndCoords = { ...endCoords };
|
|
68
|
+
firstRegionEndCoords[axisToSplit] = mid - 1;
|
|
69
|
+
// 创建第二个子区域的起点坐标
|
|
70
|
+
const secondRegionStartCoords = { ...startCoords };
|
|
71
|
+
secondRegionStartCoords[axisToSplit] = mid;
|
|
72
|
+
// 将两个新的子区域推入队列等待处理
|
|
73
|
+
queue.push(new gameRegion_js_1.CubeRegion(region.dimensionId, startCoords, firstRegionEndCoords));
|
|
74
|
+
queue.push(new gameRegion_js_1.CubeRegion(region.dimensionId, secondRegionStartCoords, endCoords));
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.regionHelper = new RegionHelper();
|
|
@@ -1 +1,39 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutoStopState = void 0;
|
|
4
|
+
const main_js_1 = require("../../main.js");
|
|
5
|
+
const index_js_1 = require("../../utils/index.js");
|
|
6
|
+
/**自动在groupSet所有玩家寄了之后停止游戏 */
|
|
7
|
+
class AutoStopState extends main_js_1.GameState {
|
|
8
|
+
onEnter() {
|
|
9
|
+
if (!this.config?.groupSet)
|
|
10
|
+
return;
|
|
11
|
+
this.subscribe(main_js_1.Game.events.interval, this.tick.bind(this), new index_js_1.Duration(20));
|
|
12
|
+
}
|
|
13
|
+
tick() {
|
|
14
|
+
let liveSize = 0;
|
|
15
|
+
this.config.groupSet.getAllPlayers().forEach((p) => {
|
|
16
|
+
if (p.ttl > 0)
|
|
17
|
+
liveSize++;
|
|
18
|
+
if (p.isValid) {
|
|
19
|
+
p.ttl = p.initialTTL; //重置TTL
|
|
20
|
+
}
|
|
21
|
+
else if (p.ttl > 0) {
|
|
22
|
+
p.ttl--; //下线的ttl减少
|
|
23
|
+
if (this.config?.immediateDie)
|
|
24
|
+
p.ttl = 0;
|
|
25
|
+
if (p.ttl == 0) {
|
|
26
|
+
this.config.onLeave?.(p);
|
|
27
|
+
//自动释放玩家
|
|
28
|
+
if (this.config?.shouldRelease ?? true)
|
|
29
|
+
main_js_1.Game.playerManager.releasePlayerFromGame(p.id, this.engine.key);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (liveSize === 0) {
|
|
34
|
+
this.logger.debug("检测到玩家已全部下线超时,游戏结束");
|
|
35
|
+
this.engine.stopGame();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AutoStopState = AutoStopState;
|