Search in sources :

Example 1 with WorldSaveHandler

use of net.minecraft.world.WorldSaveHandler in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorld method regenerate.

@Override
public boolean regenerate(Region region, EditSession editSession) {
    // Don't even try to regen if it's going to fail.
    ChunkManager provider = getWorld().getChunkManager();
    if (!(provider instanceof ServerChunkManager)) {
        return false;
    }
    File saveFolder = Files.createTempDir();
    // register this just in case something goes wrong
    // normally it should be deleted at the end of this method
    saveFolder.deleteOnExit();
    try {
        ServerWorld originalWorld = (ServerWorld) getWorld();
        MinecraftServer server = originalWorld.getServer();
        WorldSaveHandler saveHandler = new WorldSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDir().getName(), server, server.getDataFixer());
        World freshWorld = new ServerWorld(server, server.getWorkerExecutor(), saveHandler, originalWorld.getLevelProperties(), originalWorld.dimension.getType(), originalWorld.getProfiler(), new NoOpChunkStatusListener());
        // Pre-gen all the chunks
        // We need to also pull one more chunk in every direction
        CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16));
        for (BlockVector2 chunk : expandedPreGen.getChunks()) {
            freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
        }
        FabricWorld from = new FabricWorld(freshWorld);
        for (BlockVector3 vec : region) {
            editSession.setBlock(vec, from.getFullBlock(vec));
        }
    } catch (MaxChangedBlocksException e) {
        throw new RuntimeException(e);
    } finally {
        saveFolder.delete();
    }
    return true;
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ServerWorld(net.minecraft.server.world.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) World(net.minecraft.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) MinecraftServer(net.minecraft.server.MinecraftServer) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) ServerWorld(net.minecraft.server.world.ServerWorld) File(java.io.File) ServerChunkManager(net.minecraft.server.world.ServerChunkManager) ChunkManager(net.minecraft.world.chunk.ChunkManager) WorldSaveHandler(net.minecraft.world.WorldSaveHandler)

Aggregations

MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 AbstractWorld (com.sk89q.worldedit.world.AbstractWorld)1 File (java.io.File)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerChunkManager (net.minecraft.server.world.ServerChunkManager)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 World (net.minecraft.world.World)1 WorldSaveHandler (net.minecraft.world.WorldSaveHandler)1 ChunkManager (net.minecraft.world.chunk.ChunkManager)1