- show map on presets page

- interface out 'masked surfaces'
This commit is contained in:
dags- 2020-06-25 19:35:57 +01:00
parent 8abd851f77
commit e37d6bce63
29 changed files with 146 additions and 84 deletions

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface;
package com.terraforged.api.biome.surface;
import net.minecraft.world.biome.Biome;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface;
package com.terraforged.api.biome.surface;
import com.terraforged.api.chunk.ChunkDelegate;
import net.minecraft.block.BlockState;

View File

@ -0,0 +1,18 @@
package com.terraforged.api.biome.surface;
import com.terraforged.core.cell.Cell;
import com.terraforged.n2d.util.NoiseUtil;
public interface MaskedSurface extends Surface {
default float getMask(Cell cell) {
return cell.biomeEdge * NoiseUtil.map(cell.riverMask,0, 0.0005F, 0.0005F);
}
@Override
default void buildSurface(int x, int z, int height, SurfaceContext ctx) {
buildSurface(x, z, height, getMask(ctx.cell), ctx);
}
void buildSurface(int x, int z, int height, float mask, SurfaceContext ctx);
}

View File

@ -23,10 +23,10 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface;
package com.terraforged.api.biome.surface;
import com.terraforged.api.chunk.surface.builder.Combiner;
import com.terraforged.api.biome.surface.builder.Combiner;
import net.minecraft.block.BlockState;
import net.minecraft.world.chunk.IChunk;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface;
package com.terraforged.api.biome.surface;
import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.world.climate.Climate;

View File

@ -23,9 +23,9 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface;
package com.terraforged.api.biome.surface;
import com.terraforged.api.chunk.surface.builder.Delegate;
import com.terraforged.api.biome.surface.builder.Delegate;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;

View File

@ -23,10 +23,10 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface.builder;
package com.terraforged.api.biome.surface.builder;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
public class Combiner implements Surface {

View File

@ -23,10 +23,10 @@
* SOFTWARE.
*/
package com.terraforged.api.chunk.surface.builder;
package com.terraforged.api.biome.surface.builder;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.surfacebuilders.ConfiguredSurfaceBuilder;

View File

@ -25,7 +25,7 @@
package com.terraforged.api.chunk.column;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.api.biome.surface.ChunkSurfaceBuffer;
import com.terraforged.n2d.Source;
import com.terraforged.n2d.source.FastSource;
import net.minecraft.block.BlockState;

View File

@ -27,7 +27,7 @@ package com.terraforged.api.event;
import com.terraforged.api.biome.modifier.ModifierManager;
import com.terraforged.api.chunk.column.DecoratorManager;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.api.biome.surface.SurfaceManager;
import com.terraforged.api.material.geology.GeologyManager;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.fm.modifier.FeatureModifiers;

View File

@ -11,6 +11,7 @@ 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;
import net.minecraftforge.common.BiomeManager;
public class Bryce extends BiomeVariant {
@ -43,6 +44,11 @@ public class Bryce extends BiomeVariant {
this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.WITCH, 5, 1, 1));
}
@Override
public void registerWeights() {
BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(this, 2));
}
@Override
public Biome getBase() {
return Biomes.BADLANDS;

View File

@ -57,7 +57,7 @@ public class StoneForest extends BiomeVariant {
@Override
public void registerWeights() {
BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(this, 5));
BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(this, 2));
}
@Override

View File

