MCSugar_cane 发表于 2018-1-28 15:28:43

【修复】随身背包-支持多人 附OOC

本帖最后由 MCSugar_cane 于 2018-1-28 15:40 编辑

随身背包
用命令方块实现背包,支持多人,已测试~代码适用版本为1.11.2-1.12,逻辑支持1.8.x以上版本
PS: 在写完代码后我又双叒叕惊喜的发现:我拓麻为什么要做这个模组,用原本有的潜影盒不好吗!(自己开的坑,哭着都要填完!)

效果演示:



原理:
首先我们来看单人里面的随身背包,无非就是用箱子或箱子矿车来实现,但箱子有个不好的地方就是它不是实体而无法被选择器选中。只能获取它的绝对位置进行clone才行,而不像箱子矿车可以被选择器选中。在单人中,我们只需要召唤一个箱子矿车,当玩家丢出掉落物后tp至掉落物,不要的时候再tp回来,十分简单。 有关检测指定掉落物可以查看此教程: 检测掉落物
按照单人的雏形,在多人中只需要一人有一个箱子矿车就可以了,难点就在于如何区分谁是谁的矿车,在这里我引用了之前做箱子商店区分主人的逻辑,为每一个矿车分配ID,并令其所有者ID=矿车ID,判定主人只需要令所有矿车ID减去玩家其ID,若差值等于0则为其所有者。


OOC见下一页

/summon falling_block ~ ~1.5 ~ {Time:1,Block:"minecraft:redstone_block",Motion:,Passengers:[{id:falling_block,Time:1,Block:"minecraft:activator_rail",Passengers:[{id:commandblock_minecart,Command:"blockdata ~ ~-2 ~ {auto:0b,Command:\"\"}"},{id:commandblock_minecart,Command:"fill ~1 ~-1 ~0 ~5 ~1 ~5 stained_glass 0 hollow"},{id:commandblock_minecart,Command:"fill ~1 ~-2 ~0 ~5 ~-2 ~5 planks 0 hollow"},{id:commandblock_minecart,Command:"fill ~1 ~2 ~0 ~5 ~2 ~5 planks 0 hollow"},{id:commandblock_minecart,Command:"setblock ~4 ~1 ~3 chain_command_block 3 replace {Command:\"/scoreboard objectives add bagID dummy 背包ID\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~1 ~3 chain_command_block 5 replace {Command:\"/scoreboard objectives add gtemp dummy 信息匹配\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~1 ~3 chain_command_block 5 replace {Command:\"/scoreboard objectives add gbag dummy\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~1 ~2 command_block 3 replace {Command:\"/summon armor_stand ~ ~ ~ {CustomName:\\\"bagIDStats\\\"}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~1 ~2 chain_command_block 4 replace {Command:\"/kill @e\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~1 ~2 chain_command_block 4 replace {Command:\"/execute @e ~ ~ ~ scoreboard players set @p gbag -1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~1 ~1 chain_command_block 3 replace {Command:\"/execute @e ~ ~ ~ scoreboard players set @e gbag -1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~1 ~1 chain_command_block 5 replace {Command:\"/scoreboard players tag @e add nobag {Item:{id:\\\"minecraft:barrier\\\",Damage:0s,tag:{nobag:1}},OnGround:1b}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~1 ~1 chain_command_block 5 replace {Command:\"/replaceitem entity @a slot.hotbar.8 barrier 1 0 {display:{Name:\\\"回收箱子(按Q使用)\\\"},nobag:1,HideFlags:127,ench:[{id:34,lvl:10}]}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~1 chain_command_block 1 replace {Command:\"/clear @a barrier 0 64 {display:{Name:\\\"回收箱子(按Q使用)\\\"}}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~0 ~1 chain_command_block 4 replace {Command:\"/scoreboard players set @a gbag 2\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~0 ~1 chain_command_block 4 replace {Command:\"/scoreboard players reset @e gtemp\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~0 ~2 chain_command_block 2 replace {Command:\"/execute @e ~ ~ ~ kill @e\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~0 ~2 chain_command_block 5 replace {Command:\"scoreboard players set @e gbag 2\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~2 chain_command_block 5 replace {Command:\"/execute @p ~ ~ ~ /tp @e @e\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~3 chain_command_block 2 replace {Command:\"/execute @p ~ ~ ~ execute @e ~ ~ ~ scoreboard players operation @e gtemp -= @p bagID\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~0 ~3 chain_command_block 4 replace {Command:\"/execute @p ~ ~ ~ execute @e ~ ~ ~ /scoreboard players operation @e gtemp = @e bagID\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~0 ~3 chain_command_block 4 replace {Command:\"/execute @e ~ ~ ~ scoreboard players set @p gbag 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~0 ~4 chain_command_block 2 replace {Command:\"/scoreboard players tag @e add isbag {Item:{id:\\\"minecraft:chest_minecart\\\",Damage:0s,tag:{isbag:1}},OnGround:1b}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~0 ~4 chain_command_block 5 replace {Command:\"/execute @e ~ ~ ~ scoreboard players operation @e bagID = @e bagID\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~4 chain_command_block 5 replace {Command:\"/execute @e ~ ~ ~ scoreboard players add @e bagID 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~4 chain_command_block 1 replace {Command:\"/scoreboard players add @e bagID 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~-1 ~4 chain_command_block 4 replace {Command:\"/scoreboard players set @e gbag 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~-1 ~4 chain_command_block 4 replace {Command:\"/teleport @e ~ ~1 ~\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~-1 ~3 chain_command_block 3 replace {Command:\"/scoreboard players tag @e remove newbag\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~-1 ~3 chain_command_block 5 replace {Command:\"/scoreboard players set @e gbag -1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~3 chain_command_block 5 replace {Command:\"/execute @e ~ ~ ~ scoreboard players operation @p bagID = @e bagID\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~2 chain_command_block 3 replace {Command:\"/replaceitem entity @a slot.hotbar.8 chest_minecart 1 0 {display:{Name:\\\"随身箱子(按Q使用)\\\"},isbag:1,HideFlags:127,ench:[{id:34,lvl:10}]}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~-1 ~2 chain_command_block 4 replace {Command:\"/clear @a chest_minecart 0 64 {display:{Name:\\\"随身箱子(按Q使用)\\\"}}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~-1 ~2 chain_command_block 4 replace {Command:\"/scoreboard players set @a gbag -1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~4 ~-1 ~1 chain_command_block 3 replace {Command:\"/tellraw @a [{\\\"text\\\":\\\"\\\\n[随身背包] \\\",\\\"color\\\":\\\"dark_green\\\",\\\"bold\\\":\\\"true\\\"},{\\\"text\\\":\\\"已为您配置您的随身背包。\\\",\\\"color\\\":\\\"green\\\",\\\"bold\\\":\\\"true\\\"},{\\\"text\\\":\\\" [\\\\u00a7l了解更多\\\\u00a78]\\\\n\\\",\\\"color\\\":\\\"dark_gray\\\",\\\"clickEvent\\\":{\\\"action\\\":\\\"open_url\\\",\\\"value\\\":\\\"https://www.ganxiaozhe.com/mc/?from=map\\\"},\\\"bold\\\":\\\"false\\\"}]\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~3 ~-1 ~1 chain_command_block 5 replace {Command:\"/execute @a ~ ~ ~ /summon minecraft:chest_minecart ~ ~-.6 ~ {CustomName:\\\"随身背包 - www.Ganxiaozhe.com\\\",NoGravity:1b,Invulnerable:1b,Tags:[\\\"newbag\\\",\\\"bag\\\"]}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~1 repeating_command_block 5 replace {Command:\"/scoreboard players add @a gbag 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~ ~1 ~ command_block 0 replace {auto:1b,Command:\"fill ~ ~ ~ ~ ~-2 ~ air\"}"},{id:commandblock_minecart,Command:"kill @e"}]}]}注:OOC为1.12版本,如发现上诉代码运行无效,请前往出处查看或下载附件使用。




