Why set entity location is not correct value?

Sponge 8.0
When I set entity location by double value.

Entity entity;
ServerWorld world;
ServerLocation location = world.location(15.5, 70.5, 19.5);


the entity will teleport to 15, 70, 19

but I want the entity teleport to 15.5, 70.5, 19.5

How can I teleport entity to correct location ?

Please help me.

Ive not had a issue with this. Is it a specific entity?

ServerPlayer ← this entity.

Could you please test it.

Sure when i get a sec.

Im making a plugin now that teleports a player, so ill just add .5 onto the location

Just double checked. it works fine on my version of sponge (SpongeVanilla → RC1340)

Mind showing your code? Just to see your not doing anything special

I use spongeforge-1.16.5-36.2.5-8.1.0-RC1340-universal still teleport not has decimal

Just trying with a slightly newer version of SpongeForge (RC1344).

0.5 works.

My guess is one of your mods is preventing it

I would advise doing a binary search to find your mod

Ok, I’ll test 1 mod to make sure. Thank for you care!

1 Like

still not correct.

So you only have forge, spongeforge and your plugin?

If so then its probably your code. Have you ran though it with debug to ensure that the exact location is 0.5

1 Like

Yes, I use only have forge, spongeforge and my plugin.
I’m sure that is the exact location.

this is my custom tp command code.

public CommandResult execute(CommandContext context) {
	try {
		Audience source = context.cause().audience();
		if (!(source instanceof ServerPlayer)) {
			return CommandResult.success();
		ServerPlayer p = (ServerPlayer) source;
		double x = context.one(CommandParameters.X).get();
		double y = context.one(CommandParameters.Y).get();
		double z = context.one(CommandParameters.Z).get();
		ServerLocation location = p.world().location(x, y, z);
		p.sendMessage(Utils.replaceColor("&fTeleported! " + x + " " + y + " " + z));
		return CommandResult.success();
	} catch (Exception ex) {
		return CommandResult.success();

public Command.Parameterized getCommand() {
	return Command.builder().addParameters(CommandParameters.X, CommandParameters.Y, CommandParameters.Z).shortDescription(Component.text(description())).permission(permission()).executor(this).build();

This is command.
/test tp 25.5 73.5 64.9

When I teleport it teleport in 25, 73, 64 not 25.5 73.5 64.9

Message in chat


That looks right. Mind changing your teleported message to use the location xyz. It shouldnt matter.

Personally i tested using my own public plugin of Essentials-S. I set a spawn with 0.5 and then ran the /spawn command to teleport to that spawn

Also a quick sidenote. Obviously fixing bugs is the most important bit. But here is some notes about your code

You dont actually need the ServerLocation part, there is a Entity#setPosition(double, double, double) which will teleport the player to that position in the world the player is in. (Javadocs)[Entity (SpongeAPI 8.0.0 API)]

You shouldnt be using the audience as the target. Instead it should be the root of the context or if the command accepts a target player then use that instead.

Exceptions should still be warned to the user, even if it is “a internal error occured, please check console”

1 Like

Entity#setPosition(double, double, double) is working well for me. It teleport to correct location. but, How can I set position & world simultaneously in one time with correct value ?

The way you did before (by using server location) should work.

When i tested it on sponge vanilla i used my custom plugin that does teleport across works using server location and it works fine.

But thinking about Essentials-S, it does use the setPosition if the destination world and the players current world are the same for support of local players