Skip to content

Commit

Permalink
refactor: remove light related things in allay world generator
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Nov 10, 2024
1 parent be62d90 commit 452bc7c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public enum ChunkState {
EMPTY,
NOISED,
POPULATED,
LIGHTED,
ENTITY_SPAWNED,
FINISHED
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.allaymc.api.world.Dimension;
import org.allaymc.api.world.chunk.Chunk;
import org.allaymc.api.world.generator.function.EntitySpawner;
import org.allaymc.api.world.generator.function.Lighter;
import org.allaymc.api.world.generator.function.Noiser;
import org.allaymc.api.world.generator.function.Populator;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -134,15 +133,6 @@ interface WorldGeneratorBuilder {
*/
WorldGeneratorBuilder populators(Populator... populators);

/**
* Set the lighters of the generator.
*
* @param lighters the lighters
*
* @return the builder
*/
WorldGeneratorBuilder lighters(Lighter... lighters);

/**
* Set the entity spawners of the generator.
*
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import org.allaymc.api.world.generator.WorldGenerator;
import org.allaymc.api.world.generator.WorldGeneratorType;
import org.allaymc.api.world.generator.context.EntitySpawnContext;
import org.allaymc.api.world.generator.context.LightContext;
import org.allaymc.api.world.generator.context.NoiseContext;
import org.allaymc.api.world.generator.context.PopulateContext;
import org.allaymc.api.world.generator.function.EntitySpawner;
import org.allaymc.api.world.generator.function.Lighter;
import org.allaymc.api.world.generator.function.Noiser;
import org.allaymc.api.world.generator.function.Populator;
import org.allaymc.server.AllayServer;
Expand All @@ -44,7 +42,6 @@ public class AllayWorldGenerator implements WorldGenerator {
private final String preset;
private final List<Noiser> noisers;
private final List<Populator> populators;
private final List<Lighter> lighters;
private final List<EntitySpawner> entitySpawners;
private final Consumer<Dimension> onDimensionSet;
private final Map<Long, CompletableFuture<Chunk>> chunkNoiseFutures = new Long2ObjectNonBlockingMap<>();
Expand All @@ -63,7 +60,6 @@ private AllayWorldGenerator(
String preset,
List<Noiser> noisers,
List<Populator> populators,
List<Lighter> lighters,
List<EntitySpawner> entitySpawners,
Consumer<Dimension> onDimensionSet
) {
Expand All @@ -72,7 +68,6 @@ private AllayWorldGenerator(
this.preset = preset;
this.noisers = noisers;
this.populators = populators;
this.lighters = lighters;
this.entitySpawners = entitySpawners;
this.onDimensionSet = onDimensionSet;
this.populationQueueThread = Thread.ofVirtual()
Expand All @@ -85,7 +80,6 @@ private AllayWorldGenerator(

this.noisers.forEach(noiser -> noiser.init(this));
this.populators.forEach(populator -> populator.init(this));
this.lighters.forEach(lighter -> lighter.init(this));
this.entitySpawners.forEach(entitySpawner -> entitySpawner.init(this));
}

Expand Down Expand Up @@ -258,20 +252,6 @@ private void statusNoisedToPopulated(Chunk chunk) {
}

private void statusPopulatedToFinished(Chunk chunk) {
// Bake lighting
var lightContext = new LightContext(chunk.toUnsafeChunk());
for (var lighter : lighters) {
try {
if (!lighter.apply(lightContext)) {
log.error("Failed to light chunk {} with lighter {}", chunk, lighter.getName());
}
} catch (Throwable t) {
log.error("Error while lighting chunk {} with lighter {}", chunk, lighter.getName());
}
}

((AllayChunk) chunk).setState(ChunkState.LIGHTED);

// Spawn entities
var entitySpawnContext = new EntitySpawnContext(chunk.toUnsafeChunk());
for (var entitySpawner : entitySpawners) {
Expand All @@ -295,7 +275,6 @@ protected static final class AllayWorldGeneratorBuilder implements WorldGenerato
private String preset = "";
private List<Noiser> noisers = List.of();
private List<Populator> populators = List.of();
private List<Lighter> lighters = List.of();
private List<EntitySpawner> entitySpawners = List.of();
private Consumer<Dimension> onDimensionSet = dimension -> {};

Expand Down Expand Up @@ -324,11 +303,6 @@ public AllayWorldGeneratorBuilder populators(Populator... populators) {
return this;
}

public AllayWorldGeneratorBuilder lighters(Lighter... lighters) {
this.lighters = List.of(lighters);
return this;
}

public AllayWorldGeneratorBuilder entitySpawners(EntitySpawner... entitySpawners) {
this.entitySpawners = List.of(entitySpawners);
return this;
Expand All @@ -343,7 +317,7 @@ public WorldGenerator build() {
if (name == null || name.isBlank()) {
throw new IllegalStateException("Name cannot be null or blank");
}
return new AllayWorldGenerator(name, type, preset, noisers, populators, lighters, entitySpawners, onDimensionSet);
return new AllayWorldGenerator(name, type, preset, noisers, populators, entitySpawners, onDimensionSet);
}
}

Expand Down

0 comments on commit 452bc7c

Please sign in to comment.