Since 1.14 this is possible relatively easily with the wandering trader. It has the WanderTarget
NBT field that you can set to any coordinates to make it use its regular pathfinding to walk there.
You need the dummy
scoreboards x
, y
and z
.
/execute at @e[type=rabbit] run summon wandering_trader
/execute at @e[type=rabbit] store result entity @e[type=wandering_trader,distance=0,limit=1] WanderTarget.X int 1 run data get entity @e[tag=fruit,distance=5..25,limit=1] Pos[0]
/execute at @e[type=rabbit] store result entity @e[type=wandering_trader,distance=0,limit=1] WanderTarget.Y int 1 run data get entity @e[tag=fruit,distance=5..25,limit=1] Pos[1]
/execute at @e[type=rabbit] store result entity @e[type=wandering_trader,distance=0,limit=1] WanderTarget.Z int 1 run data get entity @e[tag=fruit,distance=5..25,limit=1] Pos[2]
Then you continuously teleport the rabbit to the wandering trader. When it's within about 2 blocks or so, kill the wandering trader.
The downside of this is that it won't hop. It will also not go exactly towards the target, because the wandering target stops about two blocks before its target coordinates. But maybe it's already good enough to teleport the rabbit the remaining distance. This system also only works properly at night, otherwise the wandering trader is visible. You could give it invisibility repeatedly, but then it will still show its milk bucket whenever it tries to get rid of the effect.
Thanks to "🐾 Aelicorn_v2 🐾" and "remy - 1.14" in the Minecraft commands Discord for their help with this answer (mainly the as
vs. at
confusion).
execute as @e[type=rabbit] store result entity @e[type=wandering_trader,distance=0,limit=1] WanderTarget.X int 1 run data get entity @e[tag=fruit,distance=5..25,limit=1] Pos[0]
But the problem is: It doesn't work. I couldn't get the wandering trader to actually move, except when I set the tag when summoning. – Fabian Röling Jul 21 '19 at 12:51as
andat
… 🤦♂️ – Fabian Röling Jul 21 '19 at 13:17