Add MCUtil#toLocation from Folia

Helper methods to convert NMS world/position to Bukkit Location
This commit is contained in:
Spottedleaf
2025-05-29 04:58:00 -07:00
parent 4765010083
commit 6f315356b6

View File

@@ -22,7 +22,9 @@ import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.Waitable;
@@ -150,6 +152,20 @@ public final class MCUtil {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
}
/**
* Converts a NMS World/Vector to Bukkit Location
*/
public static Location toLocation(Level world, Vec3 pos) {
return new Location(world.getWorld(), pos.x(), pos.y(), pos.z());
}
/**
* Converts a NMS World/Vector to Bukkit Location
*/
public static Location toLocation(Level world, Vec3 pos, float yaw, float pitch) {
return new Location(world.getWorld(), pos.x(), pos.y(), pos.z(), yaw, pitch);
}
public static BlockPos toBlockPos(Position pos) {
return new BlockPos(pos.blockX(), pos.blockY(), pos.blockZ());
}