mbler 0.1.3-alpha → 0.1.3-alpha-r2
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 -21
- package/README.md +15 -6
- package/bin/mbler.js +12 -12
- package/bin/minify.js +58 -44
- package/lib/build/base.js +1 -297
- package/lib/build/build-g-config.json +12 -12
- package/lib/build/getModule.js +1 -182
- package/lib/build/index.js +1 -370
- package/lib/build/manifest.build.js +1 -103
- package/lib/build/mcVersion.js +1 -86
- package/lib/build/utils.js +1 -6
- package/lib/code-processor/c-handler-export.js +1 -12
- package/lib/code-processor/index.js +1 -141
- package/lib/code-processor/mtreehandler.js +1 -164
- package/lib/commander/index.js +1 -154
- package/lib/data/includes.json +13 -13
- package/lib/data/version.json +88 -88
- package/lib/git/clone.js +1 -28
- package/lib/git/index.js +1 -12
- package/lib/git/pull.js +1 -100
- package/lib/lang/__translate.js +1 -93
- package/lib/lang/en.js +1 -128
- package/lib/lang/index.js +1 -78
- package/lib/lang/zh.js +1 -146
- package/lib/loger/colors.js +1 -13
- package/lib/loger/index.js +1 -136
- package/lib/mcx/ast/index.js +1 -11
- package/lib/mcx/ast/prop.js +1 -78
- package/lib/mcx/ast/tag.js +1 -246
- package/lib/mcx/compile-component/lib.js +1 -106
- package/lib/mcx/compile-component/types.js +1 -2
- package/lib/mcx/compile-component/utils.js +1 -26
- package/lib/mcx/compile-mcx/compile.js +1 -34
- package/lib/mcx/compile-mcx/compiler/bundler.js +1 -0
- package/lib/mcx/compile-mcx/compiler/compileData.js +1 -0
- package/lib/mcx/compile-mcx/compiler/compileMain.js +1 -0
- package/lib/mcx/compile-mcx/compiler/index.js +1 -0
- package/lib/mcx/compile-mcx/compiler/utils.js +1 -0
- package/lib/mcx/compile-mcx/context.js +1 -19
- package/lib/mcx/compile-mcx/index.js +1 -10
- package/lib/mcx/compile-mcx/mcx/index.js +1 -2
- package/lib/mcx/compile-mcx/mcx/types.js +1 -2
- package/lib/mcx/compile-mcx/template/module.js +1 -42
- package/lib/mcx/compile-mcx/types.js +1 -2
- package/lib/mcx/compile-mcx/utils.node.js +1 -207
- package/lib/mcx/index.js +1 -13
- package/lib/mcx/test/index.js +1 -7
- package/lib/mcx/test.js +1 -21
- package/lib/mcx/types.js +1 -2
- package/lib/mcx/utils.js +1 -86
- package/lib/module-handler/index.js +1 -482
- package/lib/modules/create-game/mbler.config.json +13 -13
- package/lib/modules/create-game/src/Runner/RunnerManager.js +1 -113
- package/lib/modules/create-game/src/Runner/scriptRunner.js +1 -70
- package/lib/modules/create-game/src/config.js +1 -27
- package/lib/modules/create-game/src/constants.js +1 -19
- package/lib/modules/create-game/src/createGameModule.js +1 -24
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +1 -38
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +1 -76
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +1 -36
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +1 -90
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +1 -29
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +1 -36
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +1 -29
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +1 -87
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +1 -53
- package/lib/modules/create-game/src/gameComponent/index.js +1 -31
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +1 -40
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +1 -48
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +1 -48
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +1 -22
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +1 -59
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +1 -69
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +1 -53
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +1 -71
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +1 -20
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +1 -77
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +1 -83
- package/lib/modules/create-game/src/gameContext.js +1 -6
- package/lib/modules/create-game/src/gameEngine.js +1 -139
- package/lib/modules/create-game/src/gameEvent/eventManager.js +1 -108
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +1 -28
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +1 -41
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +1 -77
- package/lib/modules/create-game/src/gameEvent/events/interval.js +1 -51
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +1 -36
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +1 -106
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +1 -105
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +1 -45
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +1 -54
- package/lib/modules/create-game/src/gameEvent/index.js +1 -20
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +1 -101
- package/lib/modules/create-game/src/gameEvent/subscription.js +1 -17
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +1 -102
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +1 -38
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +1 -96
- package/lib/modules/create-game/src/gamePlayer/index.js +1 -25
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +1 -145
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +1 -57
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +1 -229
- package/lib/modules/create-game/src/gameRegion/index.js +1 -43
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +1 -79
- package/lib/modules/create-game/src/gameState/common/autoStop.js +1 -39
- package/lib/modules/create-game/src/gameState/gameState.js +1 -169
- package/lib/modules/create-game/src/gameState/index.js +1 -7
- package/lib/modules/create-game/src/gameState/types.js +1 -35
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +1 -36
- package/lib/modules/create-game/src/main.js +1 -86
- package/lib/modules/create-game/src/system/gameCommand.js +1 -107
- package/lib/modules/create-game/src/system/gameManager.js +1 -124
- package/lib/modules/create-game/src/system/globalPlayerManager.js +1 -119
- package/lib/modules/create-game/src/utils/GameError.js +1 -31
- package/lib/modules/create-game/src/utils/algorithm.js +1 -95
- package/lib/modules/create-game/src/utils/chunk.js +1 -63
- package/lib/modules/create-game/src/utils/deferredObject.js +1 -27
- package/lib/modules/create-game/src/utils/duration.js +1 -25
- package/lib/modules/create-game/src/utils/func.js +1 -20
- package/lib/modules/create-game/src/utils/index.js +1 -52
- package/lib/modules/create-game/src/utils/interfaces.js +1 -2
- package/lib/modules/create-game/src/utils/logger.js +1 -47
- package/lib/modules/create-game/src/utils/random.js +1 -76
- package/lib/modules/create-game/src/utils/vanila-data.js +1 -123
- package/lib/modules/create-game/src/utils/vector.js +1 -96
- package/lib/modules/gameLib/mbler.config.json +15 -15
- package/lib/modules/gameLib/src/config.js +1 -134
- package/lib/modules/gameLib/src/data.js +1 -77
- package/lib/modules/gameLib/src/entity.js +1 -256
- package/lib/modules/gameLib/src/event.js +1 -285
- package/lib/modules/gameLib/src/index.js +1 -20
- package/lib/modules/gameLib/src/loger.js +1 -21
- package/lib/modules/gameLib/src/ui.js +1 -209
- package/lib/modules/gameLib/src/utils.js +1 -122
- package/lib/modules/gutils/mbler.config.json +11 -11
- package/lib/modules/gutils/src/index.js +1 -22
- package/lib/modules/innerDef.json +4 -4
- package/lib/runTemp/File.js +1 -54
- package/lib/runTemp/config.json +3 -3
- package/lib/runTemp/index.js +1 -137
- package/lib/runTemp/securityFile.js +1 -93
- package/lib/start/addPack.js +1 -3
- package/lib/start/clean.js +1 -84
- package/lib/start/create.js +1 -146
- package/lib/start/dev.js +1 -99
- package/lib/start/getResConfig.js +1 -3
- package/lib/start/incg.js +1 -3
- package/lib/start/index.js +1 -207
- package/lib/start/init.js +1 -125
- package/lib/start/rechce.js +1 -57
- package/lib/start/unaddPack.js +1 -3
- package/lib/start/unincg.js +1 -67
- package/lib/start/version.js +1 -73
- package/lib/utils/index.js +1 -298
- package/lib/uuid/index.js +1 -27
- package/package.json +49 -1
- package/test/2x sword/behavior/scripts/index.js +24 -24
- package/test/2x sword/mbler.config.json +11 -11
- package/test/2x sword/package.json +13 -13
- package/test/README.md +7 -7
- package/test/des/index.js +19 -19
- package/test/des/mbler.config.json +4 -4
- package/test/des/package.json +6 -6
- package/test/initializer/index.js +5 -5
- package/test/initializer/mbler.config.json +4 -4
- package/test/initializer/package.json +6 -6
- package/test/mbler-int/behavior/res/items/mang_one_int.json +21 -21
- package/test/mbler-int/behavior/scripts/index.js +7 -7
- package/test/mbler-int/behavior/scripts/lib/event/index.js +19 -19
- package/test/mbler-int/behavior/scripts/lib/ui/Lore.js +18 -18
- package/test/mbler-int/behavior/scripts/lib/ui/baseUi.js +6 -6
- package/test/mbler-int/behavior/scripts/lib/ui/index.js +206 -206
- package/test/mbler-int/behavior/scripts/lib/utils/index.js +51 -51
- package/test/mbler-int/mbler.config.json +18 -18
- package/test/mbler-int/package.json +12 -12
- package/test/script-mbler/behavior/scripts/index.js +5 -0
- package/test/script-mbler/behavior/scripts/index.ts +5 -5
- package/test/script-mbler/mbler.config.json +14 -14
- package/test/script-mbler/package.json +15 -15
- package/lib/mcx/compile-mcx/_compile.js +0 -602
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import ui from "./../ui/index"
|
|
2
|
-
import {
|
|
3
|
-
world
|
|
4
|
-
} from "@minecraft/server"
|
|
5
|
-
let scriptUi;
|
|
6
|
-
const useItem = ({
|
|
7
|
-
source: player,
|
|
8
|
-
itemStack: item
|
|
9
|
-
}) => {
|
|
10
|
-
if (!player.typeId.includes('player')) return;
|
|
11
|
-
if (item.typeId === "mbler_int:mang_one_int")
|
|
12
|
-
scriptUi.openHomeForm(player, item)
|
|
13
|
-
}
|
|
14
|
-
const regEvent = (game) => {
|
|
15
|
-
world.afterEvents.itemUse.subscribe(useItem);
|
|
16
|
-
scriptUi = new ui(game)
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
regEvent
|
|
1
|
+
import ui from "./../ui/index"
|
|
2
|
+
import {
|
|
3
|
+
world
|
|
4
|
+
} from "@minecraft/server"
|
|
5
|
+
let scriptUi;
|
|
6
|
+
const useItem = ({
|
|
7
|
+
source: player,
|
|
8
|
+
itemStack: item
|
|
9
|
+
}) => {
|
|
10
|
+
if (!player.typeId.includes('player')) return;
|
|
11
|
+
if (item.typeId === "mbler_int:mang_one_int")
|
|
12
|
+
scriptUi.openHomeForm(player, item)
|
|
13
|
+
}
|
|
14
|
+
const regEvent = (game) => {
|
|
15
|
+
world.afterEvents.itemUse.subscribe(useItem);
|
|
16
|
+
scriptUi = new ui(game)
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
regEvent
|
|
20
20
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export class Lore {
|
|
2
|
-
name;
|
|
3
|
-
count;
|
|
4
|
-
constructor(item) {
|
|
5
|
-
const LoreArr = item.getLore();
|
|
6
|
-
let count = parseInt(`0x${LoreArr[1]}`) // 加上16进制表明式
|
|
7
|
-
if (!/^[a-z0-9_]+(\:)?[a-z0-9_]+$/.test(LoreArr[0] + ''))
|
|
8
|
-
LoreArr[0] = undefined;
|
|
9
|
-
if (isNaN(count)) count = 0;
|
|
10
|
-
this.count = count;
|
|
11
|
-
this.name = LoreArr[0];
|
|
12
|
-
}
|
|
13
|
-
parseArr() {
|
|
14
|
-
return [
|
|
15
|
-
this.name,
|
|
16
|
-
this.count.toString(16)
|
|
17
|
-
]
|
|
18
|
-
}
|
|
1
|
+
export class Lore {
|
|
2
|
+
name;
|
|
3
|
+
count;
|
|
4
|
+
constructor(item) {
|
|
5
|
+
const LoreArr = item.getLore();
|
|
6
|
+
let count = parseInt(`0x${LoreArr[1]}`) // 加上16进制表明式
|
|
7
|
+
if (!/^[a-z0-9_]+(\:)?[a-z0-9_]+$/.test(LoreArr[0] + ''))
|
|
8
|
+
LoreArr[0] = undefined;
|
|
9
|
+
if (isNaN(count)) count = 0;
|
|
10
|
+
this.count = count;
|
|
11
|
+
this.name = LoreArr[0];
|
|
12
|
+
}
|
|
13
|
+
parseArr() {
|
|
14
|
+
return [
|
|
15
|
+
this.name,
|
|
16
|
+
this.count.toString(16)
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export class baseUi {
|
|
2
|
-
game;
|
|
3
|
-
constructor(game) {
|
|
4
|
-
this.game = game;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
1
|
+
export class baseUi {
|
|
2
|
+
game;
|
|
3
|
+
constructor(game) {
|
|
4
|
+
this.game = game;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
import {
|
|
2
|
-
baseUi
|
|
3
|
-
} from "./baseUi";
|
|
4
|
-
import {
|
|
5
|
-
utils
|
|
6
|
-
} from "./../utils/index";
|
|
7
|
-
import {
|
|
8
|
-
Lore
|
|
9
|
-
} from "./Lore";
|
|
10
|
-
class ItemBagUI extends baseUi {
|
|
11
|
-
initLayout() {
|
|
12
|
-
this.layouts = this.game.regLayout({
|
|
13
|
-
regIds: ["Home", "NumSelect", "showInNoFound"],
|
|
14
|
-
Home: {
|
|
15
|
-
title: "菜单",
|
|
16
|
-
layout: [{
|
|
17
|
-
type: "button",
|
|
18
|
-
param: ["存入物品"]
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: "button",
|
|
22
|
-
param: ["取出物品"]
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
NumSelect: {
|
|
27
|
-
title: "选择数量",
|
|
28
|
-
layout: []
|
|
29
|
-
},
|
|
30
|
-
showInNoFound: {
|
|
31
|
-
title: "请选择要存入的物品",
|
|
32
|
-
layout: [{
|
|
33
|
-
type: "label",
|
|
34
|
-
param: ["点击你想要存放的物品"]
|
|
35
|
-
}]
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 打开主菜单:存入物品 / 取出物品
|
|
41
|
-
*/
|
|
42
|
-
openHomeForm(player, itemOnHand) {
|
|
43
|
-
if (!this.layouts) this.initLayout();
|
|
44
|
-
const lore = new Lore(itemOnHand);
|
|
45
|
-
const form = this.game.createForm("Action", this.layouts[0]);
|
|
46
|
-
form.addLayout({
|
|
47
|
-
type: "label",
|
|
48
|
-
param: [`无尽袋子 - 菜单\n物品 : ${lore.name} , 数量 : ${lore.count}`]
|
|
49
|
-
})
|
|
50
|
-
form.show(player, true).onCommit(({
|
|
51
|
-
selection
|
|
52
|
-
}) => {
|
|
53
|
-
switch (selection) {
|
|
54
|
-
case 0:
|
|
55
|
-
this.openAddItemForm(player, itemOnHand);
|
|
56
|
-
break;
|
|
57
|
-
case 1:
|
|
58
|
-
this.hanlerTakeOutItems(player, itemOnHand);
|
|
59
|
-
break;
|
|
60
|
-
default:
|
|
61
|
-
player.sendMessage("请选择存入或取出");
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
hanlerTakeOutItems(player, itemOnHand) {
|
|
66
|
-
const lore = new Lore(itemOnHand)
|
|
67
|
-
if (!lore.name) return player.sendMessage('没有存入任何东西');
|
|
68
|
-
this.selectionNum({
|
|
69
|
-
min: 1,
|
|
70
|
-
max: lore.count,
|
|
71
|
-
tit: lore.name,
|
|
72
|
-
callback: ({
|
|
73
|
-
formValues
|
|
74
|
-
}) => {
|
|
75
|
-
const TakeOutCount = formValues[0];
|
|
76
|
-
player.runCommand(`give @s ${lore.name} ${TakeOutCount}`)
|
|
77
|
-
lore.count = lore.count - TakeOutCount;
|
|
78
|
-
itemOnHand.setLore(lore.parseArr())
|
|
79
|
-
utils.setMainHand(player, itemOnHand);
|
|
80
|
-
},
|
|
81
|
-
lastUi: () => this.openHomeForm(player, itemOnHand)
|
|
82
|
-
}, player)
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 打开“存入物品”表单(自动识别物品类型)
|
|
86
|
-
*/
|
|
87
|
-
openAddItemForm(player, itemOnHand) {
|
|
88
|
-
const currencyLore = new Lore(itemOnHand);
|
|
89
|
-
// 如果 Lore 无法识别此物品(比如没有 name 字段),则进入手动选择模式
|
|
90
|
-
if (currencyLore.name === undefined) {
|
|
91
|
-
return this.showInNoData(player, currencyLore, itemOnHand);
|
|
92
|
-
}
|
|
93
|
-
const inventoryData = utils.getAllPlayerInt(player);
|
|
94
|
-
let totalItemAmount = 0;
|
|
95
|
-
// 统计当前玩家拥有该物品的总数量
|
|
96
|
-
for (const [itemId, itemData] of inventoryData) {
|
|
97
|
-
const [itemName, itemCount] = itemData;
|
|
98
|
-
if (itemName === currencyLore.name) {
|
|
99
|
-
totalItemAmount += itemCount;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// 如果该物品数量为 0,则提示无法存入
|
|
103
|
-
if (totalItemAmount <= 0) {
|
|
104
|
-
return player.sendMessage("你没有该物品,无法存入!");
|
|
105
|
-
}
|
|
106
|
-
// 弹出滑条,让用户选择存入多少个
|
|
107
|
-
this.selectionNum({
|
|
108
|
-
min: 0,
|
|
109
|
-
max: totalItemAmount,
|
|
110
|
-
tit: currencyLore.name,
|
|
111
|
-
callback: ({
|
|
112
|
-
formValues
|
|
113
|
-
}) => {
|
|
114
|
-
const countToStore = formValues[0];
|
|
115
|
-
currencyLore.count = countToStore + totalItemAmount;
|
|
116
|
-
this.handlerAdd(currencyLore, player, itemOnHand, countToStore);
|
|
117
|
-
},
|
|
118
|
-
lastUi: () => this.openHomeForm(player, itemOnHand),
|
|
119
|
-
},
|
|
120
|
-
player
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* 当物品无法自动识别时,让用户从列表中手动选择要存入的物品
|
|
125
|
-
*/
|
|
126
|
-
showInNoData(player, placeholderLore, itemOnHand) {
|
|
127
|
-
const form = this.game.createForm("Action", this.layouts[2]);
|
|
128
|
-
const inventoryData = utils.getAllPlayerInt(player);
|
|
129
|
-
const itemButtons = [];
|
|
130
|
-
const itemKeys = [];
|
|
131
|
-
let buttonIndex = 0;
|
|
132
|
-
for (const [itemId, itemData] of inventoryData) {
|
|
133
|
-
if (!Array.isArray(itemData)) continue;
|
|
134
|
-
const [itemName, itemCount] = itemData;
|
|
135
|
-
form.addLayout({
|
|
136
|
-
type: "button",
|
|
137
|
-
param: [`${itemName} x${itemCount}`],
|
|
138
|
-
});
|
|
139
|
-
itemKeys[buttonIndex] = itemId;
|
|
140
|
-
buttonIndex++;
|
|
141
|
-
}
|
|
142
|
-
form.show(player).then(({
|
|
143
|
-
selection,
|
|
144
|
-
canceled
|
|
145
|
-
}) => {
|
|
146
|
-
if (canceled) {
|
|
147
|
-
return this.openHomeForm(player, itemOnHand);
|
|
148
|
-
}
|
|
149
|
-
if (selection === undefined || selection >= itemKeys.length) {
|
|
150
|
-
return player.sendMessage("你选择的物品无效");
|
|
151
|
-
}
|
|
152
|
-
const selectedItemId = itemKeys[selection];
|
|
153
|
-
const selectedItemData = inventoryData.get(selectedItemId);
|
|
154
|
-
if (!selectedItemData || !Array.isArray(selectedItemData)) {
|
|
155
|
-
return player.sendMessage("该物品数据异常");
|
|
156
|
-
}
|
|
157
|
-
const [selectedItemName, selectedItemCount] = selectedItemData;
|
|
158
|
-
this.selectionNum({
|
|
159
|
-
tit: `存入 ${selectedItemName}`,
|
|
160
|
-
min: 0,
|
|
161
|
-
max: selectedItemCount,
|
|
162
|
-
callback: ({
|
|
163
|
-
formValues
|
|
164
|
-
}) => {
|
|
165
|
-
const countToStore = formValues[0];
|
|
166
|
-
const manualLore = new Lore(itemOnHand);
|
|
167
|
-
manualLore.name = selectedItemName;
|
|
168
|
-
manualLore.count = countToStore + selectedItemCount;
|
|
169
|
-
this.handlerAdd(manualLore, player, itemOnHand, countToStore);
|
|
170
|
-
},
|
|
171
|
-
lastUi: () => this.openHomeForm(player, itemOnHand),
|
|
172
|
-
},
|
|
173
|
-
player
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
handlerAdd(lore, player, originalItem, countToStore) {
|
|
178
|
-
utils.removeItems(player, {
|
|
179
|
-
name: lore.name,
|
|
180
|
-
count: countToStore,
|
|
181
|
-
});
|
|
182
|
-
originalItem.setLore(lore.parseArr())
|
|
183
|
-
utils.setMainHand(player, originalItem);
|
|
184
|
-
player.sendMessage(`成功存入 ${countToStore} 个「${lore.name}」`);
|
|
185
|
-
}
|
|
186
|
-
selectionNum({
|
|
187
|
-
min = 0,
|
|
188
|
-
max = 1,
|
|
189
|
-
tit = "",
|
|
190
|
-
callback = () => {},
|
|
191
|
-
lastUi = () => {},
|
|
192
|
-
} = {},
|
|
193
|
-
player
|
|
194
|
-
) {
|
|
195
|
-
const form = this.game
|
|
196
|
-
.createForm("Modal", this.layouts[1])
|
|
197
|
-
form.addLayout({
|
|
198
|
-
type: "slider",
|
|
199
|
-
param: [tit, min, max]
|
|
200
|
-
})
|
|
201
|
-
const show = form.show(player, true)
|
|
202
|
-
show.onCancel(lastUi)
|
|
203
|
-
show.onCommit(callback);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
1
|
+
import {
|
|
2
|
+
baseUi
|
|
3
|
+
} from "./baseUi";
|
|
4
|
+
import {
|
|
5
|
+
utils
|
|
6
|
+
} from "./../utils/index";
|
|
7
|
+
import {
|
|
8
|
+
Lore
|
|
9
|
+
} from "./Lore";
|
|
10
|
+
class ItemBagUI extends baseUi {
|
|
11
|
+
initLayout() {
|
|
12
|
+
this.layouts = this.game.regLayout({
|
|
13
|
+
regIds: ["Home", "NumSelect", "showInNoFound"],
|
|
14
|
+
Home: {
|
|
15
|
+
title: "菜单",
|
|
16
|
+
layout: [{
|
|
17
|
+
type: "button",
|
|
18
|
+
param: ["存入物品"]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "button",
|
|
22
|
+
param: ["取出物品"]
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
NumSelect: {
|
|
27
|
+
title: "选择数量",
|
|
28
|
+
layout: []
|
|
29
|
+
},
|
|
30
|
+
showInNoFound: {
|
|
31
|
+
title: "请选择要存入的物品",
|
|
32
|
+
layout: [{
|
|
33
|
+
type: "label",
|
|
34
|
+
param: ["点击你想要存放的物品"]
|
|
35
|
+
}]
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 打开主菜单:存入物品 / 取出物品
|
|
41
|
+
*/
|
|
42
|
+
openHomeForm(player, itemOnHand) {
|
|
43
|
+
if (!this.layouts) this.initLayout();
|
|
44
|
+
const lore = new Lore(itemOnHand);
|
|
45
|
+
const form = this.game.createForm("Action", this.layouts[0]);
|
|
46
|
+
form.addLayout({
|
|
47
|
+
type: "label",
|
|
48
|
+
param: [`无尽袋子 - 菜单\n物品 : ${lore.name} , 数量 : ${lore.count}`]
|
|
49
|
+
})
|
|
50
|
+
form.show(player, true).onCommit(({
|
|
51
|
+
selection
|
|
52
|
+
}) => {
|
|
53
|
+
switch (selection) {
|
|
54
|
+
case 0:
|
|
55
|
+
this.openAddItemForm(player, itemOnHand);
|
|
56
|
+
break;
|
|
57
|
+
case 1:
|
|
58
|
+
this.hanlerTakeOutItems(player, itemOnHand);
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
player.sendMessage("请选择存入或取出");
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
hanlerTakeOutItems(player, itemOnHand) {
|
|
66
|
+
const lore = new Lore(itemOnHand)
|
|
67
|
+
if (!lore.name) return player.sendMessage('没有存入任何东西');
|
|
68
|
+
this.selectionNum({
|
|
69
|
+
min: 1,
|
|
70
|
+
max: lore.count,
|
|
71
|
+
tit: lore.name,
|
|
72
|
+
callback: ({
|
|
73
|
+
formValues
|
|
74
|
+
}) => {
|
|
75
|
+
const TakeOutCount = formValues[0];
|
|
76
|
+
player.runCommand(`give @s ${lore.name} ${TakeOutCount}`)
|
|
77
|
+
lore.count = lore.count - TakeOutCount;
|
|
78
|
+
itemOnHand.setLore(lore.parseArr())
|
|
79
|
+
utils.setMainHand(player, itemOnHand);
|
|
80
|
+
},
|
|
81
|
+
lastUi: () => this.openHomeForm(player, itemOnHand)
|
|
82
|
+
}, player)
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 打开“存入物品”表单(自动识别物品类型)
|
|
86
|
+
*/
|
|
87
|
+
openAddItemForm(player, itemOnHand) {
|
|
88
|
+
const currencyLore = new Lore(itemOnHand);
|
|
89
|
+
// 如果 Lore 无法识别此物品(比如没有 name 字段),则进入手动选择模式
|
|
90
|
+
if (currencyLore.name === undefined) {
|
|
91
|
+
return this.showInNoData(player, currencyLore, itemOnHand);
|
|
92
|
+
}
|
|
93
|
+
const inventoryData = utils.getAllPlayerInt(player);
|
|
94
|
+
let totalItemAmount = 0;
|
|
95
|
+
// 统计当前玩家拥有该物品的总数量
|
|
96
|
+
for (const [itemId, itemData] of inventoryData) {
|
|
97
|
+
const [itemName, itemCount] = itemData;
|
|
98
|
+
if (itemName === currencyLore.name) {
|
|
99
|
+
totalItemAmount += itemCount;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// 如果该物品数量为 0,则提示无法存入
|
|
103
|
+
if (totalItemAmount <= 0) {
|
|
104
|
+
return player.sendMessage("你没有该物品,无法存入!");
|
|
105
|
+
}
|
|
106
|
+
// 弹出滑条,让用户选择存入多少个
|
|
107
|
+
this.selectionNum({
|
|
108
|
+
min: 0,
|
|
109
|
+
max: totalItemAmount,
|
|
110
|
+
tit: currencyLore.name,
|
|
111
|
+
callback: ({
|
|
112
|
+
formValues
|
|
113
|
+
}) => {
|
|
114
|
+
const countToStore = formValues[0];
|
|
115
|
+
currencyLore.count = countToStore + totalItemAmount;
|
|
116
|
+
this.handlerAdd(currencyLore, player, itemOnHand, countToStore);
|
|
117
|
+
},
|
|
118
|
+
lastUi: () => this.openHomeForm(player, itemOnHand),
|
|
119
|
+
},
|
|
120
|
+
player
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 当物品无法自动识别时,让用户从列表中手动选择要存入的物品
|
|
125
|
+
*/
|
|
126
|
+
showInNoData(player, placeholderLore, itemOnHand) {
|
|
127
|
+
const form = this.game.createForm("Action", this.layouts[2]);
|
|
128
|
+
const inventoryData = utils.getAllPlayerInt(player);
|
|
129
|
+
const itemButtons = [];
|
|
130
|
+
const itemKeys = [];
|
|
131
|
+
let buttonIndex = 0;
|
|
132
|
+
for (const [itemId, itemData] of inventoryData) {
|
|
133
|
+
if (!Array.isArray(itemData)) continue;
|
|
134
|
+
const [itemName, itemCount] = itemData;
|
|
135
|
+
form.addLayout({
|
|
136
|
+
type: "button",
|
|
137
|
+
param: [`${itemName} x${itemCount}`],
|
|
138
|
+
});
|
|
139
|
+
itemKeys[buttonIndex] = itemId;
|
|
140
|
+
buttonIndex++;
|
|
141
|
+
}
|
|
142
|
+
form.show(player).then(({
|
|
143
|
+
selection,
|
|
144
|
+
canceled
|
|
145
|
+
}) => {
|
|
146
|
+
if (canceled) {
|
|
147
|
+
return this.openHomeForm(player, itemOnHand);
|
|
148
|
+
}
|
|
149
|
+
if (selection === undefined || selection >= itemKeys.length) {
|
|
150
|
+
return player.sendMessage("你选择的物品无效");
|
|
151
|
+
}
|
|
152
|
+
const selectedItemId = itemKeys[selection];
|
|
153
|
+
const selectedItemData = inventoryData.get(selectedItemId);
|
|
154
|
+
if (!selectedItemData || !Array.isArray(selectedItemData)) {
|
|
155
|
+
return player.sendMessage("该物品数据异常");
|
|
156
|
+
}
|
|
157
|
+
const [selectedItemName, selectedItemCount] = selectedItemData;
|
|
158
|
+
this.selectionNum({
|
|
159
|
+
tit: `存入 ${selectedItemName}`,
|
|
160
|
+
min: 0,
|
|
161
|
+
max: selectedItemCount,
|
|
162
|
+
callback: ({
|
|
163
|
+
formValues
|
|
164
|
+
}) => {
|
|
165
|
+
const countToStore = formValues[0];
|
|
166
|
+
const manualLore = new Lore(itemOnHand);
|
|
167
|
+
manualLore.name = selectedItemName;
|
|
168
|
+
manualLore.count = countToStore + selectedItemCount;
|
|
169
|
+
this.handlerAdd(manualLore, player, itemOnHand, countToStore);
|
|
170
|
+
},
|
|
171
|
+
lastUi: () => this.openHomeForm(player, itemOnHand),
|
|
172
|
+
},
|
|
173
|
+
player
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
handlerAdd(lore, player, originalItem, countToStore) {
|
|
178
|
+
utils.removeItems(player, {
|
|
179
|
+
name: lore.name,
|
|
180
|
+
count: countToStore,
|
|
181
|
+
});
|
|
182
|
+
originalItem.setLore(lore.parseArr())
|
|
183
|
+
utils.setMainHand(player, originalItem);
|
|
184
|
+
player.sendMessage(`成功存入 ${countToStore} 个「${lore.name}」`);
|
|
185
|
+
}
|
|
186
|
+
selectionNum({
|
|
187
|
+
min = 0,
|
|
188
|
+
max = 1,
|
|
189
|
+
tit = "",
|
|
190
|
+
callback = () => {},
|
|
191
|
+
lastUi = () => {},
|
|
192
|
+
} = {},
|
|
193
|
+
player
|
|
194
|
+
) {
|
|
195
|
+
const form = this.game
|
|
196
|
+
.createForm("Modal", this.layouts[1])
|
|
197
|
+
form.addLayout({
|
|
198
|
+
type: "slider",
|
|
199
|
+
param: [tit, min, max]
|
|
200
|
+
})
|
|
201
|
+
const show = form.show(player, true)
|
|
202
|
+
show.onCancel(lastUi)
|
|
203
|
+
show.onCommit(callback);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
207
|
export default ItemBagUI;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EntityComponentTypes,
|
|
3
|
-
EquipmentSlot
|
|
4
|
-
} from "@minecraft/server"
|
|
5
|
-
|
|
6
|
-
export class utils {
|
|
7
|
-
static getAllPlayerInt(player) {
|
|
8
|
-
const data = new Map();
|
|
9
|
-
const inventory = player
|
|
10
|
-
.getComponent("inventory")
|
|
11
|
-
.container;
|
|
12
|
-
for (let i = 0; i < inventory.size; i++) {
|
|
13
|
-
const item = inventory.getItem(i);
|
|
14
|
-
if (!item) continue;
|
|
15
|
-
let num = item.amount;
|
|
16
|
-
// 自动合并
|
|
17
|
-
const it = data.get(item.typeId);
|
|
18
|
-
if (Array.isArray(it)) num += it[1]
|
|
19
|
-
data.set(item.typeId, [item.typeId, num]);
|
|
20
|
-
}
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
static setMainHand(player, item) {
|
|
24
|
-
const Equippable = player
|
|
25
|
-
.getComponent(EntityComponentTypes.Equippable);
|
|
26
|
-
Equippable
|
|
27
|
-
.setEquipment(EquipmentSlot.Mainhand, item);
|
|
28
|
-
}
|
|
29
|
-
static removeItems(player, {
|
|
30
|
-
name,
|
|
31
|
-
count
|
|
32
|
-
} = {}) {
|
|
33
|
-
const inventory = player
|
|
34
|
-
.getComponent("inventory")
|
|
35
|
-
.container;
|
|
36
|
-
let RemoveNum = count;
|
|
37
|
-
for (let i = 0; i < inventory.size; i++) {
|
|
38
|
-
const item = inventory.getItem(i);
|
|
39
|
-
if (!item || !item.typeId || item.typeId !== name) continue;
|
|
40
|
-
const num = item.amount;
|
|
41
|
-
if (RemoveNum >= num) {
|
|
42
|
-
inventory.setItem(i, null);
|
|
43
|
-
RemoveNum -= num;
|
|
44
|
-
} else {
|
|
45
|
-
const remNum = RemoveNum >= 64 ? 64 : Math.max(RemoveNum, item.amount) - Math.min(RemoveNum, item.amount)
|
|
46
|
-
item.amount = remNum;
|
|
47
|
-
RemoveNum -= remNum
|
|
48
|
-
inventory.setItem(i, item);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
EntityComponentTypes,
|
|
3
|
+
EquipmentSlot
|
|
4
|
+
} from "@minecraft/server"
|
|
5
|
+
|
|
6
|
+
export class utils {
|
|
7
|
+
static getAllPlayerInt(player) {
|
|
8
|
+
const data = new Map();
|
|
9
|
+
const inventory = player
|
|
10
|
+
.getComponent("inventory")
|
|
11
|
+
.container;
|
|
12
|
+
for (let i = 0; i < inventory.size; i++) {
|
|
13
|
+
const item = inventory.getItem(i);
|
|
14
|
+
if (!item) continue;
|
|
15
|
+
let num = item.amount;
|
|
16
|
+
// 自动合并
|
|
17
|
+
const it = data.get(item.typeId);
|
|
18
|
+
if (Array.isArray(it)) num += it[1]
|
|
19
|
+
data.set(item.typeId, [item.typeId, num]);
|
|
20
|
+
}
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
static setMainHand(player, item) {
|
|
24
|
+
const Equippable = player
|
|
25
|
+
.getComponent(EntityComponentTypes.Equippable);
|
|
26
|
+
Equippable
|
|
27
|
+
.setEquipment(EquipmentSlot.Mainhand, item);
|
|
28
|
+
}
|
|
29
|
+
static removeItems(player, {
|
|
30
|
+
name,
|
|
31
|
+
count
|
|
32
|
+
} = {}) {
|
|
33
|
+
const inventory = player
|
|
34
|
+
.getComponent("inventory")
|
|
35
|
+
.container;
|
|
36
|
+
let RemoveNum = count;
|
|
37
|
+
for (let i = 0; i < inventory.size; i++) {
|
|
38
|
+
const item = inventory.getItem(i);
|
|
39
|
+
if (!item || !item.typeId || item.typeId !== name) continue;
|
|
40
|
+
const num = item.amount;
|
|
41
|
+
if (RemoveNum >= num) {
|
|
42
|
+
inventory.setItem(i, null);
|
|
43
|
+
RemoveNum -= num;
|
|
44
|
+
} else {
|
|
45
|
+
const remNum = RemoveNum >= 64 ? 64 : Math.max(RemoveNum, item.amount) - Math.min(RemoveNum, item.amount)
|
|
46
|
+
item.amount = remNum;
|
|
47
|
+
RemoveNum -= remNum
|
|
48
|
+
inventory.setItem(i, item);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
52
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "无尽袋子",
|
|
3
|
-
"description": "一个袋子装无限的单种物品",
|
|
4
|
-
"mcVersion": "1.21.120",
|
|
5
|
-
"version": "0.0.1",
|
|
6
|
-
"script": {
|
|
7
|
-
"main": "index.js",
|
|
8
|
-
"ui": true,
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"gameLib": "inner"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"minify": true,
|
|
14
|
-
"outdir": {
|
|
15
|
-
"resources": "./dist/res",
|
|
16
|
-
"behavior": "./dist/dep",
|
|
17
|
-
"dist": "./dist.mcaddon"
|
|
18
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "无尽袋子",
|
|
3
|
+
"description": "一个袋子装无限的单种物品",
|
|
4
|
+
"mcVersion": "1.21.120",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"script": {
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"ui": true,
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"gameLib": "inner"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"minify": true,
|
|
14
|
+
"outdir": {
|
|
15
|
+
"resources": "./dist/res",
|
|
16
|
+
"behavior": "./dist/dep",
|
|
17
|
+
"dist": "./dist.mcaddon"
|
|
18
|
+
}
|
|
19
19
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "mbler/test mbler-int",
|
|
3
|
-
"description": "能存无数物品的袋子 !",
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=16.0.0"
|
|
7
|
-
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"dev": "mbler dev",
|
|
10
|
-
"build": "MBLER_BUILD_MODULE=dist mbler build",
|
|
11
|
-
"dev-build": "MBLER_BUILD_MODULE=dev mbler build"
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "mbler/test mbler-int",
|
|
3
|
+
"description": "能存无数物品的袋子 !",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=16.0.0"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "mbler dev",
|
|
10
|
+
"build": "MBLER_BUILD_MODULE=dist mbler build",
|
|
11
|
+
"dev-build": "MBLER_BUILD_MODULE=dev mbler build"
|
|
12
|
+
}
|
|
13
13
|
}
|