generation settings

This commit is contained in:
Zoë Gidiere 2023-12-12 18:52:31 -07:00
parent 56b428d501
commit e83b70b5ae
7 changed files with 69 additions and 24 deletions

View File

@ -29,7 +29,6 @@ public class MonsterSettingsConfig implements ObjectTemplate<MonsterSettingsConf
@Default @Default
private Integer monsterSpawnBlockLightLimit = null; private Integer monsterSpawnBlockLightLimit = null;
public Boolean getPiglinSafe() { public Boolean getPiglinSafe() {
return piglinSafe; return piglinSafe;
} }
@ -46,6 +45,8 @@ public class MonsterSettingsConfig implements ObjectTemplate<MonsterSettingsConf
return monsterSpawnBlockLightLimit; return monsterSpawnBlockLightLimit;
} }
@Override @Override
public MonsterSettingsConfig get() { public MonsterSettingsConfig get() {
return this; return this;

View File

@ -24,6 +24,10 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
@Default @Default
private String vanillaDimension = "minecraft:overworld"; private String vanillaDimension = "minecraft:overworld";
@Value("vanilla-generation")
@Default
private String vanillaGeneration = vanillaDimension;
@Value("minecraft.fixed-time") @Value("minecraft.fixed-time")
@Default @Default
private Long fixedTime = null; private Long fixedTime = null;
@ -80,6 +84,9 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
@Default @Default
private MonsterSettingsConfig monsterSettings = null; private MonsterSettingsConfig monsterSettings = null;
@Value("minecraft.mob-generation")
@Default
private Boolean mobGeneration = null;
@Value("minecraft.sealevel") @Value("minecraft.sealevel")
@Default @Default
@ -89,6 +96,10 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
return vanillaDimension; return vanillaDimension;
} }
public String getVanillaGeneration() {
return vanillaGeneration;
}
public Long getFixedTime() { public Long getFixedTime() {
return fixedTime; return fixedTime;
} }
@ -121,8 +132,13 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
return respawnAnchorWorks; return respawnAnchorWorks;
} }
public Range getHeight() { public ConstantRange getHeight() {
return height; //TODO THIS IS BAD
if (height != null) {
return new ConstantRange(height.getMin(), height.getMax());
} else {
return null;
}
} }
public Integer getLogicalHeight() { public Integer getLogicalHeight() {
@ -145,6 +161,10 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
return monsterSettings; return monsterSettings;
} }
public Boolean getMobGeneration() {
return mobGeneration;
}
public Integer getSealevel() { public Integer getSealevel() {
return sealevel; return sealevel;
} }

View File

