mbler 0.1.6 → 0.1.8-beta
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/lib/start/init.js +1 -1
- package/package.json +2 -3
- package/test/2x sword/.cache__mbler__/config-hash.txt +0 -1
- package/test/2x sword/.cache__mbler__/package-hash.txt +0 -1
- package/test/2x sword/behavior/scripts/index.js +0 -25
- package/test/2x sword/mbler.config.json +0 -12
- package/test/2x sword/package.json +0 -14
- package/test/README.md +0 -8
- package/test/des/index.js +0 -20
- package/test/des/mbler.config.json +0 -5
- package/test/des/package.json +0 -7
- package/test/initializer/index.js +0 -6
- package/test/initializer/mbler.config.json +0 -5
- package/test/initializer/package.json +0 -7
- package/test/initializer/test.js +0 -1
- package/test/mbler-int/behavior/res/items/mang_one_int.json +0 -22
- package/test/mbler-int/behavior/res/pack_icon.png +0 -0
- package/test/mbler-int/behavior/res/recipes/mang_one_int.json +0 -31
- package/test/mbler-int/behavior/scripts/index.js +0 -8
- package/test/mbler-int/behavior/scripts/lib/event/index.js +0 -20
- package/test/mbler-int/behavior/scripts/lib/ui/Lore.js +0 -19
- package/test/mbler-int/behavior/scripts/lib/ui/baseUi.js +0 -6
- package/test/mbler-int/behavior/scripts/lib/ui/index.js +0 -207
- package/test/mbler-int/behavior/scripts/lib/utils/index.js +0 -52
- package/test/mbler-int/mbler.config.json +0 -19
- package/test/mbler-int/package.json +0 -13
- package/test/script-mbler/.cache__mbler__/config-hash.txt +0 -1
- package/test/script-mbler/.cache__mbler__/package-hash.txt +0 -1
- package/test/script-mbler/behavior/res/pack_icon.png +0 -0
- package/test/script-mbler/behavior/scripts/index.js +0 -5
- package/test/script-mbler/behavior/scripts/index.ts +0 -6
- package/test/script-mbler/mbler.config.json +0 -15
- package/test/script-mbler/package.json +0 -16
package/lib/start/init.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(i,e,t,r){void 0===r&&(r=t);var n=Object.getOwnPropertyDescriptor(e,t);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(i,r,n)}:function(i,e,t,r){void 0===r&&(r=t),i[r]=e[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(i,e){Object.defineProperty(i,"default",{enumerable:!0,value:e})}:function(i,e){i.default=e}),__importStar=this&&this.__importStar||function(){var i=function(e){return i=Object.getOwnPropertyNames||function(i){var e=[];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(e[e.length]=t);return e},i(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),n=0;n<r.length;n++)"default"!==r[n]&&__createBinding(t,e,r[n]);return __setModuleDefault(t,e),t}}(),__importDefault=this&&this.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};const fs=__importStar(require("fs/promises")),utils=__importStar(require("../utils/index.js")),index_js_1=__importDefault(require("./../loger/index.js")),path=__importStar(require("path")),build_g_config_json_1=__importDefault(require("./../build/build-g-config.json")),index_js_2=require("./../commander/index.js"),mcVersion_js_1=require("./../build/mcVersion.js");let dirname="";class Init{dir;dirName;constructor(i,e){dirname=e,this.dir=i,this.dirName=e}async start(){if(!await utils.FileExsit(this.dir))return void index_js_1.default.w("init","无效的配置");if(await utils.isMblerProject(this.dir))return void index_js_1.default.i("init","已经初始化过了");const i=await this.input("项目名称: "),e=await this.input("项目描述: "),t=await this.input("支持的minecraft版本: "),r={name:i,description:e,version:"0.0.1",engines:{node:">=20.0.0"},scripts:{dev:"mbler dev",build:"MBLER_BUILD_MODULE=dist mbler build","dev-build":"MBLER_BUILD_MODULE=dev mbler build"},dependencies:Object.create(null)},n={name:i,description:e,mcVersion:t,version:"0.0.1",minify:!1};if("y"===(await this.input("使用Script Api吗?(Y/N) ")).toLowerCase()){n.script={},n.script.main=await this.input("主脚本路径(如 ./index.js): ")||"index",n.script.ui="y"===(await this.input("使用 UI 吗?(Y/N) ")).toLowerCase(),n.script.ui&&(r.dependencies["@minecraft/server-ui"]=mcVersion_js_1.mcVersionGeter.ToServerUi(t)),await Promise.all([fs.mkdir(path.join(this.dir,"behavior","scripts"),{recursive:!0}),fs.mkdir(path.join(this.dir,"resources"),{recursive:!0})]);const i=await index_js_2.Input.select("选择语言",["ts","js","mcx"]);n.script.lang=i,"ts"===i
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(i,e,t,r){void 0===r&&(r=t);var n=Object.getOwnPropertyDescriptor(e,t);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(i,r,n)}:function(i,e,t,r){void 0===r&&(r=t),i[r]=e[t]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(i,e){Object.defineProperty(i,"default",{enumerable:!0,value:e})}:function(i,e){i.default=e}),__importStar=this&&this.__importStar||function(){var i=function(e){return i=Object.getOwnPropertyNames||function(i){var e=[];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(e[e.length]=t);return e},i(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),n=0;n<r.length;n++)"default"!==r[n]&&__createBinding(t,e,r[n]);return __setModuleDefault(t,e),t}}(),__importDefault=this&&this.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};const fs=__importStar(require("fs/promises")),utils=__importStar(require("../utils/index.js")),index_js_1=__importDefault(require("./../loger/index.js")),path=__importStar(require("path")),build_g_config_json_1=__importDefault(require("./../build/build-g-config.json")),index_js_2=require("./../commander/index.js"),mcVersion_js_1=require("./../build/mcVersion.js");let dirname="";class Init{dir;dirName;constructor(i,e){dirname=e,this.dir=i,this.dirName=e}async start(){if(!await utils.FileExsit(this.dir))return void index_js_1.default.w("init","无效的配置");if(await utils.isMblerProject(this.dir))return void index_js_1.default.i("init","已经初始化过了");const i=await this.input("项目名称: "),e=await this.input("项目描述: "),t=await this.input("支持的minecraft版本: "),r={name:i,description:e,version:"0.0.1",engines:{node:">=20.0.0"},scripts:{dev:"mbler dev",build:"MBLER_BUILD_MODULE=dist mbler build","dev-build":"MBLER_BUILD_MODULE=dev mbler build"},dependencies:Object.create(null)},n={name:i,description:e,mcVersion:t,version:"0.0.1",minify:!1};if("y"===(await this.input("使用Script Api吗?(Y/N) ")).toLowerCase()){n.script={},n.script.main=await this.input("主脚本路径(如 ./index.js): ")||"index",n.script.ui="y"===(await this.input("使用 UI 吗?(Y/N) ")).toLowerCase(),n.script.ui&&(r.dependencies["@minecraft/server-ui"]=mcVersion_js_1.mcVersionGeter.ToServerUi(t)),await Promise.all([fs.mkdir(path.join(this.dir,"behavior","scripts"),{recursive:!0}),fs.mkdir(path.join(this.dir,"resources"),{recursive:!0})]);const i=await index_js_2.Input.select("选择语言",["ts","js","mcx"]);n.script.lang=i,"ts"===i?r.dependencies["@minecraft/server"]=mcVersion_js_1.mcVersionGeter.ToServer(t):"mcx"==i&&(r.dependencies["@mbler/mcx"]="latest")}n.outdir={resources:"./dist/res",behavior:"./dist/dep",dist:"./dist.mcaddon"},await fs.writeFile(path.join(this.dir,"package.json"),JSON.stringify(r,null,2)),await fs.writeFile(path.join(this.dir,build_g_config_json_1.default.PackageFile),JSON.stringify(n,null,2))}async getVersion(i){let e,t=!1;for(;e=await utils.input(t?"格式错误,重新输入: "+i:i),!utils.isVerison(e);)t=!0;return e}async input(i,e=!1){return await utils.input((e?"不符合规范,重试: ":"")+i)||this.input(i,!0)}}module.exports=Init;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mbler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8-beta",
|
|
4
4
|
"description": "一个针对Minecraft JavaScript API 的CLI工具,让你的附加包版本管理更简单",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@babel/parser": "7.28.5",
|
|
27
27
|
"@babel/traverse": "7.28.5",
|
|
28
28
|
"@babel/types": "7.28.6",
|
|
29
|
-
"@mbler/mcx-core": "
|
|
29
|
+
"@mbler/mcx-core": "latest",
|
|
30
30
|
"adm-zip": "0.5.16",
|
|
31
31
|
"chokidar": "4.0.3",
|
|
32
32
|
"dayjs": "1.11.18",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"lib",
|
|
38
|
-
"test",
|
|
39
38
|
"bin",
|
|
40
39
|
"README.md",
|
|
41
40
|
"LICENSE"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ba9e19e27533c85678ae256b688d8daeb7672d47
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
656d6fae1681c5cda2ad25f63d34b39f48a334ce
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
itemId: "§r§6§lmbler_test_2xsword:as§r§l §8 二倍剑",
|
|
3
|
-
ForRanger: 2
|
|
4
|
-
}
|
|
5
|
-
import {
|
|
6
|
-
EntityComponentTypes,
|
|
7
|
-
EquipmentSlot,
|
|
8
|
-
world,
|
|
9
|
-
system
|
|
10
|
-
} from "@minecraft/server"
|
|
11
|
-
world.afterEvents.entityDie.subscribe(({
|
|
12
|
-
deadEntity: entity,
|
|
13
|
-
damageSource: source
|
|
14
|
-
}) => {
|
|
15
|
-
system.run(()=>{ try { // 排除非正常人
|
|
16
|
-
if (!source.typeId.includes("player") || !getMainHand(source).nameTag.includes(config.itemId)) return;
|
|
17
|
-
} catch {}
|
|
18
|
-
for (let i = 0; i < config.ForRanger; i++) {
|
|
19
|
-
try {
|
|
20
|
-
entity.dimension.spawnEntity(entity.typeId)
|
|
21
|
-
} catch (err){
|
|
22
|
-
console.error(err)
|
|
23
|
-
}
|
|
24
|
-
}})
|
|
25
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "双倍剑",
|
|
3
|
-
"description": "打生物会再生成一个的奇葩剑",
|
|
4
|
-
"mcVersion": "1.21.80",
|
|
5
|
-
"version": "0.0.2",
|
|
6
|
-
"script": {
|
|
7
|
-
"main": "index",
|
|
8
|
-
"ui": true
|
|
9
|
-
},
|
|
10
|
-
"minify": false,
|
|
11
|
-
"outdir": "/storage/emulated/0/Android/data/com.mojang.minecraftpe/files/games/com.mojang/development_behavior_packs/test/"
|
|
12
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "双倍剑",
|
|
3
|
-
"description": "打生物会再生成一个的奇葩剑",
|
|
4
|
-
"version": "0.0.2",
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=20.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
|
-
}
|
package/test/README.md
DELETED
package/test/des/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
exports.main = async function main(content) {
|
|
2
|
-
const name = await MblerApi.input("名称")
|
|
3
|
-
const desc = await MblerApi.input(`描述 `)
|
|
4
|
-
const main = await MblerApi.input(`主脚本 `)
|
|
5
|
-
content.setWorkDir
|
|
6
|
-
.writeFile("./mbler.config.json", JSON.stringify({
|
|
7
|
-
name,
|
|
8
|
-
description: desc,
|
|
9
|
-
script: {
|
|
10
|
-
main: "src/index.js",
|
|
11
|
-
dependencies: {}
|
|
12
|
-
},
|
|
13
|
-
type: "scriptsDes",
|
|
14
|
-
version: "0.0.1",
|
|
15
|
-
mcVersion: [
|
|
16
|
-
"1.21.00",
|
|
17
|
-
"1.21.100"
|
|
18
|
-
]
|
|
19
|
-
}, null, 2))
|
|
20
|
-
}
|
package/test/des/package.json
DELETED
package/test/initializer/test.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("Test Load")
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"format_version": "1.20.100",
|
|
3
|
-
"minecraft:item": {
|
|
4
|
-
"description": {
|
|
5
|
-
"identifier": "mbler_int:mang_one_int"
|
|
6
|
-
},
|
|
7
|
-
"components": {
|
|
8
|
-
"minecraft:hand_equipped": false,
|
|
9
|
-
"minecraft:foil": true,
|
|
10
|
-
"minecraft:glint": true,
|
|
11
|
-
"allow_off_hand": {
|
|
12
|
-
"value": true
|
|
13
|
-
},
|
|
14
|
-
"minecraft:max_stack_size": 1,
|
|
15
|
-
"minecraft:stacked_by_data": true,
|
|
16
|
-
"minecraft:icon": "iconMangOneIntMbler",
|
|
17
|
-
"minecraft:display_name": {
|
|
18
|
-
"value": "无尽袋子 \n能存入无限的单种物品 右键打开"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
Binary file
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"format_version": "1.21",
|
|
3
|
-
"minecraft:recipe_shaped": {
|
|
4
|
-
"description": {
|
|
5
|
-
"identifier": "mbler_int:recipes_mang_one_int"
|
|
6
|
-
},
|
|
7
|
-
"tags": [
|
|
8
|
-
"crafting_table"
|
|
9
|
-
],
|
|
10
|
-
"unlock": [
|
|
11
|
-
{
|
|
12
|
-
"item": "minecraft:leather"
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
|
-
"pattern": [
|
|
16
|
-
"A ",
|
|
17
|
-
"AB "
|
|
18
|
-
],
|
|
19
|
-
"key": {
|
|
20
|
-
"A": {
|
|
21
|
-
"item": "minecraft:leather"
|
|
22
|
-
},
|
|
23
|
-
"B": {
|
|
24
|
-
"item": "minecraft:stick"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"result": {
|
|
28
|
-
"item": "mbler_int:mang_one_int"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,207 +0,0 @@
|
|
|
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
|
-
export default ItemBagUI;
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
80fa1241600cf387733e2616d0212ba44aafb473
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dabb5660e507e23f52e1a5dbbd14f86b38f49e2b
|
|
Binary file
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|