t1546542
版本:1.15.2
将玩家主手槽位的物品放到玩家的头部槽位
如果头部槽位有物品,先将主手物品放到头部槽位,再将原头部槽位的物品放到主手
可以使用数据包,但除functions外的必须说明意思
@Chelove_C60 @Jokey_钥匙 @SPGoding @⊙u⊙

彩元素凋灵
https://www.mcmod.cn/tools/cbcreator/你试试用这个软件

fallingCB
参考这个帖子
点我跳转~

cowb
  1. /replaceitem entity @s armor.head 物品id
复制代码

Chelover_C60
本帖最后由 Chelove_C60 于 2020-4-20 09:50 编辑

谢邀

简单的c=a,a=b,b=c问题,同时借助如花影盒潜影盒来完成动态替换

execute as @a at @s run function hat

hat.mcfunction
  1. execute if entity @s Inventory[{Slot:103b}] run function have_hat
  2. setblock ~ 255 ~ shulker_box{Items:[{Slot:0b,id:"minecraft:stone",Count:1b}]}
  3. data modify block ~ 255 ~ Items[0] merge from entity @s SelectedItem
  4. replaceitem entity @s armor.head air
  5. loot replace entity @s armor.head 1 mine ~ 255 ~ minecraft:diamond_pickaxe{isShulkerMarker:1b}
  6. execute if entity @s[tag=have_hat] run function return_hat
  7. setblock ~ 255 ~ air
复制代码


have_hat.mcfunction
  1. tag @s add have_hat
  2. data modify storage hat_info hat set from entity @s Inventory[{Slot:103b}]
复制代码


return_hat.mcfunction
  1. data modify block ~ 255 ~ Items[0].id set from storage hat_info hat.id
  2. data modify block ~ 255 ~ Items[0].Count set from storage hat_info hat.Count
  3. data modify block ~ 255 ~ Items[0].tag set from storage hat_info hat.tag
  4. replaceitem entity @s weapon.mainhand air
  5. loot replace entity @s weapon.mainhand 1 mine ~ 255 ~ minecraft:diamond_pickaxe{isShulkerMarker:1b}
  6. tag @s remove have_hat
复制代码


修改潜影盒的战利品表
  1. {
  2.     "type": "minecraft:block",
  3.     "pools": [
  4.         {
  5.             "rolls": 1,
  6.             "entries": [
  7.                 {
  8.                     "type": "minecraft:alternatives",
  9.                     "children": [
  10.                         {
  11.                             "type": "minecraft:dynamic",
  12.                             "name": "minecraft:contents",
  13.                             "conditions": [
  14.                                 {
  15.                                     "condition": "minecraft:match_tool",
  16.                                     "predicate": {
  17.                                         "nbt":"{isShulkerMarker:1b}"
  18.                                     }
  19.                                 }
  20.                             ]
  21.                         },
  22.                         {
  23.                             "type": "minecraft:item",
  24.                             "functions": [
  25.                                 {
  26.                                     "function": "minecraft:copy_name",
  27.                                     "source": "block_entity"
  28.                                 },
  29.                                 {
  30.                                     "function": "minecraft:copy_nbt",
  31.                                     "source": "block_entity",
  32.                                     "ops": [
  33.                                         {
  34.                                             "source": "Lock",
  35.                                             "target": "BlockEntityTag.Lock",
  36.                                             "op": "replace"
  37.                                         },
  38.                                         {
  39.                                             "source": "LootTable",
  40.                                             "target": "BlockEntityTag.LootTable",
  41.                                             "op": "replace"
  42.                                         },
  43.                                         {
  44.                                             "source": "LootTableSeed",
  45.                                             "target": "BlockEntityTag.LootTableSeed",
  46.                                             "op": "replace"
  47.                                         }
  48.                                     ]
  49.                                 },
  50.                                 {
  51.                                     "function": "minecraft:set_contents",
  52.                                     "entries": [
  53.                                         {
  54.                                             "type": "minecraft:dynamic",
  55.                                             "name": "minecraft:contents"
  56.                                         }
  57.                                     ]
  58.                                 }
  59.                             ],
  60.                             "name": "minecraft:shulker_box"
  61.                         }
  62.                     ]
  63.                 }
  64.             ]
  65.         }
  66.     ]
  67. }
复制代码


部分内容及原理参考自https://www.mcbbs.net/thread-860954-1-1.html

t1546542
Chelove_C60 发表于 2020-4-20 09:33
谢邀

简单的c=a,a=b,b=c问题,同时借助如花影盒潜影盒来完成动态替换

这个战利品表的意思

Chelover_C60
t1546542 发表于 2020-4-20 10:44
这个战利品表的意思

所以你到底有没有看我下面附的链接
修改minecraft/loot_tables/blocks/shulker_box.json为使用特定nbt的镐挖掘时,掉落内含物而且不掉落潜影盒。

t1546542
Chelove_C60 发表于 2020-4-20 10:50
所以你到底有没有看我下面附的链接

能不能直接返回一个item呢

Chelover_C60
t1546542 发表于 2020-4-20 11:24
能不能直接返回一个item呢

什么叫直接返回一个item呢?
定向替换玩家物品栏的只有两个命令,一个replaceitem,一个loot
replaceitem只能指定物品后替换,没法动态替换物品,所以不考虑
那只能用loot,而用loot就必须要改战利品表(因为原版数据包里没有能用得上的战利品表)
而要解决动态物品id问题,战利品表随机池的type就不能写item、tag、loot_table,那么只剩一个dynamic,而dynamic又与方块有关,所以只能用一个方块做辅助使用。

或者,如果你愿意穷举物品id,可以参考chyx的帖子。这应该就是你说的直接返回一个item吧
https://www.mcbbs.net/thread-837334-1-1.html

Kunst
这个就是将物品戴在头上的治疗,可以试一下
/replaceitem entity @r armor.head 物品id

t1546542
本帖最后由 t1546542 于 2020-4-20 19:14 编辑
Chelove_C60 发表于 2020-4-20 12:03
什么叫直接返回一个item呢?
定向替换玩家物品栏的只有两个命令,一个replaceitem,一个loot
replaceitem ...

我的意思是
既然loot可以直接指定槽位并替换
那么战利品表能不能返回一个物品
这个物品的信息就是玩家主手的物品信息

刚刚翻了一下SPG的战利品表教程
发现不行,只能用潜影盒


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