-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathCraftLocation.java
More file actions
79 lines (61 loc) · 2.66 KB
/
CraftLocation.java
File metadata and controls
79 lines (61 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.bukkit.craftbukkit.util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.pathfinder.Node;
import net.minecraft.world.phys.Vec3;
import org.bukkit.Location;
import org.bukkit.World;
import org.jspecify.annotations.Nullable;
public final class CraftLocation {
private CraftLocation() {
}
public static Location toBukkit(Vec3 pos) {
return toBukkit(pos, (World) null);
}
public static Location toBukkit(Vec3 pos, World world) {
return toBukkit(pos, world, 0.0F, 0.0F);
}
public static Location toBukkit(Vec3 pos, World world, float yaw, float pitch) {
return new Location(world, pos.x(), pos.y(), pos.z(), yaw, pitch);
}
public static Location toBukkit(Vec3 pos, Level level) {
return toBukkit(pos, level.getWorld());
}
public static Location toBukkit(Vec3 pos, Level level, float yaw, float pitch) {
return toBukkit(pos, level.getWorld(), yaw, pitch);
}
public static Location toBukkit(Vec3i pos) {
return toBukkit(pos, (World) null);
}
public static Location toBukkit(Vec3i pos, World world) {
return toBukkit(pos, world, 0.0F, 0.0F);
}
public static Location toBukkit(Vec3i pos, World world, float yaw, float pitch) {
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);
}
public static Location toBukkit(Vec3i pos, Level level) {
return toBukkit(pos, level.getWorld());
}
public static Location toBukkit(Vec3i pos, Level level, float yaw, float pitch) {
return toBukkit(pos, level.getWorld(), yaw, pitch);
}
public static Location toBukkit(Node point, Level level) {
return new Location(level.getWorld(), point.x, point.y, point.z);
}
public static BlockPos toBlockPosition(Location loc) {
return new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
public static net.minecraft.core.GlobalPos toGlobalPos(Location loc) {
return net.minecraft.core.GlobalPos.of(((org.bukkit.craftbukkit.CraftWorld) loc.getWorld()).getHandle().dimension(), toBlockPosition(loc));
}
public static @Nullable Location fromGlobalPos(net.minecraft.core.GlobalPos globalPos) {
ServerLevel level = MinecraftServer.getServer().getLevel(globalPos.dimension());
return level != null ? CraftLocation.toBukkit(globalPos.pos(), level) : null;
}
public static Vec3 toVec3(Location loc) {
return new Vec3(loc.getX(), loc.getY(), loc.getZ());
}
}