diff --git a/paper-api/src/main/java/org/bukkit/entity/Entity.java b/paper-api/src/main/java/org/bukkit/entity/Entity.java index 19272cff8d..3fe738c0d0 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -3,6 +3,7 @@ package org.bukkit.entity; import java.util.List; import java.util.Set; import java.util.UUID; +import io.papermc.paper.entity.LookAnchor; import org.bukkit.Chunk; // Paper import org.bukkit.EntityEffect; import org.bukkit.Location; @@ -150,6 +151,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent * @return true if the teleport was successful */ boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags); + + /** + * Causes the entity to look towards the given position. + * + * @param x x coordinate + * @param y y coordinate + * @param z z coordinate + * @param entityAnchor What part of the entity should face the given position + */ + void lookAt(double x, double y, double z, @NotNull LookAnchor entityAnchor); + + /** + * Causes the entity to look towards the given position. + * + * @param position Position to look at in the player's current world + * @param entityAnchor What part of the entity should face the given position + */ + default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull LookAnchor entityAnchor) { + this.lookAt(position.x(), position.y(), position.z(), entityAnchor); + } // Paper end - Teleport API /** diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index fac4aec289..be9bea56aa 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -9,6 +9,7 @@ import java.util.Date; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import io.papermc.paper.entity.LookAnchor; import org.bukkit.BanEntry; import org.bukkit.DyeColor; import org.bukkit.Effect; @@ -1309,8 +1310,8 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM * they have seen it before because this method was called. * Note this method does not make the player invulnerable, which is normally expected when viewing credits. * - * @see #hasSeenWinScreen() - * @see #setHasSeenWinScreen(boolean) + * @see #hasSeenWinScreen() + * @see #setHasSeenWinScreen(boolean) * @see https://minecraft.wiki/wiki/End_Poem#Technical_details */ public void showWinScreen(); @@ -3392,7 +3393,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM * @param simulationDistance the player's new simulation distance */ public void setSimulationDistance(int simulationDistance); - + /** * Gets the no-ticking view distance for this player. *

@@ -3730,26 +3731,6 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM */ void setRotation(float yaw, float pitch); - /** - * Causes the player to look towards the given position. - * - * @param x x coordinate - * @param y y coordinate - * @param z z coordinate - * @param playerAnchor What part of the player should face the given position - */ - void lookAt(double x, double y, double z, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor); - - /** - * Causes the player to look towards the given position. - * - * @param position Position to look at in the player's current world - * @param playerAnchor What part of the player should face the given position - */ - default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor) { - this.lookAt(position.x(), position.y(), position.z(), playerAnchor); - } - /** * Causes the player to look towards the given entity. * @@ -3757,7 +3738,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM * @param playerAnchor What part of the player should face the entity * @param entityAnchor What part of the entity the player should face */ - void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor, @NotNull io.papermc.paper.entity.LookAnchor entityAnchor); + void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull LookAnchor playerAnchor, @NotNull LookAnchor entityAnchor); // Paper end - Teleport API // Paper start diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 91b78711ec..5587c8828a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -8,6 +8,7 @@ import com.google.common.collect.Lists; import java.util.List; import java.util.Set; import java.util.UUID; +import io.papermc.paper.entity.LookAnchor; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; @@ -299,6 +300,25 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { return this.teleport(destination.getLocation(), cause); } + @Override + public void lookAt(double x, double y, double z, LookAnchor entityAnchor) { + this.getHandle().lookAt(toNmsAnchor(entityAnchor), new net.minecraft.world.phys.Vec3(x, y, z)); + } + + public static net.minecraft.commands.arguments.EntityAnchorArgument.Anchor toNmsAnchor(LookAnchor nmsAnchor) { + return switch (nmsAnchor) { + case EYES -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.EYES; + case FEET -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.FEET; + }; + } + + public static LookAnchor toApiAnchor(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor playerAnchor) { + return switch (playerAnchor) { + case EYES -> LookAnchor.EYES; + case FEET -> LookAnchor.FEET; + }; + } + @Override public List getNearbyEntities(double x, double y, double z) { Preconditions.checkState(!this.entity.generation, "Cannot get nearby entities during world generation"); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index c9436e82dc..ceb672bfae 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -7,6 +7,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import io.netty.buffer.Unpooled; import io.papermc.paper.FeatureHooks; +import io.papermc.paper.entity.LookAnchor; import it.unimi.dsi.fastutil.shorts.ShortArraySet; import it.unimi.dsi.fastutil.shorts.ShortSet; import java.io.ByteArrayOutputStream; @@ -1377,29 +1378,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } @Override - public void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor, @NotNull io.papermc.paper.entity.LookAnchor entityAnchor) { + public void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull LookAnchor playerAnchor, @NotNull LookAnchor entityAnchor) { this.getHandle().lookAt(toNmsAnchor(playerAnchor), ((CraftEntity) entity).getHandle(), toNmsAnchor(entityAnchor)); } - @Override - public void lookAt(double x, double y, double z, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor) { - this.getHandle().lookAt(toNmsAnchor(playerAnchor), new net.minecraft.world.phys.Vec3(x, y, z)); - } - - public static net.minecraft.commands.arguments.EntityAnchorArgument.Anchor toNmsAnchor(io.papermc.paper.entity.LookAnchor nmsAnchor) { - return switch (nmsAnchor) { - case EYES -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.EYES; - case FEET -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.FEET; - }; - } - - public static io.papermc.paper.entity.LookAnchor toApiAnchor(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor playerAnchor) { - return switch (playerAnchor) { - case EYES -> io.papermc.paper.entity.LookAnchor.EYES; - case FEET -> io.papermc.paper.entity.LookAnchor.FEET; - }; - } - public static net.minecraft.world.entity.Relative deltaRelativeToNMS(io.papermc.paper.entity.TeleportFlag.Relative apiFlag) { return switch (apiFlag) { case VELOCITY_X -> net.minecraft.world.entity.Relative.DELTA_X;