use of com.sk89q.worldedit.world.storage.McRegionReader in project FastAsyncWorldEdit by IntellectualSites.
the class FolderSnapshot method getChunkTag.
@Override
public CompoundTag getChunkTag(BlockVector3 position) throws DataException, IOException {
BlockVector2 pos = position.toBlockVector2();
Optional<Path> regFolder = getRegionFolder();
if (!regFolder.isPresent()) {
Path chunkFile = getFolder().resolve(LegacyChunkStore.getFilename(pos, "/"));
if (!Files.exists(chunkFile)) {
throw new MissingChunkException();
}
return ChunkStoreHelper.readCompoundTag(() -> new GZIPInputStream(Files.newInputStream(chunkFile)));
}
Path regionFile = regFolder.get().resolve(McRegionChunkStore.getFilename(pos));
if (!Files.exists(regionFile)) {
// Try mcr as well
regionFile = regionFile.resolveSibling(regionFile.getFileName().toString().replace(".mca", ".mcr"));
if (!Files.exists(regionFile)) {
throw new MissingChunkException();
}
}
try (InputStream stream = Files.newInputStream(regionFile)) {
McRegionReader regionReader = new McRegionReader(stream);
return ChunkStoreHelper.readCompoundTag(() -> regionReader.getChunkInputStream(pos));
}
}
use of com.sk89q.worldedit.world.storage.McRegionReader in project FastAsyncWorldEdit by IntellectualSites.
the class FileSystemSnapshotDatabaseTest method setUpStatic.
@BeforeAll
static void setUpStatic() throws IOException, DataException {
try (InputStream in = Resources.getResource("world_region.mca.gzip").openStream();
GZIPInputStream gzIn = new GZIPInputStream(in)) {
REGION_DATA = ByteStreams.toByteArray(gzIn);
}
McRegionReader reader = new McRegionReader(new ByteArrayInputStream(REGION_DATA));
try {
// Find the single chunk
BlockVector2 chunkPos = IntStream.range(0, 32).mapToObj(x -> IntStream.range(0, 32).filter(z -> reader.hasChunk(x, z)).mapToObj(z -> BlockVector2.at(x, z))).flatMap(Function.identity()).findAny().orElseThrow(() -> new AssertionError("No chunk in region file."));
ByteArrayOutputStream cap = new ByteArrayOutputStream();
try (InputStream in = reader.getChunkInputStream(chunkPos);
GZIPOutputStream gzOut = new GZIPOutputStream(cap)) {
ByteStreams.copy(in, gzOut);
}
CHUNK_DATA = cap.toByteArray();
CHUNK_TAG = ChunkStoreHelper.readCompoundTag(() -> new GZIPInputStream(new ByteArrayInputStream(CHUNK_DATA)));
CHUNK_POS = chunkPos.toBlockVector3();
} finally {
reader.close();
}
TEMP_DIR = Files.createTempDirectory("worldedit-fs-snap-dbs").toRealPath();
}
Aggregations