Hi, I’m new here.
I’m having a hard time trying to figure out how to simply teleport a player to a specific coord?
Location<World> spawn = ??? //I tried using "Location" but it needs an extent (idk what the hell that is.)
Player player = (Player)src;
player.setLocation(spawn);
player.sendMessage(Text.of("Teleporting to Spawn..."));
An Extent
is a 3D volume that can hold blocks, entities etc.
Most commonly, the extent is a World
object.
So to create a Location
object, you can do the following:
Location<World> someLocation = new Location<>(someWorld, somePosition);
You are correct in using player.setLocation
, all we need to do is get the world the player is in so we can create a new Location
object.
World playerWorld = player.getWorld();
Location<World> newLocation = new Location<>(playerWorld, spawnPosition);
Where spawnPosition
is either a Vector3i
or Vector3d
.
Then you can set the player to that location
player.setLocation(newLocation)
You can do all that in one line like so:
player.setLocation(new Location<>(player.getWorld(), spawnPosition));
1 Like
Thank you so much for your reply. So an “extent” represents anything that exists in the world (entities and blocks)? I was under the impression that “extent” meant “extends” in java terms.
I will try this, thank you for your post.
Basically, an extent is a container for entities, blocks, and tile entities (eg chests).
While the most obvious definition is a World
, so are Chunk
s, and also potentially a region plugin could make their regions Extent
s. Thus you could have region-relative Location
s. It’s a very flexible system, and allows you to do things relative to any area of the World
.
3 Likes
Thank you for clarifying that. I have a better understanding now.