[1.16.5]Minecraft数据包---装备耐久可视化

cover
该数据包及配套资源包允许玩家在游戏界面上能直接看到装备以及耐久度的情况。
该数据包隶属于 cAsual woRk (3/99)

效果演示

B站视频演示:

https://www.bilibili.com/video/bv1ji4y1T7ry

演示1

大致原理

通过字体黑科技在actionbar显示图片,反向空格调整到适合位置。
然后生成4个药水云,分别检测玩家的4个装备槽位,并且更改药水云的名字

1
2
3
4
5
6
7
8
9
# eqv:main
execute as @a at @s unless entity @s[predicate=eqv:helmet] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue103"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:leather_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue120"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:chainmail_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue10A"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:golden_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue10F"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:iron_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue113"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:diamond_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue117"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:netherite_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue11B"}'}
execute as @a at @s if data entity @s Inventory.[{Slot:103b,id:"minecraft:turtle_helmet",Count:1b}] run data merge entity @e[type=area_effect_cloud,limit=1,tag=eqv-helmet,distance=..1] {CustomName:'{"text": "\\ue11C"}'}

值得注意的是,由于头上可以戴很多奇怪的东西,所以写个断言来处理所有无效物品的情况。
然后再生成4个药水云,用于显示装备耐久条。
令药水云分别把对应装备的Damage存到计分板,然后就是简单粗暴的穷举( ,判断装备然后对应比较现在的Damage位于哪个区间并显示耐久条

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# eqv:main
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if entity @a[distance=..1,limit=1,predicate=eqv:helmet] run execute as @s store result score @s eqv-durability run data get entity @a[distance=..1,limit=1,predicate=eqv:helmet] Inventory.[{Slot:103b}].tag.Damage
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:leather_helmet",Count:1b}] run function eqv:helmet/leather
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:chainmail_helmet",Count:1b}] run function eqv:helmet/chainmail
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:golden_helmet",Count:1b}] run function eqv:helmet/golden
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:iron_helmet",Count:1b}] run function eqv:helmet/iron
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:diamond_helmet",Count:1b}] run function eqv:helmet/diamond
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:netherite_helmet",Count:1b}] run function eqv:helmet/netherite
execute as @e[type=area_effect_cloud,tag=eqv-h-d] at @s if data entity @a[limit=1,distance=..1] Inventory.[{Slot:103b,id:"minecraft:turtle_helmet",Count:1b}] run function eqv:helmet/turtle

# eqv:helmet/golden
execute as @s if score @s eqv-durability matches 1..6 run data merge entity @s {CustomName:'{"text":"\\ue121"}'}
execute as @s if score @s eqv-durability matches 7..11 run data merge entity @s {CustomName:'{"text":"\\ue122"}'}
execute as @s if score @s eqv-durability matches 12..16 run data merge entity @s {CustomName:'{"text":"\\ue123"}'}
execute as @s if score @s eqv-durability matches 17..21 run data merge entity @s {CustomName:'{"text":"\\ue124"}'}
execute as @s if score @s eqv-durability matches 22..27 run data merge entity @s {CustomName:'{"text":"\\ue125"}'}
execute as @s if score @s eqv-durability matches 28..32 run data merge entity @s {CustomName:'{"text":"\\ue126"}'}
execute as @s if score @s eqv-durability matches 33..37 run data merge entity @s {CustomName:'{"text":"\\ue127"}'}
execute as @s if score @s eqv-durability matches 38..42 run data merge entity @s {CustomName:'{"text":"\\ue128"}'}
execute as @s if score @s eqv-durability matches 43..48 run data merge entity @s {CustomName:'{"text":"\\ue129"}'}
execute as @s if score @s eqv-durability matches 49..53 run data merge entity @s {CustomName:'{"text":"\\ue12A"}'}
execute as @s if score @s eqv-durability matches 54..58 run data merge entity @s {CustomName:'{"text":"\\ue12B"}'}
execute as @s if score @s eqv-durability matches 59..64 run data merge entity @s {CustomName:'{"text":"\\ue12C"}'}
execute as @s if score @s eqv-durability matches 65..69 run data merge entity @s {CustomName:'{"text":"\\ue12D"}'}
execute as @s if score @s eqv-durability matches 73..77 run data merge entity @s {CustomName:'{"text":"\\ue12E"}'}

这种做法是非常naive的方案,不过好就好在非常无脑XD。可能会导致耐久条显示可能和实际有些出入,但是大体上的范围是差不多的。
同样的方法操作下来,我们就会得到8个有不同名字的药水云,然后使用title里的selector显示他们的名字,配以反向空格调整位置。

1
execute as @a at @s run title @s actionbar ["",{"text": "\ue102"},{"selector":"@e[type=area_effect_cloud,tag=eqv-helmet,distance=..1,limit=1]"},{"text":"\ue101"},{"selector":"@e[type=area_effect_cloud,tag=eqv-h-d,distance=..1,limit=1]"},{"text":"  "},{"selector":"@e[type=area_effect_cloud,tag=eqv-chestplate,distance=..1,limit=1]"},{"text":"\ue100"},{"selector":"@e[type=area_effect_cloud,tag=eqv-c-d,distance=..1,limit=1]"},{"text":"  "},{"selector":"@e[type=area_effect_cloud,tag=eqv-leggings,distance=..1,limit=1]"},{"text":"\ue101"},{"selector":"@e[type=area_effect_cloud,tag=eqv-l-d,distance=..1,limit=1]"},{"text":"  "},{"selector":"@e[type=area_effect_cloud,tag=eqv-boots,distance=..1,limit=1]"},{"text":"\ue100"},{"selector":"@e[type=area_effect_cloud,tag=eqv-b-d,distance=..1,limit=1]"}]

当然,由于位置关系是我用眼看着大概写的,所以难免会有点误差,但是我又不是强迫症XD。
另外,我本来是想通过类似”245 / 562”这样的方式来显示耐久的,但是我一用ttf字体,mc就直接崩溃,作罢。

鸣谢

  • 国外大佬的潜影盒显示黑科技给我的灵感和一些思路
  • 黑猫的字体艺术教程
  • dhp好用

datapack

链接: https://pan.baidu.com/s/1e7yhgb4R77ynFKj3P73TiA
提取码: itaf

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2020-2021 Argon_gas

请我喝杯咖啡吧~