Prefer position over entity

This commit is contained in:
LeoDog896 2021-03-04 11:54:29 -05:00
parent 7c505ecc17
commit 283469e025
3 changed files with 6 additions and 5 deletions

View File

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

View File

@ -1,6 +1,7 @@
package net.minestom.server.utils.location;
import net.minestom.server.entity.Entity;
import net.minestom.server.utils.Position;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -27,7 +28,7 @@ public abstract class RelativeLocation<T> {
* @param entity the entity to get the relative position from
* @return the location
*/
public abstract T from(@Nullable Entity entity);
public abstract T from(@Nullable Position entity);
/**
* Gets if the 'x' field is relative.

View File

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