@ -1,19 +1,18 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.MaskedSurface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.core.Seed;
import com.terraforged.core.util.Variance;
import com.terraforged.n2d.Module;
import com.terraforged.n2d.Source;
import com.terraforged.n2d.util.NoiseUtil;
import com.terraforged.world.geology.Strata;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import java.util.Random;
public class BriceSurface implements Surface {
public class BriceSurface implements MaskedSurface {
private final Module module;
private final Strata<BlockState> stackStrata;
@ -38,11 +37,14 @@ public class BriceSurface implements Surface {
}
@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;
public void buildSurface(int x, int z, int height, float mask, SurfaceContext ctx) {
float strength = 1 - ctx.cell.steepness;
float value = module.getValue(x, z) * mask * strength;
int top = (int) (value * 30);
if (top == 0) {
return;
}
stackStrata.downwards(x, top, z, ctx.depthBuffer.get(), (y, material) -> {
if (y <= 0) {

View File

@ -1,7 +1,7 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.api.material.state.States;
import com.terraforged.n2d.Module;
import com.terraforged.n2d.Source;

View File

@ -25,8 +25,9 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.MaskedSurface;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.api.material.layer.LayerMaterial;
import com.terraforged.biome.provider.DesertBiomes;
import com.terraforged.biome.provider.TerraBiomeProvider;
@ -43,7 +44,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.Heightmap;
public class DunesSurface implements Surface {
public class DunesSurface implements MaskedSurface {
private final int maxHeight;
private final Levels levels;
@ -63,8 +64,13 @@ public class DunesSurface implements Surface {
}
@Override
public void buildSurface(int x, int z, int surface, SurfaceContext ctx) {
float value = module.getValue(x, z) * getMask(ctx.cell);
public float getMask(Cell cell) {
return NoiseUtil.map(cell.biomeEdge, 0, 0.7F, 0.7F) * NoiseUtil.map(cell.riverMask, 0.5F, 0.95F, 0.45F);
}
@Override
public void buildSurface(int x, int z, int surface, float mask, SurfaceContext ctx) {
float value = module.getValue(x, z) * mask;
float baseHeight = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, x & 15, z & 15);
float duneHeight = baseHeight + value * maxHeight;
int duneBase = (int) baseHeight;
@ -94,8 +100,4 @@ public class DunesSurface implements Surface {
public static Surface create(TerraContext context, DesertBiomes desertBiomes) {
return new DunesSurface(context, 25, desertBiomes);
}
private static float getMask(Cell cell) {
return cell.biomeMask(0F, 0.7F) * (NoiseUtil.map(cell.riverMask, 0.5F, 0.95F, 0.45F));
}
}

View File

@ -1,7 +1,7 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.api.material.state.States;
import com.terraforged.n2d.Module;
import com.terraforged.n2d.Source;

View File

@ -25,8 +25,8 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.MaskedSurface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.api.material.state.States;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.cell.Cell;
@ -38,7 +38,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
public class IcebergsSurface implements Surface {
public class IcebergsSurface implements MaskedSurface {
private final Module up;
private final Module down;
@ -85,13 +85,28 @@ public class IcebergsSurface implements Surface {
}
@Override
public void buildSurface(int x, int z, int height, SurfaceContext ctx) {
float alpha = alpha(ctx.cell);
public float getMask(Cell cell) {
if (cell.value > minDepth) {
return 0;
}
float alpha = 1F;
float delta = minDepth - cell.value;
if (delta < depthRange) {
alpha -= ((depthRange - delta) / depthRange);
}
alpha *= NoiseUtil.map(cell.riverMask, 0.3F, 1F, 0.7F);
return NoiseUtil.clamp(alpha, 0, 1);
}
@Override
public void buildSurface(int x, int z, int height, float mask, SurfaceContext ctx) {
int center = levels.waterLevel - 5;
int top = center + (int) (up.getValue(x, z) * levels.worldHeight * alpha);
int topDepth = (int) (bergTop.getValue(x, z) * levels.worldHeight * alpha);
int bottom = center - (int) (down.getValue(x, z) * levels.worldHeight * alpha);
int top = center + (int) (up.getValue(x, z) * levels.worldHeight * mask);
int topDepth = (int) (bergTop.getValue(x, z) * levels.worldHeight * mask);
int bottom = center - (int) (down.getValue(x, z) * levels.worldHeight * mask);
// set iceberg materials
BlockPos.Mutable pos = new BlockPos.Mutable(x, height, z);
@ -116,20 +131,4 @@ public class IcebergsSurface implements Surface {
}
return States.PACKED_ICE.get();
}
private float alpha(Cell cell) {
if (cell.value > minDepth) {
return 0;
}
float alpha = 1F;
float delta = minDepth - cell.value;
if (delta < depthRange) {
alpha -= ((depthRange - delta) / depthRange);
}
alpha *= NoiseUtil.map(cell.riverMask, 0.3F, 1F, 0.7F);
return NoiseUtil.clamp(alpha, 0, 1);
}
}

View File

@ -1,7 +1,7 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.api.material.state.States;
import com.terraforged.n2d.Module;
import com.terraforged.n2d.Source;

View File

@ -1,15 +1,14 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.MaskedSurface;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.api.material.state.States;
import com.terraforged.core.Seed;
import com.terraforged.n2d.Module;
import com.terraforged.n2d.Source;
import com.terraforged.n2d.util.NoiseUtil;
import net.minecraft.block.BlockState;
public class StoneForestSurface implements Surface {
public class StoneForestSurface implements MaskedSurface {
private final Module module;
private final BlockState dirt;
@ -27,12 +26,12 @@ public class StoneForestSurface implements Surface {
}
@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 = height + (int) (value * 50);
public void buildSurface(int x, int z, int height, float mask, SurfaceContext ctx) {
// reduce height on steeper terrain
float strength = 1 - ctx.cell.steepness;
float value = module.getValue(x, z) * mask * strength;
int top = height + (int) (value * 50);
if (top > height) {
for (int y = height; y < top - 1; y++) {
ctx.buffer.setBlockState(ctx.pos.setPos(x, y, z), stone, false);

View File

@ -1,7 +1,7 @@
package com.terraforged.biome.surface;
import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.Surface;
import com.terraforged.api.biome.surface.SurfaceContext;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;

View File

@ -26,7 +26,7 @@
package com.terraforged.chunk;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.api.biome.surface.SurfaceManager;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.biome.provider.TerraBiomeProvider;
import com.terraforged.chunk.generator.BiomeGenerator;

View File

@ -27,8 +27,8 @@ package com.terraforged.chunk;
import com.electronwill.nightconfig.core.CommentedConfig;
import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.biome.surface.ChunkSurfaceBuffer;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.chunk.settings.TerraSettings;
import com.terraforged.config.PerfDefaults;
import com.terraforged.core.concurrent.thread.ThreadPools;

View File

@ -2,7 +2,7 @@ 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.biome.surface.SurfaceManager;
import com.terraforged.biome.ModBiomes;
import com.terraforged.biome.surface.BriceSurface;
import com.terraforged.biome.surface.DesertSurface;

View File

@ -27,7 +27,7 @@ package com.terraforged.chunk.column;
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.biome.surface.ChunkSurfaceBuffer;
import com.terraforged.material.geology.GeoManager;
import net.minecraft.world.chunk.IChunk;

View File

@ -1,8 +1,8 @@
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.api.biome.surface.ChunkSurfaceBuffer;
import com.terraforged.api.biome.surface.SurfaceContext;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.util.FastChunk;
import com.terraforged.chunk.util.TerraContainer;

View File

@ -61,7 +61,7 @@ public class SettingsScreen extends OverlayScreen {
this.instance = new Instance(settings);
this.preview = new PreviewPage(instance.settings, getSeed(parent));
this.pages = new Page[]{
new PresetsPage(instance, preview),
new PresetsPage(instance, preview, preview.getPreviewWidget()),
new WorldPage(instance, preview),
new SimplePreviewPage("Climate Settings", "climate", preview, instance, s -> s.climate),
new SimplePreviewPage("Terrain Settings", "terrain", preview, instance, s -> s.terrain),

View File

@ -10,6 +10,7 @@ import com.terraforged.gui.element.TerraButton;
import com.terraforged.gui.element.TerraLabel;
import com.terraforged.gui.element.TerraTextInput;
import com.terraforged.util.nbt.NBTHelper;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.nbt.CompoundNBT;
import java.util.Optional;
@ -22,13 +23,15 @@ public class PresetsPage extends BasePage {
private final Instance instance;
private final UpdatablePage preview;
private final Widget previewWidget;
private final TerraTextInput nameInput;
private final PresetManager manager = PresetManager.load();
public PresetsPage(Instance instance, UpdatablePage preview) {
public PresetsPage(Instance instance, UpdatablePage preview, Widget widget) {
CompoundNBT value = new CompoundNBT();
value.putString("name", "");
this.preview = preview;
this.previewWidget = widget;
this.instance = instance;
this.nameInput = new TerraTextInput("name", value);
this.nameInput.setColorValidator(NAME_VALIDATOR);
@ -79,6 +82,10 @@ public class PresetsPage extends BasePage {
manager.add(preset);
nameInput.setText("");
// select newly created preset & load
setSelected(preset);
load(preset);
// update the ui
rebuildPresetList();
}
@ -166,6 +173,14 @@ public class PresetsPage extends BasePage {
});
}
});
right.scrollPane.addButton(previewWidget);
// 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);
}
}
private boolean hasSelectedPreset() {
@ -178,6 +193,16 @@ public class PresetsPage extends BasePage {
update();
}
private void setSelected(Preset preset) {
ScrollPane pane = getColumn(0).scrollPane;
for (ScrollPane.Entry entry : pane.children()) {
if (entry.option.getMessage().equalsIgnoreCase(preset.getName())) {
pane.setSelected(entry);
return;
}
}
}
private Optional<Preset> getSelected() {
ScrollPane.Entry entry = getColumn(0).scrollPane.getSelected();
if (entry == null) {
@ -195,4 +220,11 @@ public class PresetsPage extends BasePage {
left.scrollPane.addButton(new TerraLabel(preset.getName()));
}
}
private static TerraButton createSpacer() {
return new TerraButton("") {
@Override
public void render(int x, int y, float tick) { }
};
}
}

View File

@ -45,6 +45,10 @@ public class PreviewPage extends UpdatablePage {
this.settings = settings;
}
public Preview getPreviewWidget() {
return preview;
}
public int getSeed() {
return preview.getSeed();
}

View File

@ -28,7 +28,7 @@ package com.terraforged.util.setup;
import com.terraforged.api.biome.modifier.ModifierManager;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorManager;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.api.biome.surface.SurfaceManager;
import com.terraforged.api.event.SetupEvent;
import com.terraforged.api.material.geology.GeologyManager;
import com.terraforged.api.material.layer.LayerManager;