检测掉落物

By MCSugar_cane    2017/11/17

也许你已经知道如何检测玩家背包物品了,但有时候又要遇到必须检测特定掉落物的情况。如果你不巧忘了,没关系,你将在这里找到答案。代码适用版本为1.8.1-1.11.2



代码:

testfor检测:

  1. /testfor @e[type=Item] {Item:{Count:1b,id:minecraft:sand,tag:{display:{Name:"Sugar"}},Damage:0s},OnGround:1b}

上诉代码为检测数量为1,名字为Sugar的掉落物(掉落在地上)。若无需物品附加nbt则删除tag:{display:{Name:"Sugar"}}即可。若无需检测掉落在地上删除OnGround:1b即可(此方法在scoreboard检测中同样适用)


scoreboard检测:

  1. scoreboard players set @e[type=Item] <计分板名称> 1 {Item:{id:"minecraft:iron_block",Count:1b,Damage:0s},OnGround:1b}

若这里计分板名称为a,则上诉代码为将数量为1的铁方块的分数a设置为1,在检测此掉落物或要根据掉落物位置执行命令只需要用@e[type=Item,score_a_min=1,score_a=1]即可选中该掉落物。



拓展:

丢弃掉落物生成新掉落物:

    创建变量:
  1. /scoreboard objectives add a dummy
  2. 高频:
  3. /scoreboard players set @e[type=Item] a 1 {Item:{id:"minecraft:wool",Count:2b,Damage:14s},OnGround:1b}
  4. /scoreboard players set @e[type=Item] a 2 {Item:{id:"minecraft:planks",Count:2b},OnGround:1b}
  5. /execute @e[type=Item,score_a_min=1,score_a=1] ~ ~ ~ execute @e[type=Item,score_a_min=2,score_a=2,r=1] ~ ~ ~ summon Item ~ ~0.5 ~ {Item:{id:"minecraft:bed",Count:1b,Damage:0s,tag:{display:{Name:"红色的床",Lore:["甘蔗家具制造,100%实木"]}}},Motion:[0.0,0.4,0.0]}
  6. /execute @e[type=Item,score_a_min=1,score_a=1] ~ ~ ~ execute @e[type=Item,score_a_min=2,score_a=2,r=1] ~ ~ ~ kill @e[type=Item,score_a_min=1,r=1]

上诉代码可将你丢出的2个红色羊毛和2个木板生成为一个红色的床。



欢迎加群交流划水:481528679