From 904580ef387e08210a66c353aee38a8099357cb8 Mon Sep 17 00:00:00 2001 From: dags- Date: Mon, 1 Jun 2020 15:43:11 +0100 Subject: [PATCH] - refactored/renamed classes - pool cell/chunk arrays --- Engine | 2 +- src/main/java/com/terraforged/TerraWorld.java | 4 +- .../api/chunk/column/DecoratorContext.java | 8 +- .../api/chunk/surface/SurfaceContext.java | 4 +- .../biome/modifier/BeachModifier.java | 8 +- .../biome/modifier/BiomeModifierManager.java | 14 ++- .../biome/provider/BiomeAccess.java | 58 +++++++++ .../biome/provider/BiomeAccessor.java | 10 ++ .../biome/provider/BiomeProvider.java | 37 ++---- .../biome/surface/DunesSurface.java | 4 +- .../chunk/TerraChunkGenerator.java | 16 +-- .../com/terraforged/chunk/TerraContext.java | 6 +- .../chunk/column/ChunkPopulator.java | 2 +- .../chunk/column/CoastDecorator.java | 6 +- .../chunk/column/ErosionDecorator.java | 8 +- .../chunk/column/post/SnowEroder.java | 2 +- .../chunk/generator/TerrainGenerator.java | 4 +- .../java/com/terraforged/chunk/test/Test.java | 4 +- .../terraforged/chunk/test/TestHeightMap.java | 4 +- .../com/terraforged/chunk/util/FastChunk.java | 26 ++++ .../com/terraforged/command/TerraCommand.java | 6 +- .../command/search/TerrainSearchTask.java | 2 +- .../terraforged/feature/TerrainHelper.java | 67 +++++++---- .../feature/context/ChanceContext.java | 2 +- .../decorator/poisson/PoissonDecorator.java | 2 +- .../com/terraforged/gui/SettingsScreen.java | 23 ++-- .../com/terraforged/gui/page/ClimatePage.java | 68 ----------- .../com/terraforged/gui/page/MiscPage.java | 65 ---------- .../com/terraforged/gui/page/PresetPage.java | 16 --- .../com/terraforged/gui/page/RiverPage.java | 67 ----------- .../com/terraforged/gui/page/SimplePage.java | 44 +++++++ .../gui/page/SimplePreviewPage.java | 22 ++++ .../terraforged/gui/page/StructurePage.java | 58 --------- .../com/terraforged/gui/page/TerrainPage.java | 67 ----------- .../terraforged/gui/page/UpdatablePage.java | 23 ++++ .../com/terraforged/gui/page/WorldPage.java | 4 +- .../com/terraforged/gui/preview/Preview.java | 10 +- .../terraforged/gui/preview/PreviewPage.java | 18 ++- .../gui/preview/again/MCRenderAPI.java | 44 +++++++ .../gui/preview/again/MCRenderBuffer.java | 66 +++++++++++ .../gui/preview/again/Preview2.java | 111 ++++++++++++++++++ .../gui/preview/again/PreviewPage2.java | 76 ++++++++++++ .../gui/preview/again/PreviewSettings.java | 14 +++ .../terraforged/util/DummyBlockReader.java | 2 +- .../features/trees/spruce_tundra.json | 46 +++++--- 45 files changed, 656 insertions(+), 494 deletions(-) create mode 100644 src/main/java/com/terraforged/biome/provider/BiomeAccess.java create mode 100644 src/main/java/com/terraforged/biome/provider/BiomeAccessor.java delete mode 100644 src/main/java/com/terraforged/gui/page/ClimatePage.java delete mode 100644 src/main/java/com/terraforged/gui/page/MiscPage.java delete mode 100644 src/main/java/com/terraforged/gui/page/PresetPage.java delete mode 100644 src/main/java/com/terraforged/gui/page/RiverPage.java create mode 100644 src/main/java/com/terraforged/gui/page/SimplePage.java create mode 100644 src/main/java/com/terraforged/gui/page/SimplePreviewPage.java delete mode 100644 src/main/java/com/terraforged/gui/page/StructurePage.java delete mode 100644 src/main/java/com/terraforged/gui/page/TerrainPage.java create mode 100644 src/main/java/com/terraforged/gui/page/UpdatablePage.java create mode 100644 src/main/java/com/terraforged/gui/preview/again/MCRenderAPI.java create mode 100644 src/main/java/com/terraforged/gui/preview/again/MCRenderBuffer.java create mode 100644 src/main/java/com/terraforged/gui/preview/again/Preview2.java create mode 100644 src/main/java/com/terraforged/gui/preview/again/PreviewPage2.java create mode 100644 src/main/java/com/terraforged/gui/preview/again/PreviewSettings.java diff --git a/Engine b/Engine index 637b43e..7f617d3 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit 637b43efb49d4aabe5332118caf8d72be1339a49 +Subproject commit 7f617d303c09d52d4242379ef87bc4b679d8fcea diff --git a/src/main/java/com/terraforged/TerraWorld.java b/src/main/java/com/terraforged/TerraWorld.java index 8edc09d..304e4cc 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; 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()); - TerrainTypes terrains = TerrainTypes.create(settings); + Terrains terrains = Terrains.create(settings); OverworldGenSettings genSettings = new TerraGenSettings(settings.structures); OverworldBiomeProviderSettings biomeSettings = new OverworldBiomeProviderSettings(world.getWorldInfo()); 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 994080b..b305eeb 100644 --- a/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java +++ b/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java @@ -31,7 +31,7 @@ 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.IChunk; @@ -40,18 +40,18 @@ public class DecoratorContext extends ChunkContext implements AutoCloseable { public final Levels levels; public final Climate climate; - public final TerrainTypes terrains; + public final Terrains 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, TerrainTypes terrain, Climate climate) { + public DecoratorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate) { this(chunk, levels, terrain, climate, true); } - public DecoratorContext(IChunk chunk, Levels levels, TerrainTypes terrain, Climate climate, boolean depthBuffer) { + public DecoratorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate, boolean depthBuffer) { super(chunk); this.levels = levels; this.climate = climate; 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 28230b4..4b98116 100644 --- a/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java +++ b/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java @@ -28,7 +28,7 @@ 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.block.BlockState; import net.minecraft.world.gen.GenerationSettings; @@ -42,7 +42,7 @@ public class SurfaceContext extends DecoratorContext implements AutoCloseable { public double noise; - public SurfaceContext(ChunkSurfaceBuffer buffer, Levels levels, TerrainTypes terrain, Climate climate, GenerationSettings settings, long seed) { + public SurfaceContext(ChunkSurfaceBuffer buffer, Levels levels, Terrains 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/modifier/BeachModifier.java b/src/main/java/com/terraforged/biome/modifier/BeachModifier.java index 82f50db..b1cd91a 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.world.biome.Biome; public class BeachModifier implements BiomeModifier { private final Levels levels; - private final TerrainTypes terrain; + private final Terrains terrain; private final BiomeMap biomeMap; public BeachModifier(BiomeMap biomeMap, TerraContext context) { @@ -57,10 +57,10 @@ public class BeachModifier implements BiomeModifier { @Override public Biome modify(Biome in, Cell cell, int x, int z) { - if (cell.terrainType == terrain.beach) { + if (cell.terrain == terrain.beach) { return biomeMap.getBeach(cell.temperature, cell.moisture, cell.biome); } - if (cell.terrainType == terrain.coast && cell.value <= levels.water) { + if (cell.terrain == terrain.coast && cell.value <= levels.water) { return biomeMap.getOcean(cell.temperature, cell.moisture, cell.biome); } return in; diff --git a/src/main/java/com/terraforged/biome/modifier/BiomeModifierManager.java b/src/main/java/com/terraforged/biome/modifier/BiomeModifierManager.java index 267f937..084815b 100644 --- a/src/main/java/com/terraforged/biome/modifier/BiomeModifierManager.java +++ b/src/main/java/com/terraforged/biome/modifier/BiomeModifierManager.java @@ -32,6 +32,8 @@ import com.terraforged.biome.provider.DesertBiomes; import com.terraforged.chunk.TerraContext; import com.terraforged.core.cell.Cell; import com.terraforged.world.biome.BiomeType; +import com.terraforged.world.terrain.ITerrain; +import com.terraforged.world.terrain.TerrainType; import net.minecraft.world.biome.Biome; import java.util.ArrayList; @@ -53,16 +55,20 @@ public class BiomeModifierManager implements BiomeModifier, ModifierManager { this.biomeModifiers = modifiers; } - @Override - public void register(BiomeModifier modifier) { - biomeModifiers.add(modifier); - Collections.sort(biomeModifiers); + public boolean hasModifiers(ITerrain type) { + return type.isOverground(); } public DesertBiomes getDesertBiomes() { return desertBiomes; } + @Override + public void register(BiomeModifier modifier) { + biomeModifiers.add(modifier); + Collections.sort(biomeModifiers); + } + @Override public int priority() { return -1; diff --git a/src/main/java/com/terraforged/biome/provider/BiomeAccess.java b/src/main/java/com/terraforged/biome/provider/BiomeAccess.java new file mode 100644 index 0000000..a3b0ba8 --- /dev/null +++ b/src/main/java/com/terraforged/biome/provider/BiomeAccess.java @@ -0,0 +1,58 @@ +package com.terraforged.biome.provider; + +import com.terraforged.core.cell.Cell; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.TerrainType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.biome.Biome; + +public class BiomeAccess { + + private static final BiomeAccessor DEEP_OCEAN = (m, c) -> m.getDeepOcean(c.temperature, c.moisture, c.biome); + private static final BiomeAccessor SHALLOW_OCEAN = (m, c) -> m.getOcean(c.temperature, c.moisture, c.biome); + private static final BiomeAccessor LAKE = (m, c) -> m.getLake(c.temperature, c.moisture, c.biome); + private static final BiomeAccessor WETLAND = (m, c) -> m.getWetland(c.temperature, c.moisture, c.biome); + private static final BiomeAccessor NORMAL = (m, c) -> m.getBiome(c.biomeType, c.temperature, c.moisture, c.biome); + private static final BiomeAccessor RIVER = (m, c) -> { + Biome biome = m.getBiome(c.biomeType, c.temperature, c.moisture, c.biome); + if (overridesRiver(biome)) { + return biome; + } + return m.getRiver(c.temperature, c.moisture, c.biome); + }; + + private static final BiomeAccessor[] accessors = createAccessorArray(); + + private final Levels levels; + + public BiomeAccess(Levels levels) { + this.levels = levels; + } + + public BiomeAccessor getAccessor(Cell cell) { + TerrainType type = cell.terrain.getType(); + if (type.isSubmerged() && cell.value > levels.water) { + return NORMAL; + } + return accessors[cell.terrain.getType().ordinal()]; + } + + private static BiomeAccessor[] createAccessorArray() { + BiomeAccessor[] accessors = new BiomeAccessor[TerrainType.values().length]; + accessors[TerrainType.SHALLOW_OCEAN.ordinal()] = SHALLOW_OCEAN; + accessors[TerrainType.DEEP_OCEAN.ordinal()] = DEEP_OCEAN; + accessors[TerrainType.WETLAND.ordinal()] = WETLAND; + accessors[TerrainType.RIVER.ordinal()] = RIVER; + accessors[TerrainType.LAKE.ordinal()] = LAKE; + for (TerrainType type : TerrainType.values()) { + if (accessors[type.ordinal()] == null) { + accessors[type.ordinal()] = NORMAL; + } + } + return accessors; + } + + private static boolean overridesRiver(Biome biome) { + return biome.getCategory() == Biome.Category.SWAMP || biome.getCategory() == Biome.Category.JUNGLE; + } +} diff --git a/src/main/java/com/terraforged/biome/provider/BiomeAccessor.java b/src/main/java/com/terraforged/biome/provider/BiomeAccessor.java new file mode 100644 index 0000000..1d58350 --- /dev/null +++ b/src/main/java/com/terraforged/biome/provider/BiomeAccessor.java @@ -0,0 +1,10 @@ +package com.terraforged.biome.provider; + +import com.terraforged.biome.map.BiomeMap; +import com.terraforged.core.cell.Cell; +import net.minecraft.world.biome.Biome; + +public interface BiomeAccessor { + + Biome getBiome(BiomeMap map, Cell cell); +} diff --git a/src/main/java/com/terraforged/biome/provider/BiomeProvider.java b/src/main/java/com/terraforged/biome/provider/BiomeProvider.java index c9e21d8..f77a8fc 100644 --- a/src/main/java/com/terraforged/biome/provider/BiomeProvider.java +++ b/src/main/java/com/terraforged/biome/provider/BiomeProvider.java @@ -52,6 +52,7 @@ import java.util.Set; public class BiomeProvider extends AbstractBiomeProvider { private final BiomeMap biomeMap; + private final BiomeAccess biomeAccess; private final TerraContext context; private final WorldLookup worldLookup; private final BiomeModifierManager modifierManager; @@ -60,6 +61,7 @@ public class BiomeProvider extends AbstractBiomeProvider { public BiomeProvider(TerraContext context) { this.context = context; this.biomeMap = BiomeHelper.getDefaultBiomeMap(); + this.biomeAccess = new BiomeAccess(context.levels); this.worldLookup = new WorldLookup(context.factory, context); this.modifierManager = SetupHooks.setup(new BiomeModifierManager(context, biomeMap), context.copy()); } @@ -153,39 +155,16 @@ public class BiomeProvider extends AbstractBiomeProvider { } public Biome getBiome(Cell cell, int x, int z) { - if (cell.terrainType.isWetland()) { - return biomeMap.getWetland(cell.temperature, cell.moisture, cell.biome); + BiomeAccessor accessor = biomeAccess.getAccessor(cell); + Biome biome = accessor.getBiome(biomeMap, cell); + if (modifierManager.hasModifiers(cell.terrain)) { + return modifierManager.modify(biome, cell, x, z); } - - if (cell.value > context.levels.water) { - return getModifierManager().modify(biomeMap.getBiome(cell), cell, x, z); - } - - if (cell.terrainType.isLake()) { - return biomeMap.getLake(cell.temperature, cell.moisture, cell.biome); - } - - if (cell.terrainType.isRiver()) { - Biome biome = biomeMap.getBiome(cell); - if (overridesRiver(biome)) { - return biome; - } - return biomeMap.getRiver(cell.temperature, cell.moisture, cell.biome); - } - - if (cell.terrainType.isShallowOcean()) { - return biomeMap.getOcean(cell.temperature, cell.moisture, cell.biome); - } - - return biomeMap.getDeepOcean(cell.temperature, cell.moisture, cell.biome); + return biome; } public boolean canSpawnAt(Cell cell) { - return cell.terrainType != context.terrain.ocean && cell.terrainType != context.terrain.deepOcean; - } - - private static boolean overridesRiver(Biome biome) { - return biome.getCategory() == Biome.Category.SWAMP || biome.getCategory() == Biome.Category.JUNGLE; + return cell.terrain != context.terrain.ocean && cell.terrain != context.terrain.deepOcean; } public static TerraContainer getBiomeContainer(TerraChunkGenerator generator, IChunk chunk) { diff --git a/src/main/java/com/terraforged/biome/surface/DunesSurface.java b/src/main/java/com/terraforged/biome/surface/DunesSurface.java index cdb1f39..211460f 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; 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 TerrainTypes terrains; + private final Terrains 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 ddbb4e0..0bf4a88 100644 --- a/src/main/java/com/terraforged/chunk/TerraChunkGenerator.java +++ b/src/main/java/com/terraforged/chunk/TerraChunkGenerator.java @@ -25,17 +25,11 @@ package com.terraforged.chunk; -import com.terraforged.Log; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.surface.SurfaceManager; import com.terraforged.api.material.layer.LayerManager; 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.chunk.generator.*; import com.terraforged.core.cell.Cell; import com.terraforged.core.region.Size; import com.terraforged.core.region.chunk.ChunkReader; @@ -46,7 +40,6 @@ import com.terraforged.fm.data.DataManager; import com.terraforged.fm.structure.StructureManager; import com.terraforged.material.Materials; import com.terraforged.material.geology.GeoManager; -import com.terraforged.util.Environment; import com.terraforged.util.setup.SetupHooks; import net.minecraft.entity.EntityClassification; import net.minecraft.util.math.BlockPos; @@ -54,11 +47,7 @@ import net.minecraft.world.IWorld; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.BiomeManager; import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.GenerationSettings; -import net.minecraft.world.gen.GenerationStage; -import net.minecraft.world.gen.Heightmap; -import net.minecraft.world.gen.WorldGenRegion; +import net.minecraft.world.gen.*; import net.minecraft.world.gen.feature.template.TemplateManager; import net.minecraft.world.server.ServerWorld; @@ -113,7 +102,6 @@ public class TerraChunkGenerator extends ChunkGenerator { SetupHooks.setup(getLayerManager(), context.copy()); SetupHooks.setup(baseDecorators, postProcessors, context.copy()); - Log.info("Vanilla Biomes: {}", Environment.isVanillaBiomes()); } @Override diff --git a/src/main/java/com/terraforged/chunk/TerraContext.java b/src/main/java/com/terraforged/chunk/TerraContext.java index 50e6287..91ead09 100644 --- a/src/main/java/com/terraforged/chunk/TerraContext.java +++ b/src/main/java/com/terraforged/chunk/TerraContext.java @@ -28,7 +28,7 @@ package com.terraforged.chunk; import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer; import com.terraforged.api.chunk.surface.SurfaceContext; -import com.terraforged.core.concurrent.pool.ThreadPools; +import com.terraforged.core.concurrent.thread.ThreadPools; import com.terraforged.core.region.gen.RegionCache; import com.terraforged.core.region.gen.RegionGenerator; import com.terraforged.material.Materials; @@ -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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; 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, TerrainTypes terrain, TerraSettings settings) { + public TerraContext(IWorld world, Terrains terrain, TerraSettings settings) { super(terrain, settings, TerraTerrainProvider::new, TerraContext::createCache); this.world = world; this.materials = new Materials(); diff --git a/src/main/java/com/terraforged/chunk/column/ChunkPopulator.java b/src/main/java/com/terraforged/chunk/column/ChunkPopulator.java index 2d602ed..9377ec8 100644 --- a/src/main/java/com/terraforged/chunk/column/ChunkPopulator.java +++ b/src/main/java/com/terraforged/chunk/column/ChunkPopulator.java @@ -36,7 +36,7 @@ public class ChunkPopulator implements ColumnDecorator { @Override public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.terrainType == context.terrains.volcanoPipe && context.cell.riverMask > 0.25F) { + if (context.cell.terrain == context.terrains.volcanoPipe && context.cell.riverMask > 0.25F) { int lavaStart = Math.max(context.levels.waterY + 10, y - 30); int lavaEnd = Math.max(5, context.levels.waterY - 10); fillDown(context, chunk, x, z, lavaStart, lavaEnd, States.LAVA.get()); diff --git a/src/main/java/com/terraforged/chunk/column/CoastDecorator.java b/src/main/java/com/terraforged/chunk/column/CoastDecorator.java index 5ca5665..b649081 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.block.BlockState; import net.minecraft.world.chunk.IChunk; public class CoastDecorator implements ColumnDecorator { - private final TerrainTypes terrains; + private final Terrains terrains; private final BlockState sand; private final BlockState gravel; private final VariablePredicate height; @@ -59,7 +59,7 @@ public class CoastDecorator implements ColumnDecorator { @Override public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.terrainType != terrains.beach) { + if (context.cell.terrain != terrains.beach) { return; } diff --git a/src/main/java/com/terraforged/chunk/column/ErosionDecorator.java b/src/main/java/com/terraforged/chunk/column/ErosionDecorator.java index 37b20f2..af48a03 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; 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 TerrainTypes terrain; + private final Terrains terrain; private final Materials materials; public ErosionDecorator(TerraContext context) { @@ -75,11 +75,11 @@ public class ErosionDecorator implements ColumnDecorator { @Override public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.value < minY || context.cell.terrainType == terrain.river || context.cell.terrainType == terrain.riverBanks) { + if (context.cell.value < minY || context.cell.terrain == terrain.river || context.cell.terrain == terrain.riverBanks) { return; } - if (context.cell.terrainType == terrain.volcanoPipe) { + if (context.cell.terrain == terrain.volcanoPipe) { return; } diff --git a/src/main/java/com/terraforged/chunk/column/post/SnowEroder.java b/src/main/java/com/terraforged/chunk/column/post/SnowEroder.java index 81c2b8b..ab00cd9 100644 --- a/src/main/java/com/terraforged/chunk/column/post/SnowEroder.java +++ b/src/main/java/com/terraforged/chunk/column/post/SnowEroder.java @@ -71,7 +71,7 @@ public class SnowEroder extends ErosionDecorator { float var = -ColumnDecorator.getNoise(x, z, seed1, 16, 0); float hNoise = rand.getValue(x, z, seed2) * HEIGHT_MODIFIER; float sNoise = rand.getValue(x, z, seed3) * SLOPE_MODIFIER; - float vModifier = context.cell.terrainType == context.terrains.volcano ? 0.15F : 0F; + float vModifier = context.cell.terrain == context.terrains.volcano ? 0.15F : 0F; float height = context.cell.value + var + hNoise + vModifier; float steepness = context.cell.steepness + var + sNoise + vModifier; if (snowErosion(x, z, steepness, height)) { diff --git a/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java b/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java index 35f1c5a..2afe367 100644 --- a/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java +++ b/src/main/java/com/terraforged/chunk/generator/TerrainGenerator.java @@ -13,7 +13,7 @@ import com.terraforged.feature.TerrainHelper; import com.terraforged.util.Environment; import com.terraforged.world.climate.Climate; import com.terraforged.world.heightmap.Levels; -import com.terraforged.world.terrain.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; import net.minecraft.world.biome.Biome; @@ -28,7 +28,7 @@ public class TerrainGenerator { private final Levels levels; private final Climate climate; - private final TerrainTypes terrain; + private final Terrains terrain; private final TerraChunkGenerator generator; private final TerrainHelper terrainHelper; diff --git a/src/main/java/com/terraforged/chunk/test/Test.java b/src/main/java/com/terraforged/chunk/test/Test.java index 8d88b72..07ee78d 100644 --- a/src/main/java/com/terraforged/chunk/test/Test.java +++ b/src/main/java/com/terraforged/chunk/test/Test.java @@ -26,7 +26,7 @@ package com.terraforged.chunk.test; import com.terraforged.world.terrain.Terrain; -import com.terraforged.world.terrain.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biomes; @@ -34,7 +34,7 @@ public class Test { public static boolean fixedBiome = false; - public static Terrain getTerrainType(TerrainTypes terrains) { + public static Terrain getTerrainType(Terrains terrains) { return terrains.badlands; } diff --git a/src/main/java/com/terraforged/chunk/test/TestHeightMap.java b/src/main/java/com/terraforged/chunk/test/TestHeightMap.java index e71f09d..22ec06b 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; public class TestHeightMap extends WorldHeightmap { - private final TerrainTypes terrains; + private final Terrains terrains; public TestHeightMap(GeneratorContext context) { super(context); diff --git a/src/main/java/com/terraforged/chunk/util/FastChunk.java b/src/main/java/com/terraforged/chunk/util/FastChunk.java index a310c48..2a22e94 100644 --- a/src/main/java/com/terraforged/chunk/util/FastChunk.java +++ b/src/main/java/com/terraforged/chunk/util/FastChunk.java @@ -4,6 +4,7 @@ import com.terraforged.api.chunk.ChunkDelegate; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.palette.PalettedContainer; import net.minecraft.world.biome.BiomeContainer; import net.minecraft.world.chunk.ChunkPrimer; import net.minecraft.world.chunk.ChunkSection; @@ -63,6 +64,31 @@ public class FastChunk implements ChunkDelegate { return Blocks.VOID_AIR.getDefaultState(); } + public void fill(BlockState state) { + int surfaceMinY = 255; + for (int dz = 0; dz < 16; dz++) { + for (int dx = 0; dx < 16; dx++) { + int y = primer.getTopBlockY(Heightmap.Type.OCEAN_FLOOR_WG, dx, dz); + surfaceMinY = Math.min(surfaceMinY, y); + } + } + + int topSection = (surfaceMinY >> 4); + for (int sectionIndex = 0; sectionIndex < topSection; sectionIndex++) { + ChunkSection section = primer.getSection(sectionIndex); + section.lock(); + PalettedContainer container = section.getData(); + for (int dy = 0; dy < 16; dy++) { + for (int dz = 0; dz < 16; dz++) { + for (int dx = 0; dx < 16; dx++) { + container.swap(dx, dy, dz, state); + } + } + } + section.unlock(); + } + } + public void setBiomes(BiomeContainer biomes) { primer.func_225548_a_(biomes); } diff --git a/src/main/java/com/terraforged/command/TerraCommand.java b/src/main/java/com/terraforged/command/TerraCommand.java index 1909c00..7ace97a 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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraft.command.arguments.ArgumentSerializer; @@ -129,7 +129,7 @@ public class TerraCommand { Cell cell = biomeProvider.lookupPos(pos.getX(), pos.getZ()); Biome biome = biomeProvider.getBiome(cell, pos.getX(), pos.getZ()); context.getSource().sendFeedback( - new StringTextComponent("Terrain=" + cell.terrainType.getName() + ", Biome=" + biome.getRegistryName()), + new StringTextComponent("Terrain=" + cell.terrain.getName() + ", Biome=" + biome.getRegistryName()), false ); @@ -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, TerrainTypes terrains) { + private static Terrain getTerrainInstance(Terrain find, Terrains terrains) { for (Terrain t : terrains.index) { if (t.getName().equals(find.getName())) { return t; diff --git a/src/main/java/com/terraforged/command/search/TerrainSearchTask.java b/src/main/java/com/terraforged/command/search/TerrainSearchTask.java index 8a55ac3..1a7155e 100644 --- a/src/main/java/com/terraforged/command/search/TerrainSearchTask.java +++ b/src/main/java/com/terraforged/command/search/TerrainSearchTask.java @@ -25,6 +25,6 @@ public class TerrainSearchTask extends Search { @Override public boolean test(BlockPos pos) { generator.getHeightmap().apply(cell, pos.getX(), pos.getZ()); - return cell.terrainType == type; + return cell.terrain == type; } } diff --git a/src/main/java/com/terraforged/feature/TerrainHelper.java b/src/main/java/com/terraforged/feature/TerrainHelper.java index eaa96da..fec1126 100644 --- a/src/main/java/com/terraforged/feature/TerrainHelper.java +++ b/src/main/java/com/terraforged/feature/TerrainHelper.java @@ -25,6 +25,7 @@ package com.terraforged.feature; +import com.google.common.collect.ImmutableSet; import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectList; @@ -37,15 +38,22 @@ import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.world.IWorld; import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.Heightmap; -import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.jigsaw.JigsawPattern; -import net.minecraft.world.gen.feature.structure.AbstractVillagePiece; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraft.world.gen.feature.structure.StructurePiece; -import net.minecraft.world.gen.feature.structure.StructureStart; +import net.minecraft.world.gen.feature.structure.*; + +import java.util.List; +import java.util.Set; public class TerrainHelper { + private static final Set SURFACE_STRUCTURES = ImmutableSet.of( + IStructurePieceType.PCP, // outpost + IStructurePieceType.NVI, // village + IStructurePieceType.TEJP, // jungle temple + IStructurePieceType.IGLU, // igloo + IStructurePieceType.TEDP // desert pyramid + ); + private final float radius; public TerrainHelper(float radius) { @@ -53,15 +61,15 @@ public class TerrainHelper { } public void flatten(IWorld world, IChunk chunk) { - ObjectList pieces = new ObjectArrayList<>(10); + ObjectList pieces = new ObjectArrayList<>(10); collectPieces(world, chunk, pieces); buildBases(chunk, pieces); } // see NoiseChunkGenerator - private void collectPieces(IWorld world, IChunk chunk, ObjectList pieces) { + private void collectPieces(IWorld world, IChunk chunk, ObjectList pieces) { ChunkPos pos = chunk.getPos(); - for (Structure structure : Feature.ILLAGER_STRUCTURES) { + for (Structure structure : Structure.ILLAGER_STRUCTURES) { String name = structure.getStructureName(); LongIterator structureIds = chunk.getStructureReferences(name).iterator(); @@ -72,12 +80,9 @@ public class TerrainHelper { StructureStart structurestart = neighbourChunk.getStructureStart(name); if (structurestart != null && structurestart.isValid()) { for (StructurePiece structurepiece : structurestart.getComponents()) { - if (structurepiece.func_214810_a(pos, 12) && structurepiece instanceof AbstractVillagePiece) { - AbstractVillagePiece piece = (AbstractVillagePiece) structurepiece; - JigsawPattern.PlacementBehaviour placement = piece.getJigsawPiece().getPlacementBehaviour(); - if (placement == JigsawPattern.PlacementBehaviour.RIGID) { - pieces.add(piece); - } + // collect if piece is within radius of the chunk + if (structurepiece.func_214810_a(pos, 12)) { + collectPiece(structurepiece, pieces); } } } @@ -86,11 +91,11 @@ public class TerrainHelper { } // lowers or raises the terrain matcher the base height of each structure piece - private void buildBases(IChunk chunk, ObjectList pieces) { + private void buildBases(IChunk chunk, ObjectList pieces) { int chunkStartX = chunk.getPos().getXStart(); int chunkStartZ = chunk.getPos().getZStart(); BlockPos.Mutable pos = new BlockPos.Mutable(); - ObjectListIterator iterator = pieces.iterator(); + ObjectListIterator iterator = pieces.iterator(); MutableBoundingBox chunkBounds = new MutableBoundingBox(chunkStartX, chunkStartZ, chunkStartX + 15, chunkStartZ + 15); for (int dz = 0; dz < 16; dz++) { @@ -100,9 +105,10 @@ public class TerrainHelper { int surface = chunk.getTopBlockY(Heightmap.Type.OCEAN_FLOOR_WG, dx, dz); float y = surface; - AbstractVillagePiece highest = null; + int highestOffset = 0; + StructurePiece highest = null; while (iterator.hasNext()) { - AbstractVillagePiece piece = iterator.next(); + StructurePiece piece = iterator.next(); MutableBoundingBox pieceBounds = piece.getBoundingBox(); int length = Math.min(pieceBounds.maxX - pieceBounds.minX, pieceBounds.maxZ - pieceBounds.minZ); int borderRadius = Math.min(5, Math.max(10, NoiseUtil.round(length * radius))); @@ -111,7 +117,8 @@ public class TerrainHelper { continue; } - int level = pieceBounds.minY + piece.getGroundLevelDelta(); + int offset = getGroundLevelDelta(piece); + int level = pieceBounds.minY + offset; if (level > y) { y = raise(pieceBounds, pos.setPos(x, surface, z), level, y, borderRadius); } @@ -119,6 +126,7 @@ public class TerrainHelper { if (x > pieceBounds.minX && x < pieceBounds.maxX && z > pieceBounds.minZ && z < pieceBounds.maxZ) { if (highest == null || pieceBounds.minY > highest.getBoundingBox().minY) { highest = piece; + highestOffset = offset; } } } @@ -136,7 +144,7 @@ public class TerrainHelper { if (highest != null) { MutableBoundingBox bounds = highest.getBoundingBox(); - for (int dy = bounds.minY + highest.getGroundLevelDelta(); dy <= surface; dy++) { + for (int dy = bounds.minY + highestOffset; dy <= surface; dy++) { pos.setPos(dx, dy, dz); chunk.setBlockState(pos, Blocks.AIR.getDefaultState(), false); } @@ -152,6 +160,25 @@ public class TerrainHelper { return NoiseUtil.lerp(surface, level, alpha); } + private static void collectPiece(StructurePiece structurepiece, List list) { + if (structurepiece instanceof AbstractVillagePiece) { + AbstractVillagePiece piece = (AbstractVillagePiece) structurepiece; + JigsawPattern.PlacementBehaviour placement = piece.getJigsawPiece().getPlacementBehaviour(); + if (placement == JigsawPattern.PlacementBehaviour.RIGID) { + list.add(piece); + } + } else if (SURFACE_STRUCTURES.contains(structurepiece.getStructurePieceType())) { + list.add(structurepiece); + } + } + + private static int getGroundLevelDelta(StructurePiece piece) { + if (piece instanceof AbstractVillagePiece) { + return ((AbstractVillagePiece) piece).getGroundLevelDelta(); + } + return 0; + } + private static MutableBoundingBox expand(MutableBoundingBox box, int radius) { return new MutableBoundingBox( box.minX - radius, diff --git a/src/main/java/com/terraforged/feature/context/ChanceContext.java b/src/main/java/com/terraforged/feature/context/ChanceContext.java index 2f1edc5..1cb1397 100644 --- a/src/main/java/com/terraforged/feature/context/ChanceContext.java +++ b/src/main/java/com/terraforged/feature/context/ChanceContext.java @@ -3,7 +3,7 @@ package com.terraforged.feature.context; import com.terraforged.chunk.fix.RegionDelegate; import com.terraforged.chunk.util.TerraContainer; import com.terraforged.core.cell.Cell; -import com.terraforged.core.concurrent.ObjectPool; +import com.terraforged.core.concurrent.pool.ObjectPool; import com.terraforged.core.concurrent.Resource; import com.terraforged.core.region.chunk.ChunkReader; import com.terraforged.world.heightmap.Levels; diff --git a/src/main/java/com/terraforged/feature/decorator/poisson/PoissonDecorator.java b/src/main/java/com/terraforged/feature/decorator/poisson/PoissonDecorator.java index af19d68..eadb599 100644 --- a/src/main/java/com/terraforged/feature/decorator/poisson/PoissonDecorator.java +++ b/src/main/java/com/terraforged/feature/decorator/poisson/PoissonDecorator.java @@ -23,7 +23,7 @@ public abstract class PoissonDecorator extends Placement { } @Override - public final > boolean place(IWorld world, ChunkGenerator generator, Random random, BlockPos pos, PoissonConfig config, ConfiguredFeature feature) { + public > boolean place(IWorld world, ChunkGenerator generator, Random random, BlockPos pos, PoissonConfig config, ConfiguredFeature feature) { int radius = Math.max(1, Math.min(30, config.radius)); Poisson poisson = getInstance(radius); PoissonVisitor visitor = new PoissonVisitor(this, feature, world, generator, random, pos); diff --git a/src/main/java/com/terraforged/gui/SettingsScreen.java b/src/main/java/com/terraforged/gui/SettingsScreen.java index f5ba88d..ac9a237 100644 --- a/src/main/java/com/terraforged/gui/SettingsScreen.java +++ b/src/main/java/com/terraforged/gui/SettingsScreen.java @@ -26,15 +26,13 @@ package com.terraforged.gui; import com.terraforged.gui.element.TerraLabel; -import com.terraforged.gui.page.ClimatePage; -import com.terraforged.gui.page.MiscPage; import com.terraforged.gui.page.Page; import com.terraforged.gui.page.PresetsPage; -import com.terraforged.gui.page.RiverPage; -import com.terraforged.gui.page.StructurePage; -import com.terraforged.gui.page.TerrainPage; +import com.terraforged.gui.page.SimplePage; +import com.terraforged.gui.page.SimplePreviewPage; import com.terraforged.gui.page.WorldPage; import com.terraforged.gui.preview.PreviewPage; +import com.terraforged.gui.preview.again.PreviewPage2; import com.terraforged.settings.SettingsHelper; import com.terraforged.settings.TerraSettings; import com.terraforged.util.nbt.NBTHelper; @@ -51,7 +49,7 @@ public class SettingsScreen extends OverlayScreen { private static final Button.IPressable NO_ACTION = b -> {}; private final Page[] pages; - private final PreviewPage preview; + private final PreviewPage2 preview; private final CreateWorldScreen parent; private final TerraSettings settings = new TerraSettings(); @@ -60,15 +58,16 @@ public class SettingsScreen extends OverlayScreen { public SettingsScreen(CreateWorldScreen parent) { SettingsHelper.applyDefaults(parent.chunkProviderSettingsJson, settings); this.parent = parent; - this.preview = new PreviewPage(settings, getSeed(parent)); + this.preview = new PreviewPage2(settings, getSeed(parent)); this.pages = new Page[]{ new PresetsPage(), new WorldPage(settings, preview), - new ClimatePage(settings, preview), - new TerrainPage(settings, preview), - new RiverPage(settings, preview), - new StructurePage(settings), - new MiscPage(settings) + new SimplePreviewPage("Climate Settings", "climate", preview, settings, s -> s.climate), + new SimplePreviewPage("Terrain Settings", "terrain", preview, settings, s -> s.terrain), + new SimplePreviewPage("River Settings", "rivers", preview, settings, s -> s.rivers), + new SimplePreviewPage("Filter Settings", "filters", preview, settings, s -> s.filters), + new SimplePage("Structure Settings", "structures", settings, s -> s.structures), + new SimplePage("Feature Settings", "features", settings, s -> s.features) }; } diff --git a/src/main/java/com/terraforged/gui/page/ClimatePage.java b/src/main/java/com/terraforged/gui/page/ClimatePage.java deleted file mode 100644 index dbc48cf..0000000 --- a/src/main/java/com/terraforged/gui/page/ClimatePage.java +++ /dev/null @@ -1,68 +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.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.gui.OverlayScreen; -import com.terraforged.gui.preview.PreviewPage; -import com.terraforged.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class ClimatePage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT climateSettings; - - public ClimatePage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.climateSettings = NBTHelper.serialize("climate", settings.climate); - } - - @Override - public String getTitle() { - return "Climate Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(climateSettings, settings.climate); - } - - @Override - public void init(OverlayScreen parent) { - Column center = getColumn(0); - center.scrollPane.setScrollAmount(0D); - addElements(0, 0, center, climateSettings, true, center.scrollPane::addButton, this::update); - } - - @Override - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(climateSettings, settings.climate)); - } -} diff --git a/src/main/java/com/terraforged/gui/page/MiscPage.java b/src/main/java/com/terraforged/gui/page/MiscPage.java deleted file mode 100644 index b3257f5..0000000 --- a/src/main/java/com/terraforged/gui/page/MiscPage.java +++ /dev/null @@ -1,65 +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.gui.page; - -import com.terraforged.gui.OverlayScreen; -import com.terraforged.gui.element.TerraLabel; -import com.terraforged.settings.TerraSettings; -import com.terraforged.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class MiscPage extends BasePage { - - private final TerraSettings settings; - private final CompoundNBT filterSettings; - private final CompoundNBT featureSettings; - - public MiscPage(TerraSettings settings) { - this.settings = settings; - this.filterSettings = NBTHelper.serialize("filters", settings.filters); - this.featureSettings = NBTHelper.serialize("features", settings.features); - } - - @Override - public String getTitle() { - return "Miscellaneous Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(filterSettings, settings.filters); - NBTHelper.deserialize(featureSettings, settings.features); - } - - @Override - public void init(OverlayScreen parent) { - Column left = getColumn(0); - addElements(left.left, left.top, left, filterSettings, true, left.scrollPane::addButton, this::update); - - left.scrollPane.addButton(new TerraLabel("Features & Decorators")); - addElements(left.left, left.top, left, featureSettings, false, left.scrollPane::addButton, this::update); - } -} diff --git a/src/main/java/com/terraforged/gui/page/PresetPage.java b/src/main/java/com/terraforged/gui/page/PresetPage.java deleted file mode 100644 index d4eb011..0000000 --- a/src/main/java/com/terraforged/gui/page/PresetPage.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.terraforged.gui.page; - -import com.terraforged.gui.OverlayScreen; - -public class PresetPage extends BasePage { - - @Override - public void save() { - - } - - @Override - public void init(OverlayScreen parent) { - - } -} diff --git a/src/main/java/com/terraforged/gui/page/RiverPage.java b/src/main/java/com/terraforged/gui/page/RiverPage.java deleted file mode 100644 index 354858b..0000000 --- a/src/main/java/com/terraforged/gui/page/RiverPage.java +++ /dev/null @@ -1,67 +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.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.gui.OverlayScreen; -import com.terraforged.gui.preview.PreviewPage; -import com.terraforged.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class RiverPage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT riverSettings; - - public RiverPage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.riverSettings = NBTHelper.serialize("rivers", settings.rivers); - } - - @Override - public String getTitle() { - return "River Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(riverSettings, settings.rivers); - } - - @Override - public void init(OverlayScreen parent) { - Column center = getColumn(0); - center.scrollPane.setScrollAmount(0D); - addElements(0, 0, center, riverSettings, true, center.scrollPane::addButton, this::update); - } - - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(riverSettings, settings.rivers)); - } -} diff --git a/src/main/java/com/terraforged/gui/page/SimplePage.java b/src/main/java/com/terraforged/gui/page/SimplePage.java new file mode 100644 index 0000000..d5dcf0c --- /dev/null +++ b/src/main/java/com/terraforged/gui/page/SimplePage.java @@ -0,0 +1,44 @@ +package com.terraforged.gui.page; + +import com.terraforged.gui.OverlayScreen; +import com.terraforged.settings.TerraSettings; +import com.terraforged.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; + +import java.util.function.Function; + +public class SimplePage extends BasePage { + + private final String title; + protected final TerraSettings settings; + protected final CompoundNBT sectionSettings; + protected final Function section; + + public SimplePage(String title, String sectionName, TerraSettings settings, Function section) { + this.title = title; + this.section = section; + this.settings = settings; + this.sectionSettings = NBTHelper.serialize(sectionName, section.apply(settings)); + } + + @Override + public String getTitle() { + return title; + } + + @Override + public void save() { + NBTHelper.deserialize(sectionSettings, section); + } + + @Override + public void init(OverlayScreen parent) { + Column left = getColumn(0); + addElements(left.left, left.top, left, sectionSettings, true, left.scrollPane::addButton, this::update); + } + + @Override + protected void update() { + super.update(); + } +} diff --git a/src/main/java/com/terraforged/gui/page/SimplePreviewPage.java b/src/main/java/com/terraforged/gui/page/SimplePreviewPage.java new file mode 100644 index 0000000..2806d0f --- /dev/null +++ b/src/main/java/com/terraforged/gui/page/SimplePreviewPage.java @@ -0,0 +1,22 @@ +package com.terraforged.gui.page; + +import com.terraforged.settings.TerraSettings; +import com.terraforged.util.nbt.NBTHelper; + +import java.util.function.Function; + +public class SimplePreviewPage extends SimplePage { + + private final UpdatablePage preview; + + public SimplePreviewPage(String title, String sectionName, UpdatablePage preview, TerraSettings settings, Function section) { + super(title, sectionName, settings, section); + this.preview = preview; + } + + @Override + protected void update() { + super.update(); + preview.apply(settings -> NBTHelper.deserialize(sectionSettings, section.apply(settings))); + } +} diff --git a/src/main/java/com/terraforged/gui/page/StructurePage.java b/src/main/java/com/terraforged/gui/page/StructurePage.java deleted file mode 100644 index aab4187..0000000 --- a/src/main/java/com/terraforged/gui/page/StructurePage.java +++ /dev/null @@ -1,58 +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.gui.page; - -import com.terraforged.gui.OverlayScreen; -import com.terraforged.settings.TerraSettings; -import com.terraforged.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class StructurePage extends BasePage { - - private final TerraSettings settings; - private final CompoundNBT structureSettings; - - public StructurePage(TerraSettings settings) { - this.settings = settings; - this.structureSettings = NBTHelper.serialize("structures", settings.structures); - } - - @Override - public String getTitle() { - return "Structure Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(structureSettings, settings.structures); - } - - @Override - public void init(OverlayScreen parent) { - Column left = getColumn(0); - addElements(left.left, left.top, left, structureSettings, true, left.scrollPane::addButton, this::update); - } -} diff --git a/src/main/java/com/terraforged/gui/page/TerrainPage.java b/src/main/java/com/terraforged/gui/page/TerrainPage.java deleted file mode 100644 index 96237bb..0000000 --- a/src/main/java/com/terraforged/gui/page/TerrainPage.java +++ /dev/null @@ -1,67 +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.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.gui.OverlayScreen; -import com.terraforged.gui.preview.PreviewPage; -import com.terraforged.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class TerrainPage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT terrainSettings; - - public TerrainPage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.terrainSettings = NBTHelper.serialize("terrain", settings.terrain); - } - - @Override - public String getTitle() { - return "Terrain Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(terrainSettings, settings.terrain); - } - - @Override - public void init(OverlayScreen parent) { - Column center = getColumn(0); - center.scrollPane.setScrollAmount(0D); - addElements(0, 0, center, terrainSettings, true, center.scrollPane::addButton, this::update); - } - - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(terrainSettings, settings.terrain)); - } -} diff --git a/src/main/java/com/terraforged/gui/page/UpdatablePage.java b/src/main/java/com/terraforged/gui/page/UpdatablePage.java new file mode 100644 index 0000000..5ad636a --- /dev/null +++ b/src/main/java/com/terraforged/gui/page/UpdatablePage.java @@ -0,0 +1,23 @@ +package com.terraforged.gui.page; + +import com.terraforged.gui.OverlayScreen; +import com.terraforged.settings.TerraSettings; + +import java.util.function.Consumer; + +public class UpdatablePage extends BasePage { + + @Override + public void save() { + + } + + @Override + public void init(OverlayScreen parent) { + + } + + public void apply(Consumer consumer) { + + } +} diff --git a/src/main/java/com/terraforged/gui/page/WorldPage.java b/src/main/java/com/terraforged/gui/page/WorldPage.java index 495eaa8..eb71908 100644 --- a/src/main/java/com/terraforged/gui/page/WorldPage.java +++ b/src/main/java/com/terraforged/gui/page/WorldPage.java @@ -42,11 +42,11 @@ import net.minecraftforge.registries.ForgeRegistries; public class WorldPage extends BasePage { private final TerraSettings settings; - private final PreviewPage preview; + private final UpdatablePage preview; private final CompoundNBT worldSettings; private final CompoundNBT dimSettings; - public WorldPage(TerraSettings settings, PreviewPage preview) { + public WorldPage(TerraSettings settings, UpdatablePage preview) { this.settings = settings; this.preview = preview; this.worldSettings = NBTHelper.serialize("world", settings.world); diff --git a/src/main/java/com/terraforged/gui/preview/Preview.java b/src/main/java/com/terraforged/gui/preview/Preview.java index 64591eb..cc0e33f 100644 --- a/src/main/java/com/terraforged/gui/preview/Preview.java +++ b/src/main/java/com/terraforged/gui/preview/Preview.java @@ -29,7 +29,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.terraforged.core.cell.Cell; import com.terraforged.core.concurrent.cache.CacheEntry; -import com.terraforged.core.concurrent.pool.ThreadPools; +import com.terraforged.core.concurrent.thread.ThreadPools; import com.terraforged.core.region.Region; import com.terraforged.core.region.Size; import com.terraforged.core.region.gen.RegionGenerator; @@ -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.TerrainTypes; +import com.terraforged.world.terrain.Terrains; 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(TerrainTypes.create(settings), settings); + GeneratorContext context = GeneratorContext.createNoCache(Terrains.create(settings), settings); MutableVeci center = new MutableVeci(); context.factory.getHeightmap().getContinent().getNearestCenter(offsetX, offsetZ, center); @@ -276,7 +276,7 @@ public class Preview extends Button { } private static String getTerrainName(Cell cell) { - String terrain = cell.terrainType.getName().toLowerCase(); + String terrain = cell.terrain.getName().toLowerCase(); if (terrain.contains("river")) { return "river"; } @@ -284,7 +284,7 @@ public class Preview extends Button { } private static String getBiomeName(Cell cell) { - String terrain = cell.terrainType.getName().toLowerCase(); + String terrain = cell.terrain.getName().toLowerCase(); if (terrain.contains("ocean")) { if (cell.temperature < 0.3) { return "cold_ocean"; diff --git a/src/main/java/com/terraforged/gui/preview/PreviewPage.java b/src/main/java/com/terraforged/gui/preview/PreviewPage.java index 784987f..f22cc6e 100644 --- a/src/main/java/com/terraforged/gui/preview/PreviewPage.java +++ b/src/main/java/com/terraforged/gui/preview/PreviewPage.java @@ -25,22 +25,23 @@ package com.terraforged.gui.preview; -import com.terraforged.core.settings.Settings; import com.terraforged.gui.OverlayScreen; import com.terraforged.gui.element.TerraButton; import com.terraforged.gui.page.BasePage; +import com.terraforged.gui.page.UpdatablePage; +import com.terraforged.settings.TerraSettings; import com.terraforged.util.nbt.NBTHelper; import net.minecraft.nbt.CompoundNBT; import java.util.function.Consumer; -public class PreviewPage extends BasePage { +public class PreviewPage extends UpdatablePage { private final Preview preview; - private final Settings settings; + private final TerraSettings settings; private final CompoundNBT previewerSettings = NBTHelper.serialize("preview", new PreviewSettings()); - public PreviewPage(Settings settings, int seed) { + public PreviewPage(TerraSettings settings, int seed) { this.preview = new Preview(seed); this.settings = settings; } @@ -49,7 +50,8 @@ public class PreviewPage extends BasePage { return preview.getSeed(); } - public void apply(Consumer consumer) { + @Override + public void apply(Consumer consumer) { consumer.accept(settings); preview.update(settings, previewerSettings); } @@ -59,11 +61,6 @@ public class PreviewPage extends BasePage { preview.close(); } - @Override - public void save() { - - } - @Override public void init(OverlayScreen parent) { Column right = getColumn(1); @@ -92,6 +89,7 @@ public class PreviewPage extends BasePage { update(); } + @Override public void update() { preview.update(settings, previewerSettings); } diff --git a/src/main/java/com/terraforged/gui/preview/again/MCRenderAPI.java b/src/main/java/com/terraforged/gui/preview/again/MCRenderAPI.java new file mode 100644 index 0000000..6192831 --- /dev/null +++ b/src/main/java/com/terraforged/gui/preview/again/MCRenderAPI.java @@ -0,0 +1,44 @@ +package com.terraforged.gui.preview.again; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.terraforged.core.render.RenderAPI; +import com.terraforged.core.render.RenderBuffer; +import net.minecraft.client.renderer.BufferBuilder; + +public class MCRenderAPI implements RenderAPI { + + @Override + public void pushMatrix() { + RenderSystem.pushMatrix(); + } + + @Override + public void popMatrix() { + RenderSystem.popMatrix(); + } + + @Override + public void translate(float x, float y, float z) { + RenderSystem.translatef(x, y, z); + } + + @Override + public void rotateX(float angle) { + + } + + @Override + public void rotateY(float angle) { + + } + + @Override + public void rotateZ(float angle) { + + } + + @Override + public RenderBuffer createBuffer() { + return new MCRenderBuffer(new BufferBuilder(4096)); + } +} diff --git a/src/main/java/com/terraforged/gui/preview/again/MCRenderBuffer.java b/src/main/java/com/terraforged/gui/preview/again/MCRenderBuffer.java new file mode 100644 index 0000000..ec25af4 --- /dev/null +++ b/src/main/java/com/terraforged/gui/preview/again/MCRenderBuffer.java @@ -0,0 +1,66 @@ +package com.terraforged.gui.preview.again; + +import com.terraforged.core.render.RenderBuffer; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldVertexBufferUploader; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class MCRenderBuffer implements RenderBuffer { + + private final Object lock = new Object(); + private final BufferBuilder buffer; + + private BufferBuilder.State state = null; + + private float r, g, b; + + public MCRenderBuffer(BufferBuilder buffer) { + this.buffer = buffer; + } + + @Override + public void beginQuads() { + buffer.reset(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + } + + @Override + public void endQuads() { + synchronized (lock) { + state = buffer.getVertexState(); + buffer.finishDrawing(); + } + } + + @Override + public void vertex(float x, float y, float z) { + buffer.pos(x, y, z).color(r, g, b, 1).endVertex(); + } + + @Override + public void color(float hue, float saturation, float brightness) { + Color color = Color.getHSBColor(hue / 100F, saturation / 100F, brightness / 100F); + r = color.getRed() / 255F; + g = color.getGreen() / 255F; + b = color.getBlue() / 255F; + } + + @Override + public void draw() { + synchronized (lock) { + if (state != null) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder builder = tessellator.getBuffer(); + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + builder.setVertexState(state); + builder.sortVertexData(0, 0, 5000); + builder.finishDrawing(); + WorldVertexBufferUploader.draw(builder); + } + } + } +} diff --git a/src/main/java/com/terraforged/gui/preview/again/Preview2.java b/src/main/java/com/terraforged/gui/preview/again/Preview2.java new file mode 100644 index 0000000..38c8784 --- /dev/null +++ b/src/main/java/com/terraforged/gui/preview/again/Preview2.java @@ -0,0 +1,111 @@ +package com.terraforged.gui.preview.again; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.terraforged.core.concurrent.thread.ThreadPool; +import com.terraforged.core.concurrent.thread.ThreadPools; +import com.terraforged.core.region.gen.RegionGenerator; +import com.terraforged.core.render.RenderAPI; +import com.terraforged.core.render.RenderSettings; +import com.terraforged.core.render.RenderWorld; +import com.terraforged.settings.TerraSettings; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.continent.MutableVeci; +import com.terraforged.world.terrain.Terrains; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.renderer.RenderHelper; + +public class Preview2 extends Widget { + + private final ThreadPool threadPool = ThreadPools.getPool(); + + private final TerraSettings settings; + + private int seed; + private float zoom = 50; + private float offsetX = 0; + private float offsetZ = 0; + private float angle = 45F; + private RenderWorld world; + private PreviewSettings previewSettings = new PreviewSettings(); + + public Preview2(TerraSettings settings, int seed) { + super(0, 0, "preview"); + this.seed = seed; + this.settings = settings; + this.world = createWorld(settings); + this.world.update(offsetX, offsetZ, zoom, true); + } + + public int getSeed() { + return seed; + } + + public void nextSeed() { + seed++; + world = createWorld(settings); + world.update(offsetX, offsetZ, zoom, true); + } + + @Override + public void render(int mx, int my, float ticks) { + try { + float scale = 0.75F; + + angle += 0.35F; + if (angle >= 360) { + angle = 0; + } + + RenderSystem.pushMatrix(); + RenderSystem.enableLighting(); + RenderHelper.enableStandardItemLighting(); + RenderHelper.setupGui3DDiffuseLighting(); + + RenderSystem.translatef(x, y, 0); + RenderSystem.translatef(width / 2F, width / 2F, 0); + RenderSystem.rotatef(70, 1, 0, 0); + RenderSystem.rotatef(angle, 0, 0, 1); + RenderSystem.scalef(scale, scale, scale); + + world.refresh(); + world.render(); + + RenderHelper.disableStandardItemLighting(); + RenderSystem.popMatrix(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public void update(PreviewSettings settings, TerraSettings genSettings) { + this.previewSettings = settings; +// this.world = createWorld(genSettings); + world.update(offsetX, offsetZ, previewSettings.zoom, true); + } + + private RenderWorld createWorld(TerraSettings settings) { + int size = 4; + int regions = 1; + settings.world.seed = seed; + GeneratorContext context = GeneratorContext.createNoCache(Terrains.create(settings), settings); + + MutableVeci center = new MutableVeci(); + context.factory.getHeightmap().getContinent().getNearestCenter(0, 0, center); + + RegionGenerator generator = RegionGenerator.builder() + .pool(threadPool) + .size(size, 0) + .factory(context.factory) + .batch(6) + .build(); + + RenderAPI renderAPI = new MCRenderAPI(); + RenderSettings renderSettings = new RenderSettings(context); + renderSettings.width = width; + renderSettings.height = height; + renderSettings.zoom = previewSettings.zoom; + renderSettings.renderMode = previewSettings.renderMode; + + return new RenderWorld(generator, renderAPI, renderSettings, regions, size); + } +} diff --git a/src/main/java/com/terraforged/gui/preview/again/PreviewPage2.java b/src/main/java/com/terraforged/gui/preview/again/PreviewPage2.java new file mode 100644 index 0000000..28413ff --- /dev/null +++ b/src/main/java/com/terraforged/gui/preview/again/PreviewPage2.java @@ -0,0 +1,76 @@ +package com.terraforged.gui.preview.again; + +import com.terraforged.gui.OverlayScreen; +import com.terraforged.gui.element.TerraButton; +import com.terraforged.gui.page.UpdatablePage; +import com.terraforged.gui.preview.Preview; +import com.terraforged.settings.TerraSettings; +import com.terraforged.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; + +import java.util.function.Consumer; + +public class PreviewPage2 extends UpdatablePage { + + private final Preview2 preview; + private final CompoundNBT settings; + private final TerraSettings genSettings = new TerraSettings(); + + public PreviewPage2(TerraSettings settings, int seed) { + this.preview = new Preview2(settings, seed); + this.settings = NBTHelper.serialize(new PreviewSettings()); + } + + public int getSeed() { + return preview.getSeed(); + } + + @Override + public void apply(Consumer consumer) { +// consumer.accept(genSettings); + update(); + } + + @Override + public void init(OverlayScreen parent) { + Column right = getColumn(1); + preview.x = 0; + preview.y = 0; + preview.setWidth(Preview.WIDTH); + preview.setHeight(Preview.HEIGHT); + + addElements(right.left, right.top, right, settings, right.scrollPane::addButton, this::update); + + right.scrollPane.addButton(new TerraButton("New Seed") { + @Override + public void onPress() { + preview.nextSeed(); + update(); + } + }); + + right.scrollPane.addButton(preview); + + // used to pad the scroll-pane out so that the preview legend scrolls on larger gui scales + TerraButton spacer = createSpacer(); + for (int i = 0; i < 7; i++) { + right.scrollPane.addButton(spacer); + } + + update(); + } + + @Override + public void update() { + PreviewSettings settings = new PreviewSettings(); + NBTHelper.deserialize(this.settings, settings); + preview.update(settings, genSettings); + } + + private static TerraButton createSpacer() { + return new TerraButton("") { + @Override + public void render(int x, int y, float tick) { } + }; + } +} diff --git a/src/main/java/com/terraforged/gui/preview/again/PreviewSettings.java b/src/main/java/com/terraforged/gui/preview/again/PreviewSettings.java new file mode 100644 index 0000000..b6668a6 --- /dev/null +++ b/src/main/java/com/terraforged/gui/preview/again/PreviewSettings.java @@ -0,0 +1,14 @@ +package com.terraforged.gui.preview.again; + +import com.terraforged.core.render.RenderMode; +import com.terraforged.core.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Serializable; + +@Serializable +public class PreviewSettings { + + @Range(min = 1, max = 200) + public float zoom = 10F; + + public RenderMode renderMode = RenderMode.BIOME_TYPE; +} diff --git a/src/main/java/com/terraforged/util/DummyBlockReader.java b/src/main/java/com/terraforged/util/DummyBlockReader.java index 67d03a9..4f40fd1 100644 --- a/src/main/java/com/terraforged/util/DummyBlockReader.java +++ b/src/main/java/com/terraforged/util/DummyBlockReader.java @@ -25,7 +25,7 @@ package com.terraforged.util; -import com.terraforged.core.concurrent.ObjectPool; +import com.terraforged.core.concurrent.pool.ObjectPool; import com.terraforged.core.concurrent.Resource; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; diff --git a/src/main/resources/data/terraforged/features/trees/spruce_tundra.json b/src/main/resources/data/terraforged/features/trees/spruce_tundra.json index cbb134f..5b61be8 100644 --- a/src/main/resources/data/terraforged/features/trees/spruce_tundra.json +++ b/src/main/resources/data/terraforged/features/trees/spruce_tundra.json @@ -14,31 +14,43 @@ "name": "minecraft:decorated", "config": { "feature": { - "name": "minecraft:random_selector", + "name": "minecraft:decorated", "config": { - "features": [ - { - "name": "terraforged:template", - "config": { - "template": "terraforged:pine" - }, - "chance": 0.3 - } - ], - "default": { - "name": "terraforged:template", + "feature": { + "name": "minecraft:random_selector", "config": { - "template": "terraforged:pine" + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + }, + "chance": 0.3 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 10, + "density_noise_scale": 120, + "density_noise_min": 0.5, + "density_noise_max": 1.5 } } } }, "decorator": { - "name": "minecraft:count_extra_heightmap", + "name": "minecraft:chance_passthrough", "config": { - "count": 0, - "extra_chance": 0.02, - "extra_count": 1 + "chance": 0.02 } } }