minecraft-src/net/minecraft/server/commands/LookAt.java
2025-07-04 02:49:36 +03:00

30 lines
1 KiB
Java

package net.minecraft.server.commands;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
@FunctionalInterface
public interface LookAt {
void perform(CommandSourceStack source, Entity entity);
public record LookAtEntity(Entity entity, Anchor anchor) implements LookAt {
@Override
public void perform(CommandSourceStack commandSourceStack, Entity entity) {
if (entity instanceof ServerPlayer serverPlayer) {
serverPlayer.lookAt(commandSourceStack.getAnchor(), this.entity, this.anchor);
} else {
entity.lookAt(commandSourceStack.getAnchor(), this.anchor.apply(this.entity));
}
}
}
public record LookAtPosition(Vec3 position) implements LookAt {
@Override
public void perform(CommandSourceStack commandSourceStack, Entity entity) {
entity.lookAt(commandSourceStack.getAnchor(), this.position);
}
}
}