Move all pops to feature

This commit is contained in:
dfsek
2020-12-18 15:13:59 -07:00
parent fd89c1128a
commit 817b962c4a
3 changed files with 29 additions and 23 deletions

View File

@@ -22,7 +22,7 @@ import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor;
import com.dfsek.terra.fabric.world.FabricBiome;
import com.dfsek.terra.fabric.world.FabricWorldHandle;
import com.dfsek.terra.fabric.world.TerraBiomeSource;
import com.dfsek.terra.fabric.world.features.FloraFeature;
import com.dfsek.terra.fabric.world.features.PopulatorFeature;
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
import com.dfsek.terra.registry.ConfigRegistry;
import net.fabricmc.api.EnvType;
@@ -72,8 +72,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
return instance;
}
public static final FloraFeature FLORA = new FloraFeature(DefaultFeatureConfig.CODEC);
public static final ConfiguredFeature<?, ?> FLORA_CONFIGURED = FLORA.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
private final GenericLoaders genericLoaders = new GenericLoaders(this);
private final Logger logger = Logger.getLogger("Terra");
@@ -185,7 +185,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState()))); // It needs a surfacebuilder, even though we dont use it.
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, FLORA_CONFIGURED);
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE);
BiomeEffects.Builder effects = new BiomeEffects.Builder()
.waterColor(vanilla.getWaterColor())
@@ -246,9 +246,9 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
registry.loadAll(this);
Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), FLORA);
Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), POPULATOR_FEATURE);
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "flora_populator"));
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), FLORA_CONFIGURED);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
registry.forEach(pack -> pack.getBiomeRegistry().forEach(biome -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", createBiomeID(pack, biome)), createBiome(biome)))); // Register all Terra biomes.
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);

View File

@@ -13,15 +13,22 @@ import net.minecraft.world.gen.feature.Feature;
import java.util.Random;
public class FloraFeature extends Feature<DefaultFeatureConfig> {
public FloraFeature(Codec<DefaultFeatureConfig> codec) {
/**
* Feature wrapper for Terra populator
*/
public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
public PopulatorFeature(Codec<DefaultFeatureConfig> codec) {
super(codec);
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
((FabricChunkGeneratorWrapper) chunkGenerator).getFloraPopulator().populate(new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator)),
random, new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4));
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4);
FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator));
gen.getCavePopulator().populate(world1, random, chunk);
gen.getOrePopulator().populate(world1, random, chunk);
gen.getFloraPopulator().populate(world1, random, chunk);
return true;
}
}

View File

@@ -1,14 +1,11 @@
package com.dfsek.terra.fabric.world.generator;
import com.dfsek.terra.api.gaea.math.MathUtil;
import com.dfsek.terra.api.gaea.util.FastRandom;
import com.dfsek.terra.api.generic.Handle;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.world.TerraBiomeSource;
import com.dfsek.terra.fabric.world.handles.chunk.FabricChunkWorldAccess;
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
import com.dfsek.terra.fabric.world.handles.world.FabricWorldChunkRegion;
import com.dfsek.terra.generation.TerraChunkGenerator;
import com.dfsek.terra.population.CavePopulator;
import com.dfsek.terra.population.FloraPopulator;
@@ -53,6 +50,18 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance());
private final TreePopulator treePopulator = new TreePopulator(TerraFabricPlugin.getInstance());
public TreePopulator getTreePopulator() {
return treePopulator;
}
public CavePopulator getCavePopulator() {
return cavePopulator;
}
public OrePopulator getOrePopulator() {
return orePopulator;
}
public FloraPopulator getFloraPopulator() {
return floraPopulator;
}
@@ -99,16 +108,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
// No caves
}
@Override
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
FastRandom pop = new FastRandom(MathUtil.getCarverChunkSeed(region.getCenterChunkX(), region.getCenterChunkZ(), seed));
FabricWorldChunkRegion chunkRegion = new FabricWorldChunkRegion(region, this);
FabricChunkWorldAccess regionChunk = new FabricChunkWorldAccess(region, region.getCenterChunkX(), region.getCenterChunkZ());
cavePopulator.populate(chunkRegion, pop, regionChunk);
orePopulator.populate(chunkRegion, pop, regionChunk);
super.generateFeatures(region, accessor);
}
@Override
public void setStructureStarts(DynamicRegistryManager dynamicRegistryManager, StructureAccessor structureAccessor, Chunk chunk, StructureManager structureManager, long worldSeed) {