Merge pull request #146 from TerraForged/master
- possibly fixed another river bug that causes a region to be flattened
This commit is contained in:
commit
661101f2f9
@ -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")
|
||||
|
@ -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<String> 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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -39,12 +39,16 @@ public class Deserializer {
|
||||
continue;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ public class River extends TerrainPopulator {
|
||||
return;
|
||||
}
|
||||
|
||||
carveBed(cell, bedAlpha, bedHeight);
|
||||
carveBed(cell, bedHeight);
|
||||
}
|
||||
|
||||
private float getBankHeight(Cell<Terrain> cell, float x, float z) {
|
||||
@ -163,22 +163,24 @@ 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 false;
|
||||
}
|
||||
|
||||
private boolean carveBanks(Cell<Terrain> cell, float banksAlpha, float bedHeight) {
|
||||
// lerp the position's height to the riverbed height (ie the riverbank slopes)
|
||||
if (cell.value > bedHeight) {
|
||||
cell.value = NoiseUtil.lerp(cell.value, bedHeight, banksAlpha);
|
||||
tag(cell, terrains.riverBanks);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void carveBed(Cell<Terrain> cell, float bedAlpha, float bedHeight) {
|
||||
private void carveBed(Cell<Terrain> cell, float bedHeight) {
|
||||
if (cell.value > bedHeight) {
|
||||
cell.value = NoiseUtil.lerp(cell.value, bedHeight, bedAlpha);
|
||||
cell.value = bedHeight;
|
||||
}
|
||||
tag(cell, terrains.river);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"biomes": [
|
||||
"minecraft:plains"
|
||||
"minecraft:plains",
|
||||
"minecraft:river"
|
||||
],
|
||||
"match": [
|
||||
[
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user