aa0307bb
①如何为玩家手上已有附魔的物品(该物品拥有的附魔种类及附魔等级均未知)再加上其它附魔②如果该物品不存在某附魔,则不进行操作;若存在该附魔(等级未知),则可以增加附魔等级


BaiMeow
本帖最后由 锦鸡FBI 于 2019-8-8 20:39 编辑

https://minecraft-zh.gamepedia.com/%E5%91%BD%E4%BB%A4/enchant

Chelover_C60
本帖最后由 CHElover_C60 于 2019-8-8 20:42 编辑

①我能想到的就是穷举玩家手中的物品,再执行对应的操作了。以鱼竿为例,首先检测到玩家手中的物品是钓鱼竿,然后添加标签。穷举出这个工具可以有的附魔,生成拥有对应标签的药水云。检测玩家手上鱼竿拥有的附魔,并kill掉对应的药水云,最后随机选择一个药水云添加标签,并根据所添加的标签决定给予哪个附魔,最后kill掉药水云。
  1. tag @a[nbt={SelectedItem:{id:"minecraft:fishing_rod"}}] add fishing_rod
  2. execute as @a[tag=fishing_rod] at @s run function minecraft:fishing_rod
复制代码
fishing_rod.mcfunction
  1. summon minecraft:area_effect_cloud ~ ~ ~ {Tags:["enchant","fortune"],Duration:1}
  2. summon minecraft:area_effect_cloud ~ ~ ~ {Tags:["enchant","luck_of_the_sea"],Duration:1}
  3. summon minecraft:area_effect_cloud ~ ~ ~ {Tags:["enchant","unbreaking"],Duration:1}
  4. summon minecraft:area_effect_cloud ~ ~ ~ {Tags:["enchant","mending"],Duration:1}
  5. execute if entity @s[nbt={SelectedItem:{tag:{Enchantments:[{id:"minecraft:fortune"}]}}}] run kill @e[tag=fortune]
  6. execute if entity @s[nbt={SelectedItem:{tag:{Enchantments:[{id:"minecraft:luck_of_the_sea"}]}}}] run kill @e[tag=luck_of_the_sea]
  7. execute if entity @s[nbt={SelectedItem:{tag:{Enchantments:[{id:"minecraft:unbreaking"}]}}}] run kill @e[tag=unbreaking]
  8. execute if entity @s[nbt={SelectedItem:{tag:{Enchantments:[{id:"minecraft:mending"}]}}}] run kill @e[tag=mending]
  9. tag @e[sort=random,limit=1,tag=enchant] add mark
  10. execute if entity @e[tag=mark,tag=fortune] run enchant @s minecraft:fortune
  11. execute if entity @e[tag=mark,tag=luck_of_the_sea] run enchant @s minecraft:luck_of_the_sea
  12. execute if entity @e[tag=mark,tag=unbreaking] run enchant @s minecraft:unbreaking
  13. execute if entity @e[tag=mark,tag=mending] run enchant @s minecraft:mending
  14. kill @e[tag=enchant]
复制代码


②因为无法修改玩家的nbt,除了replaceitem以外几乎做不到修改指定物品栏的方法,而replaceitem不能通过变量指定,enchant又无法改变已经拥有的附魔的等级,所以几乎无解(至少我想不到)

aa0307bb
CHElover_C60 发表于 2019-8-8 20:38
①我能想到的就是穷举玩家手中的物品,再执行对应的操作了。以鱼竿为例,首先检测到玩家手中的物品是钓鱼竿 ...

②data不能修改,那就改成把所需的装备放在箱子/物品展示框/盔甲架上操作吧

Chelover_C60
aa0307bb 发表于 2019-8-8 20:43
②data不能修改,那就改成把所需的装备放在箱子/物品展示框/盔甲架上操作吧 ...

就物品展示框吧,感觉简单些,其他的懒得想了
先建立计分板,获取等级并加1分后保存至原位置,最后重置分数,即可。
  1. scoreboard objectives add lvl dummy
复制代码
  1. execute as @e[type=minecraft:item_frame] store result score @s lvl run data get entity @s Item.tag.Enchantments[0].lvl
  2. scoreboard players add @e[type=minecraft:item_frame,scores={lvl=1..}] lvl 1
  3. execute as @e[type=minecraft:item_frame,scores={lvl=1..}] store result entity @s Item.tag.Enchantments[0].lvl short 1 run scoreboard players get @s lvl
  4. scoreboard players reset @e[type=minecraft:item_frame,scores={lvl=1..}] lvl
