From 9b9a9919ccd2a6d1ba0a364b436351c585e98571 Mon Sep 17 00:00:00 2001 From: dags- Date: Mon, 18 May 2020 23:22:31 +0100 Subject: [PATCH] renames + further work on surface generation --- Engine | 2 +- FeatureManager | 2 +- src/main/java/com/terraforged/TerraWorld.java | 13 +-- .../api/chunk/column/DecoratorContext.java | 23 ++++- .../api/chunk/surface/SurfaceContext.java | 6 +- .../java/com/terraforged/biome/Brice.java | 50 ++++++++++ .../java/com/terraforged/biome/Dunes.java | 1 - .../java/com/terraforged/biome/ModBiomes.java | 3 +- .../biome/modifier/BeachModifier.java | 4 +- .../biome/provider/BiomeProvider.java | 20 ++++ .../biome/surface/BriceSurface.java | 55 +++++++++++ .../biome/surface/DunesSurface.java | 4 +- .../chunk/TerraChunkGenerator.java | 5 +- .../com/terraforged/chunk/TerraContext.java | 6 +- .../terraforged/chunk/TerraSetupFactory.java | 2 + .../chunk/column/CoastDecorator.java | 4 +- .../chunk/column/ErosionDecorator.java | 4 +- .../chunk/column/GeologyDecorator.java | 2 +- .../chunk/column/post/LayerDecorator.java | 22 ++--- .../chunk/generator/SurfaceGenerator.java | 63 +++++++++++++ .../chunk/generator/TerrainGenerator.java | 94 +++++-------------- .../java/com/terraforged/chunk/test/Test.java | 10 +- .../terraforged/chunk/test/TestHeightMap.java | 4 +- .../com/terraforged/command/TerraCommand.java | 4 +- .../feature/predicate/TreeLine.java | 57 ----------- .../com/terraforged/gui/preview/Preview.java | 4 +- 26 files changed, 274 insertions(+), 190 deletions(-) create mode 100644 src/main/java/com/terraforged/biome/Brice.java create mode 100644 src/main/java/com/terraforged/biome/surface/BriceSurface.java create mode 100644 src/main/java/com/terraforged/chunk/generator/SurfaceGenerator.java delete mode 100644 src/main/java/com/terraforged/feature/predicate/TreeLine.java diff --git a/Engine b/Engine index 72761ae..638e803 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit 72761aee8511f7c30c99ec5a8f291211325a433a +Subproject commit 638e8033704f282b7e737ce2fd6d4e5653a1e1b8 diff --git a/FeatureManager b/FeatureManager index da99ddb..e0a7f10 160000 --- a/FeatureManager +++ b/FeatureManager @@ -1 +1 @@ -Subproject commit da99ddb3bbfbb6dbd4ced8a8278c27742a1da272 +Subproject commit e0a7f101243b6d54a6e5943b424e5a3b4cf3b93c diff --git a/src/main/java/com/terraforged/TerraWorld.java b/src/main/java/com/terraforged/TerraWorld.java index 27d96da..8edc09d 100644 --- a/src/main/java/com/terraforged/TerraWorld.java +++ b/src/main/java/com/terraforged/TerraWorld.java @@ -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 consumer) { types.forEach(consumer); } diff --git a/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java b/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java index 45ae033..994080b 100644 --- a/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java +++ b/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java @@ -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; 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(); + } } } diff --git a/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java b/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java index c9ec75e..28230b4 100644 --- a/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java +++ b/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java @@ -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(); diff --git a/src/main/java/com/terraforged/biome/Brice.java b/src/main/java/com/terraforged/biome/Brice.java new file mode 100644 index 0000000..c07fe0e --- /dev/null +++ b/src/main/java/com/terraforged/biome/Brice.java @@ -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; + } +} diff --git a/src/main/java/com/terraforged/biome/Dunes.java b/src/main/java/com/terraforged/biome/Dunes.java index 441f309..660e728 100644 --- a/src/main/java/com/terraforged/biome/Dunes.java +++ b/src/main/java/com/terraforged/biome/Dunes.java @@ -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)); diff --git a/src/main/java/com/terraforged/biome/ModBiomes.java b/src/main/java/com/terraforged/biome/ModBiomes.java index fd57006..fe4c313 100644 --- a/src/main/java/com/terraforged/biome/ModBiomes.java +++ b/src/main/java/com/terraforged/biome/ModBiomes.java @@ -39,8 +39,9 @@ public class ModBiomes { private static final ArrayList 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()); diff --git a/src/main/java/com/terraforged/biome/modifier/BeachModifier.java b/src/main/java/com/terraforged/biome/modifier/BeachModifier.java index 822ed75..82f50db 100644 --- a/src/main/java/com/terraforged/biome/modifier/BeachModifier.java +++ b/src/main/java/com/terraforged/biome/modifier/BeachModifier.java @@ -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) { diff --git a/src/main/java/com/terraforged/biome/provider/BiomeProvider.java b/src/main/java/com/terraforged/biome/provider/BiomeProvider.java index ef8b401..c9e21d8 100644 --- a/src/main/java/com/terraforged/biome/provider/BiomeProvider.java +++ b/src/main/java/com/terraforged/biome/provider/BiomeProvider.java @@ -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; + } } diff --git a/src/main/java/com/terraforged/biome/surface/BriceSurface.java b/src/main/java/com/terraforged/biome/surface/BriceSurface.java new file mode 100644 index 0000000..07b9f71 --- /dev/null +++ b/src/main/java/com/terraforged/biome/surface/BriceSurface.java @@ -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 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.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; + }); + } +} diff --git a/src/main/java/com/terraforged/biome/surface/DunesSurface.java b/src/main/java/com/terraforged/biome/surface/DunesSurface.java index 211460f..cdb1f39 100644 --- a/src/main/java/com/terraforged/biome/surface/DunesSurface.java +++ b/src/main/java/com/terraforged/biome/surface/DunesSurface.java @@ -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(); diff --git a/src/main/java/com/terraforged/chunk/TerraChunkGenerator.java b/src/main/java/com/terraforged/chunk/TerraChunkGenerator.java index d69721b..ddbb4e0 100644 --- a/src/main/java/com/terraforged/chunk/TerraChunkGenerator.java +++ b/src/main/java/com/terraforged/chunk/TerraChunkGenerator.java @@ -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 { 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 { 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 { @Override public final void func_225551_a_(WorldGenRegion world, IChunk chunk) { - terrainGenerator.generateSurface(world, chunk); + surfaceGenerator.generateSurface(world, chunk); } @Override diff --git a/src/main/java/com/terraforged/chunk/TerraContext.java b/src/main/java/com/terraforged/chunk/TerraContext.java index a380d24..50e6287 100644 --- a/src/main/java/com/terraforged/chunk/TerraContext.java +++ b/src/main/java/com/terraforged/chunk/TerraContext.java @@ -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) { diff --git a/src/main/java/com/terraforged/chunk/TerraSetupFactory.java b/src/main/java/com/terraforged/chunk/TerraSetupFactory.java index ff51456..1a2f64a 100644 --- a/src/main/java/com/terraforged/chunk/TerraSetupFactory.java +++ b/src/main/java/com/terraforged/chunk/TerraSetupFactory.java @@ -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); } diff --git a/src/main/java/com/terraforged/chunk/column/CoastDecorator.java b/src/main/java/com/terraforged/chunk/column/CoastDecorator.java index 1d7eb52..5ca5665 100644 --- a/src/main/java/com/terraforged/chunk/column/CoastDecorator.java +++ b/src/main/java/com/terraforged/chunk/column/CoastDecorator.java @@ -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; diff --git a/src/main/java/com/terraforged/chunk/column/ErosionDecorator.java b/src/main/java/com/terraforged/chunk/column/ErosionDecorator.java index 93065de..37b20f2 100644 --- a/src/main/java/com/terraforged/chunk/column/ErosionDecorator.java +++ b/src/main/java/com/terraforged/chunk/column/ErosionDecorator.java @@ -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) { diff --git a/src/main/java/com/terraforged/chunk/column/GeologyDecorator.java b/src/main/java/com/terraforged/chunk/column/GeologyDecorator.java index 2f37b2f..b0eb2ea 100644 --- a/src/main/java/com/terraforged/chunk/column/GeologyDecorator.java +++ b/src/main/java/com/terraforged/chunk/column/GeologyDecorator.java @@ -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; diff --git a/src/main/java/com/terraforged/chunk/column/post/LayerDecorator.java b/src/main/java/com/terraforged/chunk/column/post/LayerDecorator.java index 0dca4a9..30ccf81 100644 --- a/src/main/java/com/terraforged/chunk/column/post/LayerDecorator.java +++ b/src/main/java/com/terraforged/chunk/column/post/LayerDecorator.java @@ -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) { diff --git a/src/main/java/com/terraforged/chunk/generator/SurfaceGenerator.java b/src/main/java/com/terraforged/chunk/generator/SurfaceGenerator.java new file mode 100644 index 0000000..306b918 --- /dev/null +++ b/src/main/java/com/terraforged/chunk/generator/SurfaceGenerator.java @@ -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); + } +} diff --git a/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java b/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java index f64183a..35f1c5a 100644 --- a/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java +++ b/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java @@ -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; - } } diff --git a/src/main/java/com/terraforged/chunk/test/Test.java b/src/main/java/com/terraforged/chunk/test/Test.java index 3c6c8c8..8d88b72 100644 --- a/src/main/java/com/terraforged/chunk/test/Test.java +++ b/src/main/java/com/terraforged/chunk/test/Test.java @@ -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; } } diff --git a/src/main/java/com/terraforged/chunk/test/TestHeightMap.java b/src/main/java/com/terraforged/chunk/test/TestHeightMap.java index 22ec06b..e71f09d 100644 --- a/src/main/java/com/terraforged/chunk/test/TestHeightMap.java +++ b/src/main/java/com/terraforged/chunk/test/TestHeightMap.java @@ -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); diff --git a/src/main/java/com/terraforged/command/TerraCommand.java b/src/main/java/com/terraforged/command/TerraCommand.java index bbb7894..1909c00 100644 --- a/src/main/java/com/terraforged/command/TerraCommand.java +++ b/src/main/java/com/terraforged/command/TerraCommand.java @@ -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; diff --git a/src/main/java/com/terraforged/feature/predicate/TreeLine.java b/src/main/java/com/terraforged/feature/predicate/TreeLine.java deleted file mode 100644 index c9f9c54..0000000 --- a/src/main/java/com/terraforged/feature/predicate/TreeLine.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/com/terraforged/gui/preview/Preview.java b/src/main/java/com/terraforged/gui/preview/Preview.java index cbfb13b..64591eb 100644 --- a/src/main/java/com/terraforged/gui/preview/Preview.java +++ b/src/main/java/com/terraforged/gui/preview/Preview.java @@ -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);