本帖最后由 ruhuasiyu 于 2019-6-20 13:42 编辑
命令loot replace 可用于动态替换实体/方块物品,是个十分便利的命令。然而可能很多人不知道,该命令是可以一次性替换多个槽位物品的。
复制代码执行该命令之后,
(1)首先会根据掉落品表确定将要掉落的物品序列,这些物品可能会相同。如果是潜影箱 "type":"dynamic"得到的掉落物,第X个就是第X个槽位的物品,即使该位置为空。但是通常的战利品表会忽视那些没有掉落物的项。
(2)根据liach查看源代码(见2L)得到结论(或见英文版wiki),确定槽位对应的编号,然后从其开始的编号从小到大依次排列构成将要放入的槽位的序列。
注意到,无论是玩家还是容器,选择槽位container.0和hotbar.0是一样的,实际效果是相同的。
(3)然后确定槽位数量。玩家可以在命令中指定槽位数量
复制代码如果未指定槽位数量,替换的槽位数量为战利品表的物品序列长度,对于潜影箱 "type":"dynamic"而言,固定是27个槽位。
(4)最后将物品序列塞入槽位序列。
例如使用
复制代码挖掘修改过战利品表的潜影盒时,
主手塞入潜影盒内第1个掉落物,若空则清空该位置
副手塞入潜影盒内第2个掉落物,若空则清空该位置
靴子塞入潜影盒内第3个掉落物品,若空或非法则清空该位置
护腿塞入潜影盒内第4个掉落物品,若空或非法则清空该位置
胸甲塞入潜影盒内第5个掉落物品,若空或非法则清空该位置
头盔塞入潜影盒内第6个掉落物品,若空或非法则清空该位置
例如使用
复制代码快捷栏塞入第1-9个物品
背包塞入第10-36个物品
主手、副手、靴子、护腿、胸甲、头盔塞入第99-104个物品
末影箱塞入第201-227个物品
下面这个例子中,我们可以将玩家手部的一个物品转移到头部,类似于插件/hat指令。
复制代码\data\minecraft\loot_tables\blocks\shulker_box.json复制代码
来自群组: The Command's Power
命令loot replace 可用于动态替换实体/方块物品,是个十分便利的命令。然而可能很多人不知道,该命令是可以一次性替换多个槽位物品的。
- loot replace entity @s 槽位 <source>
- loot replace block x y z 槽位 <source>
(1)首先会根据掉落品表确定将要掉落的物品序列,这些物品可能会相同。如果是潜影箱 "type":"dynamic"得到的掉落物,第X个就是第X个槽位的物品,即使该位置为空。但是通常的战利品表会忽视那些没有掉落物的项。
(2)根据liach查看源代码(见2L)得到结论(或见英文版wiki),确定槽位对应的编号,然后从其开始的编号从小到大依次排列构成将要放入的槽位的序列。
槽位 | 编号 | |
容器 | container.0~container.53 | 0~53 |
快捷栏 | hotbar.0~hotbar.8 | 0~8 |
背包 | inventory.0~inventory.26 | 9+0~26,即9~35 |
主手 | weapon或weapon.mainhand | 98 |
副手 | weapon.offhand | 99 |
靴子栏 | armor.feet | 100 |
护腿栏 | armor.legs | 101 |
胸甲栏 | armor.chest | 102 |
头盔栏 | armor.head | 103 |
末影箱 | enderchest.0~enderchest.26 | 200+0~26,即200~226 |
村民背包 | villager.0~villager.7 | 300+0~7,即300~307 |
马、驴、骡的鞍 | horse.saddle | 400 |
马的马铠、羊驼的地毯 | horse.armor | 401 |
驴、骡、羊驼的箱子 | horse.chest | 499 |
驴、骡、羊驼的背包 | horse.0~horse.14 | 500+0~14,即500~514 |
(3)然后确定槽位数量。玩家可以在命令中指定槽位数量
- loot replace entity @s 槽位 槽位数量 <source>
- loot replace block x y z 槽位 槽位数量 <source>
(4)最后将物品序列塞入槽位序列。
- 尝试塞入不合法的物品(头盔塞入非头部的盔甲、胸甲塞入非胸部的物品、马鞍塞入非马鞍)时,原物品不会被替换掉。
- 没有相应槽位时,也是无法塞入物品的。包括container序号大于27的槽位也是不存在的,即使是大箱子。
- 物品数量不足以塞满确定的槽位数量时,多余的槽位物品会被清空。
例如使用
- loot replace entity @s weapon.mainhand mine x y z diamond_pickaxe{isShulkerMarker:1b}
主手塞入潜影盒内第1个掉落物,若空则清空该位置
副手塞入潜影盒内第2个掉落物,若空则清空该位置
靴子塞入潜影盒内第3个掉落物品,若空或非法则清空该位置
护腿塞入潜影盒内第4个掉落物品,若空或非法则清空该位置
胸甲塞入潜影盒内第5个掉落物品,若空或非法则清空该位置
头盔塞入潜影盒内第6个掉落物品,若空或非法则清空该位置
例如使用
- loot replace entity @s hotbar.0 loot 战利品表
- 或
- loot replace entity @s container.0 loot 战利品表
背包塞入第10-36个物品
主手、副手、靴子、护腿、胸甲、头盔塞入第99-104个物品
末影箱塞入第201-227个物品
下面这个例子中,我们可以将玩家手部的一个物品转移到头部,类似于插件/hat指令。
- setblock ~ 255 ~ shulker_box{Items:[{Slot:0b,id:"minecraft:firework_star",Count:1b}]}
- data modify block ~ 255 ~ Items[0].id set from entity @s SelectedItem.id
- data modify block ~ 255 ~ Items[0].tag set from entity @s SelectedItem.tag
- loot replace entity @s armor.head 1 mine ~ 255 ~ diamond_pickaxe{isShulkerMarker:1b}
- execute store result score #temp sivalue run data get entity @s SelectedItem.Count
- execute store result block ~ 255 ~ Items[0].Count byte 1 run scoreboard players remove #temp sivalue 1
- loot replace entity @s weapon.mainhand 1 mine ~ 255 ~ diamond_pickaxe{isShulkerMarker:1b}
- setblock ~ 255 ~ air
- {
- "type": "minecraft:block",
- "pools": [
- {
- "rolls": 1,
- "entries": [
- {
- "type": "minecraft:alternatives",
- "children": [
- {
- "type": "minecraft:dynamic",
- "name": "minecraft:contents",
- "conditions": [
- {
- "condition": "minecraft:match_tool",
- "predicate": {
- "nbt":"{isShulkerMarker:1b}"
- }
- }
- ]
- },
- {
- "type": "minecraft:item",
- "functions": [
- {
- "function": "minecraft:copy_name",
- "source": "block_entity"
- },
- {
- "function": "minecraft:copy_nbt",
- "source": "block_entity",
- "ops": [
- {
- "source": "Lock",
- "target": "BlockEntityTag.Lock",
- "op": "replace"
- },
- {
- "source": "LootTable",
- "target": "BlockEntityTag.LootTable",
- "op": "replace"
- },
- {
- "source": "LootTableSeed",
- "target": "BlockEntityTag.LootTableSeed",
- "op": "replace"
- }
- ]
- },
- {
- "function": "minecraft:set_contents",
- "entries": [
- {
- "type": "minecraft:dynamic",
- "name": "minecraft:contents"
- }
- ]
- }
- ],
- "name": "minecraft:shulker_box"
- }
- ]
- }
- ]
- }
- ]
- }
来自群组: The Command's Power
太长慢慢去看
我先要说
bugs.mojang.com
等着你
我先要说
bugs.mojang.com
等着你
遇事不决,量子力......走错片场,打扰了
大晚上为什么要发这种看得眼睛疼的东西
大晚上为什么要发这种看得眼睛疼的东西
期待,回头试试。
真的看着眼睛疼。。。
真的看着眼睛疼。。。
遇事不决,量子力学.jpg
所以大佬的原版hat是怎么实现的?
所以大佬的原版hat是怎么实现的?
NoName德里奇 发表于 2019-6-19 10:53
遇事不决,量子力学.jpg
所以大佬的原版hat是怎么实现的?
下面列出了函数,以及对潜影盒战利品表的修改
搞晕了半天才发现这并不是bug,只是working as intended……
几个小细节:
看样子是时候详细写写这个了 https://minecraft.gamepedia.com/Commands#minecraft:item_slot
复制代码
这段代码就是 1.14.3 Pre 2 中反编译的 item slot 参数转整数格子编号的逻辑。
还有这个loot replace的时候是连号replace的,如果中间有个号断掉了那么那个对应的号的loot就没了。
不过号中间差那么多应该不会出现两头有中间没的现象。
几个小细节:
- 头盔也有非法物品(鞘翅等能放在其它装备格的物品不能放头盔格)
- 如果用非法物品填充某格失败,原先那格的东西不会被清空
看样子是时候详细写写这个了 https://minecraft.gamepedia.com/Commands#minecraft:item_slot
- private static final Map<String, Integer> slotNamesToSlotCommandId = SystemUtil.consume(Maps.newHashMap(), hashMap_1 -> {
- for (int int_1 = 0; int_1 < 54; ++int_1) {
- hashMap_1.put("container." + int_1, int_1);
- }
- for (int int_2 = 0; int_2 < 9; ++int_2) {
- hashMap_1.put("hotbar." + int_2, int_2);
- }
- for (int int_3 = 0; int_3 < 27; ++int_3) {
- hashMap_1.put("inventory." + int_3, 9 + int_3);
- }
- for (int int_4 = 0; int_4 < 27; ++int_4) {
- hashMap_1.put("enderchest." + int_4, 200 + int_4);
- }
- for (int int_5 = 0; int_5 < 8; ++int_5) {
- hashMap_1.put("villager." + int_5, 300 + int_5);
- }
- for (int int_6 = 0; int_6 < 15; ++int_6) {
- hashMap_1.put("horse." + int_6, 500 + int_6);
- }
- hashMap_1.put("weapon", 98);
- hashMap_1.put("weapon.mainhand", 98);
- hashMap_1.put("weapon.offhand", 99);
- hashMap_1.put("armor.head", 100 + EquipmentSlot.HEAD.getEntitySlotId());
- hashMap_1.put("armor.chest", 100 + EquipmentSlot.CHEST.getEntitySlotId());
- hashMap_1.put("armor.legs", 100 + EquipmentSlot.LEGS.getEntitySlotId());
- hashMap_1.put("armor.feet", 100 + EquipmentSlot.FEET.getEntitySlotId());
- hashMap_1.put("horse.saddle", 400);
- hashMap_1.put("horse.armor", 401);
- hashMap_1.put("horse.chest", 499);
- });
这段代码就是 1.14.3 Pre 2 中反编译的 item slot 参数转整数格子编号的逻辑。
还有这个loot replace的时候是连号replace的,如果中间有个号断掉了那么那个对应的号的loot就没了。
不过号中间差那么多应该不会出现两头有中间没的现象。
厉害 路过路过看不懂
有点长。。。。。等收藏起来过会再看
loot replace强行直译是战利品重放,是这个意思吗?