From c9b55cacadfb5a75e095a4dc644ef8b9851ca9ed Mon Sep 17 00:00:00 2001 From: dags- Date: Fri, 10 Apr 2020 12:23:20 +0100 Subject: [PATCH] - possibly fixed another river bug that causes a region to be flattened - replace river biome trees --- TerraForgedApp/build.gradle | 1 + .../com/terraforged/app/util/JsonReader.java | 63 +++++++++++++++++++ .../java/com/terraforged/app/util/Loader.java | 28 +++++++++ .../serializer/Deserializer.java | 14 +++-- .../core/world/rivermap/river/River.java | 12 ++-- .../features/trees/oak_plains.json | 3 +- gradle.properties | 2 +- 7 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java create mode 100644 TerraForgedApp/src/main/java/com/terraforged/app/util/Loader.java diff --git a/TerraForgedApp/build.gradle b/TerraForgedApp/build.gradle index f96bdfd..dfefdc8 100644 --- a/TerraForgedApp/build.gradle +++ b/TerraForgedApp/build.gradle @@ -7,6 +7,7 @@ repositories { } dependencies { + compile "com.google.code.gson:gson:2.8.0" compile "org.processing:core:3.3.7" compile "it.unimi.dsi:fastutil:8.2.1" compile project(":TerraForgedCore") diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java b/TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java new file mode 100644 index 0000000..7592af2 --- /dev/null +++ b/TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java @@ -0,0 +1,63 @@ +package com.terraforged.app.util; + +import com.google.gson.JsonElement; +import com.terraforged.core.util.serialization.serializer.Reader; + +import java.util.Collection; +import java.util.Map; +import java.util.stream.Collectors; + +public class JsonReader implements Reader { + + private final JsonElement element; + + public JsonReader(JsonElement element) { + this.element = element; + } + + @Override + public int getSize() { + if (element.isJsonObject()) { + return element.getAsJsonObject().size(); + } + if (element.isJsonArray()) { + return element.getAsJsonArray().size(); + } + return 0; + } + + @Override + public Reader getChild(String key) { + return new JsonReader(element.getAsJsonObject().get(key)); + } + + @Override + public Reader getChild(int index) { + return new JsonReader(element.getAsJsonArray().get(index)); + } + + @Override + public Collection getKeys() { + return element.getAsJsonObject().entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toList()); + } + + @Override + public String getString() { + return element.getAsString(); + } + + @Override + public boolean getBool() { + return element.getAsBoolean(); + } + + @Override + public float getFloat() { + return element.getAsFloat(); + } + + @Override + public int getInt() { + return element.getAsInt(); + } +} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/util/Loader.java b/TerraForgedApp/src/main/java/com/terraforged/app/util/Loader.java new file mode 100644 index 0000000..510a23f --- /dev/null +++ b/TerraForgedApp/src/main/java/com/terraforged/app/util/Loader.java @@ -0,0 +1,28 @@ +package com.terraforged.app.util; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.terraforged.core.settings.Settings; +import com.terraforged.core.util.serialization.serializer.Deserializer; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.Reader; + +public class Loader { + + public static Settings load() { + Settings settings = new Settings(); + load(settings); + return settings; + } + + private static void load(Settings settings) { + try (Reader reader = new BufferedReader(new FileReader("terraforged-generator.json"))) { + JsonElement json = new JsonParser().parse(reader); + new Deserializer().deserialize(new JsonReader(json), settings); + } catch (Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Deserializer.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Deserializer.java index bf84d51..49f899c 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Deserializer.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Deserializer.java @@ -39,11 +39,15 @@ public class Deserializer { continue; } - Reader child = reader.getChild(name); - Field field = type.getField(name); - if (Serializer.isSerializable(field)) { - field.setAccessible(true); - fromValue(child, object, field); + try { + Reader child = reader.getChild(name); + Field field = type.getField(name); + if (Serializer.isSerializable(field)) { + field.setAccessible(true); + fromValue(child, object, field); + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); } } } diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/River.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/River.java index 094a893..3592a7b 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/River.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/River.java @@ -140,7 +140,7 @@ public class River extends TerrainPopulator { return; } - carveBed(cell, bedAlpha, bedHeight); + carveBed(cell, bedHeight); } private float getBankHeight(Cell cell, float x, float z) { @@ -163,8 +163,9 @@ public class River extends TerrainPopulator { // lerp the position's height to the riverbank height if (cell.value > bankHeight) { cell.value = NoiseUtil.lerp(cell.value, bankHeight, valleyAlpha); + return true; } - return true; + return false; } private boolean carveBanks(Cell cell, float banksAlpha, float bedHeight) { @@ -172,13 +173,14 @@ public class River extends TerrainPopulator { if (cell.value > bedHeight) { cell.value = NoiseUtil.lerp(cell.value, bedHeight, banksAlpha); tag(cell, terrains.riverBanks); + return true; } - return true; + return false; } - private void carveBed(Cell cell, float bedAlpha, float bedHeight) { + private void carveBed(Cell cell, float bedHeight) { if (cell.value > bedHeight) { - cell.value = NoiseUtil.lerp(cell.value, bedHeight, bedAlpha); + cell.value = bedHeight; } tag(cell, terrains.river); } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json index 99bbb92..dbc6b7e 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json +++ b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json @@ -1,6 +1,7 @@ { "biomes": [ - "minecraft:plains" + "minecraft:plains", + "minecraft:river" ], "match": [ [ diff --git a/gradle.properties b/gradle.properties index d1a308e..a141690 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -mod_version=0.0.12 +mod_version=0.0.13 mc_version=1.15.2 forge_version=31.1.1 mcp_channel=snapshot