mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
generation settings
This commit is contained in:
parent
56b428d501
commit
e83b70b5ae
@ -29,7 +29,6 @@ public class MonsterSettingsConfig implements ObjectTemplate<MonsterSettingsConf
|
||||
@Default
|
||||
private Integer monsterSpawnBlockLightLimit = null;
|
||||
|
||||
|
||||
public Boolean getPiglinSafe() {
|
||||
return piglinSafe;
|
||||
}
|
||||
@ -46,6 +45,8 @@ public class MonsterSettingsConfig implements ObjectTemplate<MonsterSettingsConf
|
||||
return monsterSpawnBlockLightLimit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public MonsterSettingsConfig get() {
|
||||
return this;
|
||||
|
@ -24,6 +24,10 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
|
||||
@Default
|
||||
private String vanillaDimension = "minecraft:overworld";
|
||||
|
||||
@Value("vanilla-generation")
|
||||
@Default
|
||||
private String vanillaGeneration = vanillaDimension;
|
||||
|
||||
@Value("minecraft.fixed-time")
|
||||
@Default
|
||||
private Long fixedTime = null;
|
||||
@ -80,6 +84,9 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
|
||||
@Default
|
||||
private MonsterSettingsConfig monsterSettings = null;
|
||||
|
||||
@Value("minecraft.mob-generation")
|
||||
@Default
|
||||
private Boolean mobGeneration = null;
|
||||
|
||||
@Value("minecraft.sealevel")
|
||||
@Default
|
||||
@ -89,6 +96,10 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
|
||||
return vanillaDimension;
|
||||
}
|
||||
|
||||
public String getVanillaGeneration() {
|
||||
return vanillaGeneration;
|
||||
}
|
||||
|
||||
public Long getFixedTime() {
|
||||
return fixedTime;
|
||||
}
|
||||
@ -121,8 +132,13 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
|
||||
return respawnAnchorWorks;
|
||||
}
|
||||
|
||||
public Range getHeight() {
|
||||
return height;
|
||||
public ConstantRange getHeight() {
|
||||
//TODO THIS IS BAD
|
||||
if (height != null) {
|
||||
return new ConstantRange(height.getMin(), height.getMax());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getLogicalHeight() {
|
||||
@ -145,6 +161,10 @@ public class VanillaWorldProperties implements ConfigTemplate, Properties {
|
||||
return monsterSettings;
|
||||
}
|
||||
|
||||
public Boolean getMobGeneration() {
|
||||
return mobGeneration;
|
||||
}
|
||||
|
||||
public Integer getSealevel() {
|
||||
return sealevel;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.dfsek.terra.mod.data;
|
||||
import com.dfsek.terra.api.util.ConstantRange;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
import com.dfsek.terra.mod.generation.GenerationSettings;
|
||||
import com.dfsek.terra.mod.implmentation.TerraIntProvider;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
@ -44,6 +45,18 @@ public final class Codecs {
|
||||
.forGetter(TerraBiomeSource::getPack))
|
||||
.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
|
||||
.create(
|
||||
instance -> instance.group(
|
||||
@ -53,7 +66,7 @@ public final class Codecs {
|
||||
CONFIG_PACK.fieldOf("pack")
|
||||
.stable()
|
||||
.forGetter(MinecraftChunkGeneratorWrapper::getPack),
|
||||
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings")
|
||||
TERRA_GENERATION_SETTINGS.fieldOf("settings")
|
||||
.stable()
|
||||
.forGetter(MinecraftChunkGeneratorWrapper::getSettings)
|
||||
).apply(instance, instance.stable(
|
||||
|
@ -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) {
|
||||
}
|
@ -74,13 +74,13 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
private static final Logger logger = LoggerFactory.getLogger(MinecraftChunkGeneratorWrapper.class);
|
||||
|
||||
private final TerraBiomeSource biomeSource;
|
||||
private final RegistryEntry<ChunkGeneratorSettings> settings;
|
||||
private final GenerationSettings settings;
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
|
||||
|
||||
public MinecraftChunkGeneratorWrapper(TerraBiomeSource biomeSource, ConfigPack configPack,
|
||||
RegistryEntry<ChunkGeneratorSettings> settingsSupplier) {
|
||||
GenerationSettings settingsSupplier) {
|
||||
super(biomeSource);
|
||||
this.pack = configPack;
|
||||
this.settings = settingsSupplier;
|
||||
@ -102,7 +102,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(!this.settings.value().mobGenerationDisabled()) {
|
||||
if(this.settings.mobGeneration()) {
|
||||
ChunkPos chunkPos = region.getCenterPos();
|
||||
RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopY() - 1));
|
||||
ChunkRandom chunkRandom = new ChunkRandom(new CheckedRandom(RandomSeed.getSeed()));
|
||||
@ -113,7 +113,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
|
||||
@Override
|
||||
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
|
||||
public int getSeaLevel() {
|
||||
return settings.value().seaLevel();
|
||||
return settings.sealevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
return settings.value().generationShapeConfig().minimumY();
|
||||
return settings.height().getMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -233,7 +233,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public RegistryEntry<ChunkGeneratorSettings> getSettings() {
|
||||
public GenerationSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ import java.util.OptionalLong;
|
||||
|
||||
|
||||
public class DimensionUtil {
|
||||
public static DimensionType createDimension(VanillaWorldProperties vanillaWorldProperties, ModPlatform platform) {
|
||||
public static DimensionType createDimension(VanillaWorldProperties vanillaWorldProperties, DimensionType defaultDimension, ModPlatform platform) {
|
||||
|
||||
MonsterSettingsConfig monsterSettingsConfig;
|
||||
if (vanillaWorldProperties.getMonsterSettings() != null) {
|
||||
@ -34,11 +34,6 @@ public class DimensionUtil {
|
||||
monsterSettingsConfig = new MonsterSettingsConfig();
|
||||
}
|
||||
|
||||
Registry<DimensionType> dimensionTypeRegistry = platform.dimensionTypeRegistry();
|
||||
|
||||
DimensionType defaultDimension = dimensionTypeRegistry.get(new Identifier(vanillaWorldProperties.getVanillaDimension()));
|
||||
|
||||
assert defaultDimension != null;
|
||||
MonsterSettings monsterSettings = getMonsterSettings(defaultDimension, monsterSettingsConfig);
|
||||
|
||||
return new DimensionType(
|
||||
@ -52,7 +47,7 @@ public class DimensionUtil {
|
||||
vanillaWorldProperties.getBedWorks() == null ? defaultDimension.bedWorks() : vanillaWorldProperties.getBedWorks(),
|
||||
vanillaWorldProperties.getRespawnAnchorWorks() == null ? defaultDimension.respawnAnchorWorks() : vanillaWorldProperties.getRespawnAnchorWorks(),
|
||||
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.getInfiniburn() == null ? defaultDimension.infiniburn() : TagKey.of(RegistryKeys.BLOCK, vanillaWorldProperties.getInfiniburn()),
|
||||
vanillaWorldProperties.getEffects() == null ? defaultDimension.effects() : vanillaWorldProperties.getEffects(),
|
||||
|
@ -1,7 +1,10 @@
|
||||
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.generation.GenerationSettings;
|
||||
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
@ -100,7 +103,11 @@ public class PresetUtil {
|
||||
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(
|
||||
Locale.ROOT)));
|
||||
|
||||
@ -110,11 +117,12 @@ public class PresetUtil {
|
||||
|
||||
TerraBiomeSource biomeSource = new TerraBiomeSource(pack);
|
||||
|
||||
RegistryEntry<ChunkGeneratorSettings> generatorSettings = chunkGeneratorSettingsRegistry.getEntry(chunkGeneratorSettingsRegistry.get(demensionIdentifier));
|
||||
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_", ""));
|
||||
generatorSettings = chunkGeneratorSettingsRegistry.getEntry(chunkGeneratorSettingsRegistry.get(demensionIdentifier2));
|
||||
}
|
||||
RegistryEntry<ChunkGeneratorSettings> defaultGeneratorSettings = chunkGeneratorSettingsRegistry.getEntry(chunkGeneratorSettingsRegistry.get(new Identifier(vanillaWorldProperties.getVanillaGeneration())));
|
||||
|
||||
GenerationSettings generatorSettings = new GenerationSettings(
|
||||
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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user