(=°ω°)丿


[1.14+] 告示牌黑科技 / 用战利品表实现


没有在论坛里发现类似的教程,所以就来灌水了(




准备





思考


如何将分数显示在实体的自定义名称?





黑科技





延伸


还有没有其他方法?


用战利品表。



代码:

  1. {
  2. "type": "minecraft:entity",
  3. "pools": [
  4.     {
  5.    "rolls": 1,
  6.    "entries": [
  7.   {
  8.     "type": "minecraft:item",
  9.     "name": "minecraft:stone",
  10.     "functions": [
  11.    {
  12.   "function": "minecraft:set_name",
  13.   "name": [
  14.     {
  15.    "text": "",
  16.    "italic": false
  17.     },
  18.     {
  19.    "text": "玩家的分数是 "
  20.     },
  21.     {
  22.    "score": {
  23.   "objective": "foo",
  24.   "name": "*"
  25.    }
  26.     }
  27.   ],
  28.   "entity": "this"
  29.    },
  30.    {
  31.   "function": "minecraft:set_nbt",
  32.   "tag": "{ItemMarker:1b}"
  33.    }
  34.     ]
  35.   }
  36.    ]
  37.     }
  38. ]
  39. }




结语


本文编写时间仓促,如有发现错误请指出。




代码:

  1. ***

  2. ## [1.14+] 告示牌黑科技 / 用战利品表实现

  3. 没有在论坛里发现类似的教程,所以就来灌水了(

  4. ---

  5. ### 准备

  6. - `scoreboard objectives add foo dummy`
  7. -先建立一个记分板 foo。
  8. - `scoreboard players set #temp foo 233`
  9. - 将玩家 #temp 的 foo 记分板的分数设置为 233。
  10. - `tellraw @a ["",{"text":"玩家的分数是 "},{"score":{"objective":"foo","name":"#temp"}}]`
  11. - 将玩家 #temp 的 foo 记分板的分数告诉给所有玩家。
  12. - 聊天栏里显示:`玩家的分数是 233`。

  13. ---

  14. ### 思考

  15. 如何将分数显示在实体的自定义名称?

  16. - `summon armor_stand ~ ~ ~ {CustomName:'["",{"text":"玩家的分数是 "},{"score":{"objective":"foo","name":"#temp"}}]',CustomNameVisible:1b,Tags:["target"]}`
  17. - 盔甲架的自定义名称为:`玩家的分数是 `。
  18. - 失败了。

  19. ---

  20. ### 黑科技

  21. - `data modify entity @e[tag=target,limit=1] CustomName set value ''`
  22. - 先将盔甲架的自定义名称清空。
  23. - `setblock ~ ~ ~ oak_sign{Text1:'["",{"text":"玩家的分数是 "},{"score":{"objective":"foo","name":"#temp"}}]'}`
  24. - 放置一个橡木告示牌。
  25. - 告示牌第一行的内容为:`玩家的分数是 233`。
  26. - `data modify entity @e[tag=target,limit=1] CustomName set from block ~ ~ ~ Text1`
  27. - 将告示牌第一行的内容复制到盔甲架的自定义名称。
  28. - 盔甲架的自定义名称变为:`玩家的分数是 233`。
  29. - 成功了。

  30. ---

  31. ### 延伸

  32. 还有没有其他方法?

  33. 用战利品表。

  34. - 先写一个战利品表:`foo:example`。
  35. - 一块石头,自定义名称为使用该战利品表的实体的分数。

  36. ```
  37. {
  38. "type": "minecraft:entity",
  39. "pools": [
  40.     {
  41.    "rolls": 1,
  42.    "entries": [
  43.   {
  44.     "type": "minecraft:item",
  45.     "name": "minecraft:stone",
  46.     "functions": [
  47.    {
  48.   "function": "minecraft:set_name",
  49.   "name": [
  50.     {
  51.    "text": "",
  52.    "italic": false
  53.     },
  54.     {
  55.    "text": "玩家的分数是 "
  56.     },
  57.     {
  58.    "score": {
  59.   "objective": "foo",
  60.   "name": "*"
  61.    }
  62.     }
  63.   ],
  64.   "entity": "this"
  65.    },
  66.    {
  67.   "function": "minecraft:set_nbt",
  68.   "tag": "{ItemMarker:1b}"
  69.    }
  70.     ]
  71.   }
  72.    ]
  73.     }
  74. ]
  75. }
  76. ```

  77. - `summon zombie ~ -65 ~ {DeathLootTable:"foo:example",Tags:["marker"]}`
  78. - 召唤一只死亡战利品表为上述战利品表的僵尸。
  79. - `scoreboard players operation @e[tag=marker,limit=1] foo = #temp foo`
  80. - 使该僵尸的分数等于 #temp 的分数。
  81. - `loot spawn ~ -65 ~ kill @e[tag=marker,limit=1]`
  82. - 用 loot 命令 "杀死" 该僵尸,掉落物品。
  83. - `data modify entity @e[tag=target,limit=1] CustomName set from entity @e[type=item,limit=1,nbt={Item:{tag:{ItemMarker:1b}}}] Item.tag.display.Name`
  84. - 将物品的 display.Name 复制到盔甲架的自定义名称。
  85. - `kill @e[tag=marker]`
  86. - 移除该僵尸。
  87. - `kill @e[type=item,nbt={Item:{tag:{ItemMarker:1b}}}]`
  88. - 移除该物品。

  89. ---

  90. ### 结语

  91. 本文编写时间仓促,如有发现错误请指出。

  92. ---

Xiao2
嗯。。用summon的自定义名是不是只能text,然后其他类型的json文本都不支持


——————
原来还可以支持translate



永爱不忘
不错不错虽然看不懂夸就完事了

永爱不忘
日常学废   手:你别给我说话

lxt123qwe
活到老学到老