mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
include generator settings in FabricChunkGeneratorWrapper codec
This commit is contained in:
@@ -43,6 +43,7 @@ import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
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.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.feature.*;
|
||||
@@ -54,6 +55,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
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()
|
||||
.forGetter(generator -> generator.seed),
|
||||
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))
|
||||
);
|
||||
|
||||
@@ -85,10 +89,13 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
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));
|
||||
this.pack = configPack;
|
||||
this.settingsSupplier = settingsSupplier;
|
||||
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
logger.info("Loading world with config pack {}", pack.getID());
|
||||
@@ -104,7 +111,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -29,6 +29,10 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.fabric.FabricEntryPoint;
|
||||
import com.dfsek.terra.fabric.event.BiomeRegistrationEvent;
|
||||
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class TerraGeneratorType extends GeneratorType {
|
||||
@@ -41,6 +45,8 @@ public class TerraGeneratorType extends GeneratorType {
|
||||
|
||||
@Override
|
||||
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.DimensionType;
|
||||
import net.minecraft.world.gen.GeneratorOptions;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
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.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.fabric.FabricEntryPoint;
|
||||
@@ -57,16 +59,16 @@ public abstract class GeneratorOptionsMixin {
|
||||
|
||||
String prop = properties.get("level-type").toString().trim();
|
||||
if(prop.startsWith("Terra")) {
|
||||
String seed = (String) MoreObjects.firstNonNull(properties.get("level-seed"), "");
|
||||
long l = new Random().nextLong();
|
||||
if(!seed.isEmpty()) {
|
||||
String seedProperty = (String) properties.get("level-seed");
|
||||
long seed = new Random().nextLong();
|
||||
if(seedProperty != null) {
|
||||
try {
|
||||
long m = Long.parseLong(seed);
|
||||
long m = Long.parseLong(seedProperty);
|
||||
if(m != 0L) {
|
||||
l = m;
|
||||
seed = m;
|
||||
}
|
||||
} catch(NumberFormatException exception) {
|
||||
l = seed.hashCode();
|
||||
seed = seedProperty.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,23 +76,30 @@ public abstract class GeneratorOptionsMixin {
|
||||
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
|
||||
Registry<DimensionType> dimensionTypes = registryManager.get(Registry.DIMENSION_TYPE_KEY);
|
||||
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
|
||||
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(registryManager,
|
||||
l, false);
|
||||
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(registryManager, seed, false);
|
||||
|
||||
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = registryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
|
||||
Supplier<ChunkGeneratorSettings>
|
||||
settingsSupplier = () -> chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.OVERWORLD);
|
||||
|
||||
prop = prop.substring(prop.indexOf(":") + 1);
|
||||
|
||||
|
||||
String finalProp = prop;
|
||||
ConfigPack config = main.getConfigRegistry().get(prop).orElseThrow(() -> new IllegalArgumentException(
|
||||
"No such pack " + finalProp));
|
||||
|
||||
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false,
|
||||
GeneratorOptions.getRegistryWithReplacedOverworldGenerator(dimensionTypes,
|
||||
dimensionOptions,
|
||||
new FabricChunkGeneratorWrapper(
|
||||
new TerraBiomeSource(
|
||||
biomeRegistry,
|
||||
l, config),
|
||||
l, config))));
|
||||
cir.setReturnValue(
|
||||
new GeneratorOptions(seed,
|
||||
generateStructures,
|
||||
false,
|
||||
GeneratorOptions
|
||||
.getRegistryWithReplacedOverworldGenerator(
|
||||
dimensionTypes,
|
||||
dimensionOptions,
|
||||
new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, config),
|
||||
seed,
|
||||
config,
|
||||
settingsSupplier))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user