Created
November 30, 2018 19:06
-
-
Save Cryptite/0c0644b83b0522677ab82956b24f931e to your computer and use it in GitHub Desktop.
Paper-based Asynchronous Cache for looking up blocks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChunkSnapshotCache { | |
private final LoadingCache<StringChunk, ChunkSnapshot> cache; | |
private ChunkSnapshotCache() { | |
cache = CacheBuilder.newBuilder() | |
.build(new CacheLoader<StringChunk, ChunkSnapshot>() { | |
@Override | |
public ChunkSnapshot load(StringChunk chunk) { | |
return chunk.getChunk().getChunkSnapshot(false, false, false); | |
} | |
}); | |
} | |
public StringBlock getCleanBlock(StringBlock liveBlock) { | |
World cleanWorld = Bukkit.getWorld(liveBlock.getWorld() + "_clean"); | |
StringChunk chunk = new StringChunk(cleanWorld, liveBlock.getBlockX() >> 4, liveBlock.getBlockZ() >> 4); | |
ChunkSnapshot cleanSnapshot = cache.getUnchecked(chunk); | |
int x = liveBlock.getBlockX(); | |
int y = liveBlock.getBlockY(); | |
int z = liveBlock.getBlockZ(); | |
return new StringBlock(cleanWorld, x, y, z, | |
cleanSnapshot.getBlockType(x, y, z), | |
(byte) cleanSnapshot.getBlockData(x, y, z)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment