generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for default generator access in config
- Loading branch information
Showing
4 changed files
with
100 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/net/pixaurora/janerator/worldgen/generator/PreparedGenerators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.pixaurora.janerator.worldgen.generator; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import net.minecraft.core.HolderGetter; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.RegistryOps; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.chunk.ChunkGenerator; | ||
import net.minecraft.world.level.dimension.LevelStem; | ||
|
||
public class PreparedGenerators { | ||
public static final Codec<PreparedGenerators> CODEC = RecordCodecBuilder.create( | ||
instance -> instance.group( | ||
Codec.unboundedMap(Codec.STRING, ChunkGenerator.CODEC).fieldOf("defined").forGetter(PreparedGenerators::userGenerators), | ||
Codec.unboundedMap(Codec.STRING, ResourceKey.codec(Registries.DIMENSION)).fieldOf("default_generator_dimensions").forGetter(PreparedGenerators::defaultGeneratorDimensions), | ||
RegistryOps.retrieveGetter(Registries.LEVEL_STEM) | ||
).apply(instance, PreparedGenerators::new) | ||
); | ||
|
||
public final Map<String, ChunkGenerator> userGenerators; | ||
public final Map<String, ResourceKey<Level>> defaultGenerators; | ||
|
||
public final Map<String, ChunkGenerator> allGenerators; | ||
|
||
public PreparedGenerators(Map<String, ChunkGenerator> userGenerators, | ||
Map<String, ResourceKey<Level>> defaultGeneratorDimensions, | ||
HolderGetter<LevelStem> dimensionGeneratorRegistry) { | ||
this.userGenerators = userGenerators; | ||
this.defaultGenerators = defaultGeneratorDimensions; | ||
|
||
this.allGenerators = new HashMap<>(); | ||
|
||
this.allGenerators.putAll(userGenerators); | ||
for (Map.Entry<String, ResourceKey<Level>> specifiedDefault : defaultGeneratorDimensions.entrySet()) { | ||
ResourceKey<LevelStem> generatorLocation = Registries.levelToLevelStem(specifiedDefault.getValue()); | ||
LevelStem defaultGenerator = dimensionGeneratorRegistry.get(generatorLocation).get().value(); | ||
|
||
this.allGenerators.put(specifiedDefault.getKey(), defaultGenerator.generator()); | ||
} | ||
} | ||
|
||
public Map<String, ChunkGenerator> userGenerators() { | ||
return this.userGenerators; | ||
} | ||
|
||
public Map<String, ResourceKey<Level>> defaultGeneratorDimensions() { | ||
return this.defaultGenerators; | ||
} | ||
|
||
public ChunkGenerator get(String name) { | ||
return this.allGenerators.get(name); | ||
} | ||
|
||
public Collection<ChunkGenerator> getAll() { | ||
return this.allGenerators.values(); | ||
} | ||
} |