use of com.sk89q.worldedit.world.storage.MissingChunkException 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.MissingChunkException in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotRestore method restore.
/**
* Restores to world.
*
* @throws MaxChangedBlocksException if the max block change limit is exceeded
*/
public void restore() throws MaxChangedBlocksException {
missingChunks = new ArrayList<>();
errorChunks = new ArrayList<>();
// Now let's start restoring!
for (Map.Entry<BlockVector2, ArrayList<BlockVector3>> entry : neededChunks.entrySet()) {
BlockVector2 chunkPos = entry.getKey();
Chunk chunk;
try {
// This will need to be changed if we start officially supporting 3d snapshots.
chunk = snapshot.getChunk(chunkPos.toBlockVector3());
// Now just copy blocks!
for (BlockVector3 pos : entry.getValue()) {
try {
editSession.setBlock(pos, chunk.getBlock(pos));
// FAWE start - biome and entity restore
if (restoreBiomes && (pos.getX() & 3) == 0 && (pos.getY() & 3) == 0 && (pos.getZ() & 3) == 0) {
editSession.setBiome(pos, chunk.getBiome(pos));
}
// FAWE end
} catch (DataException e) {
// this is a workaround: just ignore for now
}
}
// FAWE start - biome and entity restore
if (restoreEntities) {
try {
for (BaseEntity entity : chunk.getEntities()) {
CompoundBinaryTag tag = entity.getNbtReference().getValue();
ListBinaryTag pos = tag.getList("Pos", BinaryTagTypes.LIST);
ListBinaryTag rotation = tag.getList("Rotation", BinaryTagTypes.LIST);
double x = pos.getDouble(0);
double y = pos.getDouble(1);
double z = pos.getDouble(2);
float yRot = rotation.getFloat(0);
float xRot = rotation.getFloat(1);
Location location = new Location(editSession.getWorld(), x, y, z, yRot, xRot);
editSession.createEntity(location, entity);
}
} catch (DataException e) {
// this is a workaround: just ignore for now
}
}
// FAWE end
} catch (MissingChunkException me) {
missingChunks.add(chunkPos);
} catch (IOException | DataException me) {
errorChunks.add(chunkPos);
lastErrorMessage = me.getMessage();
}
}
}
use of com.sk89q.worldedit.world.storage.MissingChunkException in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotRestore method restore.
/**
* Restores to world.
*
* @throws MaxChangedBlocksException if the max block change limit is exceeded
*/
public void restore() throws MaxChangedBlocksException {
missingChunks = new ArrayList<>();
errorChunks = new ArrayList<>();
// Now let's start restoring!
for (Map.Entry<BlockVector2, Set<BlockVector3>> entry : neededChunks.entrySet()) {
BlockVector2 chunkPos = entry.getKey();
Chunk chunk;
try {
chunk = chunkStore.getChunk(chunkPos, editSession.getWorld());
// Now just copy blocks!
for (BlockVector3 pos : entry.getValue()) {
try {
editSession.setBlock(pos, chunk.getBlock(pos));
// FAWE start - biome and entity restore
if (restoreBiomes && (pos.getX() & 3) == 0 && (pos.getY() & 3) == 0 && (pos.getZ() & 3) == 0) {
editSession.setBiome(pos, chunk.getBiome(pos));
}
// FAWE end
} catch (DataException e) {
// this is a workaround: just ignore for now
}
}
// FAWE start - biome and entity restore
if (restoreEntities) {
try {
for (BaseEntity entity : chunk.getEntities()) {
CompoundBinaryTag tag = entity.getNbtReference().getValue();
ListBinaryTag pos = tag.getList("Pos");
ListBinaryTag rotation = tag.getList("Rotation");
double x = pos.getDouble(0);
double y = pos.getDouble(1);
double z = pos.getDouble(2);
float yRot = rotation.getFloat(0);
float xRot = rotation.getFloat(1);
Location location = new Location(editSession.getWorld(), x, y, z, yRot, xRot);
editSession.createEntity(location, entity);
}
} catch (DataException e) {
// this is a workaround: just ignore for now
}
}
// FAWE end
} catch (MissingChunkException me) {
missingChunks.add(chunkPos);
} catch (IOException | DataException me) {
errorChunks.add(chunkPos);
lastErrorMessage = me.getMessage();
}
}
}
Aggregations