Renamed RelativeLocation#from

This commit is contained in:
themode 2021-02-14 00:31:49 +01:00
parent beaf25ff47
commit f1448c8c89
4 changed files with 7 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package net.minestom.server.utils.location;
import net.minestom.server.entity.Entity;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position;
import org.jetbrains.annotations.Nullable;
/**
* Represents a relative {@link BlockPosition}.
@ -16,11 +17,11 @@ public class RelativeBlockPosition extends RelativeLocation<BlockPosition> {
}
@Override
public BlockPosition fromRelativePosition(Entity entity) {
public BlockPosition from(@Nullable Entity entity) {
if (!relativeX && !relativeY && !relativeZ) {
return location.clone();
}
final Position entityPosition = entity.getPosition();
final Position entityPosition = entity != null ? entity.getPosition() : new Position();
final int x = location.getX() + (relativeX ? (int) entityPosition.getX() : 0);
final int y = location.getY() + (relativeY ? (int) entityPosition.getY() : 0);

View File

@ -27,7 +27,7 @@ public abstract class RelativeLocation<T> {
* @param entity the entity to get the relative position from
* @return the location
*/
public abstract T fromRelativePosition(@Nullable Entity entity);
public abstract T from(@Nullable Entity entity);
/**
* Gets if the 'x' field is relative.

View File

@ -17,11 +17,11 @@ public class RelativeVec extends RelativeLocation<Vector> {
}
@Override
public Vector fromRelativePosition(@Nullable Entity entity) {
public Vector from(@Nullable Entity entity) {
if (!relativeX && !relativeY && !relativeZ) {
return location.clone();
}
final Position entityPosition = entity.getPosition();
final Position entityPosition = entity != null ? entity.getPosition() : new Position();
final double x = location.getX() + (relativeX ? entityPosition.getX() : 0);
final double y = location.getY() + (relativeY ? entityPosition.getY() : 0);

View File

@ -38,7 +38,7 @@ public class TeleportCommand extends Command {
final Player player = sender.asPlayer();
final RelativeVec relativeVec = args.getRelativeVector("pos");
final Position position = relativeVec.fromRelativePosition(player).toPosition();
final Position position = relativeVec.from(player).toPosition();
player.teleport(position);
player.sendMessage("You have been teleported to " + position);