// Similar to RegionFileCache#createOrLoadRegionFile except this uses direct // file name instead of x,z public static RegionFile getRegionFile(Path regionFilePath) { File file = regionFilePath.toFile(); RegionFile regionFile = RegionFileCache.regionsByFilename.get(file); if (regionFile != null) { return regionFile; } if (RegionFileCache.regionsByFilename.size() >= 256) { RegionFileCache.clearRegionFileReferences(); } regionFile = new RegionFile(file); RegionFileCache.regionsByFilename.put(file, regionFile); return regionFile; }
public static CompletableFuture<Optional<DataContainer>> getChunkData( WorldServer world, IChunkLoader chunkLoader, Vector3i chunkCoords) { int x = chunkCoords.getX(); int y = chunkCoords.getY(); int z = chunkCoords.getZ(); if (!(chunkLoader instanceof IMixinAnvilChunkLoader) || !SpongeChunkLayout.instance.isValidChunk(x, y, z)) { return CompletableFuture.completedFuture(Optional.empty()); } File worldDir = ((IMixinAnvilChunkLoader) chunkLoader).getWorldDir().toFile(); return SpongeScheduler.getInstance() .submitAsyncTask( () -> { DataInputStream stream = RegionFileCache.getChunkInputStream(worldDir, x, z); return Optional.ofNullable(readDataFromRegion(stream)); }); }