renames + further work on surface generation

This commit is contained in:
dags- 2020-05-18 23:22:31 +01:00
parent f7acb07e2c
commit 9b9a9919cc
26 changed files with 274 additions and 190 deletions

2
Engine

@ -1 +1 @@
Subproject commit 72761aee8511f7c30c99ec5a8f291211325a433a
Subproject commit 638e8033704f282b7e737ce2fd6d4e5653a1e1b8

@ -1 +1 @@
Subproject commit da99ddb3bbfbb6dbd4ced8a8278c27742a1da272
Subproject commit e0a7f101243b6d54a6e5943b424e5a3b4cf3b93c

View File

@ -37,7 +37,7 @@ import com.terraforged.settings.SettingsHelper;
import com.terraforged.settings.TerraSettings;
import com.terraforged.util.Environment;
import com.terraforged.util.nbt.NBTHelper;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.CreateWorldScreen;
import net.minecraft.world.IWorld;
@ -76,7 +76,7 @@ public class TerraWorld extends WorldType {
settings.world.seed = world.getSeed();
settings.dimensions.dimensions.apply(world.getWorldInfo());
Terrains terrains = Terrains.create(settings);
TerrainTypes terrains = TerrainTypes.create(settings);
OverworldGenSettings genSettings = new TerraGenSettings(settings.structures);
OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo());
@ -130,15 +130,6 @@ public class TerraWorld extends WorldType {
}
}
public static WorldType getFirst() {
for (WorldType worldType : WorldType.WORLD_TYPES) {
if (worldType instanceof TerraWorld) {
return worldType;
}
}
throw new RuntimeException();
}
public static void forEach(Consumer<WorldType> consumer) {
types.forEach(consumer);
}

View File

@ -27,29 +27,42 @@ package com.terraforged.api.chunk.column;
import com.terraforged.api.chunk.ChunkContext;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.concurrent.Resource;
import com.terraforged.world.climate.Climate;
import com.terraforged.world.geology.DepthBuffer;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk;
public class DecoratorContext extends ChunkContext {
public class DecoratorContext extends ChunkContext implements AutoCloseable {
public final Levels levels;
public final Climate climate;
public final Terrains terrains;
public final DepthBuffer depthBuffer = new DepthBuffer();
public final TerrainTypes terrains;
public final Resource<DepthBuffer> depthBuffer;
public final BlockPos.Mutable pos = new BlockPos.Mutable();
public Biome biome;
public Cell cell;
public DecoratorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate) {
public DecoratorContext(IChunk chunk, Levels levels, TerrainTypes terrain, Climate climate) {
this(chunk, levels, terrain, climate, true);
}
public DecoratorContext(IChunk chunk, Levels levels, TerrainTypes terrain, Climate climate, boolean depthBuffer) {
super(chunk);
this.levels = levels;
this.climate = climate;
this.terrains = terrain;
this.depthBuffer = depthBuffer ? DepthBuffer.get() : null;
}
@Override
public void close() {
if (depthBuffer != null) {
depthBuffer.close();
}
}
}

View File

@ -28,11 +28,11 @@ package com.terraforged.api.chunk.surface;
import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.world.climate.Climate;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.block.BlockState;
import net.minecraft.world.gen.GenerationSettings;
public class SurfaceContext extends DecoratorContext {
public class SurfaceContext extends DecoratorContext implements AutoCloseable {
public final long seed;
public final BlockState solid;
@ -42,7 +42,7 @@ public class SurfaceContext extends DecoratorContext {
public double noise;
public SurfaceContext(ChunkSurfaceBuffer buffer, Levels levels, Terrains terrain, Climate climate, GenerationSettings settings, long seed) {
public SurfaceContext(ChunkSurfaceBuffer buffer, Levels levels, TerrainTypes terrain, Climate climate, GenerationSettings settings, long seed) {
super(buffer, levels, terrain, climate);
this.solid = settings.getDefaultBlock();
this.fluid = settings.getDefaultFluid();

View File

@ -0,0 +1,50 @@
package com.terraforged.biome;
import com.terraforged.api.biome.BiomeVariant;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.biome.DefaultBiomeFeatures;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.structure.MineshaftConfig;
import net.minecraft.world.gen.feature.structure.MineshaftStructure;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
public class Brice extends BiomeVariant {
public Brice() {
super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.BADLANDS, SurfaceBuilder.RED_SAND_WHITE_TERRACOTTA_GRAVEL_CONFIG).precipitation(Biome.RainType.NONE).category(Biome.Category.MESA).depth(0.1F).scale(0.2F).temperature(2.0F).downfall(0.0F).waterColor(4159204).waterFogColor(329011).parent((String)null));
setRegistryName("terraforged", "brice");
this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.MESA)));
this.addStructure(Feature.STRONGHOLD.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG));
DefaultBiomeFeatures.addCarvers(this);
DefaultBiomeFeatures.addStructures(this);
DefaultBiomeFeatures.addLakes(this);
DefaultBiomeFeatures.addMonsterRooms(this);
DefaultBiomeFeatures.addStoneVariants(this);
DefaultBiomeFeatures.addOres(this);
DefaultBiomeFeatures.addExtraGoldOre(this);
DefaultBiomeFeatures.addSedimentDisks(this);
DefaultBiomeFeatures.addGrassAndDeadBushes(this);
DefaultBiomeFeatures.addMushrooms(this);
DefaultBiomeFeatures.addReedsPumpkinsCactus(this);
DefaultBiomeFeatures.addSprings(this);
DefaultBiomeFeatures.addFreezeTopLayer(this);
this.addSpawn(EntityClassification.AMBIENT, new Biome.SpawnListEntry(EntityType.BAT, 10, 8, 8));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SPIDER, 100, 4, 4));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ZOMBIE, 95, 4, 4));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ZOMBIE_VILLAGER, 5, 1, 1));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SKELETON, 100, 4, 4));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.CREEPER, 100, 4, 4));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SLIME, 100, 4, 4));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ENDERMAN, 10, 1, 4));
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.WITCH, 5, 1, 1));
}
@Override
public Biome getBase() {
return Biomes.BADLANDS;
}
}

