diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java index cb678ecac..2cd4d5a6a 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java @@ -1,13 +1,6 @@ package com.seibel.lod.common.wrappers.worldGeneration; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - import com.seibel.lod.common.wrappers.world.WorldWrapper; -import com.seibel.lod.common.wrappers.worldGeneration.WorldGenerationStep.GenerationEvent; import com.seibel.lod.common.wrappers.worldGeneration.WorldGenerationStep.Steps; import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.enums.config.DistanceGenerationMode; @@ -20,8 +13,6 @@ import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftWrapper; import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper; import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractExperimentalWorldGeneratorWrapper; -import net.minecraft.world.level.ChunkPos; - public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWrapper { private static final IMinecraftWrapper MC = SingletonHandler.get(IMinecraftWrapper.class); @@ -34,49 +25,27 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra private int estimatedSampleNeeded = 128; - private LinkedList events = new LinkedList(); - public ExperimentalGenerator(LodBuilder newLodBuilder, LodDimension newLodDimension, IWorldWrapper worldWrapper) { super(newLodBuilder, newLodDimension, worldWrapper); System.out.println("================ExperimentalGenerator INIT============="); generationGroup = new WorldGenerationStep(((WorldWrapper) worldWrapper).getServerWorld(), newLodBuilder, newLodDimension); } - - private boolean checkIfPositionIsValid(int chunkX, int chunkZ, int range) { - for (GenerationEvent event : events) { - if (event.tooClose(chunkX, chunkZ, range)) return false; - } - return true; - } - + @Override public void queueGenerationRequests(LodDimension lodDim, LodBuilder lodBuilder) { DistanceGenerationMode mode = CONFIG.client().worldGenerator().getDistanceGenerationMode(); numberOfGenerationPoints = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(); + generationGroup.updateAllFutures(); if (mode == DistanceGenerationMode.NONE || !MC.hasSinglePlayerServer()) return; - - // Update all current out standing jobs - Iterator iter = events.iterator(); - while (iter.hasNext()) { - GenerationEvent event = iter.next(); - if (event.isCompleted()) { - event.join(); - iter.remove(); - } else if (event.hasTimeout(5, TimeUnit.SECONDS)) { - System.err.println(event.id+": Timed out and terminated!"); - event.terminate(); - iter.remove(); - } - } - + int eventsCount = generationGroup.events.size(); // If we still all jobs running, return. - if (events.size() >= numberOfGenerationPoints) + if (eventsCount >= numberOfGenerationPoints) return; - final int targetToGenerate = numberOfGenerationPoints - events.size(); + final int targetToGenerate = numberOfGenerationPoints - eventsCount; int toGenerate = targetToGenerate; int positionGoneThough = 0; @@ -106,9 +75,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra byte detailLevel = (byte) (posToGenerate.getNthDetail(i, true) - 1); int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, true)); int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, true)); - if (checkIfPositionIsValid(chunkX, chunkZ, generationGroupSize)) { - ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ); - events.add(new GenerationEvent(chunkPos, generationGroupSize, generationGroup, Steps.Surface)); + if (generationGroup.tryAddPoint(chunkX, chunkZ, generationGroupSize, Steps.Features)) { toGenerate--; } } @@ -123,9 +90,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra byte detailLevel = (byte) (posToGenerate.getNthDetail(i, false) - 1); int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, false)); int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, false)); - if (checkIfPositionIsValid(chunkX, chunkZ, generationGroupSizeFar)) { - ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ); - events.add(new GenerationEvent(chunkPos, generationGroupSizeFar, generationGroup, Steps.Surface)); + if (generationGroup.tryAddPoint(chunkX, chunkZ, generationGroupSize, Steps.Surface)) { toGenerate--; } } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java index fff0ea371..dcdf465f5 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java @@ -7,6 +7,8 @@ import com.seibel.lod.core.objects.lod.LodDimension; import java.util.ArrayList; import java.util.EnumSet; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -16,20 +18,14 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReentrantLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.mojang.datafixers.DataFixer; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.worldGeneration.WorldGenerationStep.Steps; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.entity.ai.village.VillageSiege; -import net.minecraft.world.entity.npc.CatSpawner; -import net.minecraft.world.entity.npc.WanderingTraderSpawner; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.StructureFeatureManager; @@ -38,48 +34,149 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.chunk.*; import net.minecraft.world.level.chunk.storage.ChunkScanAccess; -import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.server.level.ThreadedLevelLightEngine; +import net.minecraft.ReportedException; import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; -import net.minecraft.nbt.StreamTagVisitor; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; -import net.minecraft.world.level.levelgen.PatrolSpawner; -import net.minecraft.world.level.levelgen.PhantomSpawner; import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.structure.StructureCheck; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; -import net.minecraft.world.level.lighting.LevelLightEngine; -import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.WorldData; public class WorldGenerationStep { - /* - public static class ChunkScanner implements ChunkScanAccess { + enum Steps { + Empty, StructureStart, StructureReference, Biomes, Noise, Surface, Carvers, LiquidCarvers, Features, Light, + } - @Override - public CompletableFuture scanChunk(ChunkPos paramChunkPos, StreamTagVisitor paramStreamTagVisitor) { - // TODO Auto-generated method stub - return null; + public static final class GridList extends ArrayList implements List { + + public static class Pos { + public int x; + public int y; + public Pos(int xx, int yy) {x=xx;y=yy;} + } + + private static final long serialVersionUID = 1585978374811888116L; + public final int gridCentreToEdge; + public final int gridSize; + + public GridList(int gridCentreToEdge) { + super((gridCentreToEdge * 2 + 1) * (gridCentreToEdge * 2 + 1)); + gridSize = gridCentreToEdge * 2 + 1; + this.gridCentreToEdge = gridCentreToEdge; + } + + public final T getOffsetOf(int index, int x, int y) { + return get(index + x + y * gridSize); } - }*/ + public final int offsetOf(int index, int x, int y) { + return index + x + y * gridSize; + } + + public final Pos posOf(int index) { + return new Pos(index%gridSize, index/gridSize); + } + public final int calculateOffset(int x, int y) { + return x + y * gridSize; + } + + public GridList subGrid(int gridCentreToEdge) { + int centreIndex = size()/2; + GridList subGrid = new GridList(gridCentreToEdge); + for (int oy = -gridCentreToEdge; oy <= gridCentreToEdge; oy++) { + int begin = offsetOf(centreIndex, -gridCentreToEdge, oy); + int end = offsetOf(centreIndex, gridCentreToEdge, oy); + subGrid.addAll(this.subList(begin, end+1)); + } + //System.out.println("========================================\n"+ + //this.toDetailString() + "\nTOOOOOOOOOOOOO\n"+subGrid.toDetailString()+ + //"==========================================\n"); + return subGrid; + } + + @Override + public String toString() { + return "GridList "+gridSize+"*"+gridSize+"["+size()+"]"; + } + public String toDetailString() { + StringBuilder str = new StringBuilder("\n"); + int i = 0; + for (T t : this) { + str.append(t.toString()); + str.append(", "); + i++; + if (i%gridSize == 0) { + str.append("\n"); + } + } + return str.toString(); + } + } + + public static class GlobalParameters { + final ChunkGenerator generator; + final StructureManager structures; + final BiomeManager biomeManager; + final WorldGenSettings worldGenSettings; + final ThreadedLevelLightEngine lightEngine; + final LodBuilder lodBuilder; + final LodDimension lodDim; + final Registry biomes; + final RegistryAccess registry; + final long worldSeed; + final ChunkScanAccess chunkScanner; + final ServerLevel level; //TODO: Figure out a way to remove this. Maybe ClientLevel also works? + final DataFixer fixerUpper; + public GlobalParameters(ServerLevel level, LodBuilder lodBuilder, LodDimension lodDim) { + this.lodBuilder = lodBuilder; + this.lodDim = lodDim; + this.level = level; + lightEngine = (ThreadedLevelLightEngine) level.getLightEngine(); + MinecraftServer server = level.getServer(); + WorldData worldData = server.getWorldData(); + worldGenSettings = worldData.worldGenSettings(); + registry = server.registryAccess(); + biomes = registry.registryOrThrow(Registry.BIOME_REGISTRY); + worldSeed = worldGenSettings.seed(); + biomeManager = new BiomeManager(level, BiomeManager.obfuscateSeed(worldSeed)); + structures = server.getStructureManager(); + // TODO: Get the current level dimension + MappedRegistry mappedRegistry = worldGenSettings.dimensions(); + LevelStem levelStem = (LevelStem) mappedRegistry.get(LevelStem.OVERWORLD); + if (levelStem == null) + throw new RuntimeException("There should already be a level.... Right???"); + generator = levelStem.generator(); + chunkScanner = level.getChunkSource().chunkScanner(); + fixerUpper = server.getFixerUpper(); + } + } + public static class ThreadedParameters { + final StructureFeatureManager structFeat; + final StructureCheck structCheck; + public ThreadedParameters(GlobalParameters param) { + structCheck = new StructureCheck(param.chunkScanner, param.registry, param.structures, + Level.OVERWORLD, param.generator, param.level, param.generator.getBiomeSource(), param.worldSeed, param.fixerUpper); + structFeat = new StructureFeatureManager(param.level, param.worldGenSettings, structCheck); + } + } public static class GenerationEvent { private static int generationFutureDebugIDs = 0; - ChunkPos pos; - int range; - Future future; + final ThreadedParameters tParam; + final ChunkPos pos; + final int range; + final Future future; long nanotime; - int id; - Steps target; + final int id; + final Steps target; public GenerationEvent(ChunkPos pos, int range, WorldGenerationStep generationGroup, Steps target) { nanotime = System.nanoTime(); @@ -87,6 +184,7 @@ public class WorldGenerationStep { this.range = range; id = generationFutureDebugIDs++; this.target = target; + this.tParam = new ThreadedParameters(generationGroup.params); future = generationGroup.executors.submit(() -> { generationGroup.generateLodFromList(this); }); @@ -123,177 +221,68 @@ public class WorldGenerationStep { } } - - - - - private static T joinAsync(CompletableFuture f) { //while (!f.isDone()) Thread.yield(); return f.join(); } - ServerLevel level; - ChunkGenerator generator; - StructureManager structures; - BiomeManager biomeManager; - WorldGenSettings worldGenSettings; - ThreadedLevelLightEngine lightEngine; - LodBuilder lodBuilder; - LodDimension lodDim; - StructureFeatureManager structureFeatureManager; - StructureCheck structureCheck; - Registry biomes; - RegistryAccess registry; - long worldSeed; + final LinkedList events = new LinkedList(); + final GlobalParameters params; + final StepStructureStart stepStructureStart = new StepStructureStart(); + final StepStructureReference stepStructureReference = new StepStructureReference(); + final StepBiomes stepBiomes = new StepBiomes(); + final StepNoise stepNoise = new StepNoise(); + final StepSurface stepSurface = new StepSurface(); + final StepCarvers stepCarvers = new StepCarvers(); + final StepLiquidCarvers stepLiquidCarvers = new StepLiquidCarvers(); + final StepFeatures stepFeatures = new StepFeatures(); + //public ExecutorService executors = Executors.newWorkStealingPool(); - public ExecutorService executors = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build()); - + public final ExecutorService executors = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build()); //public ExecutorService executors = Executors.newFixedThreadPool(8, new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build()); + + public boolean tryAddPoint(int x, int z, int range, Steps target) { + x = (int)(x / range) * range; + z = (int)(z / range) * range; + + for (GenerationEvent event : events) { + if (event.tooClose(x, z, range)) return false; + } + events.add(new GenerationEvent(new ChunkPos(x,z), range, this, target)); + return true; + } + + public void updateAllFutures() { + // Update all current out standing jobs + Iterator iter = events.iterator(); + while (iter.hasNext()) { + GenerationEvent event = iter.next(); + if (event.isCompleted()) { + event.join(); + iter.remove(); + } else if (event.hasTimeout(10, TimeUnit.SECONDS)) { + System.err.println(event.id+": Timed out and terminated!"); + event.terminate(); + iter.remove(); + } + } + } public WorldGenerationStep(ServerLevel level, LodBuilder lodBuilder, LodDimension lodDim) { System.out.println("================WORLD_GEN_STEP_INITING============="); - this.level = level; - this.lodBuilder = lodBuilder; - this.lodDim = lodDim; - setupStuff(); - - StepStructureStart.onLevelLoad(generator, worldGenSettings, registry, structureFeatureManager, structures, worldSeed, structureCheck); - StepStructureReference.onLevelLoad(level, generator, structureFeatureManager); - StepBiomes.onLevelLoad(level, generator, biomes, structureFeatureManager); - StepNoise.onLevelLoad(level, generator, structureFeatureManager); - StepSurface.onLevelLoad(level, generator, structureFeatureManager); - StepCarvers.onLevelLoad(level, generator, structureFeatureManager, worldSeed, biomeManager); - StepFeatures.onLevelLoad(level, generator, structureFeatureManager, lightEngine); - StepLight.onLevelLoad(lightEngine); - - } - - - private void setupStuff() { - lightEngine = (ThreadedLevelLightEngine) level.getLightEngine(); - MinecraftServer server = level.getServer(); - WorldData worldData = server.getWorldData(); - worldGenSettings = worldData.worldGenSettings(); - registry = server.registryAccess(); - biomes = registry.registryOrThrow(Registry.BIOME_REGISTRY); - worldSeed = worldGenSettings.seed(); - long biomeSeed = BiomeManager.obfuscateSeed(worldSeed); - biomeManager = new BiomeManager(level, biomeSeed); - structures = server.getStructureManager(); - // TODO: Get the current level dimension - MappedRegistry mappedRegistry = worldGenSettings.dimensions(); - LevelStem levelStem = (LevelStem) mappedRegistry.get(LevelStem.OVERWORLD); - if (levelStem == null) { - throw new RuntimeException("There should already be a level.... Right???"); - } else { - generator = levelStem.generator(); - } - structureCheck = new StructureCheck(level.getChunkSource().chunkScanner(), registry, structures, - Level.OVERWORLD, generator, level, generator.getBiomeSource(), worldSeed, server.getFixerUpper()); - structureFeatureManager = new StructureFeatureManager(level, worldGenSettings, structureCheck); + params = new GlobalParameters(level, lodBuilder, lodDim); } - public static final class GridList extends ArrayList implements List { - - private static final long serialVersionUID = 1585978374811888116L; - public final int gridCentreToEdge; - public final int gridSize; - - public GridList(int gridCentreToEdge) { - super((gridCentreToEdge * 2 + 1) * (gridCentreToEdge * 2 + 1)); - gridSize = gridCentreToEdge * 2 + 1; - this.gridCentreToEdge = gridCentreToEdge; - } - - public final int offsetOf(int index, int x, int y) { - return index + x + y * gridSize; - } - - public GridList subGrid(int centreIndex, int gridCentreToEdge) { - GridList subGrid = new GridList(gridCentreToEdge); - for (int oy = -gridCentreToEdge; oy <= gridCentreToEdge; oy++) { - int begin = offsetOf(centreIndex, -gridCentreToEdge, oy); - int end = offsetOf(centreIndex, gridCentreToEdge, oy); - subGrid.addAll(this.subList(begin, end+1)); - } - - //System.out.println("========================================\n"+ - //this.toDetailString() + "\nTOOOOOOOOOOOOO\n"+subGrid.toDetailString()+ - //"==========================================\n"); - return subGrid; - } - - @Override - public String toString() { - return "GridList "+gridSize+"*"+gridSize+"["+size()+"]"; - } - public String toDetailString() { - StringBuilder str = new StringBuilder("\n"); - int i = 0; - for (T t : this) { - str.append(t.toString()); - str.append(", "); - i++; - if (i%gridSize == 0) { - str.append("\n"); - } - } - return str.toString(); - } - } - - public static class ChunkSynconizer { - - private ReentrantLock uniqueOwnerLock = new ReentrantLock(); - ChunkAccess chunk; - Steps completedStep = Steps.Empty; - - public ChunkSynconizer(ChunkPos pos, ServerLevel level, Registry biomes) { - chunk = new ProtoChunk(pos, UpgradeData.EMPTY, level, biomes, null); - } - - public boolean tryClaimOwnerLock() { - return uniqueOwnerLock.tryLock(); - } - - public void releaseOwnerLock() { - uniqueOwnerLock.unlock(); - } - - public boolean hasCompletedStep(Steps step) { - return step.compareTo(completedStep) <= 0; - } - - public void set(ChunkAccess newChunk, Steps newStep) { - chunk = newChunk; - completedStep = newStep; - } - - public void set(Steps newStep) { - completedStep = newStep; - } - - @Override - public String toString() { - return chunk.getPos().toString(); - } - } - - ConcurrentHashMap chunks = new ConcurrentHashMap(); + ConcurrentHashMap chunks = new ConcurrentHashMap(); // No longer using Long2ObjectLinkedOpenHashMap as I doubt it is multithread // safe. - private static final long toLongPos(int cx, int cy) { - return ChunkPos.asLong(cx, cy); - } - - private final ChunkSynconizer getChunkSynconizer(long pos) { - ChunkSynconizer chunk = chunks.get(pos); + private final ChunkAccess getCachedChunk(ChunkPos pos) { + ChunkAccess chunk = chunks.get(pos.toLong()); if (chunk != null) return chunk; - chunk = new ChunkSynconizer(new ChunkPos(pos), level, biomes); - ChunkSynconizer oldVal = chunks.putIfAbsent(pos, chunk); + chunk = new ProtoChunk(pos, UpgradeData.EMPTY, params.level, params.biomes, null); + ChunkAccess oldVal = chunks.putIfAbsent(pos.toLong(), chunk); if (oldVal != null) return oldVal; return chunk; @@ -302,38 +291,37 @@ public class WorldGenerationStep { public void generateLodFromList(GenerationEvent event) { try { System.out.println("Started event: "+event); - GridList referencedChunks; + GridList referencedChunks; DistanceGenerationMode generationMode; - Runnable lambda = () -> {event.refreshTimeout();}; switch (event.target) { case Empty: return; case StructureStart: - referencedChunks = generateStructureStart(lambda, event.pos, event.range); + referencedChunks = generateStructureStart(event, event.range); generationMode = DistanceGenerationMode.NONE; break; case StructureReference: - referencedChunks = generateStructureReference(lambda, event.pos, event.range); + referencedChunks = generateStructureReference(event, event.range); generationMode = DistanceGenerationMode.NONE; break; case Biomes: - referencedChunks = generateBiomes(lambda, event.pos, event.range); + referencedChunks = generateBiomes(event, event.range); generationMode = DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT; break; case Noise: - referencedChunks = generateNoise(lambda, event.pos, event.range); + referencedChunks = generateNoise(event, event.range); generationMode = DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT; break; case Surface: - referencedChunks = generateSurface(lambda, event.pos, event.range); + referencedChunks = generateSurface(event, event.range); generationMode = DistanceGenerationMode.SURFACE; break; case Carvers: - referencedChunks = generateCarvers(lambda, event.pos, event.range); + referencedChunks = generateCarvers(event, event.range); generationMode = DistanceGenerationMode.SURFACE; break; case Features: - referencedChunks = generateFeatures(lambda, event.pos, event.range); + referencedChunks = generateFeatures(event, event.range); generationMode = DistanceGenerationMode.FEATURES; break; case LiquidCarvers: @@ -345,16 +333,16 @@ public class WorldGenerationStep { } int centreIndex = referencedChunks.size() / 2; - for (int ox = -event.range; ox <= event.range; ox++) { - for (int oy = -event.range; oy <= event.range; oy++) { + for (int oy = -event.range; oy <= event.range; oy++) { + for (int ox = -event.range; ox <= event.range; ox++) { int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - lodBuilder.generateLodNodeFromChunk(lodDim, new ChunkWrapper(target.chunk), new LodBuilderConfig(generationMode)); + ChunkAccess target = referencedChunks.get(targetIndex); + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target), new LodBuilderConfig(generationMode)); } } - lambda.run(); - for (ChunkSynconizer sync : referencedChunks) { - chunks.remove(sync.chunk.getPos().toLong()); + event.refreshTimeout(); + for (ChunkAccess sync : referencedChunks) { + chunks.remove(sync.getPos().toLong()); } System.out.println("Ended event: "+event); } catch (RuntimeException e) { @@ -363,504 +351,293 @@ public class WorldGenerationStep { } } - public GridList generateStructureStart(Runnable r, ChunkPos pos, int range) { - int cx = pos.x; - int cy = pos.z; - GridList chunks = new GridList(range); + public GridList generateEmpty(GenerationEvent e, int range) { + int cx = e.pos.x; + int cy = e.pos.z; + GridList chunks = new GridList(range); for (int oy = -range; oy <= range; oy++) { for (int ox = -range; ox <= range; ox++) { - ChunkSynconizer target = getChunkSynconizer(toLongPos(cx + ox, cy + oy)); + ChunkAccess target = getCachedChunk(new ChunkPos(cx+ox, cy+oy)); + //ChunkAccess target = new ChunkAccess(new ChunkPos(cx+ox, cy+oy), level, biomes); chunks.add(target); - if (!target.hasCompletedStep(Steps.StructureStart)) { - - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - ChunkAccess access = target.chunk; - target.set(StepStructureStart.generate(access), - Steps.StructureStart); - } finally { - target.releaseOwnerLock(); - } - } - - - - } } } - r.run(); + e.refreshTimeout(); + return chunks; + } + + public GridList generateStructureStart(GenerationEvent e, int range) { + int prestepRange = range+8; + GridList chunks = generateEmpty(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.STRUCTURE_STARTS, range); + //System.out.println("DEBUG: StructureStart:"+pos); + //System.out.println("DEBUG: StructureStart:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepStructureStart.generateGroup(e.tParam, region, chunks.subGrid(range)); + e.refreshTimeout(); return chunks; } - public GridList generateStructureReference(Runnable r, ChunkPos pos, int range) { - int prestepRange = range + StepStructureReference.RANGE; - GridList referencedChunks = generateStructureStart(r, pos, prestepRange); - int centreIndex = referencedChunks.size() / 2; - - for (int oy = -range; oy <= range; oy++) { - for (int ox = -range; ox <= range; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - if (!target.hasCompletedStep(Steps.StructureReference)) { - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - GridList reference = referencedChunks.subGrid(targetIndex, - StepStructureReference.RANGE); - ArrayList referenceAccess = new ArrayList(reference.size()); - for (ChunkSynconizer ref : reference) { - referenceAccess.add(ref.chunk); - } - StepStructureReference.generate(referenceAccess, target.chunk); - target.set(Steps.StructureReference); - } finally { - target.releaseOwnerLock(); - } - } - } - } - } - r.run(); - return referencedChunks; + public GridList generateStructureReference(GenerationEvent e, int range) { + int prestepRange = range; + GridList chunks = generateStructureStart(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.STRUCTURE_REFERENCES, range); + //System.out.println("DEBUG: StructureReference:"+pos); + //System.out.println("DEBUG: StructureReference:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepStructureReference.generateGroup(e.tParam, region, chunks.subGrid(range)); + e.refreshTimeout(); + return chunks; } - public GridList generateBiomes(Runnable r, ChunkPos pos, int range) { - int prestepRange = range + 1; - GridList referencedChunks = generateStructureReference(r, pos, prestepRange); - int centreIndex = referencedChunks.size() / 2; - - for (int oy = -range; oy <= range; oy++) { - for (int ox = -range; ox <= range; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - if (!target.hasCompletedStep(Steps.Biomes)) { - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - GridList reference = referencedChunks.subGrid(targetIndex, - StepBiomes.RANGE); - ArrayList referenceAccess = new ArrayList(reference.size()); - for (ChunkSynconizer ref : reference) { - referenceAccess.add(ref.chunk); - } - target.set(StepBiomes.generate(referenceAccess, target.chunk, executors), Steps.Biomes); - } finally { - target.releaseOwnerLock(); - } - } - } - } - } - r.run(); - return referencedChunks; + public GridList generateBiomes(GenerationEvent e, int range) { + int prestepRange = range; + GridList chunks = generateStructureReference(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.BIOMES, range); + //System.out.println("DEBUG: Biomes:"+pos); + //System.out.println("DEBUG: Biomes:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepBiomes.generateGroup(e.tParam, region, chunks.subGrid(range), executors); + e.refreshTimeout(); + return chunks; } - public GridList generateNoise(Runnable r, ChunkPos pos, int range) { - int prestepRange = range + 1; - GridList referencedChunks = generateBiomes(r, pos, prestepRange); - int centreIndex = referencedChunks.size() / 2; - - for (int oy = -range; oy <= range; oy++) { - for (int ox = -range; ox <= range; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - if (!target.hasCompletedStep(Steps.Noise)) { - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - GridList reference = referencedChunks.subGrid(targetIndex, - StepNoise.RANGE); - ArrayList referenceAccess = new ArrayList(reference.size()); - for (ChunkSynconizer ref : reference) { - referenceAccess.add(ref.chunk); - } - target.set(StepNoise.generate(referenceAccess, target.chunk, executors), - Steps.Noise); - } finally { - target.releaseOwnerLock(); - } - } - } - } - } - r.run(); - return referencedChunks; + public GridList generateNoise(GenerationEvent e, int range) { + int prestepRange = range; + GridList chunks = generateBiomes(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.NOISE, range); + //System.out.println("DEBUG: Noise:"+pos); + //System.out.println("DEBUG: Noise:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepNoise.generateGroup(e.tParam, region, chunks.subGrid(range), executors); + e.refreshTimeout(); + return chunks; } - public GridList generateSurface(Runnable r, ChunkPos pos, int range) { - int prestepRange = range + 1; - GridList referencedChunks = generateNoise(r, pos, prestepRange); - int centreIndex = referencedChunks.size() / 2; - - for (int oy = -range; oy <= range; oy++) { - for (int ox = -range; ox <= range; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - if (!target.hasCompletedStep(Steps.Surface)) { - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - GridList reference = referencedChunks.subGrid(targetIndex, - StepSurface.RANGE); - ArrayList referenceAccess = new ArrayList(reference.size()); - for (ChunkSynconizer ref : reference) { - referenceAccess.add(ref.chunk); - } - - target.set(StepSurface.generate(referenceAccess, target.chunk), - Steps.Surface); - } finally { - target.releaseOwnerLock(); - } - } - } - } - } - r.run(); - return referencedChunks; + public GridList generateSurface(GenerationEvent e, int range) { + int prestepRange = range; + GridList chunks = generateNoise(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.SURFACE, range); + //System.out.println("DEBUG: Surface:"+pos); + //System.out.println("DEBUG: Surface:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepSurface.generateGroup(e.tParam, region, chunks.subGrid(range)); + e.refreshTimeout(); + return chunks; } - public GridList generateCarvers(Runnable r, ChunkPos pos, int range) { - int prestepRange = range + 1; - GridList referencedChunks = generateSurface(r, pos, prestepRange); - int centreIndex = referencedChunks.size() / 2; - - for (int oy = -range; oy <= range; oy++) { - for (int ox = -range; ox <= range; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - if (!target.hasCompletedStep(Steps.Carvers)) { - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - GridList reference = referencedChunks.subGrid(targetIndex, - StepCarvers.RANGE); - ArrayList referenceAccess = new ArrayList(reference.size()); - for (ChunkSynconizer ref : reference) { - referenceAccess.add(ref.chunk); - } - target.set(StepCarvers.generate(referenceAccess, target.chunk), - Steps.Carvers); - } finally { - target.releaseOwnerLock(); - } - } - } - } - } - r.run(); - return referencedChunks; + public GridList generateCarvers(GenerationEvent e, int range) { + int prestepRange = range; + GridList chunks = generateSurface(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.CARVERS, range); + //System.out.println("DEBUG: Carvers:"+pos); + //System.out.println("DEBUG: Carvers:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepCarvers.generateGroup(e.tParam, region, chunks.subGrid(range)); + e.refreshTimeout(); + return chunks; } - public GridList generateFeatures(Runnable r, ChunkPos pos, int range) { - int prestepRange = range + 1; - GridList referencedChunks = generateCarvers(r, pos, prestepRange); - int centreIndex = referencedChunks.size() / 2; - - for (int oy = -range; oy <= range; oy++) { - for (int ox = -range; ox <= range; ox++) { - int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); - ChunkSynconizer target = referencedChunks.get(targetIndex); - if (!target.hasCompletedStep(Steps.Features)) { - boolean owned = target.tryClaimOwnerLock(); - if (owned) { - try { - GridList reference = referencedChunks.subGrid(targetIndex, - StepFeatures.RANGE); - ArrayList referenceAccess = new ArrayList(reference.size()); - for (ChunkSynconizer ref : reference) { - referenceAccess.add(ref.chunk); - } - target.set(StepFeatures.generate(referenceAccess, target.chunk), - Steps.Features); - } finally { - target.releaseOwnerLock(); - } - } - } - } - } - r.run(); - return referencedChunks; + public GridList generateFeatures(GenerationEvent e, int range) { + int prestepRange = range; + GridList chunks = generateCarvers(e, prestepRange); + WorldGenRegion region = new WorldGenRegion(params.level, chunks, ChunkStatus.FEATURES, range + 1); + //System.out.println("DEBUG: Features:"+pos+" range:"+range); + //System.out.println("DEBUG: Features:\n"+referencedChunks.toDetailString()); + //System.out.println("to:\n"+referencedChunks.subGrid(centreIndex, range).toDetailString()); + stepFeatures.generateGroup(e.tParam, region, chunks.subGrid(range)); + e.refreshTimeout(); + return chunks; } - - enum Steps { - Empty, StructureStart, StructureReference, Biomes, Noise, Surface, Carvers, LiquidCarvers, Features, Light, - } - public static class StepStructureStart { - public static final ChunkStatus STATUS = ChunkStatus.STRUCTURE_STARTS; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ChunkGenerator gen; - private static boolean doGenerateFeatures = true; - private static RegistryAccess registry; - private static StructureFeatureManager structFeat; - private static StructureManager struct; - private static long seed; - private static StructureCheck structCheck; + public class StepStructureStart { + public final ChunkStatus STATUS = ChunkStatus.STRUCTURE_STARTS; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - public final static void onLevelLoad(ChunkGenerator generator, WorldGenSettings genSettings, RegistryAccess registryAccess, - StructureFeatureManager structureFeature, StructureManager structures, long worldSeed, StructureCheck structureCheck) { - gen = generator; - doGenerateFeatures = genSettings.generateFeatures(); - registry = registryAccess; - structFeat = structureFeature; - struct = structures; - seed = worldSeed; - structCheck = structureCheck; - } - - public final static ChunkAccess generate(ChunkAccess chunk) { - if (doGenerateFeatures) { - // Should be thread safe - gen.createStructures(registry, structFeat, chunk, struct, seed); + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { + // Note: Not certain StructureFeatureManager.forWorldGenRegion(...) is thread safe + for (ChunkAccess chunk : chunks) { + if (params.worldGenSettings.generateFeatures()) { + //System.out.println("StepStructureStart: "+chunk.getPos()); + // Should be thread safe + params.generator.createStructures(params.registry, tParams.structFeat, chunk, params.structures, params.worldSeed); + } + ((ProtoChunk) chunk).setStatus(STATUS); + tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts()); } - ((ProtoChunk) chunk).setStatus(STATUS); - structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts()); - return chunk; } - + /* static ChunkAccess load(ServerLevel level, ChunkAccess chunk) { ((ProtoChunk) chunk).setStatus(STATUS); structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts()); return chunk; - } + }*/ } - public static class StepStructureReference { - public static final ChunkStatus STATUS = ChunkStatus.STRUCTURE_REFERENCES; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ChunkGenerator gen; - private static StructureFeatureManager structFeat; - private static ServerLevel level; - - public final static void onLevelLoad(ServerLevel serverLevel, ChunkGenerator generator, StructureFeatureManager structureFeature) { - gen = generator; - structFeat = structureFeature; - level = serverLevel; - } + public class StepStructureReference { + public final ChunkStatus STATUS = ChunkStatus.STRUCTURE_REFERENCES; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - public static final void generate(List chunkList, ChunkAccess chunk) { - WorldGenRegion worldGenRegion = new WorldGenRegion(level, chunkList, STATUS, -1); + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { // Note: Not certain StructureFeatureManager.forWorldGenRegion(...) is thread safe - gen.createReferences(worldGenRegion, structFeat.forWorldGenRegion(worldGenRegion), chunk); - ((ProtoChunk) chunk).setStatus(STATUS); - } - - static ChunkAccess load(ChunkAccess chunk) { - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - } - - public static class StepBiomes { - public static final ChunkStatus STATUS = ChunkStatus.BIOMES; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - public static Registry biomeRegistry; - private static ChunkGenerator gen; - private static StructureFeatureManager structFeat; - private static ServerLevel level; - - public final static void onLevelLoad(ServerLevel serverLevel, ChunkGenerator generator, Registry registry, StructureFeatureManager structureFeature) { - biomeRegistry = registry; - gen = generator; - structFeat = structureFeature; - level = serverLevel; - } - - public static final ChunkAccess generate(List chunkList, ChunkAccess chunk, Executor worker) { - WorldGenRegion worldGenRegion = new WorldGenRegion(level, chunkList, STATUS, -1); - chunk = joinAsync(gen.createBiomes(biomeRegistry, worker, Blender.of(worldGenRegion), - structFeat.forWorldGenRegion(worldGenRegion), chunk)); - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - - static ChunkAccess load(ChunkAccess chunk) { - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - } - - public static class StepNoise { - public static final ChunkStatus STATUS = ChunkStatus.NOISE; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ChunkGenerator gen; - private static StructureFeatureManager structFeat; - private static ServerLevel level; - - public final static void onLevelLoad(ServerLevel serverLevel, ChunkGenerator generator, StructureFeatureManager structureFeature) { - gen = generator; - structFeat = structureFeature; - level = serverLevel; - } - - public static final ChunkAccess generate(List chunkList, ChunkAccess chunk, Executor worker) { - WorldGenRegion worldGenRegion = new WorldGenRegion(level, chunkList, STATUS, 0); - chunk = joinAsync(gen.fillFromNoise(worker, Blender.of(worldGenRegion), - structFeat.forWorldGenRegion(worldGenRegion), chunk)); - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - - static ChunkAccess load(ChunkAccess chunk) { - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - } - - public static class StepSurface { - public static final ChunkStatus STATUS = ChunkStatus.SURFACE; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ChunkGenerator gen; - private static StructureFeatureManager structFeat; - private static ServerLevel level; - - public final static void onLevelLoad(ServerLevel serverLevel, ChunkGenerator generator, StructureFeatureManager structureFeature) { - gen = generator; - structFeat = structureFeature; - level = serverLevel; - } - - public static final ChunkAccess generate(List chunkList, ChunkAccess chunk) { - WorldGenRegion worldGenRegion = new WorldGenRegion(level, chunkList, STATUS, 0); - gen.buildSurface(worldGenRegion, structFeat.forWorldGenRegion(worldGenRegion), - chunk); - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - - static ChunkAccess load(ChunkAccess chunk) { - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - } - - public static class StepCarvers { - public static final ChunkStatus STATUS = ChunkStatus.CARVERS; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ChunkGenerator gen; - private static StructureFeatureManager structFeat; - private static ServerLevel level; - private static long seed; - private static BiomeManager biomes; - - public final static void onLevelLoad(ServerLevel serverLevel, ChunkGenerator generator, StructureFeatureManager structureFeature, - long worldSeed, BiomeManager biomeManger) { - gen = generator; - structFeat = structureFeature; - level = serverLevel; - seed = worldSeed; - biomes = biomeManger; - } - - - public static final ChunkAccess generate(List chunkList, ChunkAccess chunk) { - WorldGenRegion worldGenRegion = new WorldGenRegion(level, chunkList, STATUS, 0); - Blender.addAroundOldChunksCarvingMaskFilter((WorldGenLevel) worldGenRegion, (ProtoChunk) chunk); - gen.applyCarvers(worldGenRegion, seed, biomes, structFeat.forWorldGenRegion(worldGenRegion), chunk, - GenerationStep.Carving.AIR); - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - - static ChunkAccess load(ChunkAccess chunk) { - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - } - - public static class StepLiquidCarvers { - public static final ChunkStatus STATUS = ChunkStatus.LIQUID_CARVERS; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - - public static final ChunkAccess generate(List chunkList, ChunkAccess chunk, Executor worker) { - // FIXME: I think the decompiler failed on this one. Find the actual body and - // put it here. - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - - static ChunkAccess load(ChunkAccess chunk) { - ((ProtoChunk) chunk).setStatus(STATUS); - return chunk; - } - } - - public static class StepFeatures { - public static final ChunkStatus STATUS = ChunkStatus.FEATURES; - public static final int RANGE = STATUS.getRange(); - public static final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ChunkGenerator gen; - private static StructureFeatureManager structFeat; - private static ServerLevel level; - private static LevelLightEngine lights; - - public final static void onLevelLoad(ServerLevel serverLevel, ChunkGenerator generator, StructureFeatureManager structureFeature, - LevelLightEngine lightEngine) { - gen = generator; - structFeat = structureFeature; - level = serverLevel; - lights = lightEngine; - } - - private static ReentrantLock testLock = new ReentrantLock(); - public static final ChunkAccess generate(List chunkList, ChunkAccess chunk) { - ProtoChunk protoChunk = (ProtoChunk) chunk; - if (chunk.getStatus() == STATUS) return chunk; - testLock.lock(); - try { - if (chunk.getStatus() != STATUS) { - - protoChunk.setLightEngine(lights); - - Heightmap.primeHeightmaps(chunk, - EnumSet.of(Heightmap.Types.MOTION_BLOCKING, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, - Heightmap.Types.OCEAN_FLOOR, Heightmap.Types.WORLD_SURFACE)); - - // This could be problematic. May need to lock the 8 surrounding chunks then. - WorldGenRegion worldGenRegion = new WorldGenRegion(level, chunkList, STATUS, 1); - - gen.applyBiomeDecoration(worldGenRegion, chunk, structFeat.forWorldGenRegion(worldGenRegion)); - //Blender.generateBorderTicks(worldGenRegion, chunk); - - protoChunk.setStatus(STATUS); - } - } finally { - testLock.unlock(); + for (ChunkAccess chunk : chunks) { + //System.out.println("StepStructureReference: "+chunk.getPos()); + params.generator.createReferences(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); + ((ProtoChunk) chunk).setStatus(STATUS); } - return chunk; } - + /* static ChunkAccess load(ChunkAccess chunk) { ((ProtoChunk) chunk).setStatus(STATUS); return chunk; - } + }*/ } + public class StepBiomes { + public final ChunkStatus STATUS = ChunkStatus.BIOMES; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); + + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks, Executor worker) { + for (ChunkAccess chunk : chunks) { + //System.out.println("StepBiomes: "+chunk.getPos()); + chunk = joinAsync(params.generator.createBiomes(params.biomes, worker, Blender.of(worldGenRegion), + tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk)); + ((ProtoChunk) chunk).setStatus(STATUS); + } + } + /* + static ChunkAccess load(ChunkAccess chunk) { + ((ProtoChunk) chunk).setStatus(STATUS); + return chunk; + }*/ + } + + public class StepNoise { + public final ChunkStatus STATUS = ChunkStatus.NOISE; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); + + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks, Executor worker) { + for (ChunkAccess chunk : chunks) { + //System.out.println("StepNoise: "+chunk.getPos()); + chunk = joinAsync(params.generator.fillFromNoise(worker, Blender.of(worldGenRegion), + tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk)); + ((ProtoChunk) chunk).setStatus(STATUS); + } + } + /* + static ChunkAccess load(ChunkAccess chunk) { + ((ProtoChunk) chunk).setStatus(STATUS); + return chunk; + }*/ + } + + public class StepSurface { + public final ChunkStatus STATUS = ChunkStatus.SURFACE; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); + + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { + for (ChunkAccess chunk : chunks) { + //System.out.println("StepSurface: "+chunk.getPos()); + params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), + chunk); + ((ProtoChunk) chunk).setStatus(STATUS); + } + } + /* + static ChunkAccess load(ChunkAccess chunk) { + ((ProtoChunk) chunk).setStatus(STATUS); + return chunk; + }*/ + } + + public class StepCarvers { + public final ChunkStatus STATUS = ChunkStatus.CARVERS; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); + + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { + for (ChunkAccess chunk : chunks) { + //System.out.println("StepCarvers: "+chunk.getPos()); + Blender.addAroundOldChunksCarvingMaskFilter((WorldGenLevel) worldGenRegion, (ProtoChunk) chunk); + params.generator.applyCarvers(worldGenRegion, params.worldSeed, params.biomeManager, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk, + GenerationStep.Carving.AIR); + ((ProtoChunk) chunk).setStatus(STATUS); + } + } + /* + static ChunkAccess load(ChunkAccess chunk) { + ((ProtoChunk) chunk).setStatus(STATUS); + return chunk; + }*/ + } + + public class StepLiquidCarvers { + public final ChunkStatus STATUS = ChunkStatus.LIQUID_CARVERS; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); + + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { + for (ChunkAccess chunk : chunks) { + Blender.addAroundOldChunksCarvingMaskFilter((WorldGenLevel) worldGenRegion, (ProtoChunk) chunk); + params.generator.applyCarvers(worldGenRegion, params.worldSeed, params.biomeManager, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk, + GenerationStep.Carving.AIR); + ((ProtoChunk) chunk).setStatus(STATUS); + } + } + /* + static ChunkAccess load(ChunkAccess chunk) { + ((ProtoChunk) chunk).setStatus(STATUS); + return chunk; + }*/ + } + + public class StepFeatures { + public final ChunkStatus STATUS = ChunkStatus.FEATURES; + public final int RANGE = STATUS.getRange(); + public final EnumSet HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); + + public final void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, GridList chunks) { + for (int i=0; i HEIGHTMAP_TYPES = STATUS.heightmapsAfter(); - private static ThreadedLevelLightEngine lightEngine; - - public final static void onLevelLoad(ThreadedLevelLightEngine engine) { - lightEngine = engine; - } public static final ChunkAccess generate(ChunkAccess chunk) { ((ProtoChunk) chunk).setStatus(STATUS); @@ -872,7 +649,7 @@ public class WorldGenerationStep { return joinAsync(lightEngine.lightChunk(chunk, chunk.isLightCorrect())); } } - +*/ // The following may not be needed /* * public static class Spawn implements SimpleGen {