From 661cf47eb8f7f1fa7171149a47464efffd2d5487 Mon Sep 17 00:00:00 2001 From: dags- Date: Tue, 3 Mar 2020 22:05:57 +0000 Subject: [PATCH] - filter out non-overworld (BiomeDictionary) biomes so we don't pick mod-biomes designed for other dimensions - add BiomeDict types for tf biomes - fix possible crash when setting a terrain type to 0 - rename 'generate' button to 'new seed' - reduce float slider precision to 3 decimal places --- .../core/world/terrain/TerrainPopulator.java | 42 ------------------- .../provider/StandardTerrainProvider.java | 21 +++++++--- .../com/terraforged/mod/biome/ModBiomes.java | 7 +++- .../mod/biome/provider/BiomeHelper.java | 17 +------- .../mod/gui/element/TerraSlider.java | 2 +- .../mod/gui/preview/PreviewPage.java | 2 +- 6 files changed, 25 insertions(+), 66 deletions(-) diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/TerrainPopulator.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/TerrainPopulator.java index 003779d..6622f02 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/TerrainPopulator.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/TerrainPopulator.java @@ -27,12 +27,7 @@ package com.terraforged.core.world.terrain; import com.terraforged.core.cell.Cell; import com.terraforged.core.cell.Populator; -import com.terraforged.core.util.Seed; import me.dags.noise.Module; -import me.dags.noise.Source; - -import java.util.Arrays; -import java.util.function.BiFunction; public class TerrainPopulator implements Populator { @@ -62,41 +57,4 @@ public class TerrainPopulator implements Populator { public void tag(Cell cell, float x, float y) { cell.tag = type; } - - public static TerrainPopulator[] combine(TerrainPopulator[] input, Seed seed, int scale) { - return combine(input, (tp1, tp2) -> TerrainPopulator.combine(tp1, tp2, seed, scale)); - } - - public static TerrainPopulator combine(TerrainPopulator tp1, TerrainPopulator tp2, Seed seed, int scale) { - Module combined = Source.perlin(seed.next(), scale, 1) - .warp(seed.next(), scale / 2, 2, scale / 2) - .blend(tp1.getSource(), tp2.getSource(), 0.5, 0.25); - - String name = tp1.getType().getName() + "-" + tp2.getType().getName(); - int id = Terrain.ID_START + 1 + tp1.getType().getId() * tp2.getType().getId(); - float weight = Math.min(tp1.getType().getWeight(), tp2.getType().getWeight()); - Terrain type = new Terrain(name, id, weight); - - return new TerrainPopulator(combined, type); - } - - public static T[] combine(T[] input, BiFunction operator) { - int length = input.length; - for (int i = 1; i < input.length; i++) { - length += (input.length - i); - } - - T[] result = Arrays.copyOf(input, length); - for (int i = 0, k = input.length; i < input.length; i++) { - T t1 = input[i]; - result[i] = t1; - for (int j = i + 1; j < input.length; j++, k++) { - T t2 = input[j]; - T t3 = operator.apply(t1, t2); - result[k] = t3; - } - } - - return result; - } } diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java index 166c90c..089fa03 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java @@ -101,7 +101,7 @@ public class StandardTerrainProvider implements TerrainProvider { @Override public List getPopulators() { - List mixed = combine(mixable, this::combine); + List mixed = combine(getMixable(mixable), this::combine); List result = new ArrayList<>(mixed.size() + unmixable.size()); result.addAll(mixed); result.addAll(unmixable); @@ -117,14 +117,15 @@ public class StandardTerrainProvider implements TerrainProvider { } private static TerrainPopulator combine(TerrainPopulator tp1, TerrainPopulator tp2, Seed seed, int scale) { - Module combined = Source.perlin(seed.next(), scale, 1) - .warp(seed.next(), scale / 2, 2, scale / 2) - .blend(tp1.getSource(), tp2.getSource(), 0.5, 0.25); + float weight = Math.min(tp1.getType().getWeight(), tp2.getType().getWeight()); String name = tp1.getType().getName() + "-" + tp2.getType().getName(); int id = Terrain.ID_START + 1 + tp1.getType().getId() * tp2.getType().getId(); - float weight = Math.min(tp1.getType().getWeight(), tp2.getType().getWeight()); + Terrain type = new Terrain(name, id, weight); + Module combined = Source.perlin(seed.next(), scale, 1) + .warp(seed.next(), scale / 2, 2, scale / 2D) + .blend(tp1.getSource(), tp2.getSource(), 0.5, 0.25); return new TerrainPopulator(combined, type); } @@ -152,4 +153,14 @@ public class StandardTerrainProvider implements TerrainProvider { return result; } + + private static List getMixable(List input) { + List output = new ArrayList<>(input.size()); + for (TerrainPopulator populator : input) { + if (populator.getType().getWeight() > 0) { + output.add(populator); + } + } + return output; + } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java index 70bcc26..ed926ac 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java @@ -27,6 +27,7 @@ package com.terraforged.mod.biome; import com.terraforged.api.biome.BiomeVariant; import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -53,7 +54,11 @@ public class ModBiomes { @SubscribeEvent public static void register(RegistryEvent.Register event) { - biomes.forEach(event.getRegistry()::register); + biomes.forEach(biome -> { + event.getRegistry().register(biome); + BiomeDictionary.makeBestGuess(biome); + BiomeDictionary.addTypes(biome, BiomeDictionary.Type.OVERWORLD); + }); biomes.clear(); biomes.trimToSize(); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java index 75fbe47..f683c4f 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java @@ -25,7 +25,6 @@ package com.terraforged.mod.biome.provider; -import com.google.common.collect.Sets; import com.terraforged.core.settings.BiomeSettings; import com.terraforged.core.world.biome.BiomeData; import com.terraforged.core.world.biome.BiomeType; @@ -55,20 +54,6 @@ import java.util.stream.Collectors; public class BiomeHelper { - private static final Set IGNORE_BIOMES = Sets.newHashSet( - Biomes.THE_END, - Biomes.END_BARRENS, - Biomes.END_HIGHLANDS, - Biomes.END_MIDLANDS, - Biomes.SMALL_END_ISLANDS, - Biomes.NETHER, - Biomes.THE_VOID, - Biomes.JUNGLE_EDGE, - Biomes.MODIFIED_JUNGLE_EDGE, - Biomes.MOUNTAIN_EDGE, - Biomes.STONE_SHORE - ); - private static final Map PREDICATES = new HashMap() {{ put(BiomeType.TROPICAL_RAINFOREST, BiomePredicate.TROPICAL_RAINFOREST); put(BiomeType.SAVANNA, BiomePredicate.SAVANNA.or(BiomePredicate.MESA).not(BiomePredicate.DESERT).not(BiomePredicate.STEPPE).not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN).not(BiomePredicate.WETLAND)); @@ -227,7 +212,7 @@ public class BiomeHelper { if (biome.getCategory() == Biome.Category.NETHER) { return true; } - return IGNORE_BIOMES.contains(biome); + return !BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.OVERWORLD); } private static Vec2f getRange(Collection biomes, Function getter) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java index 6689422..0f3fd6e 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java @@ -85,7 +85,7 @@ public abstract class TerraSlider extends Slider implements Slider.ISlider, Elem public Float(String prefix, CompoundNBT value) { super(prefix, value, true); - precision = 4; + precision = 3; setValue(value.getFloat("value")); updateSlider(); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java index b63103d..cb51588 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java @@ -68,7 +68,7 @@ public class PreviewPage extends BasePage { preview.setHeight(256); addElements(right.left, right.top, right, previewerSettings, right.scrollPane::addButton, this::update); - right.scrollPane.addButton(new TerraButton("Generate") { + right.scrollPane.addButton(new TerraButton("New Seed") { @Override public void onPress() { preview.regenerate();