1

I just wanted to teleport an entity relatively, but the entity is not exactly in the middle of a block.

For example the coordinates are 0.3, 63.0, 0.76 and I teleport the entity relatively using ~1 ~0 ~1. The resulting coordinated will be 1.3, 63.0, 1.76 but I want the entity to be in the center of the block. So it has to be 1.5, 63.0, 1.5 instead.

Is it possible to achieve this? Thank you!

2
  • Don't think there is such possible way to do this, simply with static command blocks. (You can't scoreboard either as there is no scoreboard variable for a player's X/Y/Z co-ordinate) | The best I can suggest is (if you know the actual position they're going to be close to, use a plain /tp @a[1.5,63,1.5,r=1] 1.5 63.0 1.5 command-block, running on a clock, or is triggered after the initial /tp @a ~1 ~0 ~1. Though it'd be a really stupid and inefficient method if the destination is a large region, instead of a single block..
    – aytimothy
    Feb 21, 2015 at 14:22
  • Sadly it is a relatively large area. Using this method I had to use 113 command blocks. But at the moment I don't have a better idea on how to do this.
    – bw2801
    Feb 21, 2015 at 14:40

3 Answers 3

2

First, teleport or summon the entity relatively as you're doing at the moment.

There are a few ways to center an entity on a block. Some of the more clunky methods involve teleporting the entity elsewhere, shoving it against the corner and then teleporting it ~0.3 ~ ~0.3, or similar things.

The method I think works best is by using paintings or item frames. When summoned, they're always at the same location in the block:

http://i.imgur.com/vlq6Zmp.png

They're horizontally centered, and -0.469 off on the Z axis. This means that to center yourself, you can teleport to an item frame, and then teleport ~0.469.

So your order of commands should be something like this:

Your relative teleport/summon
/execute @e[name=Name] ~ ~ ~ /summon ItemFrame
/execute @e[name=Name] ~ ~ ~ /tp @e[type=ItemFrame,c=1,r=1]
/tp @e[name=Name] ~ ~ ~0.469
/execute @e[name=Name] ~ ~ ~ /kill @e[type=ItemFrame,c=1,r=1]
0
2

You can use Leash Knots like this:

/execute @e[name=Name] ~ ~ ~ /summon leash_knot ~ ~ ~ {CustomName:Centre}

/tp @e[name=Name] @e[name=Centre,c=1]

/kill @e[name=Centre]

(This is for 1.11, for 1.10 or lower use LeashKnot instead of leash_knot)

For 1.13+:

/execute as @e[name=Name] at ~ ~ ~ /summon leash_knot ~ ~ ~ {Tags:["Centre"]}

/tp @e[name=Name] @e[tag=Centre,limit=1]

/kill @e[tag=Centre]
0

When summoning relatively to command blocks, like ~ ~5 ~, it will summon it in the middle of the block.

Or, you can use a spawn egg, because when you use a spawn egg to spawn a zombie, the zombie will be in the middle of the block. So you can use execute and summon something at the zombie then kill the zombie.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .