Skip to content

Instantly share code, notes, and snippets.

@TerrorBite
Last active January 2, 2016 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TerrorBite/8329344 to your computer and use it in GitHub Desktop.
Save TerrorBite/8329344 to your computer and use it in GitHub Desktop.
How homes will work in Vanilla (completely doable in CH)

##The /home Command

This command won't actually do any teleporting. Instead, it will alias to /help home which will give them information on how to teleport.

##Teleporting home

To teleport home (actually, to the last bed they slept in - no /sethome), the player must possess an Ender Pearl and then throw it directly up into the sky. The player will be teleported home assuming they fulfil the following conditions:

  • The pearl must come down and strike within a few blocks of the player. This means they have to do it out in the open.
  • The player must not have moved since they threw the pearl.
  • The player must have sufficient XP levels to pay for the teleport.
  • There must be no monsters within audible range (check 20 block radius?).
  • The pearl must hit the player themselves, or a block within 3 blocks of the player, no less than 1 second after it was thrown.
  • Their home bed must not be missing or obstructed.

If any of these fail, the teleport will not occur, and instead they will be teleported by the pearl as though thrown normally.

Currently I'm tossing up between charging 5 or 10 levels for teleporting.

##Help text [=============== Teleport to your Bed ===============] You must have an Ender Pearl and at least 10 levels of XP. Make sure you're outside and there are no monsters nearby. To teleport home, throw the Pearl directly up into the sky. Stand still, and wait for it to come back down and hit you. You will be teleported to your bed at the cost of 10 levels. If your home bed is missing or obstructed, this won't work.

##Implementation

This system will be written in CommandHelper.

The script will hook projectile_launch with a prefilter on ender pearl projectiles.

The script will check the "velocity" property of the projectile looking for one with minimal x and z velocity and a positive y velocity.

If the check succeeds it will store ploc() in an ivar and dynamically hook the projectile_hit event with a prefilter on the Entity ID of the ender pearl.

The projectile_hit event will call get_player_from_entity_id() and use ploc() on the resulting player.

First it will use plevel() to assert that the user has sufficient levels to pay for the teleport, otherwise bail out.

It will then use the player's location to:

  • check if the projectile hit within 3 blocks of the player.
  • check the player's position against the location stored by the projectile_launch event (accessible via the closure) and bail out with a message if the player moved more than half a block.
  • Check using entities_in_radius() for hostile mobs within 20 blocks of the player.

If all these checks succeed, it will call pbed_location() to get the player's bed. If null is returned (indicating bed missing or obstructed) then it will bail out.

The event handler will then set_ploc() the player to the location of their bed, and use set_plevel() to deduct levels as payment. Finally, it will use set_phealth() to deal ~2 hearts of damage to the player, before canceling the event with cancel().

##The /spawn command

To encourage use of the Nether for quick travel, there will be no /spawn command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment