Search in sources :

Example 1 with PaperweightFaweAdapter

use of com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.PaperweightFaweAdapter in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightAdapter method regenForWorld.

@SuppressWarnings("unchecked")
private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld, RegenOptions options) throws WorldEditException {
    List<CompletableFuture<ChunkAccess>> chunkLoadings = submitChunkLoadTasks(region, serverWorld);
    BlockableEventLoop<Runnable> executor;
    try {
        executor = (BlockableEventLoop<Runnable>) mainThreadProcessorField.get(serverWorld.getChunkSource());
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Couldn't get executor for chunk loading.", e);
    }
    executor.managedBlock(() -> {
        // bail out early if a future fails
        if (chunkLoadings.stream().anyMatch(ftr -> ftr.isDone() && Futures.getUnchecked(ftr) == null)) {
            return false;
        }
        return chunkLoadings.stream().allMatch(CompletableFuture::isDone);
    });
    Map<ChunkPos, ChunkAccess> chunks = new HashMap<>();
    for (CompletableFuture<ChunkAccess> future : chunkLoadings) {
        @Nullable ChunkAccess chunk = future.getNow(null);
        checkState(chunk != null, "Failed to generate a chunk, regen failed.");
        chunks.put(chunk.getPos(), chunk);
    }
    for (BlockVector3 vec : region) {
        BlockPos pos = new BlockPos(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ());
        ChunkAccess chunk = chunks.get(new ChunkPos(pos));
        final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(pos);
        BlockStateHolder<?> state = ((PaperweightFaweAdapter) WorldEditPlugin.getInstance().getBukkitImplAdapter()).adapt(blockData);
        Objects.requireNonNull(state);
        BlockEntity blockEntity = chunk.getBlockEntity(pos);
        if (blockEntity != null) {
            net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
            // FAWE start - BinaryTag
            state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
        // FAWE end
        }
        extent.setBlock(vec, state.toBaseBlock());
        if (options.shouldRegenBiomes()) {
            Biome origBiome = chunk.getNoiseBiome(vec.getX(), vec.getY(), vec.getZ());
            BiomeType adaptedBiome = adapt(serverWorld, origBiome);
            if (adaptedBiome != null) {
                extent.setBiome(vec, adaptedBiome);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) CompletableFuture(java.util.concurrent.CompletableFuture) Biome(net.minecraft.world.level.biome.Biome) PaperweightFaweAdapter(com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.PaperweightFaweAdapter) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) StructureBlockEntity(net.minecraft.world.level.block.entity.StructureBlockEntity) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Nullable(javax.annotation.Nullable)

Aggregations

PaperweightFaweAdapter (com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.PaperweightFaweAdapter)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 BiomeType (com.sk89q.worldedit.world.biome.BiomeType)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Nullable (javax.annotation.Nullable)1 BlockPos (net.minecraft.core.BlockPos)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 Biome (net.minecraft.world.level.biome.Biome)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 StructureBlockEntity (net.minecraft.world.level.block.entity.StructureBlockEntity)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1