阡喏
能不能做到将箱子里某一物品(比如钻石)的数量储存到计分板上?

堕天使之墓
  1. /execute store result score @s 【计分板名称】 run data get block 【方块坐标】 Items[{id:"【那个物品的命名空间名称,例如minecraft:diamond】"}].Count
复制代码

获取指定方块坐标(那个箱子)中路径为Items[{id:"【命名空间名称】"}].Count的值(箱子内满足条件“物品id为【命名空间名称】”的槽位的“数量”值),并将结果(那个数量)储存至【计分板名称】中

缺点就是如果箱子里有两个同种物品就废掉了......

(=°ω°)丿
将箱子中所有放了钻石的槽位筛选出来并放入一个列表,遍历列表,将数量相加。


代码:

  1. # 初始化
  2. scoreboard objectives add foo dummy
  3. data merge storage foo:example {Items:[]}

  4. # 统计
  5. data modify storage foo:example Items append from block ~ ~ ~ Items[{id:"minecraft:diamond"}]
  6. execute store result score #i foo if data storage foo:example Items[]
  7. scoreboard players set #sum foo 0
  8. execute if score #i foo matches 1.. run function foo:example
  9. tellraw @s [{"text":"箱子内钻石的总数为 "},{"score":{"name":"#sum","objective":"foo"}}]

  10. # 函数 foo:example
  11. execute store result score #temp foo run data get storage foo:example Items[0].Count
  12. scoreboard players operation #sum foo += #temp foo
  13. scoreboard players remove #i foo 1
  14. data remove storage foo:example Items[0]
  15. execute if score #i foo matches 1.. run function foo:example

第一页 上一页 下一页 最后一页