-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathAsyncChunkSnapshotBlockSource.java
54 lines (44 loc) · 1.69 KB
/
AsyncChunkSnapshotBlockSource.java
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
package net.citizensnpcs.api.astar.pathfinder;
import java.util.concurrent.Callable;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.util.SpigotUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import net.citizensnpcs.api.util.BoundingBox;
public class AsyncChunkSnapshotBlockSource extends CachingChunkBlockSource<ChunkSnapshot> {
public AsyncChunkSnapshotBlockSource(Location location, float radius) {
super(location, radius);
}
public AsyncChunkSnapshotBlockSource(World world, int x, int z, float radius) {
super(world, x, z, radius);
}
@Override
protected ChunkSnapshot getChunkObject(int x, int z) {
// TODO: pre-load multiple chunks on cache miss
Callable<ChunkSnapshot> call = () -> world.getChunkAt(x, z).getChunkSnapshot(false, false, false);
try {
if (!SpigotUtil.isFoliaServer() && !Bukkit.isPrimaryThread()) {
return Bukkit.getScheduler().callSyncMethod(null, call).get();
}
return call.call();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected BoundingBox getCollisionBox(ChunkSnapshot chunk, int x, int y, int z) {
return null; // TODO
}
@Override
protected int getLightLevel(ChunkSnapshot chunk, int x, int y, int z) {
return Math.min(15, chunk.getBlockSkyLight(x, y, z) + chunk.getBlockEmittedLight(x, y, z));
}
@Override
protected Material getType(ChunkSnapshot chunk, int x, int y, int z) {
return chunk.getBlockType(x & 15, y, z & 15);
}
}