From 8abd851f77786ed56afb76c533deede7babaf3fb Mon Sep 17 00:00:00 2001 From: dags- Date: Wed, 24 Jun 2020 23:00:08 +0100 Subject: [PATCH] - more work on presets - added stone forest biome - updated lang file --- .../assets/terraforged/lang/en_us.json | 1 + .../terraforged/api/biome/BiomeVariant.java | 5 ++ .../java/com/terraforged/biome/ModBiomes.java | 11 +++ .../com/terraforged/biome/StoneForest.java | 67 +++++++++++++++++++ .../biome/surface/StoneForestSurface.java | 45 +++++++++++++ .../terraforged/chunk/TerraSetupFactory.java | 2 + .../java/com/terraforged/chunk/test/Test.java | 4 +- .../gui/element/TerraTextInput.java | 25 ++++++- .../com/terraforged/gui/page/PresetsPage.java | 59 +++++++++++++++- .../features/trees/jungle_edge.json | 3 +- 10 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/terraforged/biome/StoneForest.java create mode 100644 src/main/java/com/terraforged/biome/surface/StoneForestSurface.java diff --git a/generated/resources/assets/terraforged/lang/en_us.json b/generated/resources/assets/terraforged/lang/en_us.json index 1ebfb70..03853f1 100644 --- a/generated/resources/assets/terraforged/lang/en_us.json +++ b/generated/resources/assets/terraforged/lang/en_us.json @@ -11,6 +11,7 @@ "biome.terraforged.snowy_fir_forest": "Snowy Fir Forest", "biome.terraforged.snowy_taiga_scrub": "Snowy Taiga Scrub", "biome.terraforged.steppe": "Steppe", + "biome.terraforged.stone_forest": "Stone Forest", "biome.terraforged.taiga_scrub": "Taiga Scrub", "biome.terraforged.warm_beach": "Warm Beach", "display.terraforged.climate": "Climate", diff --git a/src/main/java/com/terraforged/api/biome/BiomeVariant.java b/src/main/java/com/terraforged/api/biome/BiomeVariant.java index 3bf9895..d6a90ee 100644 --- a/src/main/java/com/terraforged/api/biome/BiomeVariant.java +++ b/src/main/java/com/terraforged/api/biome/BiomeVariant.java @@ -34,6 +34,11 @@ public abstract class BiomeVariant extends Biome { super(biomeBuilder); } + // override to register a custom biome weight with Forge's BiomeManager (default is 10) + public void registerWeights() { + + } + @Override public int getGrassColor(double x, double z) { return getBase().getGrassColor(x, z); diff --git a/src/main/java/com/terraforged/biome/ModBiomes.java b/src/main/java/com/terraforged/biome/ModBiomes.java index 13d4bd7..d7f8154 100644 --- a/src/main/java/com/terraforged/biome/ModBiomes.java +++ b/src/main/java/com/terraforged/biome/ModBiomes.java @@ -41,6 +41,7 @@ public class ModBiomes { public static final Biome BRYCE = register(new Bryce()); public static final Biome COLD_STEPPE = register(new ColdSteppe()); + public static final Biome ERODED_PINNACLE = register(new StoneForest()); public static final Biome FIR_FOREST = register(new FirForest()); public static final Biome FLOWER_PLAINS = register(new FlowerPlains()); public static final Biome FROZEN_LAKE = register(new FrozenLake()); @@ -63,12 +64,22 @@ public class ModBiomes { public static void register(RegistryEvent.Register event) { biomes.forEach(biome -> { event.getRegistry().register(biome); + + // TF biomes can specify a custom biome weight + biome.registerWeights(); + + // let forge generate the BiomeDictionary.Type's since TF biomes are just variants of vanilla ones BiomeDictionary.makeBestGuess(biome); + + // overworld is required for TerraForged BiomeDictionary.addTypes(biome, BiomeDictionary.Type.OVERWORLD); + + // if a variant of a rare biome, register as such if (BiomeDictionary.getTypes(biome.getBase()).contains(BiomeDictionary.Type.RARE)) { BiomeDictionary.addTypes(biome, BiomeDictionary.Type.RARE); } }); + biomes.clear(); biomes.trimToSize(); } diff --git a/src/main/java/com/terraforged/biome/StoneForest.java b/src/main/java/com/terraforged/biome/StoneForest.java new file mode 100644 index 0000000..81267eb --- /dev/null +++ b/src/main/java/com/terraforged/biome/StoneForest.java @@ -0,0 +1,67 @@ +package com.terraforged.biome; + +import com.terraforged.api.biome.BiomeVariant; +import net.minecraft.entity.EntityClassification; +import net.minecraft.entity.EntityType; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.biome.DefaultBiomeFeatures; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.IFeatureConfig; +import net.minecraft.world.gen.feature.structure.MineshaftConfig; +import net.minecraft.world.gen.feature.structure.MineshaftStructure; +import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; +import net.minecraftforge.common.BiomeManager; + +public class StoneForest extends BiomeVariant { + + public StoneForest() { + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.DEFAULT, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(Biome.RainType.RAIN).category(Biome.Category.JUNGLE).depth(0.1F).scale(0.2F).temperature(0.95F).downfall(0.9F).waterColor(4159204).waterFogColor(329011).parent((String)null)); + this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.NORMAL))); + this.addStructure(Feature.STRONGHOLD.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG)); + DefaultBiomeFeatures.addCarvers(this); + DefaultBiomeFeatures.addStructures(this); + DefaultBiomeFeatures.addLakes(this); + DefaultBiomeFeatures.addMonsterRooms(this); + DefaultBiomeFeatures.addStoneVariants(this); + DefaultBiomeFeatures.addOres(this); + DefaultBiomeFeatures.addSedimentDisks(this); + DefaultBiomeFeatures.addBamboo(this); + DefaultBiomeFeatures.addJungleTreeForest(this); + DefaultBiomeFeatures.addExtraDefaultFlowers(this); + DefaultBiomeFeatures.addJungleGrass(this); + DefaultBiomeFeatures.addMushrooms(this); + DefaultBiomeFeatures.addReedsAndPumpkins(this); + DefaultBiomeFeatures.addSprings(this); + DefaultBiomeFeatures.addJunglePlants(this); + DefaultBiomeFeatures.addFreezeTopLayer(this); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.SHEEP, 12, 4, 4)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.PIG, 10, 4, 4)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.CHICKEN, 10, 4, 4)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.COW, 8, 4, 4)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.PARROT, 40, 1, 2)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.PANDA, 1, 1, 2)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.CHICKEN, 10, 4, 4)); + this.addSpawn(EntityClassification.AMBIENT, new Biome.SpawnListEntry(EntityType.BAT, 10, 8, 8)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SPIDER, 100, 4, 4)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ZOMBIE, 95, 4, 4)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ZOMBIE_VILLAGER, 5, 1, 1)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SKELETON, 100, 4, 4)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.CREEPER, 100, 4, 4)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SLIME, 100, 4, 4)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ENDERMAN, 10, 1, 4)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.WITCH, 5, 1, 1)); + this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.OCELOT, 2, 1, 3)); + setRegistryName("terraforged", "stone_forest"); + } + + @Override + public void registerWeights() { + BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(this, 5)); + } + + @Override + public Biome getBase() { + return Biomes.JUNGLE; + } +} diff --git a/src/main/java/com/terraforged/biome/surface/StoneForestSurface.java b/src/main/java/com/terraforged/biome/surface/StoneForestSurface.java new file mode 100644 index 0000000..c7355b3 --- /dev/null +++ b/src/main/java/com/terraforged/biome/surface/StoneForestSurface.java @@ -0,0 +1,45 @@ +package com.terraforged.biome.surface; + +import com.terraforged.api.chunk.surface.Surface; +import com.terraforged.api.chunk.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 { + + private final Module module; + private final BlockState dirt; + private final BlockState grass; + private final BlockState stone; + + public StoneForestSurface(Seed seed) { + dirt = States.DIRT.get(); + stone = States.STONE.get(); + grass = States.GRASS_BLOCK.get(); + module = Source.ridge(seed.next(), 50, 4) + .clamp(0.7, 0.95).map(0, 1) + .pow(1.5) + .terrace(1, 0.25, 4, 1); + } + + @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); + + if (top > height) { + for (int y = height; y < top - 1; y++) { + ctx.buffer.setBlockState(ctx.pos.setPos(x, y, z), stone, false); + } + + ctx.buffer.setBlockState(ctx.pos.setPos(x, top, z), grass, false); + ctx.buffer.setBlockState(ctx.pos.setPos(x, top - 1, z), dirt, false); + } + } +} diff --git a/src/main/java/com/terraforged/chunk/TerraSetupFactory.java b/src/main/java/com/terraforged/chunk/TerraSetupFactory.java index 43700cb..6525e29 100644 --- a/src/main/java/com/terraforged/chunk/TerraSetupFactory.java +++ b/src/main/java/com/terraforged/chunk/TerraSetupFactory.java @@ -6,6 +6,7 @@ import com.terraforged.api.chunk.surface.SurfaceManager; import com.terraforged.biome.ModBiomes; import com.terraforged.biome.surface.BriceSurface; import com.terraforged.biome.surface.DesertSurface; +import com.terraforged.biome.surface.StoneForestSurface; import com.terraforged.biome.surface.ForestSurface; import com.terraforged.biome.surface.IcebergsSurface; import com.terraforged.biome.surface.SwampSurface; @@ -113,6 +114,7 @@ public class TerraSetupFactory { manager.replace(Biomes.DEEP_FROZEN_OCEAN, new IcebergsSurface(context, 30, 30)); manager.replace(Biomes.FROZEN_OCEAN, new IcebergsSurface(context, 20, 15)); manager.append(ModBiomes.BRYCE, new BriceSurface(context.seed)); + manager.append(ModBiomes.ERODED_PINNACLE, new StoneForestSurface(context.seed)); manager.append( new DesertSurface(context), Biomes.DESERT, diff --git a/src/main/java/com/terraforged/chunk/test/Test.java b/src/main/java/com/terraforged/chunk/test/Test.java index e85a013..8676eb0 100644 --- a/src/main/java/com/terraforged/chunk/test/Test.java +++ b/src/main/java/com/terraforged/chunk/test/Test.java @@ -39,10 +39,10 @@ public class Test { } public static Terrain getTerrainType(Terrains terrains) { - return terrains.mountains; + return terrains.plains; } public static Biome getBiome() { - return ModBiomes.TAIGA_SCRUB; + return ModBiomes.ERODED_PINNACLE; } } diff --git a/src/main/java/com/terraforged/gui/element/TerraTextInput.java b/src/main/java/com/terraforged/gui/element/TerraTextInput.java index 708e4d5..672ba72 100644 --- a/src/main/java/com/terraforged/gui/element/TerraTextInput.java +++ b/src/main/java/com/terraforged/gui/element/TerraTextInput.java @@ -14,6 +14,9 @@ public class TerraTextInput extends TextFieldWidget implements Element, Consumer private final String name; private final CompoundNBT value; private final List tooltip; + + private String stringValue = ""; + private boolean valid = true; private Predicate validator = s -> true; private Consumer callback = t -> {}; @@ -22,17 +25,31 @@ public class TerraTextInput extends TextFieldWidget implements Element, Consumer this.name = name; this.value = value; this.tooltip = Element.getToolTip(name, value); + this.stringValue = value.getString(name); setText(value.getString(name)); setResponder(this); setEnabled(true); } + public boolean isValid() { + return valid; + } + public String getValue() { - return value.getString(name); + return stringValue; } public void setColorValidator(Predicate validator) { this.validator = validator; + + // update validity immediately + if (validator.test(stringValue)) { + valid = true; + setTextColor(14737632); + } else { + valid = false; + setTextColor(0xffff3f30); + } } @Override @@ -53,12 +70,16 @@ public class TerraTextInput extends TextFieldWidget implements Element, Consumer @Override public void accept(String text) { value.put(name, StringNBT.valueOf(text)); - callback.accept(this); + stringValue = text; if (validator.test(text)) { + valid = true; setTextColor(14737632); } else { + valid = false; setTextColor(0xffff3f30); } + + callback.accept(this); } } diff --git a/src/main/java/com/terraforged/gui/page/PresetsPage.java b/src/main/java/com/terraforged/gui/page/PresetsPage.java index 4ea66e4..fa35dde 100644 --- a/src/main/java/com/terraforged/gui/page/PresetsPage.java +++ b/src/main/java/com/terraforged/gui/page/PresetsPage.java @@ -13,12 +13,16 @@ import com.terraforged.util.nbt.NBTHelper; import net.minecraft.nbt.CompoundNBT; import java.util.Optional; +import java.util.function.Predicate; +import java.util.regex.Pattern; public class PresetsPage extends BasePage { + private static final Predicate NAME_VALIDATOR = Pattern.compile("^[A-Za-z0-9\\-_ ]+$").asPredicate(); + + private final Instance instance; private final UpdatablePage preview; private final TerraTextInput nameInput; - private final Instance instance; private final PresetManager manager = PresetManager.load(); public PresetsPage(Instance instance, UpdatablePage preview) { @@ -27,6 +31,7 @@ public class PresetsPage extends BasePage { this.preview = preview; this.instance = instance; this.nameInput = new TerraTextInput("name", value); + this.nameInput.setColorValidator(NAME_VALIDATOR); } @Override @@ -59,7 +64,8 @@ public class PresetsPage extends BasePage { @Override public void render(int x, int z, float ticks) { - super.active = !nameInput.getValue().isEmpty(); + // only render as active if the text field is not empty + super.active = nameInput.isValid(); super.render(x, z, ticks); } @@ -79,6 +85,13 @@ public class PresetsPage extends BasePage { }); right.scrollPane.addButton(new TerraButton("Load") { + + @Override + public void render(int x, int z, float ticks) { + super.active = hasSelectedPreset(); + super.render(x, z, ticks); + } + @Override public void onClick(double x, double y) { super.onClick(x, y); @@ -87,6 +100,13 @@ public class PresetsPage extends BasePage { }); right.scrollPane.addButton(new TerraButton("Save") { + + @Override + public void render(int x, int z, float ticks) { + super.active = hasSelectedPreset(); + super.render(x, z, ticks); + } + @Override public void onClick(double x, double y) { super.onClick(x, y); @@ -104,7 +124,38 @@ public class PresetsPage extends BasePage { } }); + right.scrollPane.addButton(new TerraButton("Reset") { + + @Override + public void render(int x, int z, float ticks) { + super.active = hasSelectedPreset(); + super.render(x, z, ticks); + } + + @Override + public void onClick(double x, double y) { + super.onClick(x, y); + getSelected().ifPresent(preset -> { + // create new preset with the same name but default settings + Preset reset = new Preset(preset.getName(), new TerraSettings()); + + // replaces by name + manager.add(reset); + + // update the ui + rebuildPresetList(); + }); + } + }); + right.scrollPane.addButton(new TerraButton("Delete") { + + @Override + public void render(int x, int z, float ticks) { + super.active = hasSelectedPreset(); + super.render(x, z, ticks); + } + @Override public void onClick(double x, double y) { super.onClick(x, y); @@ -117,6 +168,10 @@ public class PresetsPage extends BasePage { }); } + private boolean hasSelectedPreset() { + return getColumn(0).scrollPane.getSelected() != null; + } + private void load(Preset preset) { instance.sync(preset.getSettings()); diff --git a/src/main/resources/data/terraforged/features/trees/jungle_edge.json b/src/main/resources/data/terraforged/features/trees/jungle_edge.json index 85c005d..2d14e5b 100644 --- a/src/main/resources/data/terraforged/features/trees/jungle_edge.json +++ b/src/main/resources/data/terraforged/features/trees/jungle_edge.json @@ -1,7 +1,8 @@ { "biomes": [ "minecraft:jungle_edge", - "minecraft:modified_jungle_edge" + "minecraft:modified_jungle_edge", + "terraforged:stone_forest" ], "match": [ [