Minecraft – How to teleport a player to a moving objective

minecraft-commandsminecraft-java-edition

I created a big adventure map and I was able to do lots of amazing things I never thought possible with redstone, but I came across a problem I was baffled by.

I have a house in minecraft that is movable. I want to know of a way I can teleport directly to my house using a command block. The catch is that my house is never in the same spot so the x,y,z coordinates are constantly changing.

One way I thought of that might possibly work would maybe have a clock set up to record my radius around my house using /setspawn so I'll constantly have my spawn position recorded; however, this isn't very good for teleporting as I would have to kill myself. There's a possible way of keeping your inventory after you die, but you would still lose exp. I don't really like the idea of dying to re-spawn as a "tele". It seems as though I'm trying to fit a square peg into a round hole.

Anyone have any ideas of a way to actually teleport using a command block to some how record your current x,y,z position in a certain radius? I am also open to plugin suggestions;however, I don't like releasing a map that requires a bunch of plugins.

Oh btw I'm on a 1.7.10 build. I know the 1.8.0 added a lot of new commands.

Best Answer

To teleport a player to a movable location, you'll need to use an entity. Summon a custom named entity, such as a WitherSkull, like this:

/summon WitherSkull ~ ~ ~ {CustomName:"HomeMarker",direction:[0.0,0.0,0.0]}

You haven't detailed how your house moves, but when it does, move this WitherSkull too.

Then, whenever you need to teleport back home, run something like this:

/tp @p @e[name=HomeMarker,type=WitherSkull]

Keep in mind that you cannot teleport to an unloaded entity, although if this house is "constantly" moving then you must already have it loaded.