mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 12:42:05 -07:00
Add MCUtil#toLocation from Folia
Helper methods to convert NMS world/position to Bukkit Location
This commit is contained in:
@@ -22,7 +22,9 @@ import net.minecraft.core.Vec3i;
|
|||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
import org.bukkit.craftbukkit.util.Waitable;
|
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);
|
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) {
|
public static BlockPos toBlockPos(Position pos) {
|
||||||
return new BlockPos(pos.blockX(), pos.blockY(), pos.blockZ());
|
return new BlockPos(pos.blockX(), pos.blockY(), pos.blockZ());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user