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);
}
}
}
}
Aggregations