复制代码

aa0307bb
CHElover_C60 发表于 2019-8-8 20:38
①我能想到的就是穷举玩家手中的物品,再执行对应的操作了。以鱼竿为例,首先检测到玩家手中的物品是钓鱼竿 ...

等等……已经有了附魔的物品还能用enchant吗

Chelover_C60
aa0307bb 发表于 2019-8-8 21:38
等等……已经有了附魔的物品还能用enchant吗

仍然可以,但是不能有互相冲突的附魔(如锋利和亡灵杀手),已有的附魔也不可以

aa0307bb
CHElover_C60 发表于 2019-8-8 21:05
就物品展示框吧,感觉简单些,其他的懒得想了
先建立计分板,获取等级并加1分后保存至原位置,最后 ...

忽然反应过来……你的指令用到的data只是获取玩家数据,没有修改玩家数据;而修改附魔等级你是用execute store做的,而不是用data来修改的,这样为什么不干脆直接作用在玩家身上而是作用在物品展示框呢XD

Chelover_C60
aa0307bb 发表于 2019-8-10 01:32
忽然反应过来……你的指令用到的data只是获取玩家数据,没有修改玩家数据;而修改附魔等级你是用execute  ...

玩家nbt无法被编辑,不管使用的是data还是execute store

aa0307bb
CHElover_C60 发表于 2019-8-10 09:10
玩家nbt无法被编辑,不管使用的是data还是execute store

啊咧……像/execute store result entity @s SelectedItem.tag.Damage int 1 run scoreboard players get @s Damage不是可以修改手上物品的耐久度吗……

Chelover_C60
本帖最后由 CHElover_C60 于 2019-8-10 11:29 编辑
aa0307bb 发表于 2019-8-10 11:10
啊咧……像/execute store result entity @s SelectedItem.tag.Damage int 1 run scoreboard players get ...

抱歉。。。我一直不知道execute store能改玩家的nbt
震惊!被称为不能修改的玩家nbt居然臣服于execute store这个命令!
那就可以这样
  1. execute as @a if data entity @s SelectedItem.tag.Enchantments[] run function minecraft:enchant_lvlup
复制代码

enchant_lvlup.mcfunction
  1. execute store result score @s lvl run data get entity @s SelectedItem.tag.Enchantments[0].lvl
  2. scoreboard players add @s lvl 1
  3. execute store result entity @s SelectedItem.tag.Enchantments[0].lvl short 1 run scoreboard players get @s lvl
  4. scoreboard players reset @s lvl
复制代码

aa0307bb
CHElover_C60 发表于 2019-8-10 11:26
抱歉。。。我一直不知道execute store能改玩家的nbt
震惊!被称为不能修改的玩家nbt居然臣服于execute  ...

还有一点我好刁钻啊
SelectedItem.tag.Enchantments[0].lvl

也就是无法指定获取的数据是具体哪种附魔的等级了吗(艾玛为什么我的删除线不会消失的)

Chelover_C60
aa0307bb 发表于 2019-8-10 11:56

还有一点我好刁钻啊
SelectedItem.tag.Enchantments[0].lvl

这个我想不到办法,估计只能手动改了吧,或者穷举可能的结果后做个随机(哭)

aa0307bb
CHElover_C60 发表于 2019-8-10 11:58
这个我想不到办法,估计只能手动改了吧,或者穷举可能的结果后做个随机(哭) ...

咦……忽然想到https://www.mcbbs.net/thread-898754-1-1.html的那个操作……可是NBT路径不会写...

aa0307bb
CHElover_C60 发表于 2019-8-10 11:58
这个我想不到办法,估计只能手动改了吧,或者穷举可能的结果后做个随机(哭) ...

我在说问题②如果该物品不存在某附魔,则不进行操作;若存在该附魔(等级未知),则可以增加附魔等级 虽然附魔是未知的,但是可以检测

Chelover_C60
aa0307bb 发表于 2019-8-10 12:14
我在说问题②如果该物品不存在某附魔,则不进行操作;若存在该附魔(等级未知),则可以增加附魔等级[:St ...

我理解错了,抱歉。
SelectedItem.tag.Enchantments[{id:"minecraft:sharpness"}].lvl
不知道是不是这样,这种用法我也是第一次见,选择有锋利附魔的路径