可点击的浮空字

By MCSugar_cane    2017/11/05

玩家可以通过右键或左键来对浮空字进行点击,而且在服务器里也不需要玩家具有权限,是不是要右键比告示牌炫酷多了呢?代码适用版本为1.11.2

可点击悬浮字演示地图


我的世界可以点击的浮空字

图片就介绍到这里,下面是思路以及代码部分~


整体思路:

初步思路是利用玩家右键村民这个准则实现检测右键点击,用实体受到伤害和玩家是否造成伤害来检测玩家是否左键点击。

在村民的nbt上,普通村民右键是会出现交易框的,这里为其加上Offers:{Recipes:[]}这个nbt即可消除显示。(村民无任何交易选项,无法交易,故不显示)。对于受伤害实体的nbt,你需要使它不会轻易被玩家攻击致死。这里我使用生命提升和生命恢复,因为如果用抗性提升后无法检测到实体被攻击。


代码:

创建变量:

  1. /scoreboard objectives add villager stat.talkedToVillager 右键村民
  2. /scoreboard objectives add ifhit stat.damageDealt 造成伤害
  3. /scoreboard objectives add hit dummy 受到伤害


右键浮空字:

召唤实体:

  1. /summon armor_stand ~ ~ ~ {CustomName:"领取甘蔗(右键)",CustomNameVisible:1b,NoBasePlate:1,NoGravity:1,Invisible:1}
  2. /summon villager ~ ~ ~ {NoAI:1b,Silent:1b,Offers:{Recipes:[]},ActiveEffects:[{Id:14,Duration:9999999,Amplifier:0,Ambient:1,ShowParticles:0b}],Tags:["lqgz"]}

右键触发:[高频循环]

  1. /execute @e[type=villager,tag=lqgz] ~ ~ ~ give @a[score_villager_min=1,r=6] reeds 1 0 {display:{Name:"www.Ganxiaozhe.com"}}
  2. /scoreboard players set @a[score_villager_min=1] villager 0


左键浮空字:

召唤实体:

  1. /summon armor_stand ~ ~ ~ {CustomName:"回复血量(左键)",CustomNameVisible:1b,NoBasePlate:1,NoGravity:1,Invisible:1}
  2. /summon Sheep ~ ~0.5 ~ {CustomName:"hit",NoAI:1,Silent:1,ActiveEffects:[{Id:14,Amplifier:0,Duration:500000,ShowParticles:0b},{Id:21,Amplifier:100,Duration:500000,ShowParticles:0b},{Id:10,Amplifier:100,Duration:500000,ShowParticles:0b}]}

左键触发:[高频循环]

  1. /scoreboard players add @e[type=Sheep,name=hit] hit 1 {HurtTime:10s}
  2. /execute @e[type=Sheep,name=hit,score_hit_min=1] ~ ~ ~ effect @a[score_ifhit_min=1,r=6] 10 1 10 true
  3. /execute @e[type=Sheep,name=hit,score_hit_min=1] ~ ~ ~ tellraw @a[score_ifhit_min=1,r=6] [{"text":"你的血量已回复","color":"red","bold":"true"}]
  4. /scoreboard players set @e[type=Sheep,name=hit,score_hit_min=1] hit 0
  5. /scoreboard players set @a[score_ifhit_min=1] ifhit 0


保证实体正常运行:

使村民保持隐形:[高频循环]

  1. /effect @e[type=villager,tag=lqgz] invisibility 100000 0 true

使羊保持隐形、抗性并回复血量:[高频循环]

  1. /effect @e[type=Sheep,name=hit] invisibility 100000 0 true
  2. /effect @e[type=Sheep,name=hit] health_boost 100000 100 true
  3. /effect @e[type=Sheep,name=hit] regeneration 100000 100 true


欢迎加群交流划水:481528679