Repository navigation
Routine: Nearby
Nearby is a powerful routine that enables many new kinds of interaction. Basically it allows you to go through every entity near one of the named event entities and do something with/to them.
- 'nearby.{entity}.{filter}.{radius}':
- 'more routines here'{entity} - One of the standard event entities, i.e. attacker, target, projectile
{filter} - An entity type to filter for. All entities chosen by nearby will match this type.
{radius} - Some expression for the cube radius to search in.
The way nearby works is currently a bit tricky and annoying, but that will hopefully change soon.
Inside the nearby routine, the attacker reference refers to the {entity} that is the center of the search box, and the target entity reference refers to the selected nearby entity.
In this example, the Chainmail Helmet becomes a powerful zombie repellant. Anytime a zombie attacks you while you're wearing one, all zombies within 10 blocks get thrown back.
Damage:
- 'if target.wearing.CHAINMAIL_HELMET and attacker.type.Zombie':
- 'message.target.FOOM!'
- 'nearby.target.Zombie.10':
- 'targeteffect.knockback': '10'You are a strange cross between a vampire and a healer. Anytime you kill a mob that's not undead (undead doesn't have blood), all your buddies close by get healed for 10% of the mob's maximum health.
Death:
- 'if attacker.type.player and !(target.type.zombie or target.type.skeleton)': # TODO: any other mobs undead?
- 'tag.attacker.healamount': # this is a nasty hack, because the target can't be referred to inside nearby
- '(target_maxhealth / 10)'
- 'nearby.attacker.Player.8':
- 'targeteffect.heal': 'attacker_tagvalue_healamount'
- 'untag.attacker.healamount' # don't want to leave this around. Eventually, local variables will be a better solution.Note: This is could be a bit slow. A nearby conditional will be a better solution (if it gets added)
Spawn:
- '0' # default to canceling the spawn
- 'nearby.target.Player.50':
- 'target_maxhealth' # set their health back to the default
# at this point, the health will be 0 if no players were found,
# or the default maximum health for the entity if one or more was found