mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-25 01:21:20 +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
|
@Override
|
||||||
public BlockPosition from(@Nullable Entity entity) {
|
public BlockPosition from(@Nullable Position position) {
|
||||||
if (!relativeX && !relativeY && !relativeZ) {
|
if (!relativeX && !relativeY && !relativeZ) {
|
||||||
return location.clone();
|
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 x = location.getX() + (relativeX ? (int) entityPosition.getX() : 0);
|
||||||
final int y = location.getY() + (relativeY ? (int) entityPosition.getY() : 0);
|
final int y = location.getY() + (relativeY ? (int) entityPosition.getY() : 0);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.utils.location;
|
package net.minestom.server.utils.location;
|
||||||
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
|
import net.minestom.server.utils.Position;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ public abstract class RelativeLocation<T> {
|
|||||||
* @param entity the entity to get the relative position from
|
* @param entity the entity to get the relative position from
|
||||||
* @return the location
|
* @return the location
|
||||||
*/
|
*/
|
||||||
public abstract T from(@Nullable Entity entity);
|
public abstract T from(@Nullable Position entity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if the 'x' field is relative.
|
* Gets if the 'x' field is relative.
|
||||||
|
@ -17,11 +17,11 @@ public class RelativeVec extends RelativeLocation<Vector> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector from(@Nullable Entity entity) {
|
public Vector from(@Nullable Position position) {
|
||||||
if (!relativeX && !relativeY && !relativeZ) {
|
if (!relativeX && !relativeY && !relativeZ) {
|
||||||
return location.clone();
|
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 x = location.getX() + (relativeX ? entityPosition.getX() : 0);
|
||||||
final double y = location.getY() + (relativeY ? entityPosition.getY() : 0);
|
final double y = location.getY() + (relativeY ? entityPosition.getY() : 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user