Skip to content

Commit a3a7339

Browse files
committed
Attempt to fix useVanillaChunkWorldGenerators
1 parent 2f45b0d commit a3a7339

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/main/java/io/github/opencubicchunks/cubicchunks/core/server/CubeProviderServer.java

+31-32
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
*/
2525
package io.github.opencubicchunks.cubicchunks.core.server;
2626

27+
import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld;
2728
import io.github.opencubicchunks.cubicchunks.api.world.storage.StorageFormatProviderBase;
2829
import io.github.opencubicchunks.cubicchunks.core.CubicChunksConfig;
29-
import io.github.opencubicchunks.cubicchunks.core.lighting.LightingManager;
3030
import io.github.opencubicchunks.cubicchunks.core.server.chunkio.AsyncBatchingCubeIO;
3131
import io.github.opencubicchunks.cubicchunks.core.server.chunkio.ICubeIO;
3232
import io.github.opencubicchunks.cubicchunks.core.server.chunkio.async.forge.AsyncWorldIOExecutor;
@@ -61,11 +61,11 @@
6161
import java.io.IOException;
6262
import java.io.UncheckedIOException;
6363
import java.nio.file.Path;
64+
import java.util.HashSet;
6465
import java.util.Iterator;
6566
import java.util.List;
6667
import java.util.Optional;
67-
import java.util.Random;
68-
import java.util.function.BooleanSupplier;
68+
import java.util.Set;
6969
import java.util.function.Consumer;
7070

7171
import javax.annotation.Detainted;
@@ -225,17 +225,6 @@ public boolean saveChunks(boolean alwaysTrue) {
225225

226226
@Override
227227
public boolean tick() {
228-
// NOTE: the return value is completely ignored
229-
profiler.startSection("providerTick");
230-
long i = System.currentTimeMillis();
231-
Random rand = this.world.rand;
232-
PlayerCubeMap playerCubeMap = ((PlayerCubeMap) this.world.getPlayerChunkMap());
233-
Iterator<Cube> watchersIterator = playerCubeMap.getCubeIterator();
234-
BooleanSupplier tickFaster = () -> System.currentTimeMillis() - i > 40;
235-
while (watchersIterator.hasNext()) {
236-
watchersIterator.next().tickCubeServer(tickFaster, rand);
237-
}
238-
profiler.endSection();
239228
return false;
240229
}
241230

@@ -493,25 +482,25 @@ private boolean populateCube(Cube cube, boolean forceNow) {
493482

494483
// for all cubes needed for full population - generate their population requirements
495484
Box fullPopulation = cubeGen.getFullPopulationRequirements(cube);
496-
if (CubicChunksConfig.useVanillaChunkWorldGenerators) {
497-
if (cube.getY() >= 0 && cube.getY() < 16) {
498-
fullPopulation = new Box(
499-
0, -cube.getY(), 0,
500-
0, 16 - cube.getY() - 1, 0
501-
).add(fullPopulation);
502-
}
503-
}
485+
boolean useVanillaGenerators = ((ICubicWorld) worldServer).isCubicWorld()
486+
&& CubicChunksConfig.useVanillaChunkWorldGenerators
487+
&& cube.getY() >= 0 && cube.getY() < 16;
488+
if (useVanillaGenerators) {
489+
fullPopulation = new Box(
490+
0, -cube.getY(), 0,
491+
0, 16 - cube.getY() - 1, 0
492+
).add(fullPopulation);
493+
}
494+
Set<Cube> newlyPopulatedCubes = new HashSet<>();
504495
boolean success = fullPopulation.allMatch((x, y, z) -> {
505496
// this also generates the cube
506497
Cube fullPopulationCube = getCube(x + cubeX, y + cubeY, z + cubeZ);
507498
Box newBox = cubeGen.getPopulationPregenerationRequirements(fullPopulationCube);
508-
if (CubicChunksConfig.useVanillaChunkWorldGenerators) {
509-
if (cube.getY() >= 0 && cube.getY() < 16) {
510-
newBox = new Box(
511-
0, -cube.getY(), 0,
512-
0, 16 - cube.getY() - 1, 0
513-
).add(newBox);
514-
}
499+
if (useVanillaGenerators) {
500+
newBox = new Box(
501+
0, -cube.getY(), 0,
502+
0, 16 - cube.getY() - 1, 0
503+
).add(newBox);
515504
}
516505
boolean generated = newBox.allMatch((nx, ny, nz) -> {
517506
int genX = cubeX + x + nx;
@@ -525,21 +514,31 @@ private boolean populateCube(Cube cube, boolean forceNow) {
525514
// a check for populators that populate more than one cube (vanilla compatibility generator)
526515
if (!fullPopulationCube.isPopulated()) {
527516
cubeGen.populate(fullPopulationCube);
528-
fullPopulationCube.setPopulated(true);
517+
newlyPopulatedCubes.add(fullPopulationCube);
529518
}
530519
return true;
531520
});
532521
if (!success) {
522+
for (Cube newlyPopulatedCube : newlyPopulatedCubes) {
523+
newlyPopulatedCube.setPopulated(true);
524+
}
533525
return false;
534526
}
535-
if (CubicChunksConfig.useVanillaChunkWorldGenerators) {
527+
if (useVanillaGenerators) {
536528
Box.Mutable box = fullPopulation.asMutable();
537529
box.setY1(0);
538530
box.setY2(0);
539531
box.forEachPoint((x, y, z) -> {
540-
GameRegistry.generateWorld(cube.getX() + x, cube.getZ() + z, world, chunkGenerator, world.getChunkProvider());
532+
Cube columnCube = getCube(cubeX + x, 0, cubeZ + z);
533+
if (!columnCube.isPopulated()) {
534+
GameRegistry.generateWorld(cubeX + x, cubeZ + z, world, chunkGenerator, world.getChunkProvider());
535+
columnCube.setFullyPopulated(true);
536+
}
541537
});
542538
}
539+
for (Cube newlyPopulatedCube : newlyPopulatedCubes) {
540+
newlyPopulatedCube.setPopulated(true);
541+
}
543542
cube.setFullyPopulated(true);
544543
return true;
545544
}

0 commit comments

Comments
 (0)