View File

@ -31,7 +31,6 @@ public class Dunes extends BiomeVariant {
DefaultBiomeFeatures.addSparseGrass(this);
DefaultBiomeFeatures.addDeadBushes(this);
DefaultBiomeFeatures.addMushrooms(this);
DefaultBiomeFeatures.addExtraReedsPumpkinsCactus(this);
DefaultBiomeFeatures.addFreezeTopLayer(this);
this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.RABBIT, 4, 2, 3));
this.addSpawn(EntityClassification.AMBIENT, new Biome.SpawnListEntry(EntityType.BAT, 10, 8, 8));

View File

@ -39,8 +39,9 @@ public class ModBiomes {
private static final ArrayList<BiomeVariant> biomes = new ArrayList<>();
public static final Biome BRICE = register(new Brice());
public static final Biome COLD_STEPPE = register(new ColdSteppe());
// public static final Biome DUNES = register(new Dunes());
public static final Biome DUNES = register(new Dunes());
public static final Biome FIR_FOREST = register(new FirForest());
public static final Biome FLOWER_PLAINS = register(new FlowerPlains());
public static final Biome FROZEN_LAKE = register(new FrozenLake());

View File

@ -30,13 +30,13 @@ import com.terraforged.biome.map.BiomeMap;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.cell.Cell;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.world.biome.Biome;
public class BeachModifier implements BiomeModifier {
private final Levels levels;
private final Terrains terrain;
private final TerrainTypes terrain;
private final BiomeMap biomeMap;
public BeachModifier(BiomeMap biomeMap, TerraContext context) {

View File

@ -28,7 +28,9 @@ package com.terraforged.biome.provider;
import com.google.common.collect.Sets;
import com.terraforged.biome.map.BiomeMap;
import com.terraforged.biome.modifier.BiomeModifierManager;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.TerraContext;
import com.terraforged.chunk.util.FastChunk;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.chunk.ChunkReader;
@ -37,6 +39,8 @@ import com.terraforged.world.heightmap.WorldLookup;
import com.terraforged.world.terrain.decorator.Decorator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.chunk.IChunk;
import java.util.Collections;
import java.util.HashMap;
@ -183,4 +187,20 @@ public class BiomeProvider extends AbstractBiomeProvider {
private static boolean overridesRiver(Biome biome) {
return biome.getCategory() == Biome.Category.SWAMP || biome.getCategory() == Biome.Category.JUNGLE;
}
public static TerraContainer getBiomeContainer(TerraChunkGenerator generator, IChunk chunk) {
if (chunk.getBiomes() instanceof TerraContainer) {
return (TerraContainer) chunk.getBiomes();
}
ChunkReader view = generator.getChunkReader(chunk.getPos().x, chunk.getPos().z);
TerraContainer container = generator.getBiomeProvider().createBiomeContainer(view);
if (chunk instanceof ChunkPrimer) {
((ChunkPrimer) chunk).func_225548_a_(container);
} else if (chunk instanceof FastChunk) {
((FastChunk) chunk).setBiomes(container);
}
return container;
}
}

View File

@ -0,0 +1,55 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.core.Seed;
import com.terraforged.core.util.Variance;
import com.terraforged.world.geology.Strata;
import me.dags.noise.Module;
import me.dags.noise.Source;
import me.dags.noise.util.NoiseUtil;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import java.util.Random;
public class BriceSurface implements Surface {
private final Module module;
private final Strata<BlockState> stackStrata;
public BriceSurface(Seed seed) {
Random random = new Random(seed.next());
Variance variance = Variance.of(0.1, 0.2);
module = Source.ridge(123, 60, 4)
.clamp(0.8, 0.95).map(0, 1)
.terrace(1, 0.25, 4, 1)
.mult(Source.perlin(1234, 4, 1).alpha(0.05));
stackStrata = Strata.<BlockState>builder(seed.next(), Source.build(seed.next(), 30, 3))
.add(Blocks.ORANGE_TERRACOTTA.getDefaultState(), variance.next(random))
.add(Blocks.TERRACOTTA.getDefaultState(), variance.next(random))
.add(Blocks.YELLOW_TERRACOTTA.getDefaultState(), variance.next(random))
.add(Blocks.WHITE_TERRACOTTA.getDefaultState(), variance.next(random))
.add(Blocks.BROWN_TERRACOTTA.getDefaultState(), variance.next(random))
.add(Blocks.RED_TERRACOTTA.getDefaultState(), variance.next(random))
.build();
}
@Override
public void buildSurface(int x, int z, int height, SurfaceContext ctx) {
float alpha = 1 - ctx.cell.steepness;
float mask = alpha * ctx.cell.biomeEdge * NoiseUtil.map(ctx.cell.riverMask,0, 0.0005F, 0.0005F);
float value = module.getValue(x, z) * mask;
int top = (int) (value * 30);
stackStrata.downwards(x, top, z, ctx.depthBuffer.get(), (y, material) -> {
if (y <= 0) {
return false;
}
ctx.chunk.setBlockState(ctx.pos.setPos(x, height + y, z), material, false);
return true;
});
}
}

View File

@ -33,7 +33,7 @@ import com.terraforged.biome.provider.DesertBiomes;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.cell.Cell;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import me.dags.noise.Module;
import me.dags.noise.Source;
import me.dags.noise.func.CellFunc;
@ -48,7 +48,7 @@ public class DunesSurface implements Surface {
private final int maxHeight;
private final Levels levels;
private final Module module;
private final Terrains terrains;
private final TerrainTypes terrains;
private final DesertBiomes deserts;
private final BlockPos.Mutable pos = new BlockPos.Mutable();

View File

@ -33,6 +33,7 @@ import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.chunk.generator.BiomeGenerator;
import com.terraforged.chunk.generator.MobGenerator;
import com.terraforged.chunk.generator.StructureGenerator;
import com.terraforged.chunk.generator.SurfaceGenerator;
import com.terraforged.chunk.generator.TerrainCarver;
import com.terraforged.chunk.generator.TerrainGenerator;
import com.terraforged.core.cell.Cell;
@ -72,6 +73,7 @@ public class TerraChunkGenerator extends ChunkGenerator<GenerationSettings> {
private final BiomeGenerator biomeGenerator;
private final TerrainCarver terrainCarver;
private final TerrainGenerator terrainGenerator;
private final SurfaceGenerator surfaceGenerator;
private final StructureGenerator structureGenerator;
private final GeoManager geologyManager;
@ -92,6 +94,7 @@ public class TerraChunkGenerator extends ChunkGenerator<GenerationSettings> {
this.biomeGenerator = new BiomeGenerator(this);
this.terrainCarver = new TerrainCarver(this);
this.terrainGenerator = new TerrainGenerator(this);
this.surfaceGenerator = new SurfaceGenerator(this);
this.structureGenerator = new StructureGenerator(this);
this.surfaceManager = TerraSetupFactory.createSurfaceManager(context);
@ -135,7 +138,7 @@ public class TerraChunkGenerator extends ChunkGenerator<GenerationSettings> {
@Override
public final void func_225551_a_(WorldGenRegion world, IChunk chunk) {
terrainGenerator.generateSurface(world, chunk);
surfaceGenerator.generateSurface(world, chunk);
}
@Override

View File

@ -36,7 +36,7 @@ import com.terraforged.settings.TerraSettings;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.WorldGeneratorFactory;
import com.terraforged.world.heightmap.Heightmap;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.world.IWorld;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.GenerationSettings;
@ -56,7 +56,7 @@ public class TerraContext extends GeneratorContext {
this.heightmap = factory.getHeightmap();
}
public TerraContext(IWorld world, Terrains terrain, TerraSettings settings) {
public TerraContext(IWorld world, TerrainTypes terrain, TerraSettings settings) {
super(terrain, settings, TerraTerrainProvider::new, TerraContext::createCache);
this.world = world;
this.materials = new Materials();
@ -65,7 +65,7 @@ public class TerraContext extends GeneratorContext {
}
public DecoratorContext decorator(IChunk chunk) {
return new DecoratorContext(chunk, levels, terrain, factory.getClimate());
return new DecoratorContext(chunk, levels, terrain, factory.getClimate(), false);
}
public SurfaceContext surface(ChunkSurfaceBuffer buffer, GenerationSettings settings) {

View File

@ -4,6 +4,7 @@ import com.terraforged.Log;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.biome.ModBiomes;
import com.terraforged.biome.surface.BriceSurface;
import com.terraforged.biome.surface.IcebergsSurface;
import com.terraforged.biome.surface.SwampSurface;
import com.terraforged.chunk.column.BedrockDecorator;
@ -104,6 +105,7 @@ public class TerraSetupFactory {
manager.replace(Biomes.FROZEN_OCEAN.delegate.get(), new IcebergsSurface(context, 20, 15));
manager.replace(Biomes.SWAMP.delegate.get(), new SwampSurface());
manager.replace(ModBiomes.MARSHLAND, new SwampSurface());
manager.extend(ModBiomes.BRICE, new BriceSurface(context.seed));
return SetupHooks.setup(manager, context);
}

View File

@ -30,13 +30,13 @@ import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.material.state.States;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.util.VariablePredicate;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.block.BlockState;
import net.minecraft.world.chunk.IChunk;
public class CoastDecorator implements ColumnDecorator {
private final Terrains terrains;
private final TerrainTypes terrains;
private final BlockState sand;
private final BlockState gravel;
private final VariablePredicate height;

View File

@ -30,7 +30,7 @@ import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.material.state.States;
import com.terraforged.chunk.TerraContext;
import com.terraforged.material.Materials;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material;
@ -61,7 +61,7 @@ public class ErosionDecorator implements ColumnDecorator {
private final int seed2;
private final int seed3;
private final float minY;
private final Terrains terrain;
private final TerrainTypes terrain;
private final Materials materials;
public ErosionDecorator(TerraContext context) {

View File

@ -47,7 +47,7 @@ public class GeologyDecorator implements ColumnDecorator {
@Override
public void decorate(ChunkSurfaceBuffer buffer, DecoratorContext context, int x, int y, int z) {
int top = buffer.getSurfaceBottom();
geology.getGeology(context.biome).getStrata(x, z).downwards(x, top, z, context.depthBuffer, (py, state) -> {
geology.getGeology(context.biome).getStrata(x, z).downwards(x, top, z, context.depthBuffer.get(), (py, state) -> {
context.pos.setPos(x, py, z);
buffer.getDelegate().setBlockState(context.pos, state, false);
return true;

View File

@ -47,29 +47,21 @@ public class LayerDecorator implements ColumnDecorator {
public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) {
context.pos.setPos(x, y + 1, z);
// if block is already a layer-type then simply set the layer property
BlockState state = chunk.getBlockState(context.pos);
if (state.isAir(chunk, context.pos)) {
return;
context.pos.setPos(x, y, z);
state = chunk.getBlockState(context.pos);
if (state.isAir(chunk, context.pos)) {
return;
}
}
LayerMaterial material = layerManager.getMaterial(state.getBlock());
if (material != null) {
setLayer(chunk, context.pos, material, context.cell, context.levels, 0F);
if (material == null) {
return;
}
// block is non-solid (grass/flower etc)
if (!state.getMaterial().blocksMovement()) {
// block below is solid
if (chunk.getBlockState(context.pos.setPos(x, y, z)).getMaterial().blocksMovement()) {
// block above is air
BlockState above = chunk.getBlockState(context.pos.setPos(x, y + 2, z));
if (above.isAir(chunk, context.pos)) {
// setLayer(chunk, pos.setPos(x, y + 1, z), context.cell, context.levels, 0.25F);
}
}
}
setLayer(chunk, context.pos, material, context.cell, context.levels, 0F);
}
private void setLayer(IChunk chunk, BlockPos pos, LayerMaterial material, Cell cell, Levels levels, float min) {

View File

@ -0,0 +1,63 @@
package com.terraforged.chunk.generator;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.util.FastChunk;
import com.terraforged.chunk.util.TerraContainer;
import net.minecraft.util.SharedSeedRandom;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.INoiseGenerator;
import net.minecraft.world.gen.PerlinNoiseGenerator;
import net.minecraft.world.gen.WorldGenRegion;
public class SurfaceGenerator {
private final TerraChunkGenerator generator;
private final INoiseGenerator surfaceNoise;
public SurfaceGenerator(TerraChunkGenerator generator) {
this.generator = generator;
this.surfaceNoise = new PerlinNoiseGenerator(new SharedSeedRandom(generator.getSeed()), 3, 0);
}
public final void generateSurface(WorldGenRegion world, IChunk chunk) {
TerraContainer container = BiomeProvider.getBiomeContainer(generator, chunk);
ChunkSurfaceBuffer buffer = new ChunkSurfaceBuffer(FastChunk.wrap(chunk));
try (SurfaceContext context = generator.getContext().surface(buffer, generator.getSettings())) {
container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> {
int px = ctx.blockX + dx;
int pz = ctx.blockZ + dz;
int top = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, dx, dz);
ctx.buffer.setSurfaceLevel(top);
ctx.cell = cell;
ctx.biome = container.getBiome(dx, dz);
ctx.noise = getSurfaceNoise(px, pz) * 15D;
generator.getSurfaceManager().getSurface(ctx).buildSurface(px, pz, top, ctx);
int py = ctx.levels.scale(cell.value);
for (ColumnDecorator processor : generator.getBaseDecorators()) {
processor.decorate(ctx.buffer, ctx, px, py, pz);
}
});
FastChunk.updateWGHeightmaps(chunk, context.pos);
}
}
private double getSurfaceNoise(int x, int z) {
double scale = 0.0625D;
double noiseX = x * scale;
double noiseZ = z * scale;
double unusedValue1 = scale;
double unusedValue2 = (x & 15) * scale;
return surfaceNoise.noiseAt(noiseX, noiseZ, unusedValue1, unusedValue2);
}
}

View File

@ -2,8 +2,7 @@ package com.terraforged.chunk.generator;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.column.ChunkPopulator;
import com.terraforged.chunk.fix.RegionFix;
@ -12,77 +11,55 @@ import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.feature.TerrainHelper;
import com.terraforged.util.Environment;
import net.minecraft.util.SharedSeedRandom;
import com.terraforged.world.climate.Climate;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.INoiseGenerator;
import net.minecraft.world.gen.PerlinNoiseGenerator;
import net.minecraft.world.gen.WorldGenRegion;
import java.util.List;
public class TerrainGenerator {
private final Levels levels;
private final Climate climate;
private final TerrainTypes terrain;
private final TerraChunkGenerator generator;
private final TerrainHelper terrainHelper;
private final INoiseGenerator surfaceNoise;
public TerrainGenerator(TerraChunkGenerator generator) {
this.generator = generator;
this.levels = generator.getContext().levels;
this.terrain = generator.getContext().terrain;
this.climate = generator.getContext().factory.getClimate();
this.terrainHelper = new TerrainHelper(0.75F);
this.surfaceNoise = new PerlinNoiseGenerator(new SharedSeedRandom(generator.getSeed()), 3, 0);
}
public final void generateTerrain(IWorld world, IChunk chunk) {
TerraContainer container = getBiomeContainer(chunk);
DecoratorContext context = new DecoratorContext(FastChunk.wrap(chunk), generator.getContext().levels, generator.getContext().terrain, generator.getContext().factory.getClimate());
container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> {
int px = ctx.blockX + dx;
int pz = ctx.blockZ + dz;
int py = ctx.levels.scale(cell.value);
ctx.cell = cell;
ctx.biome = container.getBiome(dx, dz);
ChunkPopulator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz);
});
terrainHelper.flatten(world, chunk);
}
public final void generateSurface(WorldGenRegion world, IChunk chunk) {
TerraContainer container = getBiomeContainer(chunk);
ChunkSurfaceBuffer buffer = new ChunkSurfaceBuffer(FastChunk.wrap(chunk));
SurfaceContext context = generator.getContext().surface(buffer, generator.getSettings());
container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> {
int px = ctx.blockX + dx;
int pz = ctx.blockZ + dz;
int top = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, dx, dz);
ctx.buffer.setSurfaceLevel(top);
ctx.cell = cell;
ctx.biome = container.getBiome(dx, dz);
ctx.noise = getSurfaceNoise(px, pz) * 15D;
generator.getSurfaceManager().getSurface(ctx).buildSurface(px, pz, top, ctx);
int py = ctx.levels.scale(cell.value);
for (ColumnDecorator processor : generator.getBaseDecorators()) {
processor.decorate(ctx.buffer, ctx, px, py, pz);
}
});
FastChunk.updateWGHeightmaps(chunk, context.pos);
TerraContainer container = BiomeProvider.getBiomeContainer(generator, chunk);
try (DecoratorContext context = new DecoratorContext(FastChunk.wrap(chunk), levels, terrain, climate)) {
container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> {
int px = ctx.blockX + dx;
int pz = ctx.blockZ + dz;
int py = ctx.levels.scale(cell.value);
ctx.cell = cell;
ctx.biome = container.getBiome(dx, dz);
ChunkPopulator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz);
});
terrainHelper.flatten(world, chunk);
}
}
public final void generateFeatures(WorldGenRegion region) {
int chunkX = region.getMainChunkX();
int chunkZ = region.getMainChunkZ();
IChunk chunk = region.getChunk(chunkX, chunkZ);
TerraContainer container = getBiomeContainer(chunk);
TerraContainer container = BiomeProvider.getBiomeContainer(generator, chunk);
Biome biome = container.getFeatureBiome();
DecoratorContext context = generator.getContext().decorator(chunk);
@ -115,29 +92,4 @@ public class TerrainGenerator {
}
});
}
private double getSurfaceNoise(int x, int z) {
double scale = 0.0625D;
double noiseX = x * scale;
double noiseZ = z * scale;
double unusedValue1 = scale;
double unusedValue2 = (x & 15) * scale;
return surfaceNoise.noiseAt(noiseX, noiseZ, unusedValue1, unusedValue2);
}
private TerraContainer getBiomeContainer(IChunk chunk) {
if (chunk.getBiomes() instanceof TerraContainer) {
return (TerraContainer) chunk.getBiomes();
}
ChunkReader view = generator.getChunkReader(chunk.getPos().x, chunk.getPos().z);
TerraContainer container = generator.getBiomeProvider().createBiomeContainer(view);
if (chunk instanceof ChunkPrimer) {
((ChunkPrimer) chunk).func_225548_a_(container);
} else if (chunk instanceof FastChunk) {
((FastChunk) chunk).setBiomes(container);
}
return container;
}
}

View File

@ -26,19 +26,19 @@
package com.terraforged.chunk.test;
import com.terraforged.world.terrain.Terrain;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
public class Test {
public static boolean fixedBiome = true;
public static boolean fixedBiome = false;
public static Terrain getTerrainType(Terrains terrains) {
return terrains.steppe;
public static Terrain getTerrainType(TerrainTypes terrains) {
return terrains.badlands;
}
public static Biome getBiome() {
return Biomes.PLAINS;
return Biomes.BADLANDS;
}
}

View File

@ -3,11 +3,11 @@ package com.terraforged.chunk.test;
import com.terraforged.core.cell.Cell;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.heightmap.WorldHeightmap;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
public class TestHeightMap extends WorldHeightmap {
private final Terrains terrains;
private final TerrainTypes terrains;
public TestHeightMap(GeneratorContext context) {
super(context);

View File

@ -46,7 +46,7 @@ import com.terraforged.data.DataGen;
import com.terraforged.settings.SettingsHelper;
import com.terraforged.world.WorldGenerator;
import com.terraforged.world.terrain.Terrain;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.ArgumentSerializer;
@ -277,7 +277,7 @@ public class TerraCommand {
// the terrain parsed from the command will not be the same instance as used in the
// world generator, so find the matching instance by name
private static Terrain getTerrainInstance(Terrain find, Terrains terrains) {
private static Terrain getTerrainInstance(Terrain find, TerrainTypes terrains) {
for (Terrain t : terrains.index) {
if (t.getName().equals(find.getName())) {
return t;

View File

@ -1,57 +0,0 @@
/*
*
* MIT License
*
* Copyright (c) 2020 TerraForged
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.terraforged.feature.predicate;
import com.terraforged.chunk.TerraContext;
import com.terraforged.fm.predicate.FeaturePredicate;
import com.terraforged.world.climate.Climate;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.Heightmap;
public class TreeLine implements FeaturePredicate {
private final int worldHeight;
private final Climate climate;
public TreeLine(TerraContext context) {
this.worldHeight = context.levels.worldHeight;
this.climate = context.heightmap.getClimate();
}
@Override
public boolean test(IChunk chunk, Biome biome) {
int x = chunk.getPos().getXStart() + 8;
int z = chunk.getPos().getZStart() + 8;
int treeline = getTreeline(x, z);
int y = chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, 8, 8);
return y < treeline;
}
private int getTreeline(int x, int z) {
return (int) (climate.getTreeLine(x, z) * worldHeight);
}
}

View File

@ -38,7 +38,7 @@ import com.terraforged.util.nbt.NBTHelper;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.continent.MutableVeci;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.world.terrain.TerrainTypes;
import me.dags.noise.util.NoiseUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
@ -197,7 +197,7 @@ public class Preview extends Button {
settings.world.seed = seed;
this.settings = settings;
GeneratorContext context = GeneratorContext.createNoCache(Terrains.create(settings), settings);
GeneratorContext context = GeneratorContext.createNoCache(TerrainTypes.create(settings), settings);
MutableVeci center = new MutableVeci();
context.factory.getHeightmap().getContinent().getNearestCenter(offsetX, offsetZ, center);