include generator settings in FabricChunkGeneratorWrapper codec

This commit is contained in:
dfsek
2021-12-22 17:52:59 -07:00
parent 26dd7e1eea
commit fd3335508b
3 changed files with 43 additions and 21 deletions
@@ -43,6 +43,7 @@ import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.Blender; import net.minecraft.world.gen.chunk.Blender;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.StructuresConfig; import net.minecraft.world.gen.chunk.StructuresConfig;
import net.minecraft.world.gen.chunk.VerticalBlockSample; import net.minecraft.world.gen.chunk.VerticalBlockSample;
import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.feature.*;
@@ -54,6 +55,7 @@ import org.slf4j.LoggerFactory;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.function.Supplier;
public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper { public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper {
@@ -76,7 +78,9 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
Codec.LONG.fieldOf("seed").stable() Codec.LONG.fieldOf("seed").stable()
.forGetter(generator -> generator.seed), .forGetter(generator -> generator.seed),
PACK_CODEC.fieldOf("pack").stable() PACK_CODEC.fieldOf("pack").stable()
.forGetter(generator -> generator.pack) .forGetter(generator -> generator.pack),
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings")
.forGetter(generator -> generator.settingsSupplier)
).apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)) ).apply(instance, instance.stable(FabricChunkGeneratorWrapper::new))
); );
@@ -85,10 +89,13 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
private ChunkGenerator delegate; private ChunkGenerator delegate;
private ConfigPack pack; private ConfigPack pack;
private net.minecraft.server.world.ServerWorld world; private net.minecraft.server.world.ServerWorld world;
private final Supplier<ChunkGeneratorSettings> settingsSupplier;
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) { public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack,
Supplier<ChunkGeneratorSettings> settingsSupplier) {
super(biomeSource, new StructuresConfig(true)); super(biomeSource, new StructuresConfig(true));
this.pack = configPack; this.pack = configPack;
this.settingsSupplier = settingsSupplier;
this.delegate = pack.getGeneratorProvider().newInstance(pack); this.delegate = pack.getGeneratorProvider().newInstance(pack);
logger.info("Loading world with config pack {}", pack.getID()); logger.info("Loading world with config pack {}", pack.getID());
@@ -104,7 +111,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
@Override @Override
public net.minecraft.world.gen.chunk.ChunkGenerator withSeed(long seed) { public net.minecraft.world.gen.chunk.ChunkGenerator withSeed(long seed) {
return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack); return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack, settingsSupplier);
} }
@Override @Override
@@ -29,6 +29,10 @@ import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint; import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent; import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class TerraGeneratorType extends GeneratorType { public class TerraGeneratorType extends GeneratorType {
@@ -41,6 +45,8 @@ public class TerraGeneratorType extends GeneratorType {
@Override @Override
protected ChunkGenerator getChunkGenerator(DynamicRegistryManager manager, long seed) { protected ChunkGenerator getChunkGenerator(DynamicRegistryManager manager, long seed) {
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(manager.get(Registry.BIOME_KEY), seed, pack), seed, pack); Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = manager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
Supplier<ChunkGeneratorSettings> settingsSupplier = () -> chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.OVERWORLD);
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(manager.get(Registry.BIOME_KEY), seed, pack), seed, pack, settingsSupplier);
} }
} }
@@ -25,6 +25,7 @@ import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionOptions; import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.GeneratorOptions; import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -32,6 +33,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Properties; import java.util.Properties;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.fabric.FabricEntryPoint; import com.dfsek.terra.fabric.FabricEntryPoint;
@@ -57,16 +59,16 @@ public abstract class GeneratorOptionsMixin {
String prop = properties.get("level-type").toString().trim(); String prop = properties.get("level-type").toString().trim();
if(prop.startsWith("Terra")) { if(prop.startsWith("Terra")) {
String seed = (String) MoreObjects.firstNonNull(properties.get("level-seed"), ""); String seedProperty = (String) properties.get("level-seed");
long l = new Random().nextLong(); long seed = new Random().nextLong();
if(!seed.isEmpty()) { if(seedProperty != null) {
try { try {
long m = Long.parseLong(seed); long m = Long.parseLong(seedProperty);
if(m != 0L) { if(m != 0L) {
l = m; seed = m;
} }
} catch(NumberFormatException exception) { } catch(NumberFormatException exception) {
l = seed.hashCode(); seed = seedProperty.hashCode();
} }
} }
@@ -74,8 +76,11 @@ public abstract class GeneratorOptionsMixin {
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures); boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
Registry<DimensionType> dimensionTypes = registryManager.get(Registry.DIMENSION_TYPE_KEY); Registry<DimensionType> dimensionTypes = registryManager.get(Registry.DIMENSION_TYPE_KEY);
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY); Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(registryManager, SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(registryManager, seed, false);
l, false);
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = registryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
Supplier<ChunkGeneratorSettings>
settingsSupplier = () -> chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.OVERWORLD);
prop = prop.substring(prop.indexOf(":") + 1); prop = prop.substring(prop.indexOf(":") + 1);
@@ -83,14 +88,18 @@ public abstract class GeneratorOptionsMixin {
ConfigPack config = main.getConfigRegistry().get(prop).orElseThrow(() -> new IllegalArgumentException( ConfigPack config = main.getConfigRegistry().get(prop).orElseThrow(() -> new IllegalArgumentException(
"No such pack " + finalProp)); "No such pack " + finalProp));
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, cir.setReturnValue(
GeneratorOptions.getRegistryWithReplacedOverworldGenerator(dimensionTypes, new GeneratorOptions(seed,
dimensionOptions, generateStructures,
new FabricChunkGeneratorWrapper( false,
new TerraBiomeSource( GeneratorOptions
biomeRegistry, .getRegistryWithReplacedOverworldGenerator(
l, config), dimensionTypes,
l, config)))); dimensionOptions,
new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, config),
seed,
config,
settingsSupplier))));
} }
} }
} }