Allow Point in setInstance

This commit is contained in:
TheMode 2021-07-08 18:26:26 +02:00
parent c2a84c25b5
commit 90ce845cdb
4 changed files with 15 additions and 8 deletions

View File

@ -40,6 +40,12 @@ public final class Pos implements Point {
this(point, 0, 0);
}
public static @NotNull Pos fromPoint(@NotNull Point point) {
if (point instanceof Pos)
return (Pos) point;
return new Pos(point.x(), point.y(), point.z());
}
public static @NotNull Pos fromPosition(@NotNull Position position) {
return new Pos(position.getX(), position.getY(), position.getZ(), position.getYaw(), position.getPitch());
}

View File

@ -12,6 +12,9 @@ import net.minestom.server.acquirable.Acquirable;
import net.minestom.server.chat.JsonMessage;
import net.minestom.server.collision.BoundingBox;
import net.minestom.server.collision.CollisionUtils;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.data.Data;
import net.minestom.server.data.DataContainer;
import net.minestom.server.entity.metadata.EntityMeta;
@ -41,9 +44,6 @@ import net.minestom.server.utils.Position;
import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.utils.entity.EntityUtils;
import net.minestom.server.utils.player.PlayerUtils;
import net.minestom.server.utils.time.Cooldown;
@ -870,6 +870,10 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
EventDispatcher.call(new EntitySpawnEvent(this, instance));
}
public void setInstance(@NotNull Instance instance, @NotNull Point spawnPosition) {
setInstance(instance, Pos.fromPoint(spawnPosition));
}
public void setInstance(@NotNull Instance instance, @NotNull Position spawnPosition) {
setInstance(instance, Pos.fromPosition(spawnPosition));
}

View File

@ -14,13 +14,11 @@ import java.util.Objects;
/**
* Represents a location which can have fields relative to an {@link Entity} position.
*
* @param <T> the location type
*/
public final class RelativeVec {
private final Vec vec;
private boolean relativeX, relativeY, relativeZ;
private final boolean relativeX, relativeY, relativeZ;
public RelativeVec(@NotNull Vec vec, boolean relativeX, boolean relativeY, boolean relativeZ) {
this.vec = vec;

View File

@ -36,8 +36,7 @@ public class SummonCommand extends Command {
private void execute(@NotNull CommandSender commandSender, @NotNull CommandContext commandContext) {
final Entity entity = commandContext.get(entityClass).instantiate(commandContext.get(this.entity));
//noinspection ConstantConditions - One couldn't possibly execute a command without being in an instance
// FIXME
//entity.setInstance(commandSender.asPlayer().getInstance(), commandContext.get(pos).fromSender(commandSender));
entity.setInstance(commandSender.asPlayer().getInstance(), commandContext.get(pos).fromSender(commandSender));
}
@SuppressWarnings("unused")