[1.15.2]Minecraft数据包---原版箱子菜单

cover
该数据包允许玩家较为容易的创建一个自定义的箱子菜单。
并且可以自定义点击物品执行命令。

效果演示

B站视频演示:
https://www.bilibili.com/video/BV1qT4y1G79T

演示1

演示2

使用

1
2
/function chestmenu:on
/function chestmenu:off

来开/关系统,在系统关闭情况下,无法使用箱子菜单

使用

1
2
/function chestmenu:store_chest
/function chestmenu:store_minecart

来创建箱子菜单/箱子矿车菜单,可自定义其中物品,摆出一个对称的菜单界面 :D

然后通过

1
/function chestmenu:upload

上传箱子菜单

使用

1
2
/function chestmenu:export_chest
/function chestmenu:export_minecart

来创建箱子菜单/矿车菜单

然后开发者可以在
datapacks\chestmenu\data\chestmenu\functions\main
修改对应物品格对应的命令
就是那两块无聊的穷举啦

大致原理

首先生成储存物品的箱子/箱子矿车,玩家摆好物品后使用命令将Items标签上传至天上的箱子矿车存起来
Items标签会加上不同tag存两份,以便于后续进行比对

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#chestmenu:upload

#储存-箱子
execute as @e[type=area_effect_cloud,tag=cm-store,limit=1] at @s run data modify block ~ ~ ~ Items.[] merge value {tag:{id:"cm-tag1"}}
execute as @e[type=area_effect_cloud,tag=cm-store,limit=1] at @s run data modify entity @e[type=chest_minecart,tag=cm-tag1,limit=1] Items set from block ~ ~ ~ Items
execute as @e[type=area_effect_cloud,tag=cm-store,limit=1] at @s run data remove block ~ ~ ~ Item.[].tag.id
execute as @e[type=area_effect_cloud,tag=cm-store,limit=1] at @s run data modify block ~ ~ ~ Items.[] merge value {tag:{id:"cm-item"}}
execute as @e[type=area_effect_cloud,tag=cm-store,limit=1] at @s run data modify entity @e[type=chest_minecart,tag=cm-tag2,limit=1] Items set from block ~ ~ ~ Items
execute as @e[type=area_effect_cloud,tag=cm-store,limit=1] at @s run setblock ~ ~ ~ air replace

#矿车
execute as @e[type=chest_minecart,tag=cm-store,limit=1] at @s run data modify entity @s Items.[] merge value {tag:{id:"cm-tag1"}}
execute as @e[type=chest_minecart,tag=cm-store,limit=1] at @s run data modify entity @e[type=chest_minecart,tag=cm-tag3,limit=1] Items set from entity @s Items
execute as @e[type=chest_minecart,tag=cm-store,limit=1] at @s run data remove entity @s Item.[].tag.id
execute as @e[type=chest_minecart,tag=cm-store,limit=1] at @s run data modify entity @s Items.[] merge value {tag:{id:"cm-item"}}
execute as @e[type=chest_minecart,tag=cm-store,limit=1] at @s run data modify entity @e[type=chest_minecart,tag=cm-tag4,limit=1] Items set from entity @s Items
tellraw @s ["",{"text":"=上传成功=","color":"red","bold":true}]
kill @e[type=chest_minecart,tag=cm-store]

然后玩家创建菜单,将菜单中的物品高频覆盖原来模板中的物品
如果菜单物品与模板物品一致,那么检测不到模板物品
如果玩家拿走某物品,那么即可检测到对应的模板物品,然后获取slot转成分数执行一遍命令
最后把模板物品覆盖到菜单里,恢复原样
(思路由雨弓提供XD)

1
2
3
4
5
6
7
8
9
#chestmenu:main

#aec,导出与对比
execute as @e[type=area_effect_cloud,tag=cm-export] at @s run data modify entity @e[type=chest_minecart,tag=cm-compare,limit=1] Items set from entity @e[type=chest_minecart,tag=cm-tag1,limit=1] Items
execute as @e[type=area_effect_cloud,tag=cm-export] at @s run data modify entity @e[type=chest_minecart,tag=cm-compare,limit=1] Items append from block ~ ~ ~ Items.[]

#minecart,导出与对比
execute as @e[type=chest_minecart,tag=cm-export] at @s run data modify entity @e[type=chest_minecart,tag=cm-compare2,limit=1] Items set from entity @e[type=chest_minecart,tag=cm-tag3,limit=1] Items
execute as @e[type=chest_minecart,tag=cm-export] at @s run data modify entity @e[type=chest_minecart,tag=cm-compare2,limit=1] Items append from entity @s Items.[]

如果系统关闭后,maker被删掉,箱子菜单无法使用,会出现提示内容

1
2
3
4
5
6
7
execute as @e[type=area_effect_cloud,tag=cm-export] at @s run data modify block ~ ~ ~ Items set from entity @e[type=chest_minecart,tag=cm-tag2,limit=1] Items
execute as @e[type=area_effect_cloud,tag=cm-export] at @s unless entity @e[type=chest_minecart,tag=cm-compare] run tellraw @p ["",{"text":"哦吼,ChestMenu系统好像坏掉勒\n","color":"gold"},{"text":"请使用 ","color":"gold"},{"text":"/function chestmenu:on ","color":"red","blod":true},{"text":"以重置系统","color":"gold"}]
execute as @e[type=area_effect_cloud,tag=cm-export] at @s unless entity @e[type=chest_minecart,tag=cm-compare] run fill ~ ~ ~ ~ ~ ~ air replace minecraft:chest

execute as @e[type=chest_minecart,tag=cm-export] at @s run data modify entity @s Items set from entity @e[type=chest_minecart,tag=cm-tag4,limit=1] Items
execute as @e[type=chest_minecart,tag=cm-export] at @s unless entity @e[type=chest_minecart,tag=cm-compare2] run tellraw @p ["",{"text":"哦吼,ChestMenu系统好像坏掉勒\n","color":"gold"},{"text":"请使用 ","color":"gold"},{"text":"/function chestmenu:on ","color":"red","blod":true},{"text":"以重置系统","color":"gold"}]
execute as @e[type=chest_minecart,tag=cm-export] at @s unless entity @e[type=chest_minecart,tag=cm-compare2] run tp @s ~ ~-1210 ~

现在可以手持特定nbt物品{id:”minecartmenu”}打开菜单了
通过断言判断玩家手持特定的物品,然后在直接玩家脸上糊个箱子矿车

1
2
3
4
5
6
7
8
9
10
11
{
"condition":"minecraft:entity_properties",
"entity": "this",
"predicate": {
"equipment":{
"mainhand":{
"nbt": "{id:\"minecartmenu\"}"
}
}
}
}

还在持续更新,自己也有一些其他的想法想尝试实现,不过自己大概是没时间了。

鸣谢

  • 雨弓,提供了核心思路

  • spg,dhp真好用

  • ⊙v⊙,UIN标签

  • 特仑苏牛奶

更新列表

  • v1.0:
    发布
  • v1.1:
    修复了生成菜单时执行奇怪指令的BUG
    更改了矿车菜单的生成方式,现在可以手持特定nbt物品打开菜单了
  • v1.2:
    优化体验,增加关闭ui的预设函数,可直接调用

datapack

链接:https://pan.baidu.com/s/1CSeJp3EH6_oOAo9VJE6VXA/
提取码:96m5

  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2020 Argon_gas
  • Powered by Hexo Theme Ayer

请我喝杯咖啡吧~

支付宝
微信