@ -3,6 +3,7 @@ package com.dfsek.terra.mod.data;
import com.dfsek.terra.api.util.ConstantRange; import com.dfsek.terra.api.util.ConstantRange;
import com.dfsek.terra.api.util.Range; import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.mod.generation.GenerationSettings;
import com.dfsek.terra.mod.implmentation.TerraIntProvider; import com.dfsek.terra.mod.implmentation.TerraIntProvider;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
@ -44,6 +45,18 @@ public final class Codecs {
.forGetter(TerraBiomeSource::getPack)) .forGetter(TerraBiomeSource::getPack))
.apply(instance, instance.stable(TerraBiomeSource::new))); .apply(instance, instance.stable(TerraBiomeSource::new)));
public static final Codec<ConstantRange> TERRA_CONSTANT_RANGE = RecordCodecBuilder.create(range -> range.group(
Codec.INT.fieldOf("min").stable().forGetter(ConstantRange::getMin),
Codec.INT.fieldOf("max").stable().forGetter(ConstantRange::getMax)).apply(range, range.stable(ConstantRange::new)));
public static final Codec<GenerationSettings> TERRA_GENERATION_SETTINGS = RecordCodecBuilder
.create(instance -> instance.group(
TERRA_CONSTANT_RANGE.fieldOf("height").stable().forGetter(GenerationSettings::height),
Codec.INT.fieldOf("sealevel").forGetter(GenerationSettings::sealevel),
Codec.BOOL.fieldOf("mob_generation").forGetter(GenerationSettings::mobGeneration))
.apply(instance, instance.stable(GenerationSettings::new)));
public static final Codec<MinecraftChunkGeneratorWrapper> MINECRAFT_CHUNK_GENERATOR_WRAPPER = RecordCodecBuilder public static final Codec<MinecraftChunkGeneratorWrapper> MINECRAFT_CHUNK_GENERATOR_WRAPPER = RecordCodecBuilder
.create( .create(
instance -> instance.group( instance -> instance.group(
@ -53,7 +66,7 @@ public final class Codecs {
CONFIG_PACK.fieldOf("pack") CONFIG_PACK.fieldOf("pack")
.stable() .stable()
.forGetter(MinecraftChunkGeneratorWrapper::getPack), .forGetter(MinecraftChunkGeneratorWrapper::getPack),
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings") TERRA_GENERATION_SETTINGS.fieldOf("settings")
.stable() .stable()
.forGetter(MinecraftChunkGeneratorWrapper::getSettings) .forGetter(MinecraftChunkGeneratorWrapper::getSettings)
).apply(instance, instance.stable( ).apply(instance, instance.stable(

View File

@ -0,0 +1,8 @@
package com.dfsek.terra.mod.generation;
import com.dfsek.terra.api.util.ConstantRange;
import com.dfsek.terra.api.util.Range;
public record GenerationSettings(ConstantRange height, Integer sealevel, Boolean mobGeneration) {
}

View File

@ -74,13 +74,13 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
private static final Logger logger = LoggerFactory.getLogger(MinecraftChunkGeneratorWrapper.class); private static final Logger logger = LoggerFactory.getLogger(MinecraftChunkGeneratorWrapper.class);
private final TerraBiomeSource biomeSource; private final TerraBiomeSource biomeSource;
private final RegistryEntry<ChunkGeneratorSettings> settings; private final GenerationSettings settings;
private ChunkGenerator delegate; private ChunkGenerator delegate;
private ConfigPack pack; private ConfigPack pack;
public MinecraftChunkGeneratorWrapper(TerraBiomeSource biomeSource, ConfigPack configPack, public MinecraftChunkGeneratorWrapper(TerraBiomeSource biomeSource, ConfigPack configPack,
RegistryEntry<ChunkGeneratorSettings> settingsSupplier) { GenerationSettings settingsSupplier) {
super(biomeSource); super(biomeSource);
this.pack = configPack; this.pack = configPack;
this.settings = settingsSupplier; this.settings = settingsSupplier;
@ -102,7 +102,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
@Override @Override
public void populateEntities(ChunkRegion region) { public void populateEntities(ChunkRegion region) {
if(!this.settings.value().mobGenerationDisabled()) { if(this.settings.mobGeneration()) {
ChunkPos chunkPos = region.getCenterPos(); ChunkPos chunkPos = region.getCenterPos();
RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopY() - 1)); RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopY() - 1));
ChunkRandom chunkRandom = new ChunkRandom(new CheckedRandom(RandomSeed.getSeed())); ChunkRandom chunkRandom = new ChunkRandom(new CheckedRandom(RandomSeed.getSeed()));
@ -113,7 +113,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
@Override @Override
public int getWorldHeight() { public int getWorldHeight() {
return settings.value().generationShapeConfig().height(); return settings.height().getRange();
} }
@ -173,12 +173,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
@Override @Override
public int getSeaLevel() { public int getSeaLevel() {
return settings.value().seaLevel(); return settings.sealevel();
} }
@Override @Override
public int getMinimumY() { public int getMinimumY() {
return settings.value().generationShapeConfig().minimumY(); return settings.height().getMin();
} }
@Override @Override
@ -233,7 +233,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
return delegate; return delegate;
} }
public RegistryEntry<ChunkGeneratorSettings> getSettings() { public GenerationSettings getSettings() {
return settings; return settings;
} }

View File

@ -25,7 +25,7 @@ import java.util.OptionalLong;
public class DimensionUtil { public class DimensionUtil {
public static DimensionType createDimension(VanillaWorldProperties vanillaWorldProperties, ModPlatform platform) { public static DimensionType createDimension(VanillaWorldProperties vanillaWorldProperties, DimensionType defaultDimension, ModPlatform platform) {
MonsterSettingsConfig monsterSettingsConfig; MonsterSettingsConfig monsterSettingsConfig;
if (vanillaWorldProperties.getMonsterSettings() != null) { if (vanillaWorldProperties.getMonsterSettings() != null) {
@ -34,11 +34,6 @@ public class DimensionUtil {
monsterSettingsConfig = new MonsterSettingsConfig(); monsterSettingsConfig = new MonsterSettingsConfig();
} }
Registry<DimensionType> dimensionTypeRegistry = platform.dimensionTypeRegistry();
DimensionType defaultDimension = dimensionTypeRegistry.get(new Identifier(vanillaWorldProperties.getVanillaDimension()));
assert defaultDimension != null;
MonsterSettings monsterSettings = getMonsterSettings(defaultDimension, monsterSettingsConfig); MonsterSettings monsterSettings = getMonsterSettings(defaultDimension, monsterSettingsConfig);
return new DimensionType( return new DimensionType(
@ -52,7 +47,7 @@ public class DimensionUtil {
vanillaWorldProperties.getBedWorks() == null ? defaultDimension.bedWorks() : vanillaWorldProperties.getBedWorks(), vanillaWorldProperties.getBedWorks() == null ? defaultDimension.bedWorks() : vanillaWorldProperties.getBedWorks(),
vanillaWorldProperties.getRespawnAnchorWorks() == null ? defaultDimension.respawnAnchorWorks() : vanillaWorldProperties.getRespawnAnchorWorks(), vanillaWorldProperties.getRespawnAnchorWorks() == null ? defaultDimension.respawnAnchorWorks() : vanillaWorldProperties.getRespawnAnchorWorks(),
vanillaWorldProperties.getHeight() == null ? defaultDimension.minY() : vanillaWorldProperties.getHeight().getMin(), vanillaWorldProperties.getHeight() == null ? defaultDimension.minY() : vanillaWorldProperties.getHeight().getMin(),
vanillaWorldProperties.getHeight() == null ? defaultDimension.height() : vanillaWorldProperties.getHeight().getMax(), vanillaWorldProperties.getHeight() == null ? defaultDimension.height() : vanillaWorldProperties.getHeight().getRange(),
vanillaWorldProperties.getLogicalHeight() == null ? defaultDimension.logicalHeight() : vanillaWorldProperties.getLogicalHeight(), vanillaWorldProperties.getLogicalHeight() == null ? defaultDimension.logicalHeight() : vanillaWorldProperties.getLogicalHeight(),
vanillaWorldProperties.getInfiniburn() == null ? defaultDimension.infiniburn() : TagKey.of(RegistryKeys.BLOCK, vanillaWorldProperties.getInfiniburn()), vanillaWorldProperties.getInfiniburn() == null ? defaultDimension.infiniburn() : TagKey.of(RegistryKeys.BLOCK, vanillaWorldProperties.getInfiniburn()),
vanillaWorldProperties.getEffects() == null ? defaultDimension.effects() : vanillaWorldProperties.getEffects(), vanillaWorldProperties.getEffects() == null ? defaultDimension.effects() : vanillaWorldProperties.getEffects(),

View File

@ -1,7 +1,10 @@
package com.dfsek.terra.mod.util; package com.dfsek.terra.mod.util;
import com.dfsek.terra.api.util.ConstantRange;
import com.dfsek.terra.mod.config.VanillaWorldProperties; import com.dfsek.terra.mod.config.VanillaWorldProperties;
import com.dfsek.terra.mod.generation.GenerationSettings;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
@ -100,7 +103,11 @@ public class PresetUtil {
vanillaWorldProperties = new VanillaWorldProperties(); vanillaWorldProperties = new VanillaWorldProperties();
} }
DimensionType dimensionType = DimensionUtil.createDimension(vanillaWorldProperties, platform); DimensionType defaultDimension = dimensionTypeRegistry.get(new Identifier(vanillaWorldProperties.getVanillaDimension()));
assert defaultDimension != null;
DimensionType dimensionType = DimensionUtil.createDimension(vanillaWorldProperties, defaultDimension, platform);
RegistryKey<DimensionType> dimensionTypeRegistryKey = MinecraftUtil.registerDimensionTypeKey(new Identifier("terra", pack.getID().toLowerCase( RegistryKey<DimensionType> dimensionTypeRegistryKey = MinecraftUtil.registerDimensionTypeKey(new Identifier("terra", pack.getID().toLowerCase(
Locale.ROOT))); Locale.ROOT)));
@ -110,11 +117,12 @@ public class PresetUtil {
TerraBiomeSource biomeSource = new TerraBiomeSource(pack); TerraBiomeSource biomeSource = new TerraBiomeSource(pack);
RegistryEntry<ChunkGeneratorSettings> generatorSettings = chunkGeneratorSettingsRegistry.getEntry(chunkGeneratorSettingsRegistry.get(demensionIdentifier)); RegistryEntry<ChunkGeneratorSettings> defaultGeneratorSettings = chunkGeneratorSettingsRegistry.getEntry(chunkGeneratorSettingsRegistry.get(new Identifier(vanillaWorldProperties.getVanillaGeneration())));
if (key.equals("minecraft:the_nether") || key.equals("minecraft:the_end")) { //TODO REMOVE WHEN ADDING CUSTOM GEN SETTINGS
Identifier demensionIdentifier2 = new Identifier(key.replace("the_", "")); GenerationSettings generatorSettings = new GenerationSettings(
generatorSettings = chunkGeneratorSettingsRegistry.getEntry(chunkGeneratorSettingsRegistry.get(demensionIdentifier2)); vanillaWorldProperties.getHeight() == null ? new ConstantRange(defaultGeneratorSettings.value().generationShapeConfig().minimumY(), defaultGeneratorSettings.value().generationShapeConfig().height()) : vanillaWorldProperties.getHeight(),
} vanillaWorldProperties.getSealevel() == null ? defaultGeneratorSettings.value().seaLevel() : vanillaWorldProperties.getSealevel(),
vanillaWorldProperties.getMobGeneration() == null ? !defaultGeneratorSettings.value().mobGenerationDisabled() : vanillaWorldProperties.getMobGeneration());
ChunkGenerator generator = new MinecraftChunkGeneratorWrapper(biomeSource, pack, generatorSettings); ChunkGenerator generator = new MinecraftChunkGeneratorWrapper(biomeSource, pack, generatorSettings);