晴路卡
本帖最后由 晴路卡 于 2020-3-19 22:40 编辑

前段时间在我发布的原版模组更多烟花
用到了玩家手持特定物品右键盔甲架的探测
当时的一个难点就是归还这个放到盔甲架上的物品
总之最后用的是选取上1tick手持物品发生数量变化的最近玩家
作为归还物品的对象(显然这是不精确的,正经的原版模组作者都老强迫症了)
但是现在在新快照里实体UUID被记录为4个整数
这意味着我们就有精准选定把物品放到盔甲架上的玩家的办法了。




先放效果:即兴做的这个东西可以向@a显示将物品放到盔甲架上的玩家名



首先我们把玩家的UUID拖到记分板里
  1. execute as @a store result score @s u0 run data get entity @s UUID[0]
  2. execute as @a store result score @s u1 run data get entity @s UUID[1]
  3. execute as @a store result score @s u2 run data get entity @s UUID[2]
  4. execute as @a store result score @s u3 run data get entity @s UUID[3]
复制代码

然后要给玩家手持的物品上一个tag(广义)
来记录是谁最后一个拿到了这个物品
  1. setblock 0 0 0 shulker_box
  2. data modify block 0 0 0 Items append from entity @s SelectedItem
  3. data modify block 0 0 0 Items[{Slot:0b}].tag merge value {init:1b}
  4. data modify block 0 0 0 Items[{Slot:0b}].tag.owneru set value [0,0,0,0]
  5. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[0] int 1 run scoreboard players get @s u0
  6. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[1] int 1 run scoreboard players get @s u1
  7. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[2] int 1 run scoreboard players get @s u2
  8. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[3] int 1 run scoreboard players get @s u3
  9. loot replace entity @s weapon.mainhand 1 mine 0 0 0 diamond_pickaxe{isShulkerMarker:1b}
复制代码

再把玩家手持物品所记录的对应的UUID也拖出来
  1. setblock 0 0 0 shulker_box
  2. data modify block 0 0 0 Items append from entity @s SelectedItem
  3. data modify block 0 0 0 Items[{Slot:0b}].tag merge value {init:1b}
  4. data modify block 0 0 0 Items[{Slot:0b}].tag.owneru set value [0,0,0,0]
  5. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[0] int 1 run scoreboard players get @s u0
  6. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[1] int 1 run scoreboard players get @s u1
  7. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[2] int 1 run scoreboard players get @s u2
  8. execute at @s store result block 0 0 0 Items[{Slot:0b}].tag.owneru[3] int 1 run scoreboard players get @s u3
  9. loot replace entity @s weapon.mainhand 1 mine 0 0 0 diamond_pickaxe{isShulkerMarker:1b}
复制代码
并且更新手持物品的tag只会在手持物品的记录与手持玩家不匹配的时候发生
否则会在多人模式下会重复播放一个音效

  1. execute as @a if data entity @s SelectedItem unless score @s u0 = @s i0 run function uuid:itemuuid
  2. execute as @a if data entity @s SelectedItem unless score @s u1 = @s i1 run function uuid:itemuuid
  3. execute as @a if data entity @s SelectedItem unless score @s u2 = @s i2 run function uuid:itemuuid
  4. execute as @a if data entity @s SelectedItem unless score @s u3 = @s i3 run function uuid:itemuuid
复制代码
把盔甲架手持物品的UUID拖出来:
  1. execute as @e[tag=test] store result score @s u0 run data get entity @s HandItems[0].tag.owneru[0]
  2. execute as @e[tag=test] store result score @s u1 run data get entity @s HandItems[0].tag.owneru[1]
  3. execute as @e[tag=test] store result score @s u2 run data get entity @s HandItems[0].tag.owneru[2]
  4. execute as @e[tag=test] store result score @s u3 run data get entity @s HandItems[0].tag.owneru[3]
复制代码
对所有玩家进行匹配 如果成功就输出这名玩家的名字
  1. execute as @a if score @s u0 = @e[tag=test,limit=1] u0 if score @s u1 = @e[tag=test,limit=1] u1 if score @s u2 = @e[tag=test,limit=1] u2 if score @s u3 = @e[tag=test,limit=1] u3 run title @a title [{"selector":"@s"}]
  2. data remove entity @e[tag=test,limit=1] HandItems[0]
复制代码





感觉这次UUID储存形式的变化还能做很多事,希望有更多的讨论吧
item_owner_uuid.zip (2.6 KB, 下载次数: 10)



来自群组: The Minecraft Lover

(=°ω°)丿
你说的好,但是盔甲架的速度永远赶不上玩家的速度,所以我还是选择胡萝卜钓竿(

晴路卡
隐退 发表于 2020-3-22 10:14
你说的好,但是盔甲架的速度永远赶不上玩家的速度,所以我还是选择胡萝卜钓竿( ...

唔 这个适用的是某个位置不变的待右键的单位
比如打火石右键某个我虚构的东西,从而“点燃”这个东西

(不过后来想了想好像这些东西旧版本就能做


(=°ω°)丿
等等,如果只是比对的话,1.16 以前不也可以吗(

代码:

  1. ## 尝试存储玩家的 UUID
  2. execute store success score #temp value run data modify storage foo:example UUIDLeast set from entity @s UUIDLeast
  3. execute store success score #temp2 value run data modify storage foo:example UUIDMost set from entity @s UUIDMost
  4. ## 若存储失败则意味着相同,也就是找到。
  5. execute if score #temp value matches 0 if score #temp2 value matches 0 run function foo:find

晴路卡
本帖最后由 晴路卡 于 2020-3-22 13:24 编辑
隐退 发表于 2020-3-22 12:17
等等,如果只是比对的话,1.16 以前不也可以吗(

是的
前几天讨论到这个的时候感觉新版本突然黯然失色了呜呜
正像原版中的OwnerUUID一样
UUID很重要的功能就是关联并匹配相对应是实体
所以除了对比之外似乎没有什么需要的其他应用,,,

小小小月丫
眼花缭乱,看不懂的我,萌新