mbler 0.1.1 → 0.1.3-alpna-r1
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 +32 -0
- package/bin/mbler.js +12 -12
- package/bin/minify.js +58 -44
- package/lib/build/build-g-config.json +11 -11
- package/lib/data/includes.json +12 -12
- package/lib/data/version.json +88 -88
- package/lib/mcx/compile-mcx/compile.js +1 -1
- 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/modules/create-game/mbler.config.json +13 -13
- package/lib/modules/gameLib/mbler.config.json +15 -15
- package/lib/modules/gutils/mbler.config.json +11 -11
- package/lib/modules/innerDef.json +4 -4
- package/lib/runTemp/config.json +3 -3
- package/lib/start/create.js +1 -1
- package/lib/start/index.js +1 -1
- package/lib/start/rechce.js +1 -1
- 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 -5
- 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,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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const server_1 = require("@minecraft/server");
|
|
4
|
-
console.log('console in ts minecraft');
|
|
5
|
-
server_1.world.getPlayers().sendMessage('text');
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const server_1 = require("@minecraft/server");
|
|
4
|
+
console.log('console in ts minecraft');
|
|
5
|
+
server_1.world.getPlayers().sendMessage('text');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
world
|
|
3
|
-
} from "@minecraft/server"
|
|
4
|
-
console.log('console in ts minecraft')
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
world
|
|
3
|
+
} from "@minecraft/server"
|
|
4
|
+
console.log('console in ts minecraft')
|
|
5
|
+
|
|
6
6
|
world.getPlayers().sendMessage('text')
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "test",
|
|
3
|
-
"description": "test",
|
|
4
|
-
"version": "0.1.1",
|
|
5
|
-
"mcVersion": "1.21.100",
|
|
6
|
-
"script": {
|
|
7
|
-
"ui": true,
|
|
8
|
-
"lang": "ts",
|
|
9
|
-
"main": "main",
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"gameLib": "inner"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"minify": true
|
|
1
|
+
{
|
|
2
|
+
"name": "test",
|
|
3
|
+
"description": "test",
|
|
4
|
+
"version": "0.1.1",
|
|
5
|
+
"mcVersion": "1.21.100",
|
|
6
|
+
"script": {
|
|
7
|
+
"ui": true,
|
|
8
|
+
"lang": "ts",
|
|
9
|
+
"main": "main",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"gameLib": "inner"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"minify": true
|
|
15
15
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "test",
|
|
3
|
-
"description": "Hello world",
|
|
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
|
-
"dependencies": {
|
|
14
|
-
"@minecraft/server": "2.1.0"
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "test",
|
|
3
|
+
"description": "Hello world",
|
|
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
|
+
"dependencies": {
|
|
14
|
+
"@minecraft/server": "2.1.0"
|
|
15
|
+
}
|
|
16
16
|
}
|