mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-15 15:16:46 +01:00
Prefer position over entity
This commit is contained in:
parent
7c505ecc17
commit
283469e025
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user