static/image/hrline/4.gif
你的支持便是我最大的动力




myworldzhang 发表于 2018-1-28 16:06:00

呆萌踮脚吻 发表于 2018-1-29 14:00:21

66666

超可爱的萌新 发表于 2018-1-29 14:13:47

前排支持

我的世界聚少年 发表于 2018-1-29 16:15:42

非常方便!!!!

cshsgsg 发表于 2018-1-30 10:56:42

支持我甘蔗!

F_G_H 发表于 2018-1-30 15:51:37

恩支持

Tommy0328 发表于 2018-1-30 17:35:26

我也要!

这名字真逗 发表于 2018-2-1 18:58:04

惊呆,原版的潜影盒还要稿子挖,现在随身背包按Q就行了!

LQH我的世界 发表于 2018-2-1 20:43:26

为什么我收回的时候没丢到他,然后就出bug了,收不回了

MCSugar_cane 发表于 2018-2-1 21:29:33

LQH我的世界 发表于 2018-2-1 20:43
为什么我收回的时候没丢到他,然后就出bug了,收不回了

是个问题,我待会再修复一下,谢谢反馈

MCSugar_cane 发表于 2018-2-1 21:42:35

LQH我的世界 发表于 2018-2-1 20:43
为什么我收回的时候没丢到他,然后就出bug了,收不回了

刚刚在服务器试了一下,如果回收没丢中,再丢一次箱子,就又有回收了

冷源 发表于 2018-2-2 12:23:36

.。。

你让我取什么 发表于 2018-2-2 15:00:51

看了一次网站网站就不见了………………

a浅梦阿 发表于 2018-2-2 15:27:03

6666666
页: [1] 2 3
查看完整版本: 【修复】随身背包-支持多人 附OOC