diff --git a/.gitignore b/.gitignore index 0028853..f8da0e0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,11 +22,11 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -build/ -out/ -run/ *.iml -/.gradle/ -/.idea/ -**/build/ -**/out/ \ No newline at end of file + +run/ +out/ +build/ +.idea/ +.gradle/ +.cache/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 94e857f..b9c1e57 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "FeatureManager"] path = FeatureManager url = https://github.com/TerraForged/FeatureManager.git -[submodule "Noise2D"] - path = Noise2D - url = https://github.com/TerraForged/Noise2D.git +[submodule "Engine"] + path = Engine + url = https://github.com/TerraForged/Engine.git diff --git a/Engine b/Engine new file mode 160000 index 0000000..2a7e3ba --- /dev/null +++ b/Engine @@ -0,0 +1 @@ +Subproject commit 2a7e3ba5a2d79b61ed697653dd81142d9c54886c diff --git a/FeatureManager b/FeatureManager index 0da0d13..1052697 160000 --- a/FeatureManager +++ b/FeatureManager @@ -1 +1 @@ -Subproject commit 0da0d13c3dc8426b18a55107b42986e9d66387f1 +Subproject commit 1052697e7d938e30593511d472a8381e677105b5 diff --git a/Noise2D b/Noise2D deleted file mode 160000 index 0bbb025..0000000 --- a/Noise2D +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0bbb025ead269860fe3a41dcb95f04c356164970 diff --git a/TerraForgedAPI/README.md b/TerraForgedAPI/README.md deleted file mode 100644 index 2d5f64e..0000000 --- a/TerraForgedAPI/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# TerraForgedAPI - -### Dependency -```groovy -repositories { - maven { - url "https://io.terraforged.com/repository/maven/" - } -} - -dependencies { - implementation "com.terraforged:TerraForgedAPI:1.15.2-0.0.1" -} -``` - -### Usage - -TerraForged fires a number of setup events each time its chunk generator is created. These events expose certain -components of the generator allowing for world-gen content to be configured, modified, or added to. - -See the `com.terraforged.api.TerraEvent` class for the available events. - -All events are fired on the `FORGE` event bus. \ No newline at end of file diff --git a/TerraForgedAPI/build.gradle b/TerraForgedAPI/build.gradle deleted file mode 100644 index 6b7e0c7..0000000 --- a/TerraForgedAPI/build.gradle +++ /dev/null @@ -1,71 +0,0 @@ -buildscript { - repositories { - maven { url "https://files.minecraftforge.net/maven" } - jcenter() - mavenCentral() - } - dependencies { - classpath group: "net.minecraftforge.gradle", name: "ForgeGradle", version: "3.+", changing: true - } -} - -apply plugin: "net.minecraftforge.gradle" -apply plugin: "maven-publish" -apply plugin: "eclipse" - -version = "${mc_version}-${mod_version}" -archivesBaseName = "TerraForgedAPI" - -repositories { - jcenter() - mavenCentral() -} - -dependencies { - minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" - compile project(":Noise2D") - compile project(":FeatureManager") - compile project(":TerraForgedCore") -} - -minecraft { - mappings channel: mcp_channel, version: mcp_version -} - -task sourceJar(type: Jar) { - classifier = "sources" - from("$projectDir/src/main/java") - from(project(":Noise2D").projectDir.getPath() + "/src/main/java") - from(project(":FeatureManager").projectDir.getPath() + "/src/main/java") - from(project(":TerraForgedCore").projectDir.getPath() + "/src/main/java") -} - -jar { - dependsOn(sourceJar) - from("$buildDir/classes/java/main") - from(project(":Noise2D").buildDir.getPath() + "/classes/java/main") - from(project(":FeatureManager").buildDir.getPath() + "/classes/java/main") - from(project(":TerraForgedCore").buildDir.getPath() + "/classes/java/main") -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifact jar - artifact sourceJar - } - } - - if (System.getenv("MAVEN_USER") != null && System.getenv("MAVEN_PASS") != null) { - repositories { - maven { - credentials { - username System.getenv("MAVEN_USER") - password System.getenv("MAVEN_PASS") - } - name = "nexus" - url = "https://io.terraforged.com/repository/maven/" - } - } - } -} \ No newline at end of file diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java deleted file mode 100644 index 87f0d5f..0000000 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateTagPredicate.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.terraforged.api.material.state; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.tags.Tag; - -import java.util.function.Predicate; - -public class StateTagPredicate implements Predicate { - - private final Tag tag; - - public StateTagPredicate(Tag tag) { - this.tag = tag; - } - - @Override - public boolean test(BlockState state) { - return tag.contains(state.getBlock()); - } -} diff --git a/TerraForgedApp/build.gradle b/TerraForgedApp/build.gradle deleted file mode 100644 index dfefdc8..0000000 --- a/TerraForgedApp/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -apply plugin: "maven-publish" -apply plugin: "java" - -repositories { - mavenCentral() - jcenter() -} - -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") -} - -jar { - manifest { attributes "Main-Class": "com.terraforged.app.Main" } - from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } -} - -publish { - dependsOn(jar) -} \ No newline at end of file diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/Applet.java b/TerraForgedApp/src/main/java/com/terraforged/app/Applet.java deleted file mode 100644 index 9945daf..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/Applet.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app; - -import com.terraforged.app.renderer.MeshRenderer; -import com.terraforged.app.renderer.Renderer; -import com.terraforged.app.renderer.VoxelRenderer; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; -import processing.core.PApplet; -import processing.event.KeyEvent; -import processing.event.MouseEvent; - -public abstract class Applet extends PApplet { - - public static final int ELEVATION = 1; - public static final int BIOME_TYPE = 2; - public static final int TEMPERATURE = 3; - public static final int MOISTURE = 4; - public static final int BIOME = 5; - public static final int STEEPNESS = 6; - public static final int TERRAIN_TYPE = 7; - public static final int EROSION = 8; - public static final int CONTINENT = 9; - - protected Renderer mesh = new MeshRenderer(this); - protected Renderer voxel = new VoxelRenderer(this); - - public final Controller controller = new Controller(); - - public abstract Cache getCache(); - - public abstract float color(Cell cell); - - @Override - public void settings() { - size(800, 800, P3D); - } - - @Override - public void mousePressed(MouseEvent event) { - controller.mousePress(event); - } - - @Override - public void mouseReleased(MouseEvent event) { - controller.mouseRelease(event); - } - - @Override - public void mouseDragged(MouseEvent event) { - controller.mouseDrag(event); - } - - @Override - public void mouseWheel(MouseEvent event) { - controller.mouseWheel(event); - } - - @Override - public void keyPressed(KeyEvent event) { - controller.keyPress(event); - } - - @Override - public void keyReleased(KeyEvent event) { - controller.keyRelease(event); - } - - public void leftAlignText(int margin, int top, int lineHeight, String... lines) { - noLights(); - fill(0, 0, 100); - for (int i = 0; i < lines.length; i++) { - int y = top + (i * lineHeight); - text(lines[i], margin, y); - } - } - - - public void drawTerrain(float zoom) { - if (controller.getRenderMode() == 0) { - voxel.render(zoom); - } else { - mesh.render(zoom); - } - } - - public String colorModeName() { - switch (controller.getColorMode()) { - case STEEPNESS: - return "GRADIENT"; - case TEMPERATURE: - return "TEMPERATURE"; - case MOISTURE: - return "MOISTURE"; - case TERRAIN_TYPE: - return "TERRAIN TYPE"; - case ELEVATION: - return "ELEVATION"; - case BIOME_TYPE: - return "BIOME TYPE"; - case BIOME: - return "BIOME"; - case EROSION: - return "EROSION"; - case CONTINENT: - return "CONTINENT"; - default: - return "-"; - } - } - - public static float hue(float value, int steps, int max) { - value = Math.round(value * (steps - 1)); - value /= (steps - 1); - return value * max; - } - - public void drawCompass() { - pushStyle(); - pushMatrix(); - textSize(200); - fill(100, 0, 100); - - char[] chars = {'N', 'E', 'S', 'W'}; - for (int r = 0; r < 4; r++) { - char c = chars[r]; - float x = -textWidth(c) / 2; - float y = -width * 1.2F; - text(c, x, y); - rotateZ(0.5F * PI); - } - - popMatrix(); - popStyle(); - textSize(16); - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/Cache.java b/TerraForgedApp/src/main/java/com/terraforged/app/Cache.java deleted file mode 100644 index 17aff83..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/Cache.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.Region; -import com.terraforged.core.region.gen.RegionGenerator; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.util.concurrent.ThreadPool; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; - -public class Cache { - - private float offsetX = 0; - private float offsetZ = 0; - private float zoom = 0F; - private boolean filter = true; - private Terrains terrain; - private Settings settings; - private GeneratorContext context; - private Region region; - private RegionGenerator renderer; - - public Cache(int seed) { - Settings settings = new Settings(); - settings.generator.seed = seed; - this.settings = settings; - this.terrain = Terrains.create(settings); - this.context = new GeneratorContext(terrain, settings); - this.renderer = RegionGenerator.builder() - .factory(new WorldGeneratorFactory(context)) - .pool(ThreadPool.getPool()) - .size(3, 2) - .build(); - } - - public Settings getSettings() { - return settings; - } - - public Terrains getTerrain() { - return terrain; - } - - public Terrain getCenterTerrain() { - Terrain tag = getCenterCell().tag; - return tag == null ? terrain.ocean : tag; - } - - public BiomeType getCenterBiomeType() { - return getCenterCell().biomeType; - } - - public int getCenterHeight() { - return (int) (context.levels.worldHeight * getCenterCell().value); - } - - public Cell getCenterCell() { - int center = region.getBlockSize().size / 2; - return region.getCell(center, center); - } - - public Region getRegion() { - return region; - } - - public void update(float offsetX, float offsetZ, float zoom, boolean filters) { - if (region == null) { - record(offsetX, offsetZ, zoom, filters); - return; - } - if (this.offsetX != offsetX || this.offsetZ != offsetZ) { - record(offsetX, offsetZ, zoom, filters); - return; - } - if (this.zoom != zoom) { - record(offsetX, offsetZ, zoom, filters); - return; - } - if (this.filter != filters) { - record(offsetX, offsetZ, zoom, filters); - } - } - - private void record(float offsetX, float offsetZ, float zoom, boolean filters) { - this.zoom = zoom; - this.filter = filters; - this.offsetX = offsetX; - this.offsetZ = offsetZ; - try { - this.region = renderer.generateRegion(offsetX, offsetZ, zoom, filters); - } catch (Throwable t) { - t.printStackTrace(); - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/Controller.java b/TerraForgedApp/src/main/java/com/terraforged/app/Controller.java deleted file mode 100644 index b5ee022..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/Controller.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app; - -import processing.core.PApplet; -import processing.event.KeyEvent; -import processing.event.MouseEvent; - -import java.awt.*; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.StringSelection; -import java.awt.event.ActionEvent; - -public class Controller { - - private static final int BUTTON_NONE = -1; - private static final int BUTTON_1 = 37; - private static final int BUTTON_2 = 39; - private static final int BUTTON_3 = 3; - - private static final float cameraSpeed = 100F; - private static final float zoomSpeed = 0.01F; - private static final float rotateSpeed = 0.002F; - private static final float translateSpeed = 2F; - private static final float moveSpeed = 10F; - - private int mouseButton = BUTTON_NONE; - private int lastX = 0; - private int lastY = 0; - - private float yaw = -0.2F; - private float pitch = 0.85F; - private float translateX = 0F; - private float translateY = 0F; - private float translateZ = -800; - private float velocityX = 0F; - private float velocityY = 0F; - - private int colorMode = 1; - private int renderMode = 0; - private int newSeed = 0; - private int left = 0; - private int right = 0; - private int up = 0; - private int down = 0; - private float zoom = 16; - private boolean filters = true; - - public void apply(PApplet applet) { - applet.translate(translateX, translateY, translateZ); - applet.translate(applet.width / 2, applet.height / 2, 0); - applet.rotateX(pitch); - applet.rotateZ(yaw); - update(); - } - - public void update() { - float forward = up + down; - float strafe = left + right; - velocityX = forward * (float) Math.sin(yaw); - velocityY = forward * (float) Math.cos(yaw); - velocityX += strafe * (float) Math.sin(yaw + Math.toRadians(90)); - velocityY += strafe * (float) Math.cos(yaw + Math.toRadians(90)); - if (velocityX != 0 || velocityY != 0) { - float magnitude = (float) Math.sqrt(velocityX * velocityX + velocityY * velocityY); - velocityX /= magnitude; - velocityY /= magnitude; - } - } - - public int getColorMode() { - return colorMode; - } - - public int getRenderMode() { - return renderMode; - } - - public float velocityX() { - return velocityX * moveSpeed / zoom; - } - - public float velocityY() { - return velocityY * moveSpeed / zoom; - } - - public float zoomLevel() { - return zoom; - } - - public boolean filters() { - return filters; - } - - public int getNewSeed() { - if (newSeed == 1) { - newSeed = 0; - return 1; - } - if (newSeed != 0) { - int val = newSeed; - newSeed = 0; - return val; - } - return 0; - } - - public void keyPress(KeyEvent event) { - switch (event.getKey()) { - case 'w': - up = -1; - break; - case 'a': - left = -1; - break; - case 's': - down = 1; - break; - case 'd': - right = 1; - break; - } - } - - public void keyRelease(KeyEvent event) { - switch (event.getKey()) { - case 'w': - up = 0; - return; - case 'a': - left = 0; - return; - case 's': - down = 0; - return; - case 'd': - right = 0; - return; - case 'r': - renderMode = renderMode == 0 ? 1 : 0; - return; - case 'n': - newSeed = 1; - return; - case 'm': - newSeed = Main.seed; - return; - case 'f': - filters = !filters; - return; - case 'c': - StringSelection selection = new StringSelection("" + Main.seed); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null); - return; - case 'v': - try { - Object data = Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); - newSeed = (int) Long.parseLong(data.toString()); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - if (event.getKey() >= '1' && event.getKey() <= '9') { - colorMode = event.getKey() - '0'; - return; - } - } - - public void mousePress(MouseEvent event) { - if (mouseButton == BUTTON_NONE) { - lastX = event.getX(); - lastY = event.getY(); - mouseButton = event.getButton(); - } - } - - public void mouseRelease(MouseEvent event) { - mouseButton = BUTTON_NONE; - } - - public void mouseWheel(MouseEvent event) { - translateZ -= event.getCount() * cameraSpeed; - } - - public void mouseDrag(MouseEvent event) { - int dx = event.getX() - lastX; - int dy = event.getY() - lastY; - boolean ctrl = (event.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK; - - lastX = event.getX(); - lastY = event.getY(); - - if (mouseButton == BUTTON_1) { - yaw -= dx * rotateSpeed; - pitch -= dy * rotateSpeed; - } - - if (mouseButton == BUTTON_2) { - translateX += dx * translateSpeed; - translateY += dy * translateSpeed; - } - - if (mouseButton == BUTTON_3) { - if (ctrl) { - zoom += (dy - dx) * zoom * zoomSpeed; - zoom = Math.max(1F, zoom); - } else { - translateZ -= (dy - dx) * cameraSpeed * 0.1F; - } - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/Main.java b/TerraForgedApp/src/main/java/com/terraforged/app/Main.java deleted file mode 100644 index b1627ff..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/Main.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app; - -import com.terraforged.app.biome.BiomeProvider; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.biome.BiomeData; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.util.NoiseUtil; - -import java.awt.*; -import java.util.Random; - -public class Main extends Applet { - - public static void main(String[] args) { - Main.start(-1); - } - - public static void start(long seed) { - Main.seed = (int) seed; - Main.random = seed == -1; - main(Main.class.getName()); - } - - private static boolean random = false; - public static int seed = -1; - - private Cache cache; - private float offsetX = 0; - private float offsetZ = 0; - private final String bits = System.getProperty("sun.arch.data.model"); - private final BiomeProvider biomeProvider = new BiomeProvider(); - - @Override - public Cache getCache() { - return cache; - } - - @Override - public void setup() { - super.setup(); - if (random) { - setSeed(new Random(System.currentTimeMillis()).nextInt()); - offsetX = 0; - offsetZ = 0; - } - setSeed(seed); - } - - public void setSeed(int seed) { - Main.seed = seed; - cache = new Cache(seed); - System.out.println(seed); - } - - @Override - public float color(Cell cell) { - switch (controller.getColorMode()) { - case STEEPNESS: - return hue(1 - cell.steepness, 64, 70); - case TEMPERATURE: - return hue(1 - cell.temperature, 64, 70); - case MOISTURE: - return hue(cell.moisture, 64, 70); - case TERRAIN_TYPE: - if (cell.tag == getCache().getTerrain().volcano) { - return 0F; - } - return 20 + (cell.tag.getHue() * 80); - case ELEVATION: - float value = (cell.value - 0.245F) / 0.65F; - return (1 - value) * 30; - case BIOME: - BiomeData biome = biomeProvider.getBiome(cell); - if (biome == null) { - return 0F; - } - return cell.biome * 70; - case CONTINENT: - return cell.continent * 70; - default: - return 50; - } - } - - @Override - public void draw() { - int nextSeed = controller.getNewSeed(); - if (nextSeed == 1) { - setup(); - } else if (nextSeed != 0) { - setSeed(nextSeed); - } - - offsetX += controller.velocityX() * controller.zoomLevel() * controller.zoomLevel(); - offsetZ += controller.velocityY() * controller.zoomLevel() * controller.zoomLevel(); - cache.update(offsetX, offsetZ, controller.zoomLevel(), controller.filters()); - - // color stuff - noStroke(); - background(0); - colorMode(HSB, 100); - - // lighting - ambientLight(0, 0, 75, width / 2, -height, height / 2); - pointLight(0, 0, 50, width / 2, -height * 100, height / 2); - - // render - pushMatrix(); - controller.apply(this); -// translate(-width / 2F, -height / 2F); - drawTerrain(controller.zoomLevel()); - drawCompass(); -// translate(0, 0, 255 * (width / (float) controller.resolution()) / controller.zoomLevel()); -// mesh.renderWind(controller.resolution(), controller.zoomLevel()); - popMatrix(); - - pushMatrix(); - translate(0, 0, -1); -// drawGradient(0, height - 150, 100F, width, 150); - popMatrix(); - - drawStats(); - drawBiomeKey(); - drawControls(); - } - - private void drawGradient(int x, int y, float d, float w, float h) { - noFill(); - for (int dy = 0; dy <= h; dy++) { - float dist = Math.min(1, dy / d); - stroke(0, 0, 0, dist * 100F); - line(x, y + dy, x + w, y + dy); - } - noStroke(); - } - - private void drawStats() { - int resolution = cache.getRegion().getBlockSize().size; - int blocks = NoiseUtil.round(resolution * controller.zoomLevel()); - - String[][] info = { - {"Java:", String.format("x%s", bits)}, - {"Fps: ", String.format("%.3f", frameRate)}, - {"Seed:", String.format("%s", seed)}, - {"Zoom: ", String.format("%.2f", controller.zoomLevel())}, - {"Area: ", String.format("%sx%s [%sx%s]", blocks, blocks, resolution, resolution)}, - {"Center: ", String.format("x=%.0f, y=%s, z=%.0f", offsetX, cache.getCenterHeight(), offsetZ)}, - {"Terrain: ", cache.getCenterTerrain().getName()}, - {"BiomeType:", cache.getCenterBiomeType().name()}, -// {"Biome: ", String.format("%s", biomeProvider.getBiome(cache.getCenterCell()).name)}, - {"Overlay: ", colorModeName()}, - }; - - int widest = 0; - for (String[] s : info) { - widest = Math.max(widest, (int) textWidth(s[0])); - } - - int top = 20; - int lineHeight = 15; - for (String[] s : info) { - leftAlignText(10, top, 0, s[0]); - top += lineHeight; - } - - top = 20; - for (String[] s : info) { - if (s.length == 2) { - leftAlignText(12 + widest, top, 0, s[1]); - top += lineHeight; - } - } - } - - private void drawBiomeKey() { - int top = 20; - int lineHeight = 15; - int widest = 0; - for (BiomeType type : BiomeType.values()) { - widest = Math.max(widest, (int) textWidth(type.name())); - } - - int left = width - widest - lineHeight - 15; - for (BiomeType type : BiomeType.values()) { - leftAlignText(left, top, 0, type.name()); - float[] hsb = Color.RGBtoHSB(type.getColor().getRed(), type.getColor().getGreen(), - type.getColor().getBlue(), null); - fill(0, 0, 100); - rect(width - lineHeight - 11, top - lineHeight + 1, lineHeight + 2, lineHeight + 2); - - fill(hsb[0] * 100, hsb[1] * 100, hsb[2] * 100); - rect(width - lineHeight - 10, top - lineHeight + 2, lineHeight, lineHeight); - top += lineHeight; - } - } - - private void drawControls() { - String[][][] columns = { - { - {"Mouse-Left + Move", " - Rotate terrain"}, - {"Mouse-Right + Move", " - Pan terrain"}, - {"Mouse-Scroll + Move", " - Zoom camera"}, - {"Mouse-Scroll + LCTRL + Move", " - Zoom terrain"}, - {"WASD", "- Move terrain"} - }, { - {"Key 1-8", "- Select overlay"}, - {"Key R", "- Toggle mesh renderer"}, - {"Key F", "- Toggle filters"}, - {"Key N", "- Generate new world"}, - {"Key C", "- Copy seed to clipboard"}, - {"Key V", "- Paste seed from clipboard"}, - }}; - - int lineHeight = 15; - int rows = 0; - for (String[][] column : columns) { - rows = Math.max(rows, column.length); - } - - int left = 10; - int widest = 0; - for (String[][] column : columns) { - int top = (height - 10) - ((rows - 1) * lineHeight); - - for (String[] row : column) { - int width = 0; - for (String cell : row) { - leftAlignText(left + width, top, 0, cell); - width += (int) textWidth(cell); - } - top += lineHeight; - widest = Math.max(widest, width); - } - - left += widest + 10; - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/biome/BiomeColor.java b/TerraForgedApp/src/main/java/com/terraforged/app/biome/BiomeColor.java deleted file mode 100644 index 7deaa3e..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/biome/BiomeColor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.biome; - -import me.dags.noise.util.NoiseUtil; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; - -public class BiomeColor { - - private static final BufferedImage image = load(); - private static final int width = image.getWidth() - 1; - private static final int height = image.getHeight() - 1; - - public static int getRGB(float temp, float moist) { - float humidity = temp * moist; - temp = 1 - temp; - humidity = 1 - humidity; - int x = NoiseUtil.round(temp * width); - int y = NoiseUtil.round(humidity * height); - return image.getRGB(x, y); - } - - - private static BufferedImage load() { - try (InputStream inputStream = BiomeColor.class.getResourceAsStream("/grass.png")) { - return ImageIO.read(inputStream); - } catch (IOException e) { - e.printStackTrace(); - return new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/biome/BiomeProvider.java b/TerraForgedApp/src/main/java/com/terraforged/app/biome/BiomeProvider.java deleted file mode 100644 index d5b82ba..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/biome/BiomeProvider.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.biome; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.grid.FixedGrid; -import com.terraforged.core.world.biome.BiomeData; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; -import processing.data.JSONArray; -import processing.data.JSONObject; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class BiomeProvider { - - private final List> biomes; - - public BiomeProvider() { - biomes = getBiomes(5); - } - - public BiomeData getBiome(Cell cell) { - FixedGrid grid = biomes.get(cell.biomeType.ordinal()); - if (grid == null) { - return null; - } - return grid.get(cell.moisture, cell.temperature, cell.biome); - } - - private static List> getBiomes(int gridSize) { - List> data = new ArrayList<>(); - for (BiomeType type : BiomeType.values()) { - data.add(type.ordinal(), null); - } - - Map biomes = loadBiomes(); - Map> types = loadBiomeTypes(); - for (Map.Entry> e : types.entrySet()) { - List list = new LinkedList<>(); - for (String id : e.getValue()) { - BiomeData biome = biomes.get(id); - if (biome != null) { - list.add(biome); - } - } - FixedGrid grid = FixedGrid.generate(gridSize, list, b -> b.rainfall, b -> b.temperature); - data.set(e.getKey().ordinal(), grid); - } - - return data; - } - - private static Map loadBiomes() { - try (InputStream inputStream = BiomeProvider.class.getResourceAsStream("/biome_data.json")) { - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - StringBuilder sb = new StringBuilder(); - reader.lines().forEach(sb::append); - JSONArray array = JSONArray.parse(sb.toString()); - Map biomes = new HashMap<>(); - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - String name = object.getString("id"); - float moisture = object.getFloat("moisture"); - float temperature = object.getFloat("temperature"); - int color = BiomeColor.getRGB(temperature, moisture); - BiomeData biome = new BiomeData(name, null, color, moisture, temperature); - biomes.put(name, biome); - } - return biomes; - } catch (IOException e) { - e.printStackTrace(); - return Collections.emptyMap(); - } - } - - private static Map> loadBiomeTypes() { - try (InputStream inputStream = BiomeProvider.class.getResourceAsStream("/biome_groups.json")) { - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - StringBuilder sb = new StringBuilder(); - reader.lines().forEach(sb::append); - JSONObject object = JSONObject.parse(sb.toString()); - Iterator iterator = object.keyIterator(); - Map> biomes = new HashMap<>(); - while (iterator.hasNext()) { - String key = "" + iterator.next(); - if (key.contains("rivers")) { - continue; - } - if (key.contains("oceans")) { - continue; - } - BiomeType type = BiomeType.valueOf(key); - List group = new LinkedList<>(); - JSONArray array = object.getJSONArray(key); - for (int i = 0; i < array.size(); i++) { - group.add(array.getString(i)); - } - biomes.put(type, group); - } - return biomes; - } catch (IOException e) { - e.printStackTrace(); - return Collections.emptyMap(); - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/mesh/Mesh.java b/TerraForgedApp/src/main/java/com/terraforged/app/mesh/Mesh.java deleted file mode 100644 index 2696c06..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/mesh/Mesh.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.mesh; - -public class Mesh { - - private final Mesh inner; - private final float x0; - private final float y0; - private final float x1; - private final float y1; - private final float quality; - - public Mesh(Mesh inner, float x0, float y0, float x1, float y1, float quality) { - this.inner = inner; - this.x0 = x0; - this.y0 = y0; - this.x1 = x1; - this.y1 = y1; - this.quality = quality; - } - - public Mesh expand(float scale) { - return expand(scale, scale); - } - - public Mesh expand(float scale, float quality) { - float width0 = getWidth(); - float height0 = getHeight(); - float width1 = width0 * scale; - float height1 = height0 * scale; - float deltaX = (width1 - width0) / 2F; - float deltaY = (height1 - height0) / 2F; - float newQuality = this.quality * quality; - return new Mesh(this, x0 - deltaX, y0 - deltaY, x1 + deltaX, y1 + deltaY, newQuality); - } - - public float getWidth() { - return x1 - x0; - } - - public float getHeight() { - return y1 - y0; - } - - public void start(float width, float height) { - if (inner != null) { - inner.start(width, height); - } - } - - public void render() { - if (inner == null) { - renderNormal(); - } else { - renderCutout(); - inner.render(); - } - } - - public void beginStrip() { - if (inner != null) { - inner.beginStrip(); - } - } - - public void endStrip() { - if (inner != null) { - inner.endStrip(); - } - } - - public void visit(float x, float y) { - if (inner != null) { - inner.visit(x, y); - } - } - - private void renderNormal() { - beginStrip(); - iterate(x0, y0, x1, y1); - endStrip(); - } - - private void renderCutout() { - beginStrip(); - iterate(x0, y0, inner.x1, inner.y0); - endStrip(); - - beginStrip(); - iterate(inner.x1, y0, x1, inner.y1); - endStrip(); - - beginStrip(); - iterate(inner.x0, inner.y1, x1, y1); - endStrip(); - - beginStrip(); - iterate(x0, inner.y0, inner.x0, y1); - endStrip(); - } - - private void iterate(float minX, float minY, float maxX, float maxY) { - float x = minX - quality; - float y = minY - quality; - while (y < maxY) { - y = Math.min(y + quality, maxY); - beginStrip(); - while (x < maxX) { - x = Math.min(x + quality, maxX); - visit(x, y); - visit(x, y + quality); - } - x = minX - quality; - endStrip(); - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/mesh/NoiseMesh.java b/TerraForgedApp/src/main/java/com/terraforged/app/mesh/NoiseMesh.java deleted file mode 100644 index 021e846..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/mesh/NoiseMesh.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.mesh; - -import com.terraforged.app.Applet; -import com.terraforged.app.renderer.Renderer; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; -import processing.core.PApplet; - -public class NoiseMesh extends Mesh { - - private final Applet applet; - private final Renderer renderer; - private final Cell cell = new Cell<>(); - - public NoiseMesh(Applet applet, Renderer renderer, float x0, float y0, float x1, float y1) { - super(null, x0, y0, x1, y1, 1F); - this.applet = applet; - this.renderer = renderer; - } - - @Override - public void start(float width, float height) { - applet.noStroke(); - } - - @Override - public void beginStrip() { - applet.beginShape(PApplet.TRIANGLE_STRIP); - } - - @Override - public void endStrip() { - applet.endShape(); - } - - @Override - public void visit(float x, float y) { - float height = cell.value * 255; - float surface = renderer.getSurface(cell, height, 63, 10F); - applet.vertex(x * 10F, y * 10F, (int) surface); - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/mesh/TestRenderer.java b/TerraForgedApp/src/main/java/com/terraforged/app/mesh/TestRenderer.java deleted file mode 100644 index 4c82c08..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/mesh/TestRenderer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.mesh; - -import com.terraforged.app.Applet; -import com.terraforged.app.renderer.Renderer; - -public class TestRenderer extends Renderer { - - private static boolean printed = false; - - public TestRenderer(Applet visualizer) { - super(visualizer); - } - - @Override - public void render(float zoom) { - Mesh mesh = new NoiseMesh(applet, this, -64, -64, 64, 64); - for (int i = 0; i < 1; i++) { -// mesh = mesh.expand(4); - } - - float width = mesh.getWidth(); - float height = mesh.getHeight(); - if (!printed) { - printed = true; - System.out.println(width + "x" + height); - } - - applet.pushMatrix(); - mesh.start(mesh.getWidth(), mesh.getHeight()); - mesh.render(); - applet.popMatrix(); - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/MeshRenderer.java b/TerraForgedApp/src/main/java/com/terraforged/app/renderer/MeshRenderer.java deleted file mode 100644 index f76ce76..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/MeshRenderer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.renderer; - -import com.terraforged.app.Applet; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import processing.core.PApplet; - -public class MeshRenderer extends Renderer { - - public MeshRenderer(Applet visualizer) { - super(visualizer); - } - - @Override - public void render(float zoom) { - float seaLevel = new Levels(applet.getCache().getSettings().generator).water; - int worldHeight = applet.getCache().getSettings().generator.world.worldHeight; - int waterLevel = (int) (seaLevel * worldHeight); - int seabedLevel = (int) ((seaLevel - 0.04) * worldHeight); - int resolution = applet.getCache().getRegion().getBlockSize().size; - - float w = applet.width / (float) (resolution - 1); - float h = applet.width / (float) (resolution - 1); - - applet.noStroke(); - applet.pushMatrix(); - applet.translate(-applet.width / 2F, -applet.width / 2F); - - for (int dy = 0; dy < resolution - 1; dy++) { - applet.beginShape(PApplet.TRIANGLE_STRIP); - for (int dx = 0; dx < resolution; dx++) { - draw(dx, dy, w, h, zoom, worldHeight, waterLevel, seabedLevel); - draw(dx, dy + 1, w, h, zoom, worldHeight, waterLevel, resolution / 2); - } - applet.endShape(); - } - - applet.popMatrix(); - } - - private void draw(int dx, int dz, float w, float h, float zoom, int worldHeight, int waterLevel, int center) { - Cell cell = applet.getCache().getRegion().getCell(dx, dz); - float height = (cell.value * worldHeight); - float x = dx * w; - float z = dz * h; - float y = (int) getSurface(cell, height, waterLevel, 1); - applet.vertex(x, z, y / (zoom * 0.2F)); - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java b/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java deleted file mode 100644 index c2472f0..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.renderer; - -import com.terraforged.app.Applet; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; - -import java.awt.*; - -public abstract class Renderer { - - protected final Applet applet; - - protected Renderer(Applet visualizer) { - this.applet = visualizer; - } - - public float getSurface(Cell cell, float height, int waterLevel, float el) { - if (cell.tag == applet.getCache().getTerrain().volcanoPipe) { - applet.fill(2, 80, 64); - return height * 0.95F * el; - } - if (height < waterLevel) { - float temp = cell.temperature; - float tempDelta = temp > 0.5 ? temp - 0.5F : -(0.5F - temp); - float tempAlpha = (tempDelta / 0.5F); - float hueMod = 4 * tempAlpha; - - float depth = (waterLevel - height) / (float) (90); - float darkness = (1 - depth); - float darknessMod = 0.5F + (darkness * 0.5F); - - applet.fill(60 - hueMod, 65, 90 * darknessMod); - return height * el; - } else if (applet.controller.getColorMode() == Applet.ELEVATION) { - float hei = Math.min(1, Math.max(0, height - waterLevel) / (255F - waterLevel)); - float temp = cell.temperature; - float moist = Math.min(temp, cell.moisture); - - float hue = 35 - (temp * (1 - moist)) * 25; - float sat = 75 * (1 - hei); - float bri = 50 + 40 * hei; - applet.fill(hue, sat, bri); - return height * el; - } else if (applet.controller.getColorMode() == Applet.BIOME_TYPE) { - Color c = cell.biomeType.getColor(); - if (cell.riverMask < 0.025) { - c = Color.white; - } - float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); - float bri = 90 + cell.biomeTypeMask * 10; - applet.fill(hsb[0] * 100, hsb[1] * 100, hsb[2] * bri); - return height * el; - } else if (applet.controller.getColorMode() == Applet.BIOME) { - float hue = applet.color(cell); - float sat = 70; - float bright = 50 + 50 * cell.riverMask; - applet.fill(hue, sat, bright); - return height * el; - } else if(applet.controller.getColorMode() == Applet.TERRAIN_TYPE) { - float hue = applet.color(cell); - if (cell.tag == applet.getCache().getTerrain().coast) { - hue = 15; - } - float modifier = cell.mask(0.4F, 0.5F, 0F, 1F); - float modAlpha = 0.1F; - float mod = (1 - modAlpha) + (modifier * modAlpha); - float sat = 70; - float bri = 70; - applet.fill(hue, 65, 70); - return height * el; - } else if(applet.controller.getColorMode() == Applet.EROSION) { - float change = cell.sediment + cell.erosion; - float value = Math.abs(cell.sediment * 250); - value = Math.max(0, Math.min(1, value)); - float hue = value * 70; - float sat = 70; - float bri = 70; - applet.fill(hue, sat, bri); - return height * el; - } else { - float hue = applet.color(cell); - float sat = 70; - float bri = 70; - applet.fill(hue, sat, bri); - return height * el; - } - } - - public abstract void render(float zoom); - - private void renderGradLine(int steps, float x1, float y1, float x2, float y2, float hue1, float hue2, float sat, float bright) { - float dx = x2 - x1; - float dy = y2 - y1; - float fx = dx / steps; - float fy = dy / steps; - float dhue = hue2 - hue1; - float fhue = dhue / steps; - for (int i = 0; i < steps; i++) { - float px1 = x1 + (i * fx); - float py1 = y1 + (i * fy); - float px2 = x2 + ((i + 1) * fx); - float py2 = y2 + ((i + 1) * fy); - float hue = (i + 1) * fhue; - applet.stroke(hue1 + hue, sat, bright); - applet.line(px1, py1, px2, py2); - } - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/VoxelRenderer.java b/TerraForgedApp/src/main/java/com/terraforged/app/renderer/VoxelRenderer.java deleted file mode 100644 index cb42b96..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/VoxelRenderer.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.app.renderer; - -import com.terraforged.app.Applet; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import processing.core.PApplet; - -public class VoxelRenderer extends Renderer { - - public VoxelRenderer(Applet visualizer) { - super(visualizer); - } - - @Override - public void render(float zoom) { - Levels levels = new Levels(applet.getCache().getSettings().generator); - int worldHeight = applet.getCache().getSettings().generator.world.worldHeight; - int waterLevel = levels.waterY; - int resolution = applet.getCache().getRegion().getBlockSize().size; - int center = resolution / 2; - - float w = applet.width / (float) resolution; - float h = applet.width / (float) resolution; - float el = w / zoom; - - applet.pushMatrix(); - applet.translate(-applet.width / 2F, -applet.width / 2F); - - int difX = Math.max(0, applet.getCache().getRegion().getBlockSize().size - resolution); - int difY = Math.max(0, applet.getCache().getRegion().getBlockSize().size - resolution); - int offsetX = difX / 2; - int offsetZ = difY / 2; - - for (int dy = 0; dy < resolution; dy++) { - for (int dx = 0; dx < resolution; dx++) { - Cell cell = applet.getCache().getRegion().getCell(dx + offsetX, dy + offsetZ); - - float cellHeight = cell.value * worldHeight; - int height = Math.min(worldHeight, Math.max(0, (int) cellHeight)); - - if (height < 0) { - continue; - } - - float x0 = dx * w; - float x1 = (dx + 1) * w; - float z0 = dy * h; - float z1 = (dy + 1) * h; - float y = getSurface(cell, height, waterLevel, el); - - if ((dx == center && (dy == center || dy - 1 == center || dy + 1 == center)) - || (dy == center && (dx - 1 == center || dx + 1 == center))) { - applet.fill(100F, 100F, 100F); - } - - drawColumn(x0, z0, 0, x1, z1, y); - } - } - - drawRulers(16, worldHeight, resolution, h, el); - - applet.popMatrix(); - } - - private void drawRulers(int step, int max, int resolution, float unit, float height) { - float width = (resolution + 1) * unit; - int doubleStep = step * 2; - - for (int dz = 0; dz <= 1; dz++) { - for (int dx = 0; dx <= 1; dx++) { - float x0 = dx * width; - float x1 = x0 - unit; - float z0 = dz * width; - float z1 = z0 - unit; - for (int dy = 0; dy < max; dy += step) { - float y0 = dy * height; - float y1 = y0 + (step * height); - float h = 100, s = 100, b = 100; - if ((dy % doubleStep) != step) { - s = 0; - } - applet.fill(h, s, b); - drawColumn(x0, z0, y0, x1, z1, y1); - } - } - } - } - - private void drawColumn(float x0, float y0, float z0, float x1, float y1, float z1) { - applet.beginShape(PApplet.QUADS); - // +Z "front" face - applet.vertex(x0, y0, z1); - applet.vertex(x1, y0, z1); - applet.vertex(x1, y1, z1); - applet.vertex(x0, y1, z1); - - // -Z "back" face - applet.vertex(x1, y0, z0); - applet.vertex(x0, y0, z0); - applet.vertex(x0, y1, z0); - applet.vertex(x1, y1, z0); - - // +Y "bottom" face - applet.vertex(x0, y1, z1); - applet.vertex(x1, y1, z1); - applet.vertex(x1, y1, z0); - applet.vertex(x0, y1, z0); - - // -Y "top" face - applet.vertex(x0, y0, z0); - applet.vertex(x1, y0, z0); - applet.vertex(x1, y0, z1); - applet.vertex(x0, y0, z1); - - // +X "right" face - applet.vertex(x1, y0, z1); - applet.vertex(x1, y0, z0); - applet.vertex(x1, y1, z0); - applet.vertex(x1, y1, z1); - - // -X "left" face - applet.vertex(x0, y0, z0); - applet.vertex(x0, y0, z1); - applet.vertex(x0, y1, z1); - applet.vertex(x0, y1, z0); - - applet.endShape(); - } -} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java b/TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java deleted file mode 100644 index 7592af2..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/util/JsonReader.java +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index 510a23f..0000000 --- a/TerraForgedApp/src/main/java/com/terraforged/app/util/Loader.java +++ /dev/null @@ -1,28 +0,0 @@ -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/TerraForgedApp/src/main/resources/biome_data.json b/TerraForgedApp/src/main/resources/biome_data.json deleted file mode 100644 index 1de2bf8..0000000 --- a/TerraForgedApp/src/main/resources/biome_data.json +++ /dev/null @@ -1,764 +0,0 @@ -[ - { - "id": "biomesoplenty:alps", - "moisture": 0.2, - "temperature": 0.1, - "color": -2302756 - }, - { - "id": "biomesoplenty:alps_foothills", - "moisture": 0.2, - "temperature": 0.1, - "color": -10461088 - }, - { - "id": "biomesoplenty:bayou", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "biomesoplenty:bog", - "moisture": 0.59999996, - "temperature": 0.42, - "color": -13592211 - }, - { - "id": "biomesoplenty:boreal_forest", - "moisture": 0.4, - "temperature": 0.32, - "color": -13592211 - }, - { - "id": "biomesoplenty:brushland", - "moisture": 0.06666667, - "temperature": 0.8, - "color": -13592211 - }, - { - "id": "biomesoplenty:chaparral", - "moisture": 0.29999998, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:cherry_blossom_grove", - "moisture": 0.59999996, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:cold_desert", - "moisture": 0.0, - "temperature": 0.3, - "color": -6034953 - }, - { - "id": "biomesoplenty:coniferous_forest", - "moisture": 0.33333334, - "temperature": 0.38, - "color": -13592211 - }, - { - "id": "biomesoplenty:dead_forest", - "moisture": 0.2, - "temperature": 0.32, - "color": -13592211 - }, - { - "id": "biomesoplenty:fir_clearing", - "moisture": 0.33333334, - "temperature": 0.38, - "color": -13592211 - }, - { - "id": "biomesoplenty:floodplain", - "moisture": 0.8, - "temperature": 0.56, - "color": -13592211 - }, - { - "id": "biomesoplenty:flower_meadow", - "moisture": 0.46666667, - "temperature": 0.35999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:grassland", - "moisture": 0.46666667, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:gravel_beach", - "moisture": 0.33333334, - "temperature": 0.44, - "color": -6034953 - }, - { - "id": "biomesoplenty:grove", - "moisture": 0.18333334, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:highland", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:highland_moor", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:lavender_field", - "moisture": 0.46666667, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:lush_grassland", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "biomesoplenty:lush_swamp", - "moisture": 0.6666667, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "biomesoplenty:mangrove", - "moisture": 0.46666667, - "temperature": 0.524, - "color": -13592211 - }, - { - "id": "biomesoplenty:maple_woods", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - }, - { - "id": "biomesoplenty:marsh", - "moisture": 0.46666667, - "temperature": 0.45999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:meadow", - "moisture": 0.46666667, - "temperature": 0.35999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:mire", - "moisture": 0.59999996, - "temperature": 0.42, - "color": -13592211 - }, - { - "id": "biomesoplenty:mystic_grove", - "moisture": 0.53333336, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "biomesoplenty:oasis", - "moisture": 0.33333334, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "biomesoplenty:ominous_woods", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:orchard", - "moisture": 0.26666668, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:outback", - "moisture": 0.033333335, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "biomesoplenty:overgrown_cliffs", - "moisture": 0.53333336, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "biomesoplenty:pasture", - "moisture": 0.2, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:prairie", - "moisture": 0.2, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:pumpkin_patch", - "moisture": 0.53333336, - "temperature": 0.35999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:rainforest", - "moisture": 1.0, - "temperature": 0.54, - "color": -13592211 - }, - { - "id": "biomesoplenty:redwood_forest", - "moisture": 0.4, - "temperature": 0.52, - "color": -12427646 - }, - { - "id": "biomesoplenty:redwood_forest_edge", - "moisture": 0.4, - "temperature": 0.52, - "color": -12427646 - }, - { - "id": "biomesoplenty:scrubland", - "moisture": 0.06666667, - "temperature": 0.64, - "color": -13592211 - }, - { - "id": "biomesoplenty:seasonal_forest", - "moisture": 0.53333336, - "temperature": 0.35999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:shield", - "moisture": 0.53333336, - "temperature": 0.35999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:shrubland", - "moisture": 0.033333335, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:silkglade", - "moisture": 0.13333334, - "temperature": 0.5, - "color": -13592211 - }, - { - "id": "biomesoplenty:snowy_coniferous_forest", - "moisture": 0.33333334, - "temperature": 0.1, - "color": -13592211 - }, - { - "id": "biomesoplenty:snowy_fir_clearing", - "moisture": 0.33333334, - "temperature": 0.1, - "color": -13592211 - }, - { - "id": "biomesoplenty:snowy_forest", - "moisture": 0.33333334, - "temperature": 0.1, - "color": -13592211 - }, - { - "id": "biomesoplenty:steppe", - "moisture": 0.033333335, - "temperature": 0.51, - "color": -13592211 - }, - { - "id": "biomesoplenty:temperate_rainforest", - "moisture": 0.8, - "temperature": 0.45999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:temperate_rainforest_hills", - "moisture": 0.8, - "temperature": 0.45999998, - "color": -13592211 - }, - { - "id": "biomesoplenty:tropical_rainforest", - "moisture": 0.6666667, - "temperature": 0.6, - "color": -13592211 - }, - { - "id": "biomesoplenty:tundra", - "moisture": 0.33333334, - "temperature": 0.28, - "color": -13592211 - }, - { - "id": "biomesoplenty:wasteland", - "moisture": 0.0, - "temperature": 1.0, - "color": -12427646 - }, - { - "id": "biomesoplenty:wetland", - "moisture": 0.46666667, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "biomesoplenty:white_beach", - "moisture": 0.6666667, - "temperature": 0.58000004, - "color": -6034953 - }, - { - "id": "biomesoplenty:woodland", - "moisture": 0.33333334, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "biomesoplenty:xeric_shrubland", - "moisture": 0.06666667, - "temperature": 0.9, - "color": -6034953 - }, - { - "id": "minecraft:badlands", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:badlands_plateau", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:bamboo_jungle", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "minecraft:bamboo_jungle_hills", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "minecraft:beach", - "moisture": 0.26666668, - "temperature": 0.52, - "color": -6034953 - }, - { - "id": "minecraft:birch_forest", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "minecraft:birch_forest_hills", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "minecraft:cold_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:dark_forest", - "moisture": 0.53333336, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "minecraft:dark_forest_hills", - "moisture": 0.53333336, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "minecraft:deep_cold_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:deep_frozen_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:deep_lukewarm_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:deep_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:deep_warm_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -6034953 - }, - { - "id": "minecraft:desert", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:desert_hills", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:desert_lakes", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:eroded_badlands", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:flower_forest", - "moisture": 0.53333336, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "minecraft:forest", - "moisture": 0.53333336, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "minecraft:frozen_ocean", - "moisture": 0.33333334, - "temperature": 0.2, - "color": -13592211 - }, - { - "id": "minecraft:frozen_river", - "moisture": 0.33333334, - "temperature": 0.2, - "color": -13592211 - }, - { - "id": "minecraft:giant_spruce_taiga", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - }, - { - "id": "minecraft:giant_spruce_taiga_hills", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - }, - { - "id": "minecraft:giant_tree_taiga", - "moisture": 0.53333336, - "temperature": 0.32, - "color": -13592211 - }, - { - "id": "minecraft:giant_tree_taiga_hills", - "moisture": 0.53333336, - "temperature": 0.32, - "color": -13592211 - }, - { - "id": "minecraft:gravelly_mountains", - "moisture": 0.2, - "temperature": 0.28, - "color": -13592211 - }, - { - "id": "minecraft:ice_spikes", - "moisture": 0.33333334, - "temperature": 0.2, - "color": -2302756 - }, - { - "id": "minecraft:jungle", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "minecraft:jungle_hills", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "minecraft:lukewarm_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:modified_badlands_plateau", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:modified_gravelly_mountains", - "moisture": 0.2, - "temperature": 0.28, - "color": -13592211 - }, - { - "id": "minecraft:modified_jungle", - "moisture": 0.59999996, - "temperature": 0.58000004, - "color": -13592211 - }, - { - "id": "minecraft:modified_wooded_badlands_plateau", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:mountains", - "moisture": 0.2, - "temperature": 0.28, - "color": -13592211 - }, - { - "id": "minecraft:mushroom_field_shore", - "moisture": 0.6666667, - "temperature": 0.56, - "color": -13592211 - }, - { - "id": "minecraft:mushroom_fields", - "moisture": 0.6666667, - "temperature": 0.56, - "color": -13592211 - }, - { - "id": "minecraft:ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:plains", - "moisture": 0.26666668, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "minecraft:river", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -13592211 - }, - { - "id": "minecraft:savanna", - "moisture": 0.0, - "temperature": 0.68, - "color": -13592211 - }, - { - "id": "minecraft:savanna_plateau", - "moisture": 0.0, - "temperature": 0.6, - "color": -13592211 - }, - { - "id": "minecraft:shattered_savanna", - "moisture": 0.0, - "temperature": 0.64, - "color": -13592211 - }, - { - "id": "minecraft:shattered_savanna_plateau", - "moisture": 0.0, - "temperature": 0.6, - "color": -13592211 - }, - { - "id": "minecraft:snowy_beach", - "moisture": 0.2, - "temperature": 0.22, - "color": -6034953 - }, - { - "id": "minecraft:snowy_mountains", - "moisture": 0.33333334, - "temperature": 0.2, - "color": -13592211 - }, - { - "id": "minecraft:snowy_taiga", - "moisture": 0.26666668, - "temperature": 0.0, - "color": -13592211 - }, - { - "id": "minecraft:snowy_taiga_hills", - "moisture": 0.26666668, - "temperature": 0.0, - "color": -13592211 - }, - { - "id": "minecraft:snowy_taiga_mountains", - "moisture": 0.26666668, - "temperature": 0.0, - "color": -13592211 - }, - { - "id": "minecraft:snowy_tundra", - "moisture": 0.33333334, - "temperature": 0.2, - "color": -13592211 - }, - { - "id": "minecraft:sunflower_plains", - "moisture": 0.26666668, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "minecraft:swamp", - "moisture": 0.59999996, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "minecraft:swamp_hills", - "moisture": 0.59999996, - "temperature": 0.52, - "color": -13592211 - }, - { - "id": "minecraft:taiga", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - }, - { - "id": "minecraft:taiga_hills", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - }, - { - "id": "minecraft:taiga_mountains", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - }, - { - "id": "minecraft:tall_birch_forest", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "minecraft:tall_birch_hills", - "moisture": 0.4, - "temperature": 0.44, - "color": -13592211 - }, - { - "id": "minecraft:warm_ocean", - "moisture": 0.33333334, - "temperature": 0.4, - "color": -6034953 - }, - { - "id": "minecraft:wooded_badlands_plateau", - "moisture": 0.0, - "temperature": 1.0, - "color": -6034953 - }, - { - "id": "minecraft:wooded_hills", - "moisture": 0.53333336, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "minecraft:wooded_mountains", - "moisture": 0.2, - "temperature": 0.28, - "color": -13592211 - }, - { - "id": "terraforged:cold_steppe", - "moisture": 0.06666667, - "temperature": 0.28, - "color": -13592211 - }, - { - "id": "terraforged:savanna_scrub", - "moisture": 0.0, - "temperature": 0.68, - "color": -13592211 - }, - { - "id": "terraforged:shattered_savanna_scrub", - "moisture": 0.0, - "temperature": 0.64, - "color": -13592211 - }, - { - "id": "terraforged:snowy_taiga_scrub", - "moisture": 0.26666668, - "temperature": 0.0, - "color": -13592211 - }, - { - "id": "terraforged:steppe", - "moisture": 0.06666667, - "temperature": 0.48000002, - "color": -13592211 - }, - { - "id": "terraforged:taiga_scrub", - "moisture": 0.53333336, - "temperature": 0.3, - "color": -13592211 - } -] \ No newline at end of file diff --git a/TerraForgedApp/src/main/resources/biome_groups.json b/TerraForgedApp/src/main/resources/biome_groups.json deleted file mode 100644 index 5eed0dd..0000000 --- a/TerraForgedApp/src/main/resources/biome_groups.json +++ /dev/null @@ -1,168 +0,0 @@ -{ - "TROPICAL_RAINFOREST": [ - "biomesoplenty:overgrown_cliffs", - "biomesoplenty:tropical_rainforest", - "minecraft:bamboo_jungle", - "minecraft:bamboo_jungle_hills", - "minecraft:jungle", - "minecraft:jungle_hills", - "minecraft:modified_jungle" - ], - "SAVANNA": [ - "biomesoplenty:brushland", - "biomesoplenty:scrubland", - "biomesoplenty:xeric_shrubland", - "minecraft:savanna", - "minecraft:savanna_plateau", - "minecraft:shattered_savanna", - "minecraft:shattered_savanna_plateau", - "terraforged:savanna_scrub", - "terraforged:shattered_savanna_scrub" - ], - "DESERT": [ - "biomesoplenty:oasis", - "biomesoplenty:outback", - "biomesoplenty:wasteland", - "minecraft:badlands", - "minecraft:badlands_plateau", - "minecraft:desert", - "minecraft:desert_hills", - "minecraft:desert_lakes", - "minecraft:eroded_badlands", - "minecraft:modified_badlands_plateau", - "minecraft:modified_wooded_badlands_plateau", - "minecraft:wooded_badlands_plateau" - ], - "TEMPERATE_RAINFOREST": [ - "biomesoplenty:rainforest", - "biomesoplenty:temperate_rainforest", - "biomesoplenty:temperate_rainforest_hills", - "minecraft:plains" - ], - "TEMPERATE_FOREST": [ - "biomesoplenty:cherry_blossom_grove", - "biomesoplenty:grove", - "biomesoplenty:mystic_grove", - "biomesoplenty:orchard", - "biomesoplenty:pumpkin_patch", - "biomesoplenty:redwood_forest", - "biomesoplenty:redwood_forest_edge", - "biomesoplenty:seasonal_forest", - "biomesoplenty:silkglade", - "biomesoplenty:temperate_rainforest", - "biomesoplenty:temperate_rainforest_hills", - "biomesoplenty:woodland", - "minecraft:birch_forest", - "minecraft:birch_forest_hills", - "minecraft:dark_forest", - "minecraft:flower_forest", - "minecraft:forest", - "minecraft:plains", - "minecraft:tall_birch_forest", - "minecraft:wooded_hills" - ], - "GRASSLAND": [ - "biomesoplenty:bayou", - "biomesoplenty:bog", - "biomesoplenty:chaparral", - "biomesoplenty:floodplain", - "biomesoplenty:grassland", - "biomesoplenty:highland_moor", - "biomesoplenty:lavender_field", - "biomesoplenty:lush_grassland", - "biomesoplenty:lush_swamp", - "biomesoplenty:mangrove", - "biomesoplenty:marsh", - "biomesoplenty:mire", - "biomesoplenty:pasture", - "biomesoplenty:prairie", - "biomesoplenty:shrubland", - "biomesoplenty:steppe", - "biomesoplenty:wetland", - "minecraft:plains", - "minecraft:sunflower_plains", - "minecraft:swamp" - ], - "COLD_STEPPE": [ - "terraforged:cold_steppe" - ], - "STEPPE": [ - "biomesoplenty:steppe", - "terraforged:steppe" - ], - "TAIGA": [ - "biomesoplenty:boreal_forest", - "biomesoplenty:coniferous_forest", - "biomesoplenty:dead_forest", - "biomesoplenty:fir_clearing", - "biomesoplenty:flower_meadow", - "biomesoplenty:maple_woods", - "biomesoplenty:meadow", - "biomesoplenty:ominous_woods", - "biomesoplenty:shield", - "biomesoplenty:tundra", - "minecraft:giant_spruce_taiga", - "minecraft:giant_tree_taiga", - "minecraft:giant_tree_taiga_hills", - "minecraft:taiga", - "minecraft:taiga_hills", - "terraforged:taiga_scrub" - ], - "TUNDRA": [ - "biomesoplenty:alps", - "biomesoplenty:alps_foothills", - "biomesoplenty:snowy_coniferous_forest", - "biomesoplenty:snowy_fir_clearing", - "biomesoplenty:snowy_forest", - "minecraft:ice_spikes", - "minecraft:snowy_taiga", - "minecraft:snowy_taiga_hills", - "minecraft:snowy_tundra", - "terraforged:snowy_taiga_scrub" - ], - "ALPINE": [ - "biomesoplenty:highland", - "minecraft:gravelly_mountains", - "minecraft:modified_gravelly_mountains", - "minecraft:mountains", - "minecraft:snowy_mountains", - "minecraft:snowy_taiga_mountains", - "minecraft:taiga_mountains", - "minecraft:wooded_mountains" - ], - "rivers": { - "COLD": [ - "minecraft:frozen_river" - ], - "MEDIUM": [ - "minecraft:river" - ], - "WARM": [] - }, - "oceans": { - "COLD": [ - "minecraft:cold_ocean", - "minecraft:frozen_ocean" - ], - "MEDIUM": [ - "minecraft:ocean" - ], - "WARM": [ - "minecraft:lukewarm_ocean", - "minecraft:warm_ocean" - ] - }, - "deep_oceans": { - "COLD": [ - "minecraft:deep_cold_ocean", - "minecraft:deep_frozen_ocean" - ], - "MEDIUM": [ - "minecraft:deep_ocean" - ], - "WARM": [ - "minecraft:deep_lukewarm_ocean", - "minecraft:deep_warm_ocean" - ] - } -} \ No newline at end of file diff --git a/TerraForgedApp/src/main/resources/grass.png b/TerraForgedApp/src/main/resources/grass.png deleted file mode 100644 index f59dd38..0000000 Binary files a/TerraForgedApp/src/main/resources/grass.png and /dev/null differ diff --git a/TerraForgedApp/src/main/resources/license.txt b/TerraForgedApp/src/main/resources/license.txt deleted file mode 100644 index 0b31935..0000000 --- a/TerraForgedApp/src/main/resources/license.txt +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 TerraForged - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/TerraForgedCore/build.gradle b/TerraForgedCore/build.gradle deleted file mode 100644 index f68ce7d..0000000 --- a/TerraForgedCore/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -apply plugin: "maven-publish" - -repositories { - mavenCentral() -} - -dependencies { - compile project(":Noise2D") - compile "it.unimi.dsi:fastutil:8.2.1" -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifact jar - } - } - - if (System.getenv("MAVEN_USER") != null && System.getenv("MAVEN_PASS") != null) { - repositories { - maven { - credentials { - username System.getenv("MAVEN_USER") - password System.getenv("MAVEN_PASS") - } - name = "nexus" - url = "https://io.terraforged.com/repository/maven/" - } - } - } -} \ No newline at end of file diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Cell.java b/TerraForgedCore/src/main/java/com/terraforged/core/cell/Cell.java deleted file mode 100644 index f1b99fe..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Cell.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.cell; - -import com.terraforged.core.util.concurrent.ObjectPool; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.util.NoiseUtil; - -public class Cell { - - private static final Cell EMPTY = new Cell() { - @Override - public boolean isAbsent() { - return true; - } - }; - - private static final ObjectPool> POOL = new ObjectPool<>(100, Cell::new); - - public float continent; - public float continentEdge; - public float region; - public float regionEdge; - public float biome; - public float biomeEdge = 1F; - public float riverMask = 1F; - - public float value; - public float biomeMoisture; - public float biomeTemperature; - public float moisture; - public float temperature; - public float steepness; - public float erosion; - public float sediment; - public float biomeTypeMask = 1F; - public BiomeType biomeType = BiomeType.GRASSLAND; - - public T tag = null; - - public void copy(Cell other) { - value = other.value; - - continent = other.continent; - continentEdge = other.continentEdge; - - region = other.region; - regionEdge = other.regionEdge; - - biome = other.biome; - biomeEdge = other.biomeEdge; - - riverMask = other.riverMask; - - moisture = other.moisture; - temperature = other.temperature; - biomeMoisture = other.biomeMoisture; - biomeTemperature = other.biomeTemperature; - - steepness = other.steepness; - erosion = other.erosion; - sediment = other.sediment; - biomeType = other.biomeType; - biomeTypeMask = other.biomeTypeMask; - - tag = other.tag; - } - - public float continentMask(float min, float max) { - return NoiseUtil.map(continentEdge, min, max, max - min); - } - - public float regionMask(float min, float max) { - return NoiseUtil.map(regionEdge, min, max, max - min); - } - - public float biomeMask(float min, float max) { - return NoiseUtil.map(biomeEdge, min, max, max - min); - } - - public float mask(float cmin, float cmax, float rmin, float rmax) { - return riverMask * continentMask(cmin, cmax) * regionMask(rmin, rmax); - } - - public boolean isAbsent() { - return false; - } - - @SuppressWarnings("unchecked") - public static Cell empty() { - return EMPTY; - } - - public static ObjectPool.Item> pooled() { - return POOL.get(); - } - - public interface Visitor { - - void visit(Cell cell, int dx, int dz); - } - - public interface ContextVisitor { - - void visit(Cell cell, int dx, int dz, C ctx); - } - - public interface ZoomVisitor { - - void visit(Cell cell, float x, float z); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Extent.java b/TerraForgedCore/src/main/java/com/terraforged/core/cell/Extent.java deleted file mode 100644 index 0d8af1e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Extent.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.cell; - -import com.terraforged.core.world.terrain.Terrain; - -public interface Extent { - - void visit(int minX, int minZ, int maxX, int maxZ, Cell.Visitor visitor); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Populator.java b/TerraForgedCore/src/main/java/com/terraforged/core/cell/Populator.java deleted file mode 100644 index 60fc88d..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Populator.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.cell; - -import com.terraforged.core.util.concurrent.ObjectPool; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; - -public interface Populator extends Module { - - void apply(Cell cell, float x, float y); - - void tag(Cell cell, float x, float y); - - @Override - default float getValue(float x, float z) { - try (ObjectPool.Item> cell = Cell.pooled()) { - apply(cell.getValue(), x, z); - return cell.getValue().value; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Tag.java b/TerraForgedCore/src/main/java/com/terraforged/core/cell/Tag.java deleted file mode 100644 index 5cf6ad8..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/cell/Tag.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.cell; - -public interface Tag { - - String getName(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Erosion.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Erosion.java deleted file mode 100644 index b6228c1..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Erosion.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.filter; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.Size; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.world.heightmap.Levels; -import me.dags.noise.util.NoiseUtil; - -import java.util.Random; - -/* - * This class in an adaption of the work by Sebastian Lague which is also licensed under MIT. - * Reference: - * https://github.com/SebLague/Hydraulic-Erosion/blob/Coding-Adventure-E01/Assets/Scripts/Erosion.cs - * https://github.com/SebLague/Hydraulic-Erosion/blob/Coding-Adventure-E01/LICENSE - * - * License In Full: - * MIT License - * - * Copyright (c) 2019 Sebastian Lague - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -public class Erosion implements Filter { - - private int erosionRadius = 3; - private float inertia = 0.05f; - private float sedimentCapacityFactor = 4; - private float minSedimentCapacity = 0.01f; - private float erodeSpeed = 0.3f; - private float depositSpeed = 0.3f; - private float evaporateSpeed = 0.01f; - private float gravity = 8; - private int maxDropletLifetime = 30; - private float initialWaterVolume = 1; - private float initialSpeed = 1; - private final TerrainPos gradient = new TerrainPos(); - private int[][] erosionBrushIndices = new int[0][]; - private float[][] erosionBrushWeights = new float[0][]; - - private final Modifier modifier; - private final Random random = new Random(); - - public Erosion(Settings settings, Levels levels) { - erodeSpeed = settings.filters.erosion.erosionRate; - depositSpeed = settings.filters.erosion.depositeRate; - modifier = Modifier.range(levels.ground, levels.ground(15)); - } - - @Override - public void apply(Filterable map, int seedX, int seedZ, int iterations) { - if (erosionBrushIndices.length != map.getSize().total) { - init(map.getSize().total, erosionRadius); - } - - applyMain(map, seedX, seedZ, iterations, random); - -// applyNeighbours(map, seedX, seedZ, iterations, random); - } - - private int nextCoord(Size size, Random random) { - return random.nextInt(size.total - 1); - } - - private void applyMain(Filterable map, int seedX, int seedZ, int iterations, Random random) { - random.setSeed(NoiseUtil.seed(seedX, seedZ)); - while (iterations-- > 0) { - int posX = nextCoord(map.getSize(), random); - int posZ = nextCoord(map.getSize(), random); - apply(map.getBacking(), posX, posZ, map.getSize().total); - } - } - - private void apply(Cell[] cells, float posX, float posY, int size) { - float dirX = 0; - float dirY = 0; - float speed = initialSpeed; - float water = initialWaterVolume; - float sediment = 0; - - for (int lifetime = 0; lifetime < maxDropletLifetime; lifetime++) { - int nodeX = (int) posX; - int nodeY = (int) posY; - int dropletIndex = nodeY * size + nodeX; - // Calculate droplet's offset inside the cell (0,0) = at NW node, (1,1) = at SE node - float cellOffsetX = posX - nodeX; - float cellOffsetY = posY - nodeY; - - // Calculate droplet's height and direction of flow with bilinear interpolation of surrounding heights - gradient.update(cells, size, posX, posY); - - // Update the droplet's direction and position (move position 1 unit regardless of speed) - dirX = (dirX * inertia - gradient.gradientX * (1 - inertia)); - dirY = (dirY * inertia - gradient.gradientY * (1 - inertia)); - - // Normalize direction - float len = (float) Math.sqrt(dirX * dirX + dirY * dirY); - if (Float.isNaN(len)) { - len = 0; - } - - if (len != 0) { - dirX /= len; - dirY /= len; - } - - posX += dirX; - posY += dirY; - - // Stop simulating droplet if it's not moving or has flowed over edge of map - if ((dirX == 0 && dirY == 0) || posX < 0 || posX >= size - 1 || posY < 0 || posY >= size - 1) { - break; - } - - // Find the droplet's new height and calculate the deltaHeight - float oldHeight = gradient.height; - float newHeight = gradient.update(cells, size, posX, posY).height; - float deltaHeight = newHeight - oldHeight; - - // Calculate the droplet's sediment capacity (higher when moving fast down a slope and contains lots of water) - float sedimentCapacity = Math.max(-deltaHeight * speed * water * sedimentCapacityFactor, minSedimentCapacity); - - // If carrying more sediment than capacity, or if flowing uphill: - if (sediment > sedimentCapacity || deltaHeight > 0) { - // If moving uphill (deltaHeight > 0) try fill up to the current height, otherwise deposit a fraction of the excess sediment - float amountToDeposit = (deltaHeight > 0) ? Math.min(deltaHeight, sediment) : (sediment - sedimentCapacity) * depositSpeed; - sediment -= amountToDeposit; - - // Add the sediment to the four nodes of the current cell using bilinear interpolation - // Deposition is not distributed over a radius (like erosion) so that it can fill small pits - deposit(cells[dropletIndex], amountToDeposit * (1 - cellOffsetX) * (1 - cellOffsetY)); - deposit(cells[dropletIndex + 1], amountToDeposit * cellOffsetX * (1 - cellOffsetY)); - deposit(cells[dropletIndex + size], amountToDeposit * (1 - cellOffsetX) * cellOffsetY); - deposit(cells[dropletIndex + size + 1], amountToDeposit * cellOffsetX * cellOffsetY); - } else { - // Erode a fraction of the droplet's current carry capacity. - // Clamp the erosion to the change in height so that it doesn't dig a hole in the terrain behind the droplet - float amountToErode = Math.min((sedimentCapacity - sediment) * erodeSpeed, -deltaHeight); - - // Use erosion brush to erode from all nodes inside the droplet's erosion radius - for (int brushPointIndex = 0; brushPointIndex < erosionBrushIndices[dropletIndex].length; brushPointIndex++) { - int nodeIndex = erosionBrushIndices[dropletIndex][brushPointIndex]; - Cell cell = cells[nodeIndex]; - float brushWeight = erosionBrushWeights[dropletIndex][brushPointIndex]; - float weighedErodeAmount = amountToErode * brushWeight; - float deltaSediment = Math.min(cell.value, weighedErodeAmount);//cell.value < weighedErodeAmount) ? cell.value : weighedErodeAmount; - erode(cell, deltaSediment); - sediment += deltaSediment; - } - } - - // Update droplet's speed and water content - speed = (float) Math.sqrt(speed * speed + deltaHeight * gravity); - water *= (1 - evaporateSpeed); - - if (Float.isNaN(speed)) { - speed = 0; - } - } - } - - private void init(int size, int radius) { - erosionBrushIndices = new int[size * size][]; - erosionBrushWeights = new float[size * size][]; - - int[] xOffsets = new int[radius * radius * 4]; - int[] yOffsets = new int[radius * radius * 4]; - float[] weights = new float[radius * radius * 4]; - float weightSum = 0; - int addIndex = 0; - - for (int i = 0; i < erosionBrushIndices.length; i++) { - int centreX = i % size; - int centreY = i / size; - - if (centreY <= radius || centreY >= size - radius || centreX <= radius + 1 || centreX >= size - radius) { - weightSum = 0; - addIndex = 0; - for (int y = -radius; y <= radius; y++) { - for (int x = -radius; x <= radius; x++) { - float sqrDst = x * x + y * y; - if (sqrDst < radius * radius) { - int coordX = centreX + x; - int coordY = centreY + y; - - if (coordX >= 0 && coordX < size && coordY >= 0 && coordY < size) { - float weight = 1 - (float) Math.sqrt(sqrDst) / radius; - weightSum += weight; - weights[addIndex] = weight; - xOffsets[addIndex] = x; - yOffsets[addIndex] = y; - addIndex++; - } - } - } - } - } - - int numEntries = addIndex; - erosionBrushIndices[i] = new int[numEntries]; - erosionBrushWeights[i] = new float[numEntries]; - - for (int j = 0; j < numEntries; j++) { - erosionBrushIndices[i][j] = (yOffsets[j] + centreY) * size + xOffsets[j] + centreX; - erosionBrushWeights[i][j] = weights[j] / weightSum; - } - } - } - - private void deposit(Cell cell, float amount) { - float change = modifier.modify(cell, amount); - cell.value += change; - cell.sediment += change; - } - - private void erode(Cell cell, float amount) { - float change = modifier.modify(cell, amount); - cell.value -= change; - cell.erosion -= change; - } - - private static class TerrainPos { - private float height; - private float gradientX; - private float gradientY; - - private TerrainPos update(Cell[] nodes, int mapSize, float posX, float posY) { - int coordX = (int) posX; - int coordY = (int) posY; - - // Calculate droplet's offset inside the cell (0,0) = at NW node, (1,1) = at SE node - float x = posX - coordX; - float y = posY - coordY; - - // Calculate heights of the four nodes of the droplet's cell - int nodeIndexNW = coordY * mapSize + coordX; - float heightNW = nodes[nodeIndexNW].value; - float heightNE = nodes[nodeIndexNW + 1].value; - float heightSW = nodes[nodeIndexNW + mapSize].value; - float heightSE = nodes[nodeIndexNW + mapSize + 1].value; - - // Calculate droplet's direction of flow with bilinear interpolation of height difference along the edges - this.gradientX = (heightNE - heightNW) * (1 - y) + (heightSE - heightSW) * y; - this.gradientY = (heightSW - heightNW) * (1 - x) + (heightSE - heightNE) * x; - // Calculate height with bilinear interpolation of the heights of the nodes of the cell - this.height = heightNW * (1 - x) * (1 - y) + heightNE * x * (1 - y) + heightSW * (1 - x) * y + heightSE * x * y; - return this; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Filter.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Filter.java deleted file mode 100644 index 483ba90..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Filter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.filter; - -import com.terraforged.core.cell.Cell; - -public interface Filter { - - void apply(Filterable map, int seedX, int seedZ, int iterations); - - default void iterate(Filterable map, Visitor visitor) { - for (int dz = 0; dz < map.getSize().total; dz++) { - for (int dx = 0; dx < map.getSize().total; dx++) { - Cell cell = map.getCellRaw(dx, dz); - visitor.visit(map, cell, dx, dz); - } - } - } - - interface Visitor { - - void visit(Filterable cellMap, Cell cell, int dx, int dz); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Filterable.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Filterable.java deleted file mode 100644 index bc11e86..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Filterable.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.filter; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Tag; -import com.terraforged.core.region.Size; - -public interface Filterable { - - Size getSize(); - - Cell[] getBacking(); - - Cell getCellRaw(int x, int z); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Modifier.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Modifier.java deleted file mode 100644 index bfb9f22..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Modifier.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.filter; - -import com.terraforged.core.cell.Cell; - -public interface Modifier { - - float getModifier(float value); - - default float modify(Cell cell, float value) { - return value * getModifier(cell.value); - } - - default Modifier invert() { - return v -> 1 - getModifier(v); - } - - static Modifier range(float minValue, float maxValue) { - return new Modifier() { - - private final float min = minValue; - private final float max = maxValue; - private final float range = maxValue - minValue; - - @Override - public float getModifier(float value) { - if (value > max) { - return 1F; - } - if (value < min) { - return 0F; - } - return (value - min) / range; - } - }; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Smoothing.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Smoothing.java deleted file mode 100644 index 7e7e462..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Smoothing.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.filter; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.world.heightmap.Levels; -import me.dags.noise.util.NoiseUtil; - -public class Smoothing implements Filter { - - private final int radius; - private final float rad2; - private final float strength; - private final Modifier modifier; - - public Smoothing(Settings settings, Levels levels) { - this.radius = NoiseUtil.round(settings.filters.smoothing.smoothingRadius + 0.5F); - this.rad2 = settings.filters.smoothing.smoothingRadius * settings.filters.smoothing.smoothingRadius; - this.strength = settings.filters.smoothing.smoothingRate; - this.modifier = Modifier.range(levels.ground(1), levels.ground(120)).invert(); - } - - @Override - public void apply(Filterable map, int seedX, int seedZ, int iterations) { - while (iterations-- > 0) { - apply(map); - } - } - - private void apply(Filterable cellMap) { - int maxZ = cellMap.getSize().total - radius; - int maxX = cellMap.getSize().total - radius; - for (int z = radius; z < maxZ; z++) { - for (int x = radius; x < maxX; x++) { - Cell cell = cellMap.getCellRaw(x, z); - - float total = 0; - float weights = 0; - - for (int dz = -radius; dz <= radius; dz++) { - for (int dx = -radius; dx <= radius; dx++) { - float dist2 = dx * dx + dz * dz; - if (dist2 > rad2) { - continue; - } - int px = x + dx; - int pz = z + dz; - Cell neighbour = cellMap.getCellRaw(px, pz); - if (neighbour.isAbsent()) { - continue; - } - float value = neighbour.value; - float weight = 1F - (dist2 / rad2); - total += (value * weight); - weights += weight; - } - } - - if (weights > 0) { - float dif = cell.value - (total / weights); - cell.value -= modifier.modify(cell, dif * strength); - } - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java b/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java deleted file mode 100644 index dc16467..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/filter/Steepness.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.filter; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrains; - -public class Steepness implements Filter, Filter.Visitor { - - private final int radius; - private final float scaler; - private final float waterLevel; - private final float maxBeachLevel; - private final Terrains terrains; - - public Steepness(int radius, float scaler, Terrains terrains, Levels levels) { - this.radius = radius; - this.scaler = scaler; - this.terrains = terrains; - this.waterLevel = levels.water; - this.maxBeachLevel = levels.water(6); - } - - @Override - public void apply(Filterable cellMap, int seedX, int seedZ, int iterations) { - iterate(cellMap, this); - } - - @Override - public void visit(Filterable cellMap, Cell cell, int cx, int cz) { - float totalHeightDif = 0F; - for (int dz = -1; dz <= 2; dz++) { - for (int dx = -1; dx <= 2; dx++) { - if (dx == 0 && dz == 0) { - continue; - } - - int x = cx + dx * radius; - int z = cz + dz * radius; - Cell neighbour = cellMap.getCellRaw(x, z); - if (neighbour.isAbsent()) { - continue; - } - - float height = Math.max(neighbour.value, waterLevel); - - totalHeightDif += (Math.abs(cell.value - height) / radius); - } - } - cell.steepness = Math.min(1, totalHeightDif * scaler); - if (cell.tag == terrains.coast && cell.steepness < 0.225F && cell.value < maxBeachLevel) { - cell.tag = terrains.beach; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/module/Blender.java b/TerraForgedCore/src/main/java/com/terraforged/core/module/Blender.java deleted file mode 100644 index 2cd17d2..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/module/Blender.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.module; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.func.Interpolation; -import me.dags.noise.util.NoiseUtil; - -public class Blender extends Select implements Populator { - - private final Populator lower; - private final Populator upper; - - private final float blendLower; - private final float blendUpper; - private final float blendRange; - private final float midpoint; - private final float tagThreshold; - - public Blender(Module control, Populator lower, Populator upper, float min, float max, float split) { - super(control); - this.lower = lower; - this.upper = upper; - this.blendLower = min; - this.blendUpper = max; - this.blendRange = blendUpper - blendLower; - this.midpoint = blendLower + (blendRange * split); - this.tagThreshold = midpoint; - } - - public Blender(Populator control, Populator lower, Populator upper, float min, float max, float split, float tagThreshold) { - super(control); - this.lower = lower; - this.upper = upper; - this.blendLower = min; - this.blendUpper = max; - this.blendRange = blendUpper - blendLower; - this.midpoint = blendLower + (blendRange * split); - this.tagThreshold = tagThreshold; - } - - @Override - public void apply(Cell cell, float x, float y) { - float select = getSelect(cell, x, y); - - if (select < blendLower) { - lower.apply(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.apply(cell, x, y); - return; - } - - float alpha = Interpolation.LINEAR.apply((select - blendLower) / blendRange); - lower.apply(cell, x, y); - - float lowerVal = cell.value; - Terrain lowerType = cell.tag; - - upper.apply(cell, x, y); - float upperVal = cell.value; - - cell.value = NoiseUtil.lerp(lowerVal, upperVal, alpha); - if (select < midpoint) { - cell.tag = lowerType; - } - } - - @Override - public void tag(Cell cell, float x, float y) { - float select = getSelect(cell, x, y); - if (select < blendLower) { - lower.tag(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.tag(cell, x, y); - return; - } - - if (select < tagThreshold) { - lower.tag(cell, x, y); - } else { - upper.tag(cell, x, y); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/module/MultiBlender.java b/TerraForgedCore/src/main/java/com/terraforged/core/module/MultiBlender.java deleted file mode 100644 index 121015d..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/module/MultiBlender.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.module; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.func.Interpolation; -import me.dags.noise.util.NoiseUtil; - -public class MultiBlender extends Select implements Populator { - - private final Climate climate; - private final Populator lower; - private final Populator middle; - private final Populator upper; - private final float midpoint; - - private final float blendLower; - private final float blendUpper; - - private final float lowerRange; - private final float upperRange; - - public MultiBlender(Climate climate, Populator control, Populator lower, Populator middle, Populator upper, float min, float mid, float max) { - super(control); - this.climate = climate; - this.lower = lower; - this.upper = upper; - this.middle = middle; - - this.midpoint = mid; - this.blendLower = min; - this.blendUpper = max; - - this.lowerRange = midpoint - blendLower; - this.upperRange = blendUpper - midpoint; - } - - @Override - public void apply(Cell cell, float x, float y) { - float select = getSelect(cell, x, y); - if (select < blendLower) { - lower.apply(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.apply(cell, x, y); - return; - } - - if (select < midpoint) { - float alpha = Interpolation.CURVE3.apply((select - blendLower) / lowerRange); - - lower.apply(cell, x, y); - float lowerVal = cell.value; - Terrain lowerType = cell.tag; - - middle.apply(cell, x, y); - float upperVal = cell.value; - - cell.value = NoiseUtil.lerp(lowerVal, upperVal, alpha); - } else { - float alpha = Interpolation.CURVE3.apply((select - midpoint) / upperRange); - - middle.apply(cell, x, y); - float lowerVal = cell.value; - - upper.apply(cell, x, y); - cell.value = NoiseUtil.lerp(lowerVal, cell.value, alpha); - } - } - - @Override - public void tag(Cell cell, float x, float y) { - float select = getSelect(cell, x, y); - if (select < blendLower) { - lower.tag(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.tag(cell, x, y); - return; - } - - if (select < midpoint) { - lower.tag(cell, x, y); -// upper.tag(cell, x, y); - if (cell.value > cell.tag.getMax(climate.getRand().getValue(x, y))) { - upper.tag(cell, x, y); - } - } else { - upper.tag(cell, x, y); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/module/Select.java b/TerraForgedCore/src/main/java/com/terraforged/core/module/Select.java deleted file mode 100644 index c77fcf9..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/module/Select.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.module; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; - -public class Select { - - private final Module control; - - public Select(Module control) { - this.control = control; - } - - public float getSelect(Cell cell, float x, float y) { - return control.getValue(x, y); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/Region.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/Region.java deleted file mode 100644 index b4a145f..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/Region.java +++ /dev/null @@ -1,404 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Extent; -import com.terraforged.core.filter.Filterable; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.core.region.chunk.ChunkWriter; -import com.terraforged.core.util.concurrent.Disposable; -import com.terraforged.core.world.decorator.Decorator; -import com.terraforged.core.world.heightmap.Heightmap; -import com.terraforged.core.world.rivermap.RiverRegionList; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.util.NoiseUtil; - -import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - -public class Region implements Extent, Disposable { - - private final int regionX; - private final int regionZ; - private final int chunkX; - private final int chunkZ; - private final int blockX; - private final int blockZ; - private final int border; - private final Size blockSize; - private final Size chunkSize; - private final GenCell[] blocks; - private final GenChunk[] chunks; - private final int disposableChunks; - private final Disposable.Listener disposalListener; - private final AtomicInteger disposedChunks = new AtomicInteger(); - - public Region(int regionX, int regionZ, int size, int borderChunks) { - this(regionX, regionZ, size, borderChunks, region -> {}); - } - - public Region(int regionX, int regionZ, int size, int borderChunks, Disposable.Listener disposalListener) { - this.regionX = regionX; - this.regionZ = regionZ; - this.chunkX = regionX << size; - this.chunkZ = regionZ << size; - this.blockX = Size.chunkToBlock(chunkX); - this.blockZ = Size.chunkToBlock(chunkZ); - this.border = borderChunks; - this.chunkSize = Size.chunks(size, borderChunks); - this.blockSize = Size.blocks(size, borderChunks); - this.disposalListener = disposalListener; - this.disposableChunks = chunkSize.size * chunkSize.size; - this.blocks = new GenCell[blockSize.total * blockSize.total]; - this.chunks = new GenChunk[chunkSize.total * chunkSize.total]; - } - - @Override - public void dispose() { - int disposed = disposedChunks.incrementAndGet(); - if (disposed < disposableChunks) { - return; - } - disposalListener.onDispose(this); - } - - public long getRegionId() { - return NoiseUtil.seed(getRegionX(), getRegionZ()); - } - - public int getRegionX() { - return regionX; - } - - public int getRegionZ() { - return regionZ; - } - - public int getBlockX() { - return blockX; - } - - public int getBlockZ() { - return blockZ; - } - - public int getOffsetChunks() { - return border; - } - - public int getChunkCount() { - return chunks.length; - } - - public int getBlockCount() { - return blocks.length; - } - - public Size getChunkSize() { - return chunkSize; - } - - public Size getBlockSize() { - return blockSize; - } - - public Filterable filterable() { - return new FilterRegion(); - } - - public Cell getCell(int blockX, int blockZ) { - int relBlockX = blockSize.border + blockSize.mask(blockX); - int relBlockZ = blockSize.border + blockSize.mask(blockZ); - int index = blockSize.indexOf(relBlockX, relBlockZ); - return blocks[index]; - } - - public Cell getRawCell(int blockX, int blockZ) { - int index = blockSize.indexOf(blockX, blockZ); - return blocks[index]; - } - - public ChunkReader getChunk(int chunkX, int chunkZ) { - int relChunkX = chunkSize.border + chunkSize.mask(chunkX); - int relChunkZ = chunkSize.border + chunkSize.mask(chunkZ); - int index = chunkSize.indexOf(relChunkX, relChunkZ); - return chunks[index]; - } - - public void generate(Consumer consumer) { - for (int cz = 0; cz < chunkSize.total; cz++) { - for (int cx = 0; cx < chunkSize.total; cx++) { - int index = chunkSize.indexOf(cx, cz); - GenChunk chunk = computeChunk(index, cx, cz); - consumer.accept(chunk); - } - } - } - - public void generateBase(Heightmap heightmap) { - for (int cz = 0; cz < chunkSize.total; cz++) { - for (int cx = 0; cx < chunkSize.total; cx++) { - int index = chunkSize.indexOf(cx, cz); - GenChunk chunk = computeChunk(index, cx, cz); - for (int dz = 0; dz < 16; dz++) { - for (int dx = 0; dx < 16; dx++) { - float x = chunk.getBlockX() + dx; - float z = chunk.getBlockZ() + dz; - Cell cell = chunk.genCell(dx, dz); - heightmap.applyBase(cell, x, z); - } - } - } - } - } - - public void generateRivers(Heightmap heightmap, RiverRegionList rivers) { - for (int cz = 0; cz < chunkSize.total; cz++) { - for (int cx = 0; cx < chunkSize.total; cx++) { - int index = chunkSize.indexOf(cx, cz); - GenChunk chunk = computeChunk(index, cx, cz); - for (int dz = 0; dz < 16; dz++) { - for (int dx = 0; dx < 16; dx++) { - float x = chunk.getBlockX() + dx; - float z = chunk.getBlockZ() + dz; - Cell cell = chunk.genCell(dx, dz); - heightmap.applyRivers(cell, x, z, rivers); - heightmap.applyClimate(cell, x, z); - } - } - } - } - } - - public void generateZoom(Heightmap heightmap, float offsetX, float offsetZ, float zoom) { - float translateX = offsetX - ((blockSize.size * zoom) / 2F); - float translateZ = offsetZ - ((blockSize.size * zoom) / 2F); - for (int cz = 0; cz < chunkSize.total; cz++) { - for (int cx = 0; cx < chunkSize.total; cx++) { - int index = chunkSize.indexOf(cx, cz); - GenChunk chunk = computeChunk(index, cx, cz); - for (int dz = 0; dz < 16; dz++) { - for (int dx = 0; dx < 16; dx++) { - float x = ((chunk.getBlockX() + dx) * zoom) + translateX; - float z = ((chunk.getBlockZ() + dz) * zoom) + translateZ; - Cell cell = chunk.genCell(dx, dz); - heightmap.apply(cell, x, z); - } - } - } - } - } - - public void decorate(Collection decorators) { - for (int dz = 0; dz < blockSize.total; dz++) { - for (int dx = 0; dx < blockSize.total; dx++) { - int index = blockSize.indexOf(dx, dz); - GenCell cell = blocks[index]; - for (Decorator decorator : decorators) { - if (decorator.apply(cell, getBlockX() + dx, getBlockZ() + dz)) { - break; - } - } - } - } - } - - public void decorateZoom(Collection decorators, float offsetX, float offsetZ, float zoom) { - float translateX = offsetX - ((blockSize.size * zoom) / 2F); - float translateZ = offsetZ - ((blockSize.size * zoom) / 2F); - for (int cz = 0; cz < chunkSize.total; cz++) { - for (int cx = 0; cx < chunkSize.total; cx++) { - int index = chunkSize.indexOf(cx, cz); - GenChunk chunk = computeChunk(index, cx, cz); - chunk.iterate((cell, dx, dz) -> { - float x = ((chunk.getBlockX() + dx) * zoom) + translateX; - float z = ((chunk.getBlockZ() + dz) * zoom) + translateZ; - for (Decorator decorator : decorators) { - decorator.apply(cell, x, z); - } - }); - } - } - } - - public void iterate(Consumer consumer) { - for (int cz = 0; cz < chunkSize.size; cz++) { - int chunkZ = chunkSize.border + cz; - for (int cx = 0; cx < chunkSize.size; cx++) { - int chunkX = chunkSize.border + cx; - int index = chunkSize.indexOf(chunkX, chunkZ); - GenChunk chunk = chunks[index]; - consumer.accept(chunk); - } - } - } - - public void iterate(Cell.Visitor visitor) { - for (int dz = 0; dz < blockSize.size; dz++) { - int z = blockSize.border + dz; - for (int dx = 0; dx < blockSize.size; dx++) { - int x = blockSize.border + dx; - int index = blockSize.indexOf(x, z); - GenCell cell = blocks[index]; - visitor.visit(cell, dx, dz); - } - } - } - - @Override - public void visit(int minX, int minZ, int maxX, int maxZ, Cell.Visitor visitor) { - int regionMinX = getBlockX(); - int regionMinZ = getBlockZ(); - if (maxX < regionMinX || maxZ < regionMinZ) { - return; - } - - int regionMaxX = getBlockX() + getBlockSize().size - 1; - int regionMaxZ = getBlockZ() + getBlockSize().size - 1; - if (minX > regionMaxX || maxZ > regionMaxZ) { - return; - } - - minX = Math.max(minX, regionMinX); - minZ = Math.max(minZ, regionMinZ); - maxX = Math.min(maxX, regionMaxX); - maxZ = Math.min(maxZ, regionMaxZ); - - for (int z = minZ; z <= maxX; z++) { - for (int x = minX; x <= maxZ; x++) { - visitor.visit(getCell(x, z), x, z); - } - } - } - - private GenChunk computeChunk(int index, int chunkX, int chunkZ) { - GenChunk chunk = chunks[index]; - if (chunk == null) { - chunk = new GenChunk(chunkX, chunkZ); - chunks[index] = chunk; - } - return chunk; - } - - private GenCell computeCell(int index) { - GenCell cell = blocks[index]; - if (cell == null) { - cell = new GenCell(); - blocks[index] = cell; - } - return cell; - } - - private static class GenCell extends Cell {} - - private class GenChunk implements ChunkReader, ChunkWriter { - - private final int chunkX; - private final int chunkZ; - private final int blockX; - private final int blockZ; - private final int regionBlockX; - private final int regionBlockZ; - - // the coordinate of the chunk within this region (relative to 0,0) - private GenChunk(int regionChunkX, int regionChunkZ) { - // the block coordinate of this chunk within this region (relative 0,0) - this.regionBlockX = regionChunkX << 4; - this.regionBlockZ = regionChunkZ << 4; - // the real coordinate of this chunk within the world - this.chunkX = Region.this.chunkX + regionChunkX - getOffsetChunks(); - this.chunkZ = Region.this.chunkZ + regionChunkZ - getOffsetChunks(); - // the real block coordinate of this chunk within the world - this.blockX = chunkX << 4; - this.blockZ = chunkZ << 4; - } - - @Override - public int getChunkX() { - return chunkX; - } - - @Override - public int getChunkZ() { - return chunkZ; - } - - @Override - public int getBlockX() { - return blockX; - } - - @Override - public int getBlockZ() { - return blockZ; - } - - @Override - public void dispose() { - Region.this.dispose(); - } - - @Override - public Cell getCell(int blockX, int blockZ) { - int relX = regionBlockX + (blockX & 15); - int relZ = regionBlockZ + (blockZ & 15); - int index = blockSize.indexOf(relX, relZ); - return blocks[index]; - } - - @Override - public Cell genCell(int blockX, int blockZ) { - int relX = regionBlockX + (blockX & 15); - int relZ = regionBlockZ + (blockZ & 15); - int index = blockSize.indexOf(relX, relZ); - return computeCell(index); - } - } - - private class FilterRegion implements Filterable { - - @Override - public Size getSize() { - return blockSize; - } - - @Override - public Cell[] getBacking() { - return blocks; - } - - @Override - public Cell getCellRaw(int x, int z) { - int index = blockSize.indexOf(x, z); - if (index < 0 || index >= blocks.length) { - return Cell.empty(); - } - return blocks[index]; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/RegionFactory.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/RegionFactory.java deleted file mode 100644 index 83c927e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/RegionFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.terraforged.core.region; - -import com.terraforged.core.util.concurrent.Disposable; - -public interface RegionFactory { - - Region create(int regionX, int regionZ, int size, int borderChunks, Disposable.Listener listener); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/Size.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/Size.java deleted file mode 100644 index c9f9d34..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/Size.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region; - -public class Size { - - public final int size; - public final int total; - public final int border; - private final int mask; - - public Size(int size, int border) { - this.size = size; - this.mask = size - 1; - this.border = border; - this.total = size + (2 * border); - } - - public int mask(int i) { - return i & mask; - } - - public int indexOf(int x, int z) { - return (z * total) + x; - } - - public static int chunkToBlock(int i) { - return i << 4; - } - - public static int blockToChunk(int i) { - return i >> 4; - } - - public static int count(int minX, int minZ, int maxX, int maxZ) { - int dx = maxX - minX; - int dz = maxZ - minZ; - return dx * dz; - } - - public static Size chunks(int factor, int borderChunks) { - int chunks = 1 << factor; - return new Size(chunks, borderChunks); - } - - public static Size blocks(int factor, int borderChunks) { - int chunks = 1 << factor; - int blocks = chunks << 4; - int borderBlocks = borderChunks << 4; - return new Size(blocks, borderBlocks); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkGenTask.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkGenTask.java deleted file mode 100644 index 51cba50..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkGenTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.chunk; - -import com.terraforged.core.world.heightmap.Heightmap; - -public class ChunkGenTask implements Runnable { - - protected final ChunkWriter chunk; - protected final Heightmap heightmap; - - public ChunkGenTask(ChunkWriter chunk, Heightmap heightmap) { - this.chunk = chunk; - this.heightmap = heightmap; - } - - @Override - public void run() { - chunk.generate((cell, dx, dz) -> { - float x = chunk.getBlockX() + dx; - float z = chunk.getBlockZ() + dz; - heightmap.apply(cell, x, z); - }); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkHolder.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkHolder.java deleted file mode 100644 index 8d417d7..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkHolder.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.chunk; - -import com.terraforged.core.cell.Extent; -import com.terraforged.core.util.concurrent.Disposable; - -public interface ChunkHolder extends Extent, Disposable { - - int getChunkX(); - - int getChunkZ(); - - int getBlockX(); - - int getBlockZ(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkReader.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkReader.java deleted file mode 100644 index 11e39b8..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkReader.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.chunk; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; - -public interface ChunkReader extends ChunkHolder { - - Cell getCell(int dx, int dz); - - @Override - default void visit(int minX, int minZ, int maxX, int maxZ, Cell.Visitor visitor) { - int regionMinX = getBlockX(); - int regionMinZ = getBlockZ(); - if (maxX < regionMinX || maxZ < regionMinZ) { - return; - } - - int regionMaxX = getBlockX() + 15; - int regionMaxZ = getBlockZ() + 15; - if (minX > regionMaxX || maxZ > regionMaxZ) { - return; - } - - minX = Math.max(minX, regionMinX); - minZ = Math.max(minZ, regionMinZ); - maxX = Math.min(maxX, regionMaxX); - maxZ = Math.min(maxZ, regionMaxZ); - - for (int z = minZ; z <= maxX; z++) { - for (int x = minX; x <= maxZ; x++) { - visitor.visit(getCell(x, z), x, z); - } - } - } - - default void iterate(Cell.Visitor visitor) { - for (int dz = 0; dz < 16; dz++) { - for (int dx = 0; dx < 16; dx++) { - visitor.visit(getCell(dx, dz), dx, dz); - } - } - } - - default void iterate(C context, Cell.ContextVisitor visitor) { - for (int dz = 0; dz < 16; dz++) { - for (int dx = 0; dx < 16; dx++) { - visitor.visit(getCell(dx, dz), dx, dz, context); - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkWriter.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkWriter.java deleted file mode 100644 index d581910..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkWriter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.chunk; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; - -public interface ChunkWriter extends ChunkHolder { - - Cell genCell(int dx, int dz); - - default void generate(Cell.Visitor visitor) { - for (int dz = 0; dz < 16; dz++) { - for (int dx = 0; dx < 16; dx++) { - visitor.visit(genCell(dx, dz), dx, dz); - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkZoomTask.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkZoomTask.java deleted file mode 100644 index f089d3b..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/chunk/ChunkZoomTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.chunk; - -import com.terraforged.core.world.heightmap.Heightmap; - -public class ChunkZoomTask extends ChunkGenTask { - - private final float translateX; - private final float translateZ; - private final float zoom; - - public ChunkZoomTask(ChunkWriter chunk, Heightmap heightmap, float translateX, float translateZ, float zoom) { - super(chunk, heightmap); - this.translateX = translateX; - this.translateZ = translateZ; - this.zoom = zoom; - } - - @Override - public void run() { - chunk.generate((cell, dx, dz) -> { - float x = ((chunk.getBlockX() + dx) * zoom) + translateX; - float z = ((chunk.getBlockZ() + dz) * zoom) + translateZ; - heightmap.apply(cell, x, z); - }); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/FutureRegion.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/FutureRegion.java deleted file mode 100644 index 5ddfb3b..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/FutureRegion.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.terraforged.core.region.gen; - -import com.terraforged.core.region.Region; - -import java.util.concurrent.Callable; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -public class FutureRegion implements Future, Callable { - - private final int rx; - private final int rz; - private final RegionGenerator generator; - - private volatile Region result; - - public FutureRegion(int rx, int rz, RegionGenerator generator) { - this.rx = rx; - this.rz = rz; - this.generator = generator; - } - - @Override - public Region call() { - Region region = result; - if (region == null) { - region = generator.generateRegion(rx, rz); - result = region; - } - return region; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public boolean isDone() { - return result != null; - } - - @Override - public Region get() { - return call(); - } - - @Override - public Region get(long timeout, TimeUnit unit) { - return get(); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/FutureRegionZoom.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/FutureRegionZoom.java deleted file mode 100644 index 039f638..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/FutureRegionZoom.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.terraforged.core.region.gen; - -import com.terraforged.core.region.Region; - -import java.util.concurrent.Callable; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -public class FutureRegionZoom implements Future, Callable { - - private final float cx; - private final float cz; - private final float zoom; - private final boolean filters; - private final RegionGenerator generator; - - private volatile Region result; - - public FutureRegionZoom(float cx, float cz, float zoom, boolean filters, RegionGenerator generator) { - this.cx = cx; - this.cz = cz; - this.zoom = zoom; - this.filters = filters; - this.generator = generator; - } - - @Override - public Region call() { - Region region = result; - if (region == null) { - region = generator.generateRegion(cx, cz, zoom, filters); - result = region; - } - return region; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public boolean isDone() { - return result != null; - } - - @Override - public Region get() { - return call(); - } - - @Override - public Region get(long timeout, TimeUnit unit) { - return get(); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/GenContext.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/GenContext.java deleted file mode 100644 index 7b60433..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/GenContext.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.terraforged.core.region.gen; - -import com.terraforged.core.world.WorldGenerator; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.rivermap.RiverRegionList; - -import java.util.function.Supplier; - -public class GenContext { - - public final WorldGenerator generator; - public final RiverRegionList rivers = new RiverRegionList(); - - public GenContext(WorldGenerator generator) { - this.generator = generator; - } - - public static Supplier supplier(WorldGeneratorFactory factory) { - return () -> new GenContext(factory.get()); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionCache.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionCache.java deleted file mode 100644 index 323417f..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionCache.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.gen; - -import com.terraforged.core.region.Region; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.core.util.concurrent.Disposable; -import com.terraforged.core.util.concurrent.cache.Cache; -import com.terraforged.core.util.concurrent.cache.CacheEntry; -import com.terraforged.core.world.heightmap.RegionExtent; -import me.dags.noise.util.NoiseUtil; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -public class RegionCache implements RegionExtent, Disposable.Listener { - - private final boolean queuing; - private final RegionGenerator generator; - private final Cache> cache; - - public RegionCache(boolean queueNeighbours, RegionGenerator generator) { - this.queuing = queueNeighbours; - this.generator = new RegionGenerator(generator, this); - this.cache = new Cache<>(60, 30, TimeUnit.SECONDS); - } - - @Override - public void onDispose(Region region) { - cache.remove(region.getRegionId()); - } - - @Override - public int chunkToRegion(int coord) { - return generator.chunkToRegion(coord); - } - - @Override - public CompletableFuture getRegionAsync(int regionX, int regionZ) { - return generator.generate(regionX, regionZ); - } - - @Override - public ChunkReader getChunk(int chunkX, int chunkZ) { - int regionX = generator.chunkToRegion(chunkX); - int regionZ = generator.chunkToRegion(chunkZ); - Region region = getRegion(regionX, regionZ); - return region.getChunk(chunkX, chunkZ); - } - - @Override - public Region getRegion(int regionX, int regionZ) { - Region region = computeRegion(regionX, regionZ).get(); - - if (queuing) { - queueNeighbours(regionX, regionZ); - } - - return region; - } - - private CacheEntry computeRegion(int regionX, int regionZ) { - long id = NoiseUtil.seed(regionX, regionZ); - return cache.computeIfAbsent(id, l -> generator.compute(regionX, regionZ)); - } - - public CacheEntry queueRegion(int regionX, int regionZ) { - long id = NoiseUtil.seed(regionX, regionZ); - return cache.computeIfAbsent(id, l -> generator.queue(regionX, regionZ)); - } - - private void queueNeighbours(int regionX, int regionZ) { - for (int z = -1; z <= 1; z++) { - for (int x = -1; x <= 1; x++){ - if (x == 0 && z == 0) { - continue; - } - queueRegion(regionX + x, regionZ + z); - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionCacheFactory.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionCacheFactory.java deleted file mode 100644 index 27c2c58..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionCacheFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.gen; - -import com.terraforged.core.world.WorldGeneratorFactory; - -public interface RegionCacheFactory { - - RegionCache create(WorldGeneratorFactory factory); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionGenerator.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionGenerator.java deleted file mode 100644 index 83fc3ea..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/gen/RegionGenerator.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.region.gen; - -import com.terraforged.core.region.Region; -import com.terraforged.core.region.RegionFactory; -import com.terraforged.core.region.legacy.LegacyRegion; -import com.terraforged.core.util.concurrent.Disposable; -import com.terraforged.core.util.concurrent.ObjectPool; -import com.terraforged.core.util.concurrent.ThreadPool; -import com.terraforged.core.util.concurrent.cache.CacheEntry; -import com.terraforged.core.world.WorldGenerator; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.heightmap.RegionExtent; -import com.terraforged.core.world.rivermap.RiverRegionList; - -import java.util.concurrent.CompletableFuture; - -public class RegionGenerator implements RegionExtent { - - private final int factor; - private final int border; - private final RegionFactory regions; - private final ThreadPool threadPool; - private final ObjectPool genPool; - private final Disposable.Listener disposalListener; - - private RegionGenerator(Builder builder) { - this.factor = builder.factor; - this.border = builder.border; - this.threadPool = builder.threadPool; - this.regions = builder.regionFactory; - this.genPool = new ObjectPool<>(6, GenContext.supplier(builder.factory)); - this.disposalListener = region -> {}; - } - - protected RegionGenerator(RegionGenerator from, Disposable.Listener listener) { - this.factor = from.factor; - this.border = from.border; - this.threadPool = from.threadPool; - this.regions = from.regions; - this.genPool = from.genPool; - this.disposalListener = listener; - } - - public RegionCache toCache() { - return toCache(true); - } - - public RegionCache toCache(boolean queueNeighbours) { - return new RegionCache(queueNeighbours, this); - } - - @Override - public int chunkToRegion(int i) { - return i >> factor; - } - - @Override - public Region getRegion(int regionX, int regionZ) { - return generateRegion(regionX, regionZ); - } - - @Override - public CompletableFuture getRegionAsync(int regionX, int regionZ) { - return generate(regionX, regionZ); - } - - public CompletableFuture generate(int regionX, int regionZ) { - return CompletableFuture.supplyAsync(() -> generateRegion(regionX, regionZ), threadPool); - } - - public CompletableFuture generate(float centerX, float centerZ, float zoom, boolean filter) { - return CompletableFuture.supplyAsync(() -> generateRegion(centerX, centerZ, zoom, filter), threadPool); - } - - public CacheEntry compute(int regionX, int regionZ) { - return CacheEntry.supply(new FutureRegion(regionX, regionZ, this)); - } - - public CacheEntry compute(float centerX, float centerZ, float zoom, boolean filter) { - return CacheEntry.supply(new FutureRegionZoom(centerX, centerZ, zoom, filter, this)); - } - - public CacheEntry queue(int regionX, int regionZ) { - return CacheEntry.supplyAsync(new FutureRegion(regionX, regionZ, this), threadPool); - } - - public CacheEntry queue(float centerX, float centerZ, float zoom, boolean filter) { - return CacheEntry.supplyAsync(new FutureRegionZoom(centerX, centerZ, zoom, filter, this), threadPool); - } - - public Region generateRegion(int regionX, int regionZ) { - try (ObjectPool.Item item = genPool.get()) { - RiverRegionList rivers = item.getValue().rivers; - WorldGenerator generator = item.getValue().generator; - Region region = regions.create(regionX, regionZ, factor, border, disposalListener); - generator.getHeightmap().getRiverMap().getRivers(region, rivers); - region.generateBase(generator.getHeightmap()); - region.generateRivers(generator.getHeightmap(), rivers); - postProcess(region, generator); - rivers.clear(); - return region; - } - } - - private void postProcess(Region region, WorldGenerator generator) { - generator.getFilters().apply(region); - region.decorate(generator.getDecorators().getDecorators()); - } - - public Region generateRegion(float centerX, float centerZ, float zoom, boolean filter) { - try (ObjectPool.Item item = genPool.get()) { - WorldGenerator generator = item.getValue().generator; - Region region = regions.create(0, 0, factor, border, disposalListener); - region.generateZoom(generator.getHeightmap(), centerX, centerZ, zoom); - postProcess(region, generator, centerX, centerZ, zoom, filter); - return region; - } - } - - private void postProcess(Region region, WorldGenerator generator, float centerX, float centerZ, float zoom, boolean filter) { - if (filter) { - generator.getFilters().apply(region); - } - region.decorateZoom(generator.getDecorators().getDecorators(), centerX, centerZ, zoom); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private int factor = 0; - private int border = 0; - private ThreadPool threadPool; - private WorldGeneratorFactory factory; - private RegionFactory regionFactory = Region::new; - - public Builder size(int factor, int border) { - return factor(factor).border(border); - } - - public Builder factor(int factor) { - this.factor = factor; - return this; - } - - public Builder border(int border) { - this.border = border; - return this; - } - - public Builder pool(ThreadPool threadPool) { - this.threadPool = threadPool; - return this; - } - - public Builder regions(RegionFactory factory) { - this.regionFactory = factory; - return this; - } - - public Builder legacy(boolean legacy) { - if (legacy) { - return regions(LegacyRegion::new); - } - return this; - } - - public Builder factory(WorldGeneratorFactory factory) { - this.factory = factory; - return this; - } - - public RegionGenerator build() { - return new RegionGenerator(this); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/region/legacy/LegacyRegion.java b/TerraForgedCore/src/main/java/com/terraforged/core/region/legacy/LegacyRegion.java deleted file mode 100644 index 34d77dc..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/region/legacy/LegacyRegion.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.terraforged.core.region.legacy; - -import com.terraforged.core.region.Region; -import com.terraforged.core.util.concurrent.Disposable; - -/** - * This is here to provide compatibility for versions 0.0.2 and below which contained a - * bug where Regions generated with an x,z offset equal to the size of the chunk border - * around the region (x16) ie 32 blocks - */ -public class LegacyRegion extends Region { - - public LegacyRegion(int regionX, int regionZ, int size, int borderChunks, Disposable.Listener listener) { - super(regionX, regionZ, size, borderChunks, listener); - } - - /** - * This is used when calculating the 'real world' chunk position of the chunk-view - * and subsequently the 'real world' block start position. In versions 0.0.2 and - * below, no offset was being deducted, so return 0 here to maintain that broken - * behaviour... RIP :/ - */ - @Override - public int getOffsetChunks() { - return 0; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/BiomeSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/BiomeSettings.java deleted file mode 100644 index 8b27fcb..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/BiomeSettings.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; -import com.terraforged.core.world.biome.BiomeType; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class BiomeSettings { - - public BiomeGroup desert = new BiomeGroup(BiomeType.DESERT); - public BiomeGroup steppe = new BiomeGroup(BiomeType.STEPPE); - public BiomeGroup coldSteppe = new BiomeGroup(BiomeType.COLD_STEPPE); - public BiomeGroup grassland = new BiomeGroup(BiomeType.GRASSLAND); - public BiomeGroup savanna = new BiomeGroup(BiomeType.SAVANNA); - public BiomeGroup taiga = new BiomeGroup(BiomeType.TAIGA); - public BiomeGroup temperateForest = new BiomeGroup(BiomeType.TEMPERATE_FOREST); - public BiomeGroup temperateRainForest = new BiomeGroup(BiomeType.TEMPERATE_RAINFOREST); - public BiomeGroup tropicalRainForest = new BiomeGroup(BiomeType.TROPICAL_RAINFOREST); - public BiomeGroup tundra = new BiomeGroup(BiomeType.TUNDRA); - - public List asList() { - return Arrays.asList( - desert, - steppe, - coldSteppe, - grassland, - savanna, - taiga, - temperateForest, - temperateRainForest, - tropicalRainForest, - tundra - ); - } - - public Map asMap() { - return asList().stream().collect(Collectors.toMap(g -> g.type, g -> g)); - } - - @Serializable - public static class BiomeGroup { - - public BiomeType type; - - public BiomeWeight[] biomes = new BiomeWeight[0]; - - public BiomeGroup() { - - } - - public BiomeGroup(BiomeType biomeType) { - this.type = biomeType; - } - } - - @Serializable - public static class BiomeWeight { - - public String id; - - @Range(min = 0, max = 50) - @Comment("Controls how common this biome type is") - public int weight; - - public BiomeWeight() { - - } - - public BiomeWeight(String id, int weight) { - this.id = id; - this.weight = weight; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/ClimateSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/ClimateSettings.java deleted file mode 100644 index b6619c4..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/ClimateSettings.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; -import me.dags.noise.Module; -import me.dags.noise.Source; - -@Serializable -public class ClimateSettings { - - public RangeValue moisture = new RangeValue(0, 1F); - - public RangeValue temperature = new RangeValue(0, 1F); - - @Serializable - public static class RangeValue { - - @Range(min = 0F, max = 1F) - @Comment("The lower limit of the range") - public float min; - - @Range(min = 0F, max = 1F) - @Comment("The upper limit of the range") - public float max; - - public RangeValue() { - this(0, 1); - } - - public RangeValue(float min, float max) { - this.min = min; - this.max = max; - } - - public float getMin() { - return Math.min(min, max); - } - - public float getMax() { - return Math.max(min, max); - } - - public Module clamp(Module module) { - float min = getMin(); - float max = getMax(); - float range = max - min; - if (range == 0) { - return Source.constant(min); - } - return module.scale(range).bias(min); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java deleted file mode 100644 index 198826b..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; - -@Serializable -public class FilterSettings { - - public Erosion erosion = new Erosion(); - - public Smoothing smoothing = new Smoothing(); - - @Serializable - public static class Erosion { - - @Range(min = 1000, max = 50000) - @Comment("Controls the number of erosion iterations") - public int iterations = 12000; - - @Range(min = 0F, max = 1F) - @Comment("Controls how quickly material dissolves (during erosion)") - public float erosionRate = 0.5F; - - @Range(min = 0F, max = 1F) - @Comment("Controls how quickly material is deposited (during erosion)") - public float depositeRate = 0.2F; - } - - @Serializable - public static class Smoothing { - - @Range(min = 0, max = 5) - @Comment("Controls the number of smoothing iterations") - public int iterations = 1; - - @Range(min = 0, max = 5) - @Comment("Controls the smoothing radius") - public float smoothingRadius = 1.75F; - - @Range(min = 0, max = 1) - @Comment("Controls how strongly smoothing is applied") - public float smoothingRate = 0.85F; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/GeneratorSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/GeneratorSettings.java deleted file mode 100644 index 9d6e660..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/GeneratorSettings.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Name; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; -import me.dags.noise.Module; -import me.dags.noise.Source; - -@Serializable -public class GeneratorSettings { - - public transient long seed = 0L; - - /** - * WORLD PROPERTIES - */ - public World world = new World(); - - /** - * TERRAIN PROPERTIES - */ - public Land land = new Land(); - - /** - * BIOME PROPERTIES - */ - public Biome biome = new Biome(); - - public BiomeNoise biomeEdgeNoise = new BiomeNoise(); - - @Serializable - public static class World { - - @Range(min = 0, max = 256) - @Comment("Controls the world height") - public int worldHeight = 256; - - @Range(min = 0, max = 255) - @Comment("Controls the sea level") - public int seaLevel = 63; - - @Range(min = 0F, max = 1F) - @Comment("Controls the amount of ocean between continents") - public float oceanSize = 0.25F; - } - - @Serializable - public static class Land { - - @Range(min = 100, max = 10000) - @Comment("Controls the size of continents") - public int continentScale = 4000; - - @Range(min = 250, max = 5000) - @Name("Mountain Range Scale") - @Comment("Controls the size of mountain ranges") - public int mountainScale = 950; - - @Range(min = 125, max = 5000) - @Comment("Controls the size of terrain regions") - public int regionSize = 1000; - } - - @Serializable - public static class Biome { - - @Range(min = 50, max = 1000) - @Comment("Controls the size of individual biomes") - public int biomeSize = 200; - - @Range(min = 1, max = 500) - @Comment("Controls the scale of shape distortion for biomes") - public int biomeWarpScale = 35; - - @Range(min = 1, max = 500) - @Comment("Controls the strength of shape distortion for biomes") - public int biomeWarpStrength = 70; - } - - @Serializable - public static class BiomeNoise { - - @Comment("The noise type") - public Source type = Source.PERLIN; - - @Range(min = 1, max = 500) - @Comment("Controls the scale of the noise") - public int scale = 8; - - @Range(min = 1, max = 5) - @Comment("Controls the number of noise octaves") - public int octaves = 2; - - @Range(min = 0F, max = 5.5F) - @Comment("Controls the gain subsequent noise octaves") - public float gain = 0.5F; - - @Range(min = 0F, max = 10.5F) - @Comment("Controls the lacunarity of subsequent noise octaves") - public float lacunarity = 2.5F; - - @Range(min = 1, max = 500) - @Comment("Controls the strength of the noise") - public int strength = 24; - - public Module build(int seed) { - return Source.build(seed, scale, octaves).gain(gain).lacunarity(lacunarity).build(type).bias(-0.5); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/RiverSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/RiverSettings.java deleted file mode 100644 index 04d8d77..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/RiverSettings.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; - -@Serializable -public class RiverSettings { - - /** - * RIVER PROPERTIES - */ - @Range(min = 0.0F, max = 5F) - @Comment("Controls how frequently rivers generate") - public float riverFrequency = 1; - - public River primaryRivers = new River(5, 2, 8, 25, 8, 0.75F); - - public River secondaryRiver = new River(4, 1, 6, 15, 5, 0.75F); - - public River tertiaryRivers = new River(3, 0, 4, 10, 4, 0.75F); - - public Lake lake = new Lake(); - - @Serializable - public static class River { - - @Range(min = 1, max = 10) - @Comment("Controls the depth of the river") - public int bedDepth; - - @Range(min = 0, max = 10) - @Comment("Controls the height of river banks") - public int minBankHeight; - - @Range(min = 1, max = 10) - @Comment("Controls the height of river banks") - public int maxBankHeight; - - @Range(min = 1, max = 20) - @Comment("Controls the river-bed width") - public int bedWidth; - - @Range(min = 1, max = 50) - @Comment("Controls the river-banks width") - public int bankWidth; - - @Range(min = 0.0F, max = 1.0F) - @Comment("Controls how much rivers taper") - public float fade; - - public River() { - } - - public River(int depth, int minBank, int maxBank, int outer, int inner, float fade) { - this.minBankHeight = minBank; - this.maxBankHeight = maxBank; - this.bankWidth = outer; - this.bedWidth = inner; - this.bedDepth = depth; - this.fade = fade; - } - } - - public static class Lake { - - @Range(min = 0.0F, max = 1.0F) - @Comment("Controls the chance of a lake spawning") - public float chance = 0.2F; - - @Range(min = 0F, max = 1F) - @Comment("The minimum distance along a river that a lake will spawn") - public float minStartDistance = 0.03F; - - @Range(min = 0F, max = 1F) - @Comment("The maximum distance along a river that a lake will spawn") - public float maxStartDistance = 0.07F; - - @Range(min = 1, max = 20) - @Comment("The max depth of the lake") - public int depth = 10; - - @Range(min = 10, max = 50) - @Comment("The minimum size of the lake") - public int sizeMin = 50; - - @Range(min = 50, max = 150) - @Comment("The maximum size of the lake") - public int sizeMax = 100; - - @Range(min = 1, max = 10) - @Comment("The minimum bank height") - public int minBankHeight = 2; - - @Range(min = 1, max = 10) - @Comment("The maximum bank height") - public int maxBankHeight = 10; - - public Lake() { - - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java deleted file mode 100644 index d768788..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Serializable; - -@Serializable -public class Settings { - - public GeneratorSettings generator = new GeneratorSettings(); - - public ClimateSettings climate = new ClimateSettings(); - - public RiverSettings rivers = new RiverSettings(); - - public FilterSettings filters = new FilterSettings(); - - public TerrainSettings terrain = new TerrainSettings(); - - public BiomeSettings biomes = new BiomeSettings(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/TerrainSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/TerrainSettings.java deleted file mode 100644 index 91cc0ae..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/TerrainSettings.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; -import com.terraforged.core.world.terrain.TerrainPopulator; -import me.dags.noise.Module; - -@Serializable -public class TerrainSettings { - - @Range(min = 0, max = 1) - @Comment("Globally controls the vertical scaling of terrain") - public float globalVerticalScale = 0.985F; - - @Range(min = 0, max = 5) - @Comment("Globally controls the horizontal scaling of terrain") - public float globalHorizontalScale = 1.0F; - - public Terrain steppe = new Terrain(5F, 1F, 1F); - public Terrain plains = new Terrain(5F, 1F, 1F); - public Terrain hills = new Terrain(2F, 1F, 1F); - public Terrain dales = new Terrain(2F, 1F, 1F); - public Terrain plateau = new Terrain(2F, 1F, 1F); - public Terrain badlands = new Terrain(2F, 1F, 1F); - public Terrain torridonian = new Terrain(0.5F, 1F, 1F); - public Terrain mountains = new Terrain(0.5F, 1F, 1F); - public Terrain volcano = new Terrain(1F, 1F, 1F); - - @Serializable - public static class Terrain { - - @Range(min = 0, max = 10) - @Comment("Controls how common this terrain type is") - public float weight = 1F; - - @Range(min = 0, max = 2) - @Comment("Controls the base height of this terrain") - public float baseScale = 1F; - - @Range(min = 0F, max = 10F) - @Comment("Stretches or compresses the terrain vertically") - public float verticalScale = 1F; - - @Range(min = 0F, max = 10F) - @Comment("Stretches or compresses the terrain horizontally") - public float horizontalScale = 1F; - - public Terrain() { - - } - - public Terrain(float weight, float vertical, float horizontal) { - this.weight = weight; - this.verticalScale = vertical; - this.horizontalScale = horizontal; - } - - public Module apply(double bias, double scale, Module module) { - double moduleBias = bias * baseScale; - double moduleScale = scale * verticalScale; - Module outputModule = module.scale(moduleScale).bias(moduleBias); - return TerrainPopulator.clamp(outputModule); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/PosIterator.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/PosIterator.java deleted file mode 100644 index d2fce85..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/PosIterator.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util; - -public class PosIterator { - - private final int minX; - private final int minZ; - private final int maxX; - private final int maxY; - private final int maxZ; - private final int size; - - private int x; - private int y; - private int z; - private int index = -1; - - public PosIterator(int x, int y, int z, int width, int height, int length) { - this.x = x - 1; - this.y = y; - this.z = z; - this.minX = x; - this.minZ = z; - this.maxX = x + width; - this.maxY = y + height; - this.maxZ = z + length; - this.size = (width * height * length) - 1; - } - - /** - * Steps the iterator forward one position if there there is a new position within it's x/y/z bounds. - * - * @return true if the an increment was made, false if the maximum x,y,z coord has been reached - */ - public boolean next() { - if (x + 1 < maxX) { - x += 1; - index++; - return true; - } - - if (z + 1 < maxZ) { - x = minX; - z += 1; - index++; - return true; - } - - if (y + 1 < maxY) { - x = minX - 1; - z = minZ; - y += 1; - return true; - } - - return false; - } - - public int size() { - return size; - } - - public int index() { - return index; - } - - public int x() { - return x; - } - - public int y() { - return y; - } - - public int z() { - return z; - } - - /** - * Iterates over a 2D area in the x-z planes, centered on x:z, with the given radius - * - * Iteration Order: - * 1. Increments the x-axis from x - radius to x + radius (inclusive), then: - * 2. Increments the z-axis once, resets the x-axis to x - radius, then: - * 3. Repeats steps 1 & 2 until z reaches z + radius - */ - public static PosIterator radius2D(int x, int z, int radius) { - int startX = x - radius; - int startZ = z - radius; - int size = radius * 2 + 1; - return new PosIterator(startX, 0, startZ, size, 0, size); - } - - /** - * Iterates over a 3D volume, centered on x:y:z, with the given radius - * - * Iteration Order: - * 1. Increments the x-axis (starting from x - radius) up to x + radius (inclusive), then: - * 2. Increments the z-axis once (starting from z - radius) and resets the x-axis to x - radius, then: - * 3. Increments the y-axis once (starting from y - radius), resets the x & z axes to x - radius & z - radius - * respectively, then: - * 4. Repeats steps 1-3 until y reaches y + radius - */ - public static PosIterator radius3D(int x, int y, int z, int radius) { - int startX = x - radius; - int startY = y - radius; - int startZ = z - radius; - int size = radius * 2 + 1; - return new PosIterator(startX, startY, startZ, size, size, size); - } - - public static PosIterator area(int x, int z, int width, int length) { - return new PosIterator(x, 0, z, width, 0, length); - } - - public static PosIterator volume3D(int x, int y, int z, int width, int height, int length) { - return new PosIterator(x, y, z, width, height, length); - } - - public static PosIterator range2D(int minX, int minZ, int maxX, int maxZ) { - int width = maxX - minX; - int length = maxZ - minZ; - return new PosIterator(minX, 0, minZ, width, 0, length); - } - - public static PosIterator range2D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { - int width = 1 + maxX - minX; - int height = 1 + maxY - minY; - int length = 1 + maxZ - minZ; - return new PosIterator(minX, minY, minZ, width, height, length); - } -} \ No newline at end of file diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/Seed.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/Seed.java deleted file mode 100644 index 6148874..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/Seed.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util; - -public class Seed { - - private final Seed root; - - private final int value; - private int seed; - - public Seed(long seed) { - this((int) seed); - } - - public Seed(int seed) { - this.value = seed; - this.seed = seed; - this.root = this; - } - - private Seed(Seed root) { - this.root = root; - this.seed = root.next(); - this.value = seed; - } - - public int next() { - return ++root.seed; - } - - public int get() { - return value; - } - - public Seed nextSeed() { - return new Seed(root); - } - - public Seed reset() { - this.seed = value; - return this; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/VariablePredicate.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/VariablePredicate.java deleted file mode 100644 index e43ab95..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/VariablePredicate.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; - -import java.util.function.BiPredicate; - -public class VariablePredicate { - - private final Module module; - private final BiPredicate, Float> predicate; - - public VariablePredicate(Module module, BiPredicate, Float> predicate) { - this.module = module; - this.predicate = predicate; - } - - public boolean test(Cell cell, float x, float z) { - return predicate.test(cell, module.getValue(x, z)); - } - - public static VariablePredicate height(Seed seed, Levels levels, int min, int max, int size, int octaves) { - float bias = levels.scale(min); - float scale = levels.scale(max - min); - Module source = Source.perlin(seed.next(), size, 1).scale(scale).bias(bias); - return new VariablePredicate(source, (cell, height) -> cell.value < height); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/Disposable.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/Disposable.java deleted file mode 100644 index 3907b7d..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/Disposable.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.terraforged.core.util.concurrent; - -public interface Disposable { - - void dispose(); - - interface Listener { - - void onDispose(T t); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/ObjectPool.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/ObjectPool.java deleted file mode 100644 index 033c12c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/ObjectPool.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.concurrent; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; - -public class ObjectPool { - - private final int capacity; - private final List> pool; - private final Supplier supplier; - - public ObjectPool(int size, Supplier supplier) { - this.capacity = size; - this.pool = new ArrayList<>(size); - this.supplier = supplier; - } - - public Item get() { - synchronized (pool) { - if (pool.size() > 0) { - return pool.remove(pool.size() - 1).retain(); - } - } - return new Item<>(supplier.get(), this); - } - - public int size() { - synchronized (pool) { - return pool.size(); - } - } - - private boolean restore(Item item) { - synchronized (pool) { - int size = pool.size(); - if (size < capacity) { - pool.add(item); - return true; - } - } - return false; - } - - public static class Item implements AutoCloseable { - - private final T value; - private final ObjectPool pool; - - private boolean released = false; - - private Item(T value, ObjectPool pool) { - this.value = value; - this.pool = pool; - } - - public T getValue() { - return value; - } - - public void release() { - if (!released) { - released = true; - released = pool.restore(this); - } - } - - private Item retain() { - released = false; - return this; - } - - @Override - public void close() { - release(); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/ThreadPool.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/ThreadPool.java deleted file mode 100644 index 11690e9..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/ThreadPool.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.concurrent; - -import com.terraforged.core.util.concurrent.batcher.AsyncBatcher; -import com.terraforged.core.util.concurrent.batcher.Batcher; -import com.terraforged.core.util.concurrent.batcher.SyncBatcher; - -import java.util.concurrent.Callable; -import java.util.concurrent.Executor; -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.ForkJoinTask; - -public class ThreadPool implements Executor { - - private static final ThreadPool instance = create("TF", defaultPoolSize()); - - private final ForkJoinPool service; - - private ThreadPool(ForkJoinPool service) { - this.service = service; - } - - @Override - public void execute(Runnable command) { - service.submit(command); - } - - public ForkJoinTask submit(Runnable runnable) { - return service.submit(runnable); - } - - public ForkJoinTask submit(Callable callable) { - return service.submit(callable); - } - - public Batcher batcher(int size) { - return new AsyncBatcher(service, size); - } - - public static ThreadPool getPool() { - return instance; - } - - public static ThreadPool create(String name, int size) { - if (size < 2) { - return new SingleThreadExecutor(); - } - return new ThreadPool(createPool(name, size)); - } - - public static ForkJoinPool createPool(String name, int size) { - return new ForkJoinPool(size, new WorkerFactory.ForkJoin(name), null, true); - } - - private static int defaultPoolSize() { - int threads = Runtime.getRuntime().availableProcessors(); - return Math.max(1, (int) ((threads / 3F) * 2F)); - } - - private static class SingleThreadExecutor extends ThreadPool { - - private SingleThreadExecutor() { - super(null); - } - - @Override - public void execute(Runnable command) { - command.run(); - } - - @Override - public ForkJoinTask submit(Runnable runnable) { - ForkJoinTask task = ForkJoinTask.adapt(runnable); - task.invoke(); - return task; - } - - @Override - public ForkJoinTask submit(Callable callable) { - ForkJoinTask task = ForkJoinTask.adapt(callable); - task.invoke(); - return task; - } - - @Override - public Batcher batcher(int size) { - return new SyncBatcher(); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/WorkerFactory.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/WorkerFactory.java deleted file mode 100644 index f04ec6c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/WorkerFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.terraforged.core.util.concurrent; - -import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.ForkJoinWorkerThread; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -// As DefaultThreadPool but with custom thread names -public class WorkerFactory implements ThreadFactory { - - protected final String prefix; - protected final ThreadGroup group; - protected final AtomicInteger threadNumber = new AtomicInteger(1); - - public WorkerFactory(String name) { - group = Thread.currentThread().getThreadGroup(); - prefix = name + "-Worker-"; - } - - @Override - public Thread newThread(Runnable task) { - Thread thread = new Thread(group, task); - thread.setDaemon(true); - thread.setName(prefix + threadNumber.getAndIncrement()); - return thread; - } - - public static class ForkJoin extends WorkerFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory { - - public ForkJoin(String name) { - super(name); - } - - @Override - public ForkJoinWorkerThread newThread(ForkJoinPool pool) { - ForkJoinWorkerThread thread = new ForkJoinWorkerThread(pool) {}; - thread.setDaemon(true); - thread.setName(prefix + threadNumber.getAndIncrement()); - return thread; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/AsyncBatcher.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/AsyncBatcher.java deleted file mode 100644 index f97947c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/AsyncBatcher.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.concurrent.batcher; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; - -public class AsyncBatcher implements Batcher { - - private final List> tasks; - private final ExecutorService executor; - - public AsyncBatcher(ExecutorService executor, int size) { - this.executor = executor; - this.tasks = new ArrayList<>(size); - } - - @Override - public void submit(Runnable task) { - tasks.add(executor.submit(task)); - } - - @Override - public void submit(Callable task) { - tasks.add(executor.submit(task)); - } - - @Override - public void close() { - boolean hasMore = true; - while (hasMore) { - hasMore = false; - for (Future future : tasks) { - if (!future.isDone()) { - hasMore = true; - } - } - } - tasks.clear(); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/Batcher.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/Batcher.java deleted file mode 100644 index 2661b81..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/Batcher.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.concurrent.batcher; - -import java.util.concurrent.Callable; - -public interface Batcher extends AutoCloseable { - - void submit(Runnable task); - - void submit(Callable task); - - @Override - void close(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/SyncBatcher.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/SyncBatcher.java deleted file mode 100644 index b8feb51..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/batcher/SyncBatcher.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.concurrent.batcher; - -import java.util.concurrent.Callable; - -public class SyncBatcher implements Batcher { - - @Override - public void submit(Runnable task) { - task.run(); - } - - @Override - public void submit(Callable task) { - try { - task.call(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void close() { - - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/Cache.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/Cache.java deleted file mode 100644 index 1b2d32c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/Cache.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.terraforged.core.util.concurrent.cache; - -import com.terraforged.core.util.concurrent.ThreadPool; - -import java.util.concurrent.TimeUnit; -import java.util.function.LongFunction; - -public class Cache implements Runnable { - - private final long expireMS; - private final long intervalMS; - private final SynchronizedLongMap map; - private final ThreadPool threadPool = ThreadPool.getPool(); - - private volatile long timestamp = 0L; - - public Cache(long expireTime, long interval, TimeUnit unit) { - this.expireMS = unit.toMillis(expireTime); - this.intervalMS = unit.toMillis(interval); - this.map = new SynchronizedLongMap<>(100); - } - - public void remove(long key) { - map.remove(key); - } - - public V computeIfAbsent(long key, LongFunction func) { - V v = map.computeIfAbsent(key, func); - queueUpdate(); - return v; - } - - private void queueUpdate() { - long now = System.currentTimeMillis(); - if (now - timestamp > intervalMS) { - timestamp = now; - threadPool.submit(this); - } - } - - @Override - public void run() { - final long now = timestamp; - map.removeIf(val -> now - val.getTimestamp() > expireMS); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/CacheEntry.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/CacheEntry.java deleted file mode 100644 index 4177126..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/CacheEntry.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.terraforged.core.util.concurrent.cache; - -import com.terraforged.core.util.concurrent.ThreadPool; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ForkJoinTask; -import java.util.concurrent.Future; - -public class CacheEntry implements ExpiringEntry { - - private volatile long timestamp; - private final Future task; - - public CacheEntry(Future task) { - this.task = task; - this.timestamp = System.currentTimeMillis(); - } - - @Override - public long getTimestamp() { - return timestamp; - } - - public boolean isDone() { - return task.isDone(); - } - - public T get() { - if (task instanceof ForkJoinTask) { - return ((ForkJoinTask) task).join(); - } - - try { - return task.get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - } - - public static CacheEntry supply(Future future) { - return new CacheEntry<>(future); - } - - public static CacheEntry supplyAsync(Callable callable, ThreadPool executor) { - return new CacheEntry<>(executor.submit(callable)); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/ExpiringEntry.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/ExpiringEntry.java deleted file mode 100644 index e780212..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/ExpiringEntry.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.terraforged.core.util.concurrent.cache; - -public interface ExpiringEntry { - - long getTimestamp(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/SynchronizedLongMap.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/SynchronizedLongMap.java deleted file mode 100644 index 5f92ad9..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/SynchronizedLongMap.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.terraforged.core.util.concurrent.cache; - -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectIterator; - -import java.util.function.LongFunction; -import java.util.function.Predicate; - -public class SynchronizedLongMap { - - private final Object lock; - private final Long2ObjectOpenHashMap map; - - public SynchronizedLongMap(int size) { - this.map = new Long2ObjectOpenHashMap<>(size); - this.lock = this; - } - - public void remove(long key) { - synchronized (lock) { - map.remove(key); - } - } - - public void put(long key, V v) { - synchronized (lock) { - map.put(key, v); - } - } - - public V get(long key) { - synchronized (lock) { - return map.get(key); - } - } - - public V computeIfAbsent(long key, LongFunction func) { - synchronized (lock) { - return map.computeIfAbsent(key, func); - } - } - - public void removeIf(Predicate predicate) { - synchronized (lock) { - ObjectIterator> iterator = map.long2ObjectEntrySet().fastIterator(); - while (iterator.hasNext()) { - if (predicate.test(iterator.next().getValue())) { - iterator.remove(); - } - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/FixedGrid.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/FixedGrid.java deleted file mode 100644 index aa298a8..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/FixedGrid.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.grid; - -import me.dags.noise.util.NoiseUtil; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.function.Supplier; - -public class FixedGrid implements Iterable>> { - - private final MappedList>> grid; - - private FixedGrid(MappedList>> grid) { - this.grid = grid; - } - - public int size() { - return grid.size(); - } - - public FixedList get(float x, float y) { - return grid.get(y).get(x); - } - - public T get(float x, float y, float z) { - MappedList> row = grid.get(y); - FixedList cell = row.get(x); - return cell.get(z); - } - - @Override - public Iterator>> iterator() { - return grid.iterator(); - } - - public static FixedGrid create(List>> grid, float minX, float minY, float rangeX, float rangeY) { - List>> list = new ArrayList<>(); - for (List> src : grid) { - List> row = new ArrayList<>(src.size()); - for (List cell : src) { - row.add(FixedList.of(cell)); - } - list.add(MappedList.of(row, minX, rangeX)); - } - return new FixedGrid<>(MappedList.of(list, minY, rangeY)); - } - - public static FixedGrid generate(int size, List values, Function xFunc, Function yFunc) { - List>> src = createList(size, () -> createList(size, ArrayList::new)); - List>> dest = createList(size, () -> createList(size, ArrayList::new)); - - float minX = 1F; - float maxX = 0F; - float minY = 1F; - float maxY = 0F; - for (T value : values) { - float x = xFunc.apply(value); - float y = yFunc.apply(value); - minX = Math.min(minX, x); - maxX = Math.max(maxX, x); - minY = Math.min(minY, y); - maxY = Math.max(maxY, y); - } - - int maxIndex = size - 1; - float rangeX = maxX - minX; - float rangeY = maxY - minY; - for (T value : values) { - float colVal = (xFunc.apply(value) - minX) / rangeX; - float rowVal = (yFunc.apply(value) - minY) / rangeY; - int colIndex = NoiseUtil.round(maxIndex * colVal); - int rowIndex = NoiseUtil.round(maxIndex * rowVal); - List> row = src.get(rowIndex); - List group = row.get(colIndex); - group.add(value); - } - - for (int y = 0; y < size; y++) { - List> srcRow = src.get(y); - List> destRow = dest.get(y); - for (int x = 0; x < size; x++) { - List srcGroup = srcRow.get(x); - List destGroup = destRow.get(x); - if (srcGroup.isEmpty()) { - float fx = minX + (x / (float) maxIndex) * rangeX; - float fy = minY + (x / (float) maxIndex) * rangeY; - addClosest(values, destGroup, fx, fy, xFunc, yFunc); - } else { - destGroup.addAll(srcGroup); - } - } - } - - return create(dest, minX, minY, rangeX, rangeY); - } - - private static void addClosest(List source, List dest, float fx, float fy, Function xFunc, Function yFunc) { - float dist2 = Float.MAX_VALUE; - Map distances = new HashMap<>(); - for (T t : source) { - if (!distances.containsKey(t)) { - float dx = fx - xFunc.apply(t); - float dy = fy - yFunc.apply(t); - float d2 = dx * dx + dy * dy; - distances.put(t, d2); - if (d2 < dist2) { - dist2 = d2; - } - } - } - - if (dist2 <= 0) { - dist2 = 1F; - } - - List sorted = new ArrayList<>(distances.keySet()); - sorted.sort((o1, o2) -> Float.compare(distances.getOrDefault(o1, Float.MAX_VALUE), distances.getOrDefault(o2, Float.MAX_VALUE))); - - for (T t : sorted) { - float d2 = distances.get(t); - if (d2 / dist2 < 1.025F) { - dest.add(t); - } - } - } - - private static List createList(int size, Supplier supplier) { - List list = new ArrayList<>(); - while (list.size() < size) { - list.add(supplier.get()); - } - return list; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/FixedList.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/FixedList.java deleted file mode 100644 index 5224db5..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/FixedList.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.grid; - -import me.dags.noise.util.NoiseUtil; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -public class FixedList implements Iterable { - - private final int maxIndex; - private final T[] elements; - - FixedList(T[] elements) { - this.maxIndex = elements.length - 1; - this.elements = elements; - } - - public T get(int index) { - if (index < 0) { - return elements[0]; - } - if (index > maxIndex) { - return elements[maxIndex]; - } - return elements[index]; - } - - public T get(float value) { - return get(indexOf(value)); - } - - public int size() { - return elements.length; - } - - public int indexOf(float value) { - return NoiseUtil.round(value * maxIndex); - } - - public Set uniqueValues() { - Set set = new HashSet<>(); - Collections.addAll(set, elements); - return set; - } - - @Override - public Iterator iterator() { - return new Iterator() { - - private int index = 0; - - @Override - public boolean hasNext() { - return index < elements.length; - } - - @Override - public T next() { - return elements[index++]; - } - }; - } - - @SuppressWarnings("unchecked") - public static FixedList of(List list) { - return new FixedList<>((T[]) list.toArray()); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java deleted file mode 100644 index cb277e6..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.terraforged.core.util.points; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.Region; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.util.Vec2i; - -import javax.swing.*; -import java.awt.*; -import java.awt.image.BufferedImage; - -public class Poisson { - - public static void main(String[] args) { - Region region = new Region(0, 0, 5, 2); - BufferedImage image = new BufferedImage(region.getBlockSize().size, region.getBlockSize().size, BufferedImage.TYPE_INT_RGB); - points(region, 123,8, 20F, 0.8F); - render(region, image); - - JFrame frame = new JFrame(); - frame.add(new JLabel(new ImageIcon(image))); - frame.pack(); - frame.setVisible(true); - frame.setResizable(false); - frame.setLocationRelativeTo(null); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } - - private static void points(Region region, int seed, int scale, float radius, float threshold) { - region.generate(chunk -> chunk.generate((cell, dx, dz) -> {})); - - Module noise = Source.simplex(seed, scale, 1); - - int gridSize = (int) Math.ceil(region.getBlockSize().size / radius); - Vec2i[][] grid = new Vec2i[gridSize][gridSize]; - - for (int dz = 0; dz < region.getBlockSize().size; dz++) { - for (int dx = 0; dx < region.getBlockSize().size; dx++) { - int x = region.getBlockX() + dx; - int z = region.getBlockZ() + dz; - float value = noise.getValue(x, z); - region.getCell(dx, dz).value = value; - if (true) continue; - - if (value > threshold) { - continue; - } - - int gridX = (int) (dx / radius); - int gridZ = (int) (dz / radius); - Vec2i point = grid[gridZ][gridX]; - - if (point != null) { - Cell current = region.getCell(point.x, point.y); - if (current.value > value) { - continue; - } - } - - region.getCell(dx, dz).value = value; - grid[gridZ][gridX] = new Vec2i(dx, dz); - } - } - } - - private static void render(Region region, BufferedImage image) { - region.iterate((cell, dx, dz) -> { - if (cell.value == 0) { - return; - } - int w = (int) (cell.value * 255); - image.setRGB(dx, dz, new Color(w, w, w).getRGB()); - }); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Comment.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Comment.java deleted file mode 100644 index e339c0c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Comment.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Comment { - - String[] value(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Name.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Name.java deleted file mode 100644 index ef32732..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Name.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Name { - - String value(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Option.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Option.java deleted file mode 100644 index a1fc6d7..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Option.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Option { - -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Range.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Range.java deleted file mode 100644 index 44a0086..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Range.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Range { - - float min(); - - float max(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Serializable.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Serializable.java deleted file mode 100644 index 3fd81ba..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/annotation/Serializable.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface Serializable { -} 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 deleted file mode 100644 index 49f899c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Deserializer.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.serializer; - -import com.terraforged.core.util.serialization.annotation.Serializable; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; - -public class Deserializer { - - public void deserialize(Reader reader, Object object) throws Throwable { - Class type = object.getClass(); - for (String name : reader.getKeys()) { - if (name.charAt(0) == '#') { - 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(); - } - } - } - - private void fromValue(Reader reader, Object object, Field field) throws Throwable { - if (field.getType() == int.class) { - field.set(object, reader.getInt("value")); - return; - } - if (field.getType() == float.class) { - field.set(object, reader.getFloat("value")); - return; - } - if (field.getType() == boolean.class) { - field.set(object, reader.getString("value").equals("true")); - return; - } - if (field.getType() == String.class) { - field.set(object, reader.getString("value")); - return; - } - if (field.getType().isEnum()) { - String name = reader.getString("value"); - for (Enum e : field.getType().asSubclass(Enum.class).getEnumConstants()) { - if (e.name().equals(name)) { - field.set(object, e); - return; - } - } - } - if (field.getType().isAnnotationPresent(Serializable.class)) { - Reader child = reader.getChild("value"); - Object value = field.getType().newInstance(); - deserialize(child, value); - field.set(object, value); - return; - } - if (field.getType().isArray()) { - Class type = field.getType().getComponentType(); - if (type.isAnnotationPresent(Serializable.class)) { - Reader child = reader.getChild("value"); - Object array = Array.newInstance(type, child.getSize()); - for (int i = 0; i < child.getSize(); i++) { - Object value = type.newInstance(); - deserialize(child.getChild(i), value); - Array.set(array, i, value); - } - field.set(object, array); - } - } - } - - private static String getName(String name) { - StringBuilder sb = new StringBuilder(name.length()); - for (int i = 0; i < name.length(); i++) { - char c = name.charAt(i); - if (i == 0) { - c = Character.toLowerCase(c); - } else if (c == ' ' && i + 1 < name.length()) { - c = Character.toUpperCase(name.charAt(++i)); - } - sb.append(c); - } - return sb.toString(); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Reader.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Reader.java deleted file mode 100644 index f7ff240..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Reader.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.serializer; - -import java.util.Collection; - -public interface Reader { - - int getSize(); - - Reader getChild(String key); - - Reader getChild(int index); - - Collection getKeys(); - - String getString(); - - boolean getBool(); - - float getFloat(); - - int getInt(); - - default String getString(String key) { - return getChild(key).getString(); - } - - default boolean getBool(String key) { - return getChild(key).getBool(); - } - - default float getFloat(String key) { - return getChild(key).getFloat(); - } - - default int getInt(String key) { - return getChild(key).getInt(); - } - - default String getString(int index) { - return getChild(index).getString(); - } - - default boolean getBool(int index) { - return getChild(index).getBool(); - } - - default float getFloat(int index) { - return getChild(index).getFloat(); - } - - default int getInt(int index) { - return getChild(index).getInt(); - } - - default void writeTo(Object object) throws Throwable { - new Deserializer().deserialize(this, object); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Serializer.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Serializer.java deleted file mode 100644 index 9891b89..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Serializer.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.serializer; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Name; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public class Serializer { - - public void serialize(Object object, Writer writer) throws IllegalAccessException { - if (object.getClass().isArray()) { - writer.beginArray(); - int length = Array.getLength(object); - for (int i = 0; i < length; i++) { - Object element = Array.get(object, i); - serialize(element, writer); - } - writer.endArray(); - } else if (!object.getClass().isPrimitive()) { - int order = 0; - writer.beginObject(); - for (Field field : object.getClass().getFields()) { - if (Serializer.isSerializable(field)) { - field.setAccessible(true); - write(object, field, order, writer); - order++; - } - } - writer.endObject(); - } - } - - private void write(Object object, Field field, int order, Writer writer) throws IllegalAccessException { - if (field.getType() == int.class) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value").value((int) field.get(object)); - writeMeta(field, order, writer); - writer.endObject(); - return; - } - if (field.getType() == float.class) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value").value((float) field.get(object)); - writeMeta(field, order, writer); - writer.endObject(); - return; - } - if (field.getType() == String.class) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value").value((String) field.get(object)); - writeMeta(field, order, writer); - writer.endObject(); - return; - } - if (field.getType() == boolean.class) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value").value("" + (field.get(object))); - writeMeta(field, order, writer); - writer.endObject(); - } - if (field.getType().isEnum()) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value").value(((Enum) field.get(object)).name()); - writeMeta(field, order, writer); - writer.endObject(); - return; - } - if (field.getType().isArray()) { - if (field.getType().getComponentType().isAnnotationPresent(Serializable.class)) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value"); - serialize(field.get(object), writer); - writeMeta(field, order, writer); - writer.endObject(); - } - return; - } - if (field.getType().isAnnotationPresent(Serializable.class)) { - writer.name(field.getName()); - writer.beginObject(); - writer.name("value"); - serialize(field.get(object), writer); - writeMeta(field, order, writer); - writer.endObject(); - } - } - - private void writeMeta(Field field, int order, Writer writer) { - writer.name("#display").value(getName(field)); - writer.name("#order").value(order); - - Range range = field.getAnnotation(Range.class); - if (range != null) { - if (field.getType() == int.class) { - writer.name("#min").value((int) range.min()); - writer.name("#max").value((int) range.max()); - } else { - writer.name("#min").value(range.min()); - writer.name("#max").value(range.max()); - } - } - - Comment comment = field.getAnnotation(Comment.class); - if (comment != null) { - writer.name("#comment"); - writer.beginArray(); - for (String line : comment.value()) { - writer.value(line); - } - writer.endArray(); - } - - if (field.getType() == boolean.class) { - writer.name("#options"); - writer.beginArray(); - writer.value("true"); - writer.value("false"); - writer.endArray(); - } - - if (field.getType().isEnum()) { - writer.name("#options"); - writer.beginArray(); - for (Enum o : field.getType().asSubclass(Enum.class).getEnumConstants()) { - writer.value(o.name()); - } - writer.endArray(); - } - } - - private static String getName(Field field) { - Name nameMeta = field.getAnnotation(Name.class); - - String name = nameMeta == null ? field.getName() : nameMeta.value(); - StringBuilder sb = new StringBuilder(name.length() * 2); - for (int i = 0; i < name.length(); i++) { - char c = name.charAt(i); - if (i == 0) { - c = Character.toUpperCase(c); - } else if (Character.isUpperCase(c)) { - sb.append(' '); - } - - sb.append(c); - } - return sb.toString(); - } - - protected static boolean isSerializable(Field field) { - int modifiers = field.getModifiers(); - return Modifier.isPublic(modifiers) - && !Modifier.isFinal(modifiers) - && !Modifier.isStatic(modifiers) - && !Modifier.isTransient(modifiers); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Writer.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Writer.java deleted file mode 100644 index c9a566f..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/serialization/serializer/Writer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.util.serialization.serializer; - -public interface Writer { - - Writer name(String name); - - Writer beginObject(); - - Writer endObject(); - - Writer beginArray(); - - Writer endArray(); - - Writer value(String value); - - Writer value(float value); - - Writer value(int value); - - default void readFrom(Object value) throws IllegalAccessException { - new Serializer().serialize(value, this); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/GeneratorContext.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/GeneratorContext.java deleted file mode 100644 index 832dacb..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/GeneratorContext.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world; - -import com.terraforged.core.settings.Settings; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrains; -import com.terraforged.core.world.terrain.provider.StandardTerrainProvider; -import com.terraforged.core.world.terrain.provider.TerrainProviderFactory; - -public class GeneratorContext { - - public final Seed seed; - public final Levels levels; - public final Terrains terrain; - public final Settings settings; - public final TerrainProviderFactory terrainFactory; - - public GeneratorContext(Terrains terrain, Settings settings) { - this(terrain, settings, StandardTerrainProvider::new); - } - - public GeneratorContext(Terrains terrain, Settings settings, TerrainProviderFactory terrainFactory) { - this.terrain = terrain; - this.settings = settings; - this.seed = new Seed(settings.generator.seed); - this.levels = new Levels(settings.generator); - this.terrainFactory = terrainFactory; - } - - private GeneratorContext(GeneratorContext src) { - seed = new Seed(src.seed.get()); - levels = src.levels; - terrain = src.terrain; - settings = src.settings; - terrainFactory = src.terrainFactory; - } - - public GeneratorContext copy() { - return new GeneratorContext(this); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldDecorators.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldDecorators.java deleted file mode 100644 index 382300c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldDecorators.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world; - -import com.terraforged.core.world.decorator.Decorator; -import com.terraforged.core.world.decorator.DesertStacks; -import com.terraforged.core.world.decorator.Wetlands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class WorldDecorators { - - private final List decorators; - - public WorldDecorators(GeneratorContext context) { - context = context.copy(); - List list = new ArrayList<>(); - list.add(new DesertStacks(context.seed, context.levels)); - list.add(new Wetlands(context.seed, context.terrain, context.levels)); - decorators = Collections.unmodifiableList(list); - } - - public List getDecorators() { - return decorators; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java deleted file mode 100644 index b5f4d32..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldFilters.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world; - -import com.terraforged.core.filter.Erosion; -import com.terraforged.core.filter.Filterable; -import com.terraforged.core.filter.Smoothing; -import com.terraforged.core.filter.Steepness; -import com.terraforged.core.region.Region; -import com.terraforged.core.settings.FilterSettings; -import com.terraforged.core.world.terrain.Terrain; - -public class WorldFilters { - - private final Erosion erosion; - private final Smoothing smoothing; - private final Steepness steepness; - private final FilterSettings settings; - - public WorldFilters(GeneratorContext context) { - context = context.copy(); - this.settings = context.settings.filters; - this.erosion = new Erosion(context.settings, context.levels); - this.smoothing = new Smoothing(context.settings, context.levels); - this.steepness = new Steepness(1, 10F, context.terrain, context.levels); - } - - public void apply(Region region) { - Filterable map = region.filterable(); - erosion.apply(map, region.getRegionX(), region.getRegionZ(), settings.erosion.iterations); - smoothing.apply(map, region.getRegionX(), region.getRegionZ(), settings.smoothing.iterations); - steepness.apply(map, region.getRegionX(), region.getRegionZ(), 1); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldGenerator.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldGenerator.java deleted file mode 100644 index f750fb2..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldGenerator.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world; - -import com.terraforged.core.world.heightmap.Heightmap; - -public class WorldGenerator { - - private final Heightmap heightmap; - private final WorldFilters filters; - private final WorldDecorators decorators; - - public WorldGenerator(Heightmap heightmap, WorldDecorators decorators, WorldFilters filters) { - this.filters = filters; - this.heightmap = heightmap; - this.decorators = decorators; - } - - public Heightmap getHeightmap() { - return heightmap; - } - - public WorldFilters getFilters() { - return filters; - } - - public WorldDecorators getDecorators() { - return decorators; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldGeneratorFactory.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldGeneratorFactory.java deleted file mode 100644 index a0500ca..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/WorldGeneratorFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world; - -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.heightmap.Heightmap; -import com.terraforged.core.world.heightmap.WorldHeightmap; - -import java.util.function.Supplier; - -public class WorldGeneratorFactory implements Supplier { - - private final GeneratorContext context; - - private final Heightmap heightmap; - private final WorldDecorators decorators; - - public WorldGeneratorFactory(GeneratorContext context) { - this.context = context; - this.heightmap = new WorldHeightmap(context); - this.decorators = new WorldDecorators(context); - } - - public WorldGeneratorFactory(GeneratorContext context, Heightmap heightmap) { - this.context = context; - this.heightmap = heightmap; - this.decorators = new WorldDecorators(context); - } - - public Heightmap getHeightmap() { - return heightmap; - } - - public Climate getClimate() { - return getHeightmap().getClimate(); - } - - public WorldDecorators getDecorators() { - return decorators; - } - - public WorldFilters getFilters() { - return new WorldFilters(context); - } - - @Override - public WorldGenerator get() { - return new WorldGenerator(heightmap, decorators, getFilters()); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeData.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeData.java deleted file mode 100644 index 05d9682..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeData.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.biome; - -import java.awt.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class BiomeData implements Comparable { - - private static float[] bounds = {0, 1 / 3F, 2 / 3F, 1F}; - - public static final List BIOMES = new ArrayList<>(); - public static BiomeData DEFAULT = new BiomeData("none", "", 1, 0.5F, 0.5F); - - public final String name; - - public final Object reference; - public final float color; - public final float rainfall; - public final float temperature; - - public BiomeData(String name, Object reference, float color, float rainfall, float temperature) { - this.reference = reference; - this.name = name; - this.rainfall = rainfall; - this.temperature = temperature; - this.color = color; - } - - public BiomeData(String name, Object reference, int color, float rainfall, float temperature) { - Color c = new Color(color); - this.reference = reference; - this.name = name; - this.rainfall = rainfall; - this.temperature = temperature; - this.color = getHue(c.getRed(), c.getGreen(), c.getBlue()); - } - - @Override - public int compareTo(BiomeData o) { - return name.compareTo(o.name); - } - - public static Collection getBiomes(float temperature, float rainfall) { - int temp = Math.min(3, (int) (bounds.length * temperature)); - int rain = Math.min(3, (int) (bounds.length * rainfall)); - return getBiomes(temp, rain); - } - - public static Collection getBiomes(int tempLower, int rainLower) { - int temp0 = tempLower; - int temp1 = temp0 + 1; - int rain0 = rainLower; - int rain1 = rain0 + 1; - - float tempMin = bounds[temp0]; - float tempMax = bounds[temp1]; - float rainMin = bounds[rain0]; - float rainMax = bounds[rain1]; - - List biomes = new ArrayList<>(); - for (BiomeData biome : BIOMES) { - if (biome.temperature >= tempMin && biome.temperature <= tempMax - && biome.rainfall >= rainMin && biome.rainfall <= rainMax) { - biomes.add(biome); - } - } - - if (biomes.isEmpty()) { - biomes.add(DEFAULT); - } - - return biomes; - } - - public static Collection getTempBiomes(float temperature) { - int lower = Math.min(3, (int) (bounds.length * temperature)); - int upper = lower + 1; - - float min = bounds[lower]; - float max = bounds[upper]; - - List biomes = new ArrayList<>(); - for (BiomeData data : BIOMES) { - if (data.temperature >= min && data.temperature <= max) { - biomes.add(data); - } - } - - return biomes; - } - - public static Collection getRainBiomes(float rainfall) { - int lower = Math.min(3, (int) (bounds.length * rainfall)); - int upper = lower + 1; - - float min = bounds[lower]; - float max = bounds[upper]; - - List biomes = new ArrayList<>(); - for (BiomeData data : BIOMES) { - if (data.rainfall >= min && data.rainfall <= max) { - biomes.add(data); - } - } - - return biomes; - } - - private static float getHue(int red, int green, int blue) { - float min = Math.min(Math.min(red, green), blue); - float max = Math.max(Math.max(red, green), blue); - - if (min == max) { - return 0; - } - - float hue; - if (max == red) { - hue = (green - blue) / (max - min); - - } else if (max == green) { - hue = 2f + (blue - red) / (max - min); - - } else { - hue = 4f + (red - green) / (max - min); - } - - hue = hue * 60; - if (hue < 0) hue = hue + 360; - - return (Math.round(hue) / 360F) * 100F; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeManager.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeManager.java deleted file mode 100644 index 75e6310..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeManager.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.biome; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class BiomeManager { - - private final Map> biomes = new HashMap<>(); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeType.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeType.java deleted file mode 100644 index 9e04d36..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeType.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.biome; - -import com.terraforged.core.cell.Cell; -import me.dags.noise.util.NoiseUtil; - -import java.awt.*; - -public enum BiomeType { - - TROPICAL_RAINFOREST(7, 83, 48, new Color(7, 83, 48)), - SAVANNA(151, 165, 39, new Color(151, 165, 39)), - DESERT(200, 113, 55, new Color(200, 113, 55)), - TEMPERATE_RAINFOREST(10, 84, 109, new Color(10, 160, 65)), - TEMPERATE_FOREST(44, 137, 160, new Color(50, 200, 80)), - GRASSLAND(179, 124, 6, new Color(100, 220, 60)), - COLD_STEPPE(131, 112, 71, new Color(175, 180, 150)), - STEPPE(199, 155, 60, new Color(200, 200, 120)), - TAIGA(91, 143, 82, new Color(91, 143, 82)), - TUNDRA(147, 167, 172, new Color(147, 167, 172)), - ALPINE(0, 0, 0, new Color(160, 120, 170)); - - public static final int RESOLUTION = 256; - public static final int MAX = RESOLUTION - 1; - - private final Color lookup; - private final Color color; - - BiomeType(int r, int g, int b, Color color) { - this(new Color(r, g, b), color); - } - - BiomeType(Color lookup, Color color) { - this.lookup = lookup; - this.color = BiomeTypeColors.getInstance().getColor(name(), color); - } - - Color getLookup() { - return lookup; - } - - public Color getColor() { - return color; - } - - public boolean isExtreme() { - return this == TUNDRA || this == DESERT; - } - - public static BiomeType get(float temperature, float moisture) { - return getCurve(temperature, moisture); - } - - public static BiomeType getLinear(float temperature, float moisture) { - int x = NoiseUtil.round(MAX * temperature); - int y = getYLinear(x, temperature, moisture); - return getType(x, y); - } - - public static BiomeType getCurve(float temperature, float moisture) { - int x = NoiseUtil.round(MAX * temperature); - int y = getYCurve(x, temperature, moisture); - return getType(x, y); - } - - public static float getEdge(float temperature, float moisture) { - return getEdgeCurve(temperature, moisture); - } - - public static float getEdgeLinear(float temperature, float moisture) { - int x = NoiseUtil.round(MAX * temperature); - int y = getYLinear(x, temperature, moisture); - return getEdge(x, y); - } - - public static float getEdgeCurve(float temperature, float moisture) { - int x = NoiseUtil.round(MAX * temperature); - int y = getYCurve(x, temperature, moisture); - return getEdge(x, y); - } - - public static void apply(Cell cell) { - applyCurve(cell); - } - - public static void applyLinear(Cell cell) { - cell.biomeType = get(cell.biomeTemperature, cell.biomeMoisture); - cell.biomeTypeMask = getEdge(cell.temperature, cell.moisture); - } - - public static void applyCurve(Cell cell) { - cell.biomeType = get(cell.biomeTemperature, cell.biomeMoisture); - cell.biomeTypeMask = getEdge(cell.temperature, cell.moisture); - } - - private static BiomeType getType(int x, int y) { - return BiomeTypeLoader.getInstance().getTypeMap()[y][x]; - } - - private static float getEdge(int x, int y) { - return BiomeTypeLoader.getInstance().getEdgeMap()[y][x]; - } - - private static int getYLinear(int x, float temperature, float moisture) { - if (moisture > temperature) { - return x; - } - return NoiseUtil.round(MAX * moisture); - } - - private static int getYCurve(int x, float temperature, float moisture) { - int max = x + ((MAX - x) / 2); - int y = NoiseUtil.round(max * moisture); - return Math.min(x, y); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeTypeColors.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeTypeColors.java deleted file mode 100644 index 60b72d3..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeTypeColors.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.biome; - -import java.awt.*; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -public class BiomeTypeColors { - - private static BiomeTypeColors instance = new BiomeTypeColors(); - - private final Map colors = new HashMap<>(); - - private BiomeTypeColors() { - try (InputStream inputStream = BiomeType.class.getResourceAsStream("/biomes.txt")) { - Properties properties = new Properties(); - properties.load(inputStream); - for (Map.Entry entry : properties.entrySet()) { - Color color = Color.decode("#" + entry.getValue().toString()); - colors.put(entry.getKey().toString(), color); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - public Color getColor(String name, Color defaultColor) { - return colors.getOrDefault(name, defaultColor); - } - - public static BiomeTypeColors getInstance() { - return instance; - } - - public static void main(String[] args) throws Throwable { - try (FileWriter writer = new FileWriter("biome_colors.properties")) { - Properties properties = new Properties(); - for (BiomeType type : BiomeType.values()) { - int r = type.getColor().getRed(); - int g = type.getColor().getGreen(); - int b = type.getColor().getBlue(); - properties.setProperty(type.name(), String.format("%02x%02x%02x", r, g, b)); - } - properties.store(writer, "TerraForged BiomeType Hex Colors (do not include hash/pound character)"); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeTypeLoader.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeTypeLoader.java deleted file mode 100644 index 010855e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/biome/BiomeTypeLoader.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.biome; - -import me.dags.noise.util.NoiseUtil; - -import javax.imageio.ImageIO; -import javax.swing.*; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; - -public class BiomeTypeLoader { - - private static BiomeTypeLoader instance; - - private final float[][] edges = new float[BiomeType.RESOLUTION][BiomeType.RESOLUTION]; - private final BiomeType[][] map = new BiomeType[BiomeType.RESOLUTION][BiomeType.RESOLUTION]; - - public BiomeTypeLoader() { - generateTypeMap(); - generateEdgeMap(); - } - - public BiomeType[][] getTypeMap() { - return map; - } - - public float[][] getEdgeMap() { - return edges; - } - - private BiomeType getType(int x, int y) { - return map[y][x]; - } - - private void generateTypeMap() { - try { - BufferedImage image = ImageIO.read(BiomeType.class.getResourceAsStream("/biomes.png")); - float xf = image.getWidth() / (float) BiomeType.RESOLUTION; - float yf = image.getHeight() / (float) BiomeType.RESOLUTION; - for (int y = 0; y < BiomeType.RESOLUTION; y++) { - for (int x = 0; x < BiomeType.RESOLUTION; x++) { - if (BiomeType.MAX - y > x) { - map[BiomeType.MAX - y][x] = BiomeType.ALPINE; - continue; - } - int ix = NoiseUtil.round(x * xf); - int iy = NoiseUtil.round(y * yf); - int argb = image.getRGB(ix, iy); - Color color = fromARGB(argb); - map[BiomeType.MAX - y][x] = forColor(color); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void generateEdgeMap() { - int[] distances = new int[BiomeType.values().length]; - for (int y = 0; y < BiomeType.RESOLUTION; y++) { - for (int x = 0; x < BiomeType.RESOLUTION; x++) { - if (y > x) continue; - BiomeType type = getType(x, y); - if (type == BiomeType.ALPINE) { - continue; - } - int distance2 = getEdge(x, y, type); - edges[y][x] = distance2; - distances[type.ordinal()] = Math.max(distances[type.ordinal()], distance2); - } - } - - for (int y = 0; y < BiomeType.RESOLUTION; y++) { - for (int x = 0; x < BiomeType.RESOLUTION; x++) { - BiomeType type = getType(x, y); - int max = distances[type.ordinal()]; - float distance = edges[y][x]; - float value = NoiseUtil.pow(distance / max, 0.33F); - edges[y][x] = NoiseUtil.clamp(value, 0, 1); - } - } - } - - private int getEdge(int cx, int cy, BiomeType type) { - int radius = BiomeType.RESOLUTION / 4; - int distance2 = Integer.MAX_VALUE; - int x0 = Math.max(0, cx - radius); - int x1 = Math.min(BiomeType.MAX, cx + radius); - int y0 = Math.max(0, cy - radius); - int y1 = Math.min(BiomeType.MAX, cy + radius); - for (int y = y0; y <= y1; y++) { - for (int x = x0; x <= x1; x++) { - BiomeType neighbour = getType(x, y); - - if (neighbour == BiomeType.ALPINE) { - continue; - } - - if (neighbour != type) { - int dist2 = dist2(cx, cy, x, y); - if (dist2 < distance2) { - distance2 = dist2; - } - } - } - } - return distance2; - } - - private static BiomeType forColor(Color color) { - BiomeType type = null; - int closest = Integer.MAX_VALUE; - for (BiomeType t : BiomeType.values()) { - int distance2 = getDistance2(color, t.getLookup()); - if (distance2 < closest) { - closest = distance2; - type = t; - } - } - if (type == null) { - return BiomeType.GRASSLAND; - } - return type; - } - - private static int getDistance2(Color a, Color b) { - int dr = a.getRed() - b.getRed(); - int dg = a.getGreen() - b.getGreen(); - int db = a.getBlue() - b.getBlue(); - return dr * dr + dg * dg + db * db; - } - - private static Color fromARGB(int argb) { - int b = (argb) & 0xFF; - int g = (argb >> 8) & 0xFF; - int r = (argb >> 16) & 0xFF; - return new Color(r, g, b); - } - - private static int dist2(int x1, int y1, int x2, int y2) { - int dx = x1 - x2; - int dy = y1 - y2; - return dx * dx + dy * dy; - } - - private static BufferedImage generateEdgeMapImage() { - BufferedImage image = new BufferedImage(BiomeType.RESOLUTION, BiomeType.RESOLUTION, BufferedImage.TYPE_INT_RGB); - for (int y = 0; y < BiomeType.RESOLUTION; y++) { - for (int x = 0; x < BiomeType.RESOLUTION; x++) { - float temperature = x / (float) BiomeType.RESOLUTION; - float moisture = y / (float) BiomeType.RESOLUTION; - float value = BiomeType.getEdge(temperature, moisture); - int color = Color.HSBtoRGB(0, 0, value); - image.setRGB(x, image.getHeight() - 1 - y, color); - } - } - return image; - } - - public static BiomeTypeLoader getInstance() { - if (instance == null) { - instance = new BiomeTypeLoader(); - } - return instance; - } - - public static void main(String[] args) throws Throwable { - BufferedImage img = generateEdgeMapImage(); - ImageIO.write(img, "png", new File("biomes_dist.png")); - JLabel label = new JLabel(new ImageIcon(img)); - JFrame frame = new JFrame(); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.add(label); - frame.pack(); - frame.setLocationRelativeTo(null); - frame.setVisible(true); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java deleted file mode 100644 index 4a52538..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.climate; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.source.Rand; - -public class Climate { - - private final float seaLevel; - private final float lowerHeight; - private final float midHeight = 0.45F; - private final float upperHeight = 0.75F; - - private final float moistureModifier = 0.1F; - private final float temperatureModifier = 0.05F; - - private final Rand rand; - private final Module treeLine; - private final Module offsetX; - private final Module offsetY; - - private final ClimateModule biomeNoise; - - public Climate(GeneratorContext context) { - this.biomeNoise = new ClimateModule(context.seed, context.settings); - - this.treeLine = Source.perlin(context.seed.next(), context.settings.generator.biome.biomeSize * 2, 1) - .scale(context.levels.scale(25)) // 30 units worth of variance - .bias(context.levels.ground(40)) // start at-least 30 units above ground level - .clamp(0, 1); - - this.rand = new Rand(Source.builder().seed(context.seed.next())); - this.offsetX = context.settings.generator.biomeEdgeNoise.build(context.seed.next()); - this.offsetY = context.settings.generator.biomeEdgeNoise.build(context.seed.next()); - this.seaLevel = context.levels.water; - this.lowerHeight = context.levels.ground; - } - - public Rand getRand() { - return rand; - } - - public float getOffsetX(float x, float z, int distance) { - return offsetX.getValue(x, z) * distance; - } - - public float getOffsetZ(float x, float z, int distance) { - return offsetY.getValue(x, z) * distance; - } - - public float getTreeLine(float x, float z) { - return treeLine.getValue(x, z); - } - - public void apply(Cell cell, float x, float z, boolean mask) { - biomeNoise.apply(cell, x, z, mask); - - modifyTemp(cell, x, z); - } - - private void modifyTemp(Cell cell, float x, float z) { - float height = cell.value; - if (height > upperHeight) { - cell.temperature = Math.max(0, cell.temperature - temperatureModifier); - return; - } - - // temperature decreases away from 'midHeight' towards 'upperHeight' - if (height > midHeight) { - float delta = (height - midHeight) / (upperHeight - midHeight); - cell.temperature = Math.max(0, cell.temperature - (delta * temperatureModifier)); - return; - } - - height = Math.max(lowerHeight, height); - - // temperature increases away from 'midHeight' towards 'lowerHeight' - if (height >= lowerHeight) { - float delta = 1 - ((height - lowerHeight) / (midHeight - lowerHeight)); - cell.temperature = Math.min(1, cell.temperature + (delta * temperatureModifier)); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java deleted file mode 100644 index 4530609..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.climate; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.func.DistanceFunc; -import me.dags.noise.func.EdgeFunc; -import me.dags.noise.util.NoiseUtil; -import me.dags.noise.util.Vec2f; - -public class ClimateModule { - - private final int seed; - - private final float edgeClamp; - private final float edgeScale; - private final float biomeFreq; - private final float warpStrength; - - private final Module warpX; - private final Module warpZ; - private final Module moisture; - private final Module temperature; - - public ClimateModule(Seed seed, Settings settings) { - int biomeSize = settings.generator.biome.biomeSize; - - // todo - better solution (reduces the amount that temp/moist grows with biome size) - int tempScaler = biomeSize > 500 ? 8 : 10; - int moistScaler = biomeSize > 500 ? 20 : 40; - - float biomeFreq = 1F / biomeSize; - int moistureSize = moistScaler * biomeSize; - int temperatureSize = tempScaler * biomeSize; - int moistScale = NoiseUtil.round(moistureSize * biomeFreq); - int tempScale = NoiseUtil.round(temperatureSize * biomeFreq); - int warpScale = settings.generator.biome.biomeWarpScale; - - this.seed = seed.next(); - this.edgeClamp = 1F; - this.edgeScale = 1 / edgeClamp; - this.biomeFreq = 1F / biomeSize; - this.warpStrength = settings.generator.biome.biomeWarpStrength; - this.warpX = Source.perlin(seed.next(), warpScale, 2).bias(-0.5); - this.warpZ = Source.perlin(seed.next(), warpScale, 2).bias(-0.5); - - Module moisture = Source.simplex(seed.next(), moistScale, 2).clamp(0.15, 0.85).map(0, 1); - this.moisture = settings.climate.moisture.clamp(moisture) - .warp(seed.next(), moistScale / 2, 1, moistScale / 4D) - .warp(seed.next(), moistScale / 6, 2, moistScale / 12D); - - Module temperature = Source.sin(tempScale, Source.constant(0.9)) - .clamp(0.05, 0.95).map(0, 1); - - this.temperature = new Compressor(settings.climate.temperature.clamp(temperature), 0.1F, 0.2F) - .warp(seed.next(), tempScale * 4, 2, tempScale * 4) - .warp(seed.next(), tempScale, 1, tempScale) - .warp(seed.next(), tempScale / 8, 1, tempScale / 8D); - } - - public void apply(Cell cell, float x, float y, boolean mask) { - float ox = warpX.getValue(x, y) * warpStrength; - float oz = warpZ.getValue(x, y) * warpStrength; - - x += ox; - y += oz; - - x *= biomeFreq; - y *= biomeFreq; - - int cellX = 0; - int cellY = 0; - - Vec2f vec2f = null; - int xr = NoiseUtil.round(x); - int yr = NoiseUtil.round(y); - float edgeDistance = 999999.0F; - float edgeDistance2 = 999999.0F; - float valueDistance = 3.4028235E38F; - DistanceFunc dist = DistanceFunc.NATURAL; - - for (int dy = -1; dy <= 1; dy++) { - for (int dx = -1; dx <= 1; dx++) { - int xi = xr + dx; - int yi = yr + dy; - Vec2f vec = NoiseUtil.CELL_2D[NoiseUtil.hash2D(seed, xi, yi) & 255]; - - float vecX = xi - x + vec.x; - float vecY = yi - y + vec.y; - float distance = dist.apply(vecX, vecY); - - if (distance < valueDistance) { - valueDistance = distance; - vec2f = vec; - cellX = xi; - cellY = yi; - } - - if (distance < edgeDistance2) { - edgeDistance2 = Math.max(edgeDistance, distance); - } else { - edgeDistance2 = Math.max(edgeDistance, edgeDistance2); - } - - edgeDistance = Math.min(edgeDistance, distance); - } - } - - if (mask) { - cell.biomeEdge = edgeValue(edgeDistance, edgeDistance2); - } else { - cell.biome = cellValue(seed, cellX, cellY); - cell.biomeEdge = edgeValue(edgeDistance, edgeDistance2); - cell.biomeMoisture = moisture.getValue(cellX + vec2f.x, cellY + vec2f.y); - cell.biomeTemperature = temperature.getValue(cellX + vec2f.x, cellY + vec2f.y); - cell.moisture = moisture.getValue(x, y); - cell.temperature = temperature.getValue(x, y); - - BiomeType.apply(cell); - } - } - - private float cellValue(int seed, int cellX, int cellY) { - float value = NoiseUtil.valCoord2D(seed, cellX, cellY); - return NoiseUtil.map(value, -1, 1, 2); - } - - private float edgeValue(float distance, float distance2) { - EdgeFunc edge = EdgeFunc.DISTANCE_2_DIV; - float value = edge.apply(distance, distance2); - value = 1 - NoiseUtil.map(value, edge.min(), edge.max(), edge.range()); - if (value > edgeClamp) { - return 1F; - } - return value * edgeScale; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Compressor.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Compressor.java deleted file mode 100644 index 6c14475..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Compressor.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.climate; - -import me.dags.noise.Module; - -public class Compressor implements Module { - - private final float lowerStart; - private final float lowerEnd; - private final float lowerRange; - private final float lowerExpandRange; - - private final float upperStart; - private final float upperEnd; - private final float upperRange; - private final float upperExpandedRange; - - private final float compression; - private final float compressionRange; - - private final Module module; - - public Compressor(Module module, float inset, float amount) { - this(module, inset, inset + amount, 1 - inset - amount, 1 - inset); - } - - public Compressor(Module module, float lowerStart, float lowerEnd, float upperStart, float upperEnd) { - this.module = module; - this.lowerStart = lowerStart; - this.lowerEnd = lowerEnd; - this.lowerRange = lowerStart; - this.lowerExpandRange = lowerEnd; - this.upperStart = upperStart; - this.upperEnd = upperEnd; - this.upperRange = 1 - upperEnd; - this.upperExpandedRange = 1 - upperStart; - this.compression = upperStart - lowerEnd; - this.compressionRange = upperEnd - lowerStart; - } - - @Override - public float getValue(float x, float y) { - float value = module.getValue(x, y); - if (value <= lowerStart) { - float alpha = value / lowerRange; - return alpha * lowerExpandRange; - } else if (value >= upperEnd) { - float delta = value - upperEnd; - float alpha = delta / upperRange; - return upperStart + alpha * upperExpandedRange; - } else { - float delta = value - lowerStart; - float alpha = delta / compressionRange; - return lowerEnd + alpha * compression; - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentLerper2.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentLerper2.java deleted file mode 100644 index 0d7954e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentLerper2.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.continent; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.func.Interpolation; -import me.dags.noise.util.NoiseUtil; - -public class ContinentLerper2 implements Populator { - - private final Populator lower; - private final Populator upper; - - private final float blendLower; - private final float blendUpper; - private final float blendRange; - private final float midpoint; - private final float tagThreshold; - - public ContinentLerper2(Populator lower, Populator upper, float min, float max, float split, float tagThreshold) { - this.lower = lower; - this.upper = upper; - this.blendLower = min; - this.blendUpper = max; - this.blendRange = blendUpper - blendLower; - this.midpoint = blendLower + (blendRange * split); - this.tagThreshold = tagThreshold; - } - - @Override - public void apply(Cell cell, float x, float y) { - float select = cell.continentEdge; - - if (select < blendLower) { - lower.apply(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.apply(cell, x, y); - return; - } - - float alpha = Interpolation.LINEAR.apply((select - blendLower) / blendRange); - lower.apply(cell, x, y); - - float lowerVal = cell.value; - Terrain lowerType = cell.tag; - - upper.apply(cell, x, y); - float upperVal = cell.value; - - cell.value = NoiseUtil.lerp(lowerVal, upperVal, alpha); - if (select < midpoint) { - cell.tag = lowerType; - } - } - - @Override - public void tag(Cell cell, float x, float y) { - float select = cell.continentEdge; - if (select < blendLower) { - lower.tag(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.tag(cell, x, y); - return; - } - - if (select < tagThreshold) { - lower.tag(cell, x, y); - } else { - upper.tag(cell, x, y); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentLerper3.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentLerper3.java deleted file mode 100644 index 06252dd..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentLerper3.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.continent; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.func.Interpolation; -import me.dags.noise.util.NoiseUtil; - -public class ContinentLerper3 implements Populator { - - private final Climate climate; - private final Populator lower; - private final Populator middle; - private final Populator upper; - private final float midpoint; - - private final float blendLower; - private final float blendUpper; - - private final float lowerRange; - private final float upperRange; - - public ContinentLerper3(Climate climate, Populator lower, Populator middle, Populator upper, float min, float mid, float max) { - this.climate = climate; - this.lower = lower; - this.upper = upper; - this.middle = middle; - - this.midpoint = mid; - this.blendLower = min; - this.blendUpper = max; - - this.lowerRange = midpoint - blendLower; - this.upperRange = blendUpper - midpoint; - } - - @Override - public void apply(Cell cell, float x, float y) { - float select = cell.continentEdge; - if (select < blendLower) { - lower.apply(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.apply(cell, x, y); - return; - } - - if (select < midpoint) { - float alpha = Interpolation.CURVE3.apply((select - blendLower) / lowerRange); - - lower.apply(cell, x, y); - float lowerVal = cell.value; - Terrain lowerType = cell.tag; - - middle.apply(cell, x, y); - float upperVal = cell.value; - - cell.value = NoiseUtil.lerp(lowerVal, upperVal, alpha); - } else { - float alpha = Interpolation.CURVE3.apply((select - midpoint) / upperRange); - - middle.apply(cell, x, y); - float lowerVal = cell.value; - - upper.apply(cell, x, y); - cell.value = NoiseUtil.lerp(lowerVal, cell.value, alpha); - } - } - - @Override - public void tag(Cell cell, float x, float y) { - float select = cell.continentEdge; - if (select < blendLower) { - lower.tag(cell, x, y); - return; - } - - if (select > blendUpper) { - upper.tag(cell, x, y); - return; - } - - if (select < midpoint) { - lower.tag(cell, x, y); - if (cell.value > cell.tag.getMax(climate.getRand().getValue(x, y))) { - upper.tag(cell, x, y); - } - } else { - upper.tag(cell, x, y); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentModule.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentModule.java deleted file mode 100644 index 7773245..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/continent/ContinentModule.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.continent; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.settings.GeneratorSettings; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.domain.Domain; -import me.dags.noise.func.DistanceFunc; -import me.dags.noise.func.EdgeFunc; -import me.dags.noise.util.NoiseUtil; -import me.dags.noise.util.Vec2f; - -public class ContinentModule implements Populator { - - private static final float edgeClampMin = 0.05F; - private static final float edgeClampMax = 0.50F; - private static final float edgeClampRange = edgeClampMax - edgeClampMin; - - private final int seed; - private final float frequency; - - private final float edgeMin; - private final float edgeMax; - private final float edgeRange; - - private final Domain warp; - private final Module shape; - - public ContinentModule(Seed seed, GeneratorSettings settings) { - int tectonicScale = settings.land.continentScale * 4; - int continentScale = settings.land.continentScale / 2; - double oceans = Math.min(Math.max(settings.world.oceanSize, 0.01), 0.99); - double shapeMin = 0.15 + (oceans * 0.35); - this.seed = seed.next(); - - this.frequency = 1F / tectonicScale; - this.edgeMin = edgeClampMin; - this.edgeMax = (float) oceans; - this.edgeRange = edgeMax - edgeMin; - - this.warp = Domain.warp(Source.SIMPLEX, seed.next(), continentScale, 3, continentScale); - - this.shape = Source.perlin(seed.next(), settings.land.continentScale, 2) - .clamp(shapeMin, 0.7) - .map(0, 1) - .warp(Source.SIMPLEX, seed.next(), continentScale / 2, 1, continentScale / 4D) - .warp(seed.next(), 50, 1, 20D); - } - - @Override - public float getValue(float x, float y) { - if (true) { - throw new RuntimeException("no pls!"); - } else { - Cell cell = new Cell<>(); - apply(cell, x, y); - return cell.continentEdge; - } - } - - @Override - public void apply(Cell cell, final float x, final float y) { - float ox = warp.getOffsetX(x, y); - float oz = warp.getOffsetY(x, y); - - float px = x + ox; - float py = y + oz; - - px *= frequency; - py *= frequency; - - int cellX = 0; - int cellY = 0; - - int xr = NoiseUtil.round(px); - int yr = NoiseUtil.round(py); - float edgeDistance = 999999.0F; - float edgeDistance2 = 999999.0F; - float valueDistance = 3.4028235E38F; - DistanceFunc dist = DistanceFunc.NATURAL; - - for (int dy = -1; dy <= 1; dy++) { - for (int dx = -1; dx <= 1; dx++) { - int xi = xr + dx; - int yi = yr + dy; - Vec2f vec = NoiseUtil.CELL_2D[NoiseUtil.hash2D(seed, xi, yi) & 255]; - - float vecX = xi - px + vec.x; - float vecY = yi - py + vec.y; - float distance = dist.apply(vecX, vecY); - - if (distance < valueDistance) { - valueDistance = distance; - cellX = xi; - cellY = yi; - } - - if (distance < edgeDistance2) { - edgeDistance2 = Math.max(edgeDistance, distance); - } else { - edgeDistance2 = Math.max(edgeDistance, edgeDistance2); - } - - edgeDistance = Math.min(edgeDistance, distance); - } - } - - - float shapeNoise = shape.getValue(x, y); - float continentNoise = edgeValue(edgeDistance, edgeDistance2); - - cell.continent = cellValue(seed, cellX, cellY); - cell.continentEdge = shapeNoise * continentNoise; - } - - @Override - public void tag(Cell cell, float x, float y) { - - } - - private float cellValue(int seed, int cellX, int cellY) { - float value = NoiseUtil.valCoord2D(seed, cellX, cellY); - return NoiseUtil.map(value, -1, 1, 2); - } - - private float edgeValue(float distance, float distance2) { - EdgeFunc edge = EdgeFunc.DISTANCE_2_DIV; - float value = edge.apply(distance, distance2); - float edgeValue = 1 - NoiseUtil.map(value, edge.min(), edge.max(), edge.range()); - if (edgeValue < edgeMin) { - return 0F; - } - if (edgeValue > edgeMax) { - return 1F; - } - return (edgeValue - edgeMin) / edgeRange; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/Decorator.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/Decorator.java deleted file mode 100644 index df92f3b..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/Decorator.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.decorator; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; - -public interface Decorator { - - boolean apply(Cell cell, float x, float y); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/DesertDunes.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/DesertDunes.java deleted file mode 100644 index 21ad1c8..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/DesertDunes.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.decorator; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.func.CellFunc; - -public class DesertDunes implements Decorator { - - private final Module module; - private final float climateMin; - private final float climateMax; - private final float climateRange; - - private final Levels levels; - private final Terrains terrains; - private final Terrain dunes = new Terrain("dunes", 100); - - public DesertDunes(GeneratorContext context) { - this.climateMin = 0.6F; - this.climateMax = 0.85F; - this.climateRange = climateMax - climateMin; - this.levels = context.levels; - this.terrains = context.terrain; - this.module = Source.cell(context.seed.next(), 80, CellFunc.DISTANCE) - .warp(context.seed.next(), 70, 1, 70) - .scale(30 / 255D); - } - - @Override - public boolean apply(Cell cell, float x, float y) { - float temp = cell.temperature; - float moisture = 1 - cell.moisture; - float climate = temp * moisture; - if (climate < climateMin) { - return false; - } - - float duneHeight = module.getValue(x, y); - float climateMask = climate > climateMax ? 1F : (climate - climateMin) / climateRange; - float regionMask = cell.mask(0.4F, 0.5F, 0,0.8F); - - float height = duneHeight * climateMask * regionMask; - cell.value += height; - cell.tag = dunes; - - return height >= levels.unit; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/DesertStacks.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/DesertStacks.java deleted file mode 100644 index 8896675..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/DesertStacks.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.decorator; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; - -public class DesertStacks implements Decorator { - - private final float minY; - private final float maxY; - private final Levels levels; - private final Module module; - - public DesertStacks(Seed seed, Levels levels) { - Module mask = Source.perlin(seed.next(), 500, 1).clamp(0.7, 1).map(0, 1); - - Module shape = Source.perlin(seed.next(), 25, 1).clamp(0.6, 1).map(0, 1) - .mult(Source.perlin(seed.next(), 8, 1).alpha(0.1)); - - Module top = Source.perlin(seed.next(), 4, 1).alpha(0.25); - - Module scale = Source.perlin(seed.next(), 400, 1) - .clamp(levels.scale(20), levels.scale(35)); - - Module stack = (x, y) -> { - float value = shape.getValue(x, y); - if (value > 0.3) { - return top.getValue(x, y); - } - return value * 0.95F; - }; - - this.minY = levels.water(0); - this.maxY = levels.water(50); - this.levels = levels; - this.module = stack.scale(scale).mult(mask); - } - - @Override - public boolean apply(Cell cell, float x, float y) { - if (BiomeType.DESERT != cell.biomeType) { - return false; - } - - if (cell.value <= minY || cell.value > maxY) { - return false; - } - - float value = module.getValue(x, y); - value *= cell.biomeEdge; - cell.value += value; - - return value > levels.unit; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/Wetlands.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/Wetlands.java deleted file mode 100644 index 661d3cc..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/decorator/Wetlands.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.decorator; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; - -public class Wetlands implements Decorator { - - private final Module module; - private final float poolBase; - private final float bankHeight; - - private final Terrain wetlands; - - public Wetlands(Seed seed, Terrains terrain, Levels levels) { - this.wetlands = terrain.wetlands; - this.poolBase = levels.water(-3); - this.bankHeight = levels.water(2); - this.module = Source.perlin(seed.next(), 12, 1).clamp(0.35, 0.65).map(0, 1); - } - - @Override - public boolean apply(Cell cell, float x, float y) { - if (cell.value < poolBase) { - return false; - } - - float tempAlpha = getAlpha(cell.temperature, 0.3F, 0.7F); - if (tempAlpha == 0) { - return false; - } - - float moistAlpha = getAlpha(cell.moisture, 0.7F, 1F); - if (moistAlpha == 0) { - return false; - } - - float riverAlpha = getAlpha(1 - cell.riverMask, 0.85F, 0.95F); - if (riverAlpha == 0) { - return false; - } - - float alpha = tempAlpha * moistAlpha * riverAlpha; - float value1 = NoiseUtil.lerp(cell.value, bankHeight, alpha); - cell.value = Math.min(cell.value, value1); - - float poolAlpha = getAlpha(alpha, 0.35F, 0.55F); - float shape = module.getValue(x, y); - float value2 = NoiseUtil.lerp(cell.value, poolBase, shape * poolAlpha); - cell.value = Math.min(cell.value, value2); - - if (poolAlpha > 0.5) { - cell.tag = wetlands; - } - - return true; - } - - private static float getAlpha(float value, float min, float max) { - return getAlpha(value, min, max, false); - } - - private static float getAlpha(float value, float min, float max, boolean inverse) { - if (value < min) { - return 0F; - } - if (value >= max) { - return 1F; - } - float alpha = (value - min) / (max - min); - if (inverse) { - return 1F - alpha; - } - return alpha; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/DepthBuffer.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/DepthBuffer.java deleted file mode 100644 index 3188790..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/DepthBuffer.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.terraforged.core.world.geology; - -public class DepthBuffer { - - private float sum; - private float[] buffer; - - public void init(int size) { - sum = 0F; - if (buffer == null || buffer.length < size) { - buffer = new float[size]; - } - } - - public float getSum() { - return sum; - } - - public float get(int index) { - return buffer[index]; - } - - public float getDepth(int index) { - return buffer[index] / sum; - } - - public void set(int index, float value) { - sum += value; - buffer[index] = value; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Geology.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Geology.java deleted file mode 100644 index fd7345c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Geology.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.geology; - -import me.dags.noise.Module; - -import java.util.ArrayList; -import java.util.List; - -public class Geology { - - private final Module selector; - private final List> backing = new ArrayList<>(); - - public Geology(Module selector) { - this.selector = selector; - } - - public Geology add(Geology geology) { - backing.addAll(geology.backing); - return this; - } - - public Geology add(Strata strata) { - backing.add(strata); - return this; - } - - public Strata getStrata(float x, int y) { - float noise = selector.getValue(x, y); - return getStrata(noise); - } - - public Strata getStrata(float value) { - int index = (int) (value * backing.size()); - index = Math.min(backing.size() - 1, index); - return backing.get(index); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java deleted file mode 100644 index 1ba7be4..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.geology; - -import com.terraforged.core.util.Seed; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -public class Strata { - - private final Module heightMod; - private final List> strata; - - private Strata(Module heightMod, List> strata) { - this.strata = strata; - this.heightMod = heightMod; - } - - public boolean downwards(final int x, final int y, final int z, final Stratum.Visitor visitor) { - DepthBuffer buffer = new DepthBuffer(); - initBuffer(buffer, x, z); - return downwards(x, y, z, buffer, visitor); - } - - public boolean downwards(final int x, final int y, final int z, final DepthBuffer buffer, Stratum.Visitor visitor) { - initBuffer(buffer, x, z); - - int py = y; - T last = null; - for (int i = 0; i < strata.size(); i++) { - float depth = buffer.getDepth(i); - int height = NoiseUtil.round(depth * y); - T value = strata.get(i).getValue(); - last = value; - for (int dy = 0; dy < height; dy++) { - if (py <= y) { - boolean cont = visitor.visit(py, value); - if (!cont) { - return false; - } - } - if (--py < 0) { - return false; - } - } - } - if (last != null) { - while (py > 0) { - visitor.visit(py, last); - py--; - } - } - return true; - } - - private int getYOffset(int x, int z) { - return (int) (64 * heightMod.getValue(x, z)); - } - - private void initBuffer(DepthBuffer buffer, int x, int z) { - buffer.init(strata.size()); - for (int i = 0; i < strata.size(); i++) { - float depth = strata.get(i).getDepth(x, z); - buffer.set(i, depth); - } - } - - public static Builder builder(int seed, me.dags.noise.source.Builder noise) { - return new Builder<>(seed, noise); - } - - public static class Builder { - - private final Seed seed; - private final me.dags.noise.source.Builder noise; - private final List> strata = new LinkedList<>(); - - public Builder(int seed, me.dags.noise.source.Builder noise) { - this.seed = new Seed(seed); - this.noise = noise; - } - - public Builder add(T material, double depth) { - Module module = noise.seed(seed.next()).perlin().scale(depth); - strata.add(Stratum.of(material, module)); - return this; - } - - public Builder add(Source type, T material, double depth) { - Module module = noise.seed(seed.next()).build(type).scale(depth); - strata.add(Stratum.of(material, module)); - return this; - } - - public Strata build() { - Module height = Source.cell(seed.next(), 100); - return new Strata<>(height, new ArrayList<>(strata)); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Stratum.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Stratum.java deleted file mode 100644 index c51ab6e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Stratum.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.geology; - -import me.dags.noise.Module; -import me.dags.noise.Source; - -public class Stratum { - - private final T value; - private final Module depth; - - public Stratum(T value, double depth) { - this(value, Source.constant(depth)); - } - - public Stratum(T value, Module depth) { - this.depth = depth; - this.value = value; - } - - public T getValue() { - return value; - } - - public float getDepth(float x, float z) { - return depth.getValue(x, z); - } - - public static Stratum of(T t, double depth) { - return new Stratum<>(t, depth); - } - - public static Stratum of(T t, Module depth) { - return new Stratum<>(t, depth); - } - - public interface Visitor { - - boolean visit(int y, T value); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Heightmap.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Heightmap.java deleted file mode 100644 index a9c176f..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Heightmap.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.heightmap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Extent; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.region.Size; -import com.terraforged.core.util.concurrent.ObjectPool; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.rivermap.RiverMap; -import com.terraforged.core.world.rivermap.RiverRegionList; -import com.terraforged.core.world.terrain.Terrain; - -public interface Heightmap extends Populator, Extent { - - Climate getClimate(); - - RiverMap getRiverMap(); - - void visit(Cell cell, float x, float z); - - void applyBase(Cell cell, float x, float z); - - void applyRivers(Cell cell, float x, float z, RiverRegionList rivers); - - void applyClimate(Cell cell, float x, float z); - - @Override - default void visit(int minX, int minZ, int maxX, int maxZ, Cell.Visitor visitor) { - int chunkSize = Size.chunkToBlock(1); - - int chunkMinX = Size.blockToChunk(minX); - int chunkMinZ = Size.blockToChunk(minZ); - int chunkMaxX = Size.blockToChunk(maxX); - int chunkMaxZ = Size.blockToChunk(maxZ); - - try (ObjectPool.Item> cell = Cell.pooled()) { - for (int chunkZ = chunkMinZ; chunkZ <= chunkMaxZ; chunkZ++) { - for (int chunkX = chunkMinX; chunkX <= chunkMaxX; chunkX++) { - int chunkStartX = Size.chunkToBlock(chunkX); - int chunkStartZ = Size.chunkToBlock(chunkZ); - for (int dz = 0; dz < chunkSize; dz++) { - for (int dx = 0; dx < chunkSize; dx++) { - int x = chunkStartX + dx; - int z = chunkStartZ + dz; - apply(cell.getValue(), x, z); - if (x >= minX && x < maxX && z >= minZ && z < maxZ) { - int relX = x - minX; - int relZ = z - minZ; - visitor.visit(cell.getValue(), relX, relZ); - } - } - } - } - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java deleted file mode 100644 index bc1f6a6..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.heightmap; - -import com.terraforged.core.settings.GeneratorSettings; -import me.dags.noise.util.NoiseUtil; - -public class Levels { - - public final int worldHeight; - - public final float unit; - - // y index of the top-most water block - public final int waterY; - private final int groundY; - - // top of the first ground block (ie 1 above ground index) - public final int groundLevel; - // top of the top-most water block (ie 1 above water index) - public final int waterLevel; - - // ground index mapped between 0-1 (default 63 / 256) - public final float ground; - // water index mapped between 0-1 (default 62 / 256) - public final float water; - - public Levels(GeneratorSettings settings) { - worldHeight = Math.max(1, settings.world.worldHeight); - unit = NoiseUtil.div(1, worldHeight); - - waterLevel = settings.world.seaLevel; - groundLevel = waterLevel + 1; - - waterY = Math.min(waterLevel - 1, worldHeight); - groundY = Math.min(groundLevel - 1, worldHeight); - - ground = NoiseUtil.div(groundY, worldHeight); - water = NoiseUtil.div(waterY, worldHeight); - } - - public int scale(float value) { - if (value >= 1F) { - return worldHeight - 1; - } - return (int) (value * worldHeight); - } - - public float scale(int level) { - return NoiseUtil.div(level, worldHeight); - } - - public float water(int amount) { - return NoiseUtil.div(waterY + amount, worldHeight); - } - - public float ground(int amount) { - return NoiseUtil.div(groundY + amount, worldHeight); - } - - public static float getSeaLevel(GeneratorSettings settings) { - int worldHeight = Math.max(1, settings.world.worldHeight); - int waterLevel = Math.min(settings.world.seaLevel, worldHeight); - return NoiseUtil.div(waterLevel, worldHeight); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/RegionConfig.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/RegionConfig.java deleted file mode 100644 index 800bd95..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/RegionConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.heightmap; - -import me.dags.noise.Module; - -public class RegionConfig { - - public final int seed; - public final int scale; - public final Module warpX; - public final Module warpZ; - public final double warpStrength; - - public RegionConfig(int seed, int scale, Module warpX, Module warpZ, double warpStrength) { - this.seed = seed; - this.scale = scale; - this.warpX = warpX; - this.warpZ = warpZ; - this.warpStrength = warpStrength; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/RegionExtent.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/RegionExtent.java deleted file mode 100644 index 78134ac..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/RegionExtent.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.heightmap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Extent; -import com.terraforged.core.region.Region; -import com.terraforged.core.region.Size; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.core.world.terrain.Terrain; - -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.CompletableFuture; - -public interface RegionExtent extends Extent { - - int chunkToRegion(int coord); - - Region getRegion(int regionX, int regionZ); - - CompletableFuture getRegionAsync(int regionX, int regionZ); - - default ChunkReader getChunk(int chunkX, int chunkZ) { - int regionX = chunkToRegion(chunkX); - int regionZ = chunkToRegion(chunkZ); - Region region = getRegion(regionX, regionZ); - return region.getChunk(chunkX, chunkZ); - } - - default List> getRegions(int minRegionX, int minRegionZ, int maxRegionX, int maxRegionZ) { - List> regions = new LinkedList<>(); - for (int rz = minRegionZ; rz <= maxRegionZ; rz++) { - for (int rx = minRegionX; rx <= maxRegionX; rx++) { - regions.add(getRegionAsync(rx, rz)); - } - } - return regions; - } - - @Override - default void visit(int minX, int minZ, int maxX, int maxZ, Cell.Visitor visitor) { - int minRegionX = chunkToRegion(Size.blockToChunk(minX)); - int minRegionZ = chunkToRegion(Size.blockToChunk(minZ)); - int maxRegionX = chunkToRegion(Size.blockToChunk(maxX)); - int maxRegionZ = chunkToRegion(Size.blockToChunk(maxZ)); - List> regions = getRegions(minRegionX, minRegionZ, maxRegionX, maxRegionZ); - while (!regions.isEmpty()) { - regions.removeIf(future -> { - if (!future.isDone()) { - return false; - } - Region region = future.join(); - region.visit(minX, minZ, maxX, maxZ, visitor); - return true; - }); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/WorldHeightmap.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/WorldHeightmap.java deleted file mode 100644 index 2ecdb4c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/WorldHeightmap.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.heightmap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.module.Blender; -import com.terraforged.core.settings.GeneratorSettings; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.continent.ContinentLerper2; -import com.terraforged.core.world.continent.ContinentLerper3; -import com.terraforged.core.world.continent.ContinentModule; -import com.terraforged.core.world.rivermap.RiverMap; -import com.terraforged.core.world.rivermap.RiverRegionList; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.TerrainPopulator; -import com.terraforged.core.world.terrain.Terrains; -import com.terraforged.core.world.terrain.provider.TerrainProvider; -import com.terraforged.core.world.terrain.region.RegionLerper; -import com.terraforged.core.world.terrain.region.RegionModule; -import com.terraforged.core.world.terrain.region.RegionSelector; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.func.EdgeFunc; -import me.dags.noise.func.Interpolation; - -public class WorldHeightmap implements Heightmap { - - private static final float DEEP_OCEAN_VALUE = 0.2F; - private static final float OCEAN_VALUE = 0.3F; - private static final float BEACH_VALUE = 0.34F; - private static final float COAST_VALUE = 0.4F; - private static final float INLAND_VALUE = 0.6F; - - private final Levels levels; - private final Terrains terrain; - private final Settings settings; - - private final Populator continentModule; - private final Populator regionModule; - - private final Climate climate; - private final Populator root; - private final RiverMap riverMap; - private final TerrainProvider terrainProvider; - - public WorldHeightmap(GeneratorContext context) { - context = context.copy(); - - this.levels = context.levels; - this.terrain = context.terrain; - this.settings = context.settings; - this.climate = new Climate(context); - - Seed seed = context.seed; - Levels levels = context.levels; - GeneratorSettings genSettings = context.settings.generator; - - Seed regionSeed = seed.nextSeed(); - Seed regionWarp = seed.nextSeed(); - - int regionWarpScale = 400; - int regionWarpStrength = 200; - RegionConfig regionConfig = new RegionConfig( - regionSeed.get(), - context.settings.generator.land.regionSize, - Source.simplex(regionWarp.next(), regionWarpScale, 1), - Source.simplex(regionWarp.next(), regionWarpScale, 1), - regionWarpStrength - ); - - regionModule = new RegionModule(regionConfig); - - // controls where mountain chains form in the world - Module mountainShapeBase = Source.cellEdge(seed.next(), genSettings.land.mountainScale, EdgeFunc.DISTANCE_2_ADD) - .add(Source.cubic(seed.next(), genSettings.land.mountainScale, 1).scale(-0.05)); - - // sharpens the transition to create steeper mountains - Module mountainShape = mountainShapeBase - .curve(Interpolation.CURVE3) - .clamp(0, 0.9) - .map(0, 1); - - terrainProvider = context.terrainFactory.create(context, regionConfig, this); - - // the voronoi controlled terrain regions - Populator terrainRegions = new RegionSelector(terrainProvider.getPopulators()); - // the terrain type at region edges - Populator terrainRegionBorders = new TerrainPopulator(terrainProvider.getLandforms().plains(seed), context.terrain.steppe); - - // transitions between the unique terrain regions and the common border terrain - Populator terrain = new RegionLerper(terrainRegionBorders, terrainRegions); - - // mountain populator - Populator mountains = register(terrainProvider.getLandforms().mountains(seed), context.terrain.mountains); - - // controls what's ocean and what's land - continentModule = new ContinentModule(seed, settings.generator); - - // blends between normal terrain and mountain chains - Populator land = new Blender( - mountainShape, - terrain, - mountains, - 0.1F, - 0.9F, - 0.6F - ); - - // uses the continent noise to blend between deep ocean, to ocean, to coast - ContinentLerper3 oceans = new ContinentLerper3( - climate, - register(terrainProvider.getLandforms().deepOcean(seed.next()), context.terrain.deepOcean), - register(Source.constant(levels.water(-7)), context.terrain.ocean), - register(Source.constant(levels.water), context.terrain.coast), - DEEP_OCEAN_VALUE, // below == deep, above == transition to shallow - OCEAN_VALUE, // below == transition to deep, above == transition to coast - COAST_VALUE // below == transition to shallow, above == coast - ); - - // blends between the ocean/coast terrain and land terrains - root = new ContinentLerper2( - oceans, - land, - OCEAN_VALUE, // below == pure ocean - INLAND_VALUE, // above == pure land - COAST_VALUE, // split point - COAST_VALUE - 0.05F - ); - - riverMap = new RiverMap(this, context); - } - - @Override - public void visit(Cell cell, float x, float z) { - continentModule.apply(cell, x, z); - regionModule.apply(cell, x, z); - root.apply(cell, x, z); - } - - @Override - public void apply(Cell cell, float x, float z) { - applyBase(cell, x, z); - applyRivers(cell, x, z, riverMap.getRivers((int) x, (int) z)); - applyClimate(cell, x, z); - } - - @Override - public void applyBase(Cell cell, float x, float z) { - // initial type - cell.tag = terrain.steppe; - // basic shapes - continentModule.apply(cell, x, z); - regionModule.apply(cell, x, z); - // apply actual heightmap - root.apply(cell, x, z); - } - - @Override - public void applyRivers(Cell cell, float x, float z, RiverRegionList rivers) { - rivers.apply(cell, x, z); - } - - @Override - public void applyClimate(Cell cell, float x, float z) { - // apply climate data - if (cell.value <= levels.water) { - climate.apply(cell, x, z, false); - if (cell.tag == terrain.coast) { - cell.tag = terrain.ocean; - } - } else { - int range = settings.generator.biomeEdgeNoise.strength; - float dx = climate.getOffsetX(x, z, range); - float dz = climate.getOffsetZ(x, z, range); - float px = x + dx; - float pz = z + dz; - tag(cell, px, pz); - climate.apply(cell, px, pz, false); - climate.apply(cell, x, z, true); - } - } - - @Override - public void tag(Cell cell, float x, float z) { - continentModule.apply(cell, x, z); - regionModule.apply(cell, x, z); - root.tag(cell, x, z); - } - - public Climate getClimate() { - return climate; - } - - @Override - public RiverMap getRiverMap() { - return riverMap; - } - - public Populator getPopulator(Terrain terrain) { - return terrainProvider.getPopulator(terrain); - } - - private TerrainPopulator register(Module module, Terrain terrain) { - TerrainPopulator populator = new TerrainPopulator(module, terrain); - terrainProvider.registerMixable(populator); - return populator; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/WorldLookup.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/WorldLookup.java deleted file mode 100644 index 5d629d7..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/WorldLookup.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.terraforged.core.world.heightmap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.WorldDecorators; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.decorator.Decorator; -import com.terraforged.core.world.terrain.Terrain; - -public class WorldLookup { - - private final float waterLevel; - private final float beachLevel; - private final Heightmap heightmap; - private final WorldDecorators decorators; - private final GeneratorContext context; - - public WorldLookup(WorldGeneratorFactory factory, GeneratorContext context) { - this.context = context; - this.heightmap = factory.getHeightmap(); - this.decorators = factory.getDecorators(); - this.waterLevel = context.levels.water; - this.beachLevel = context.levels.water(5); - } - - public Cell getCell(int x, int z) { - Cell cell = new Cell<>(); - applyCell(cell, x, z); - return cell; - } - - public void applyCell(Cell cell, int x, int z) { - heightmap.apply(cell, x, z); - - // approximation - actual beaches depend on steepness but that's too expensive to calculate - if (cell.tag == context.terrain.coast && cell.value > waterLevel && cell.value <= beachLevel) { - cell.tag = context.terrain.beach; - } - - for (Decorator decorator : decorators.getDecorators()) { - if (decorator.apply(cell, x, z)) { - break; - } - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/PosGenerator.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/PosGenerator.java deleted file mode 100644 index fba5b62..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/PosGenerator.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Heightmap; -import com.terraforged.core.world.rivermap.river.RiverNode; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.domain.Domain; -import me.dags.noise.util.Vec2i; - -import java.util.Random; - -/** - * Generates random positions within (length / 4) of one of the 4 corners of a region. - * The first position generated will be near any of the four corners - * The second position generated will be near any of the 3 remaining corners to ensure a reasonable distance to the first - */ -public class PosGenerator { - - private final int size; - private final int quadSize; - private final Vec2i[] quads = new Vec2i[4]; - - private final int padding; - private final Domain domain; - private final Cell lookup; - private final Heightmap heightmap; - - private int i; - private int dx; - private int dz; - - public PosGenerator(Heightmap heightmap, Domain domain, Cell lookup, int size, int padding) { - this.domain = domain; - this.lookup = lookup; - this.padding = padding; - this.heightmap = heightmap; - this.size = size; - this.quadSize = (size - (padding * 2)) / 4; - int x1 = 0; - int y1 = 0; - int x2 = 3 * quadSize; - int y2 = 3 * quadSize; - quads[index(0, 0)] = new Vec2i(x1, y1); - quads[index(1, 0)] = new Vec2i(x2, y1); - quads[index(0, 1)] = new Vec2i(x1, y2); - quads[index(1, 1)] = new Vec2i(x2, y2); - } - - private void nextSeed(Random random) { - int index = random.nextInt(4); - Vec2i vec = quads[index]; - i = index; - dx = padding + vec.x + random.nextInt(quadSize); - dz = padding + vec.y + random.nextInt(quadSize); - } - - private void nextPos(Random random) { - int steps = 1 + random.nextInt(3); - int index = (i + steps) & 3; - Vec2i vec = quads[index]; - i = index; - dx = padding + vec.x + random.nextInt(quadSize); - dz = padding + vec.y + random.nextInt(quadSize); - } - - public RiverNode next(int x, int z, Random random, int attempts) { - for (int i = 0; i < attempts; i++) { - nextSeed(random); - int px = x + dx; - int pz = z + dz; - int wx = (int) domain.getX(px, pz); - int wz = (int) domain.getY(px, pz); - float value1 = getHeight(px, pz); - float value2 = getHeight(wx, wz); - RiverNode.Type type1 = RiverNode.getType(value1); - RiverNode.Type type2 = RiverNode.getType(value2); - if (type1 == type2 && type1 != RiverNode.Type.NONE) { - if (type1 == RiverNode.Type.END) { - return new RiverNode(wx, wz, type1); - } - return new RiverNode(px, pz, type1); - } - } - return null; - } - - public RiverNode nextFrom(int x, int z, Random random, int attempts, RiverNode point, int mindDist2) { - for (int i = 0; i < attempts; i++) { - nextPos(random); - int px = x + dx; - int pz = z + dz; - if (dist2(px, pz, point.x, point.z) < mindDist2) { - continue; - } - int wx = (int) domain.getX(px, pz); - int wz = (int) domain.getY(px, pz); - float value1 = getHeight(px, pz); - float value2 = getHeight(wx, wz); - RiverNode.Type type1 = RiverNode.getType(value1); - RiverNode.Type type2 = RiverNode.getType(value2); - if (type1 == type2 && type1 == point.type.opposite()) { - if (type1 == RiverNode.Type.END) { - return new RiverNode(wx, wz, type1); - } - return new RiverNode(px, pz, type1); - } - } - return null; - } - - public RiverNode nextRelaxed(int x, int z, Random random, int attempts) { - for (int i = 0; i < attempts; i++) { - int px = x + random.nextInt(size); - int pz = z + random.nextInt(size); - int wx = (int) domain.getX(px, pz); - int wz = (int) domain.getY(px, pz); - float value1 = getHeight(px, pz); - float value2 = getHeight(wx, wz); - RiverNode.Type type1 = RiverNode.getType(value1); - RiverNode.Type type2 = RiverNode.getType(value2); - if (type1 == type2 && type1 != RiverNode.Type.NONE) { - if (type1 == RiverNode.Type.END) { - return new RiverNode(wx, wz, type1); - } - return new RiverNode(px, pz, type1); - } - } - return null; - } - - public RiverNode nextFromRelaxed(int x, int z, Random random, int attempts, RiverNode point, int mindDist2) { - for (int i = 0; i < attempts; i++) { - int px = x + random.nextInt(size); - int pz = z + random.nextInt(size); - if (dist2(px, pz, point.x, point.z) < mindDist2) { - continue; - } - int wx = (int) domain.getX(px, pz); - int wz = (int) domain.getY(px, pz); - float value1 = getHeight(px, pz); - float value2 = getHeight(wx, wz); - RiverNode.Type type1 = RiverNode.getType(value1); - RiverNode.Type type2 = RiverNode.getType(value2); - if (type1 == type2 && type1 == point.type.opposite()) { - if (type1 == RiverNode.Type.END) { - return new RiverNode(wx, wz, type1); - } - return new RiverNode(px, pz, type1); - } - } - return null; - } - - public RiverNode nextType(int x, int z, Random random, int attempts, RiverNode.Type match) { - for (int i = 0; i < attempts; i++) { - nextSeed(random); - int px = x + dx; - int pz = z + dz; - int wx = (int) domain.getX(px, pz); - int wz = (int) domain.getY(px, pz); - float value1 = getHeight(px, pz); - float value2 = getHeight(wx, wz); - RiverNode.Type type1 = RiverNode.getType(value1); - RiverNode.Type type2 = RiverNode.getType(value2); - if (type1 == type2 && type1 == match) { - return new RiverNode(px, pz, type1); - } - } - return null; - } - - public RiverNode nextMinHeight(int x, int z, Random random, int attempts, float minHeight) { - for (int i = 0; i < attempts; i++) { - nextPos(random); - int px = x + dx; - int pz = z + dz; - int wx = (int) domain.getX(px, pz); - int wz = (int) domain.getY(px, pz); - float value1 = getHeight(px, pz); - float value2 = getHeight(wx, wz); - if (value1 > minHeight && value2 > minHeight) { - return new RiverNode(px, pz, RiverNode.Type.START); - } - } - return null; - } - - public float getHeight(int x, int z) { - heightmap.visit(lookup, x, z); - return lookup.value; - } - - private static int index(int x, int z) { - return z * 2 + x; - } - - private static float dist2(int x1, int y1, int x2, int y2) { - float dx = x2 - x1; - float dy = y2 - y1; - return dx * dx + dy * dy; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverMap.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverMap.java deleted file mode 100644 index c79f54a..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverMap.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.Region; -import com.terraforged.core.util.concurrent.ThreadPool; -import com.terraforged.core.util.concurrent.cache.Cache; -import com.terraforged.core.util.concurrent.cache.CacheEntry; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.heightmap.Heightmap; -import com.terraforged.core.world.rivermap.lake.LakeConfig; -import com.terraforged.core.world.rivermap.river.RiverConfig; -import com.terraforged.core.world.rivermap.river.RiverRegion; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.util.NoiseUtil; - -import java.util.concurrent.TimeUnit; - -public class RiverMap { - - private static final int QUAD_SIZE = (1 << RiverRegion.SCALE) / 2; - - private final Heightmap heightmap; - private final GeneratorContext context; - private final RiverMapConfig riverMapConfig; - private final Cache> cache; - private final ThreadPool threadPool = ThreadPool.getPool(); - - public RiverMap(Heightmap heightmap, GeneratorContext context) { - RiverConfig primary = RiverConfig.builder(context.levels) - .bankHeight(context.settings.rivers.primaryRivers.minBankHeight, context.settings.rivers.primaryRivers.maxBankHeight) - .bankWidth(context.settings.rivers.primaryRivers.bankWidth) - .bedWidth(context.settings.rivers.primaryRivers.bedWidth) - .bedDepth(context.settings.rivers.primaryRivers.bedDepth) - .fade(context.settings.rivers.primaryRivers.fade) - .length(2500) - .main(true) - .build(); - RiverConfig secondary = RiverConfig.builder(context.levels) - .bankHeight(context.settings.rivers.secondaryRiver.minBankHeight, context.settings.rivers.secondaryRiver.maxBankHeight) - .bankWidth(context.settings.rivers.secondaryRiver.bankWidth) - .bedWidth(context.settings.rivers.secondaryRiver.bedWidth) - .bedDepth(context.settings.rivers.secondaryRiver.bedDepth) - .fade(context.settings.rivers.secondaryRiver.fade) - .length(1000) - .build(); - RiverConfig tertiary = RiverConfig.builder(context.levels) - .bankHeight(context.settings.rivers.tertiaryRivers.minBankHeight, context.settings.rivers.tertiaryRivers.maxBankHeight) - .bankWidth(context.settings.rivers.tertiaryRivers.bankWidth) - .bedWidth(context.settings.rivers.tertiaryRivers.bedWidth) - .bedDepth(context.settings.rivers.tertiaryRivers.bedDepth) - .fade(context.settings.rivers.tertiaryRivers.fade) - .length(500) - .build(); - LakeConfig lakes = LakeConfig.of(context.settings.rivers.lake, context.levels); - - this.heightmap = heightmap; - this.context = context; - this.riverMapConfig = new RiverMapConfig(context.settings.rivers.riverFrequency, primary, secondary, tertiary, lakes); - this.cache = new Cache<>(3, 1, TimeUnit.MINUTES); - } - - public RiverRegionList getRivers(Region region) { - RiverRegionList rivers = new RiverRegionList(); - getRivers(region.getBlockX(), region.getBlockZ(), rivers); - return rivers; - } - - public RiverRegionList getRivers(int blockX, int blockZ) { - RiverRegionList rivers = new RiverRegionList(); - getRivers(blockX, blockZ, rivers); - return rivers; - } - - public void getRivers(Region region, RiverRegionList rivers) { - getRivers(region.getBlockX(), region.getBlockZ(), rivers); - } - - public void getRivers(int blockX, int blockZ, RiverRegionList rivers) { - int rx = RiverRegion.blockToRegion(blockX); - int rz = RiverRegion.blockToRegion(blockZ); - - // check which quarter of the region pos (x,y) is in & get the neighbouring regions' relative coords - int qx = blockX < RiverRegion.regionToBlock(rx) + QUAD_SIZE ? -1 : 1; - int qz = blockZ < RiverRegion.regionToBlock(rz) + QUAD_SIZE ? -1 : 1; - - // relative positions of neighbouring regions - int minX = Math.min(0, qx); - int minZ = Math.min(0, qz); - int maxX = Math.max(0, qx); - int maxZ = Math.max(0, qz); - - rivers.reset(); - for (int dz = minZ; dz <= maxZ; dz++) { - for (int dx = minX; dx <= maxX; dx++) { - rivers.add(getRegion(rx + dx, rz + dz)); - } - } - } - - public void apply(Cell cell, float x, float z) { - RiverRegionList rivers = new RiverRegionList(); - getRivers((int) x, (int) z, rivers); - rivers.apply(cell, x, z); - } - - private CacheEntry getRegion(int rx, int rz) { - long id = NoiseUtil.seed(rx, rz); - return cache.computeIfAbsent(id, l -> generateRegion(rx, rz)); - } - - private CacheEntry generateRegion(int rx, int rz) { - return CacheEntry.supplyAsync(() -> new RiverRegion(rx, rz, heightmap, context, riverMapConfig), threadPool); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverMapConfig.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverMapConfig.java deleted file mode 100644 index 957fedc..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverMapConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.terraforged.core.world.rivermap; - -import com.terraforged.core.world.rivermap.lake.LakeConfig; -import com.terraforged.core.world.rivermap.river.RiverConfig; - -public class RiverMapConfig { - - public final float frequency; - public final RiverConfig primary; - public final RiverConfig secondary; - public final RiverConfig tertiary; - public final LakeConfig lakes; - - public RiverMapConfig(float frequency, RiverConfig primary, RiverConfig secondary, RiverConfig tertiary, LakeConfig lakes) { - this.frequency = frequency; - this.primary = primary; - this.secondary = secondary; - this.tertiary = tertiary; - this.lakes = lakes; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverRegionList.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverRegionList.java deleted file mode 100644 index 9cdbc1c..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/RiverRegionList.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.terraforged.core.world.rivermap; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.concurrent.cache.CacheEntry; -import com.terraforged.core.world.rivermap.river.RiverRegion; -import com.terraforged.core.world.terrain.Terrain; - -import java.util.Arrays; - -public class RiverRegionList { - - private int index = 0; - private final CacheEntry[] regions = new CacheEntry[4]; - - protected void add(CacheEntry entry) { - if (index < regions.length) { - regions[index] = entry; - index++; - } - } - - protected void reset() { - index = 0; - } - - public void clear() { - Arrays.fill(regions, null); - } - - public void apply(Cell cell, float x, float z) { - for (CacheEntry entry : regions) { - entry.get().apply(cell, x, z); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/lake/Lake.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/lake/Lake.java deleted file mode 100644 index c41b639..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/lake/Lake.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.lake; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.rivermap.river.River; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.TerrainPopulator; -import com.terraforged.core.world.terrain.Terrains; -import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; -import me.dags.noise.util.Vec2f; - -public class Lake extends TerrainPopulator { - - private static final int VALLEY_2 = River.VALLEY_WIDTH * River.VALLEY_WIDTH; - - private final float lakeDistance2; - private final float valleyDistance2; - private final float bankAlphaMin; - private final float bankAlphaMax; - private final float bankAlphaRange; - private final Vec2f center; - private final LakeConfig config; - private final Terrains terrains; - - public Lake(Vec2f center, float radius, LakeConfig config, Terrains terrains) { - super(Source.ZERO, terrains.lake); - this.center = center; - this.config = config; - this.bankAlphaMin = config.bankMin; - this.bankAlphaMax = Math.min(1, bankAlphaMin + 0.275F); - this.bankAlphaRange = bankAlphaMax - bankAlphaMin; - this.lakeDistance2 = radius * radius; - this.valleyDistance2 = VALLEY_2 - lakeDistance2; - this.terrains = terrains; - } - - @Override - public void apply(Cell cell, float x, float z) { - float distance2 = getDistance2(x, z); - if (distance2 > VALLEY_2) { - return; - } - - float bankHeight = getBankHeight(cell); - if (distance2 > lakeDistance2) { - if (cell.value < bankHeight) { - return; - } - float valleyAlpha = 1F - ((distance2 - lakeDistance2) / valleyDistance2); - cell.value = NoiseUtil.lerp(cell.value, bankHeight, valleyAlpha); - return; - } - - cell.value = Math.min(bankHeight, cell.value); - - if (distance2 < lakeDistance2) { - float depthAlpha = 1F - (distance2 / lakeDistance2); - float lakeDepth = Math.min(cell.value, config.depth); - cell.value = NoiseUtil.lerp(cell.value, lakeDepth, depthAlpha); - cell.tag = terrains.lake; - } - } - - @Override - public void tag(Cell cell, float x, float z) { - cell.tag = terrains.lake; - } - - private float getDistance2(float x, float z) { - float dx = center.x - x; - float dz = center.y - z; - return (dx * dx + dz * dz); - } - - private float getBankHeight(Cell cell) { - // scale bank height based on elevation of the terrain (higher terrain == taller banks) - float bankHeightAlpha = NoiseUtil.map(cell.value, bankAlphaMin, bankAlphaMax, bankAlphaRange); - // lerp between the min and max heights - return NoiseUtil.lerp(config.bankMin, config.bankMax, bankHeightAlpha); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/lake/LakeConfig.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/lake/LakeConfig.java deleted file mode 100644 index 49c7f82..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/lake/LakeConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.lake; - -import com.terraforged.core.settings.RiverSettings; -import com.terraforged.core.world.heightmap.Levels; - -public class LakeConfig { - - public final float depth; - public final float chance; - public final float sizeMin; - public final float sizeMax; - public final float bankMin; - public final float bankMax; - public final float distanceMin; - public final float distanceMax; - - private LakeConfig(Builder builder) { - depth = builder.depth; - chance = builder.chance; - sizeMin = builder.sizeMin; - sizeMax = builder.sizeMax; - bankMin = builder.bankMin; - bankMax = builder.bankMax; - distanceMin = builder.distanceMin; - distanceMax = builder.distanceMax; - } - - public static LakeConfig of(RiverSettings.Lake settings, Levels levels) { - Builder builder = new Builder(); - builder.chance = settings.chance; - builder.sizeMin = settings.sizeMin; - builder.sizeMax = settings.sizeMax; - builder.depth = levels.water(-settings.depth); - builder.distanceMin = settings.minStartDistance; - builder.distanceMax = settings.maxStartDistance; - builder.bankMin = levels.water(settings.minBankHeight); - builder.bankMax = levels.water(settings.maxBankHeight); - return new LakeConfig(builder); - } - - public static class Builder { - public float chance; - public float depth = 10; - public float sizeMin = 30; - public float sizeMax = 100; - public float bankMin = 1; - public float bankMax = 8; - public float distanceMin = 0.025F; - public float distanceMax = 0.05F; - } -} 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 deleted file mode 100644 index 6ff08c9..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/River.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.river; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.TerrainPopulator; -import com.terraforged.core.world.terrain.Terrains; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.source.Line; -import me.dags.noise.util.NoiseUtil; - -public class River extends TerrainPopulator { - - public static final int VALLEY_WIDTH = 275; - protected static final float DEPTH_FADE_STRENGTH = 0.5F; - - public final boolean main; - private final boolean connecting; - - private final float bedHeight; - - private final float minBankHeight; - private final float maxBankHeight; - private final float bankAlphaMin; - private final float bankAlphaMax; - private final float bankAlphaRange; - private final Module bankVariance; - - private final Line bed; - private final Line banks; - private final Line valley; - public final RiverConfig config; - public final RiverBounds bounds; - - private final Terrains terrains; - - private final float depthFadeBias; - - public River(RiverBounds bounds, RiverConfig config, Terrains terrains, double fadeIn, double fadeOut) { - this(bounds, config, terrains, fadeIn, fadeOut, false); - } - - public River(RiverBounds bounds, RiverConfig config, Terrains terrains, double fadeIn, double fadeOut, boolean connecting) { - super(Source.ZERO, terrains.river); - Module in = Source.constant(fadeIn); - Module out = Source.constant(fadeOut); - Module bedWidth = Source.constant(config.bedWidth * config.bedWidth); - Module bankWidth = Source.constant(config.bankWidth * config.bankWidth); - Module valleyWidth = Source.constant(VALLEY_WIDTH * VALLEY_WIDTH); - this.bounds = bounds; - this.config = config; - this.main = config.main; - this.terrains = terrains; - this.connecting = connecting; - this.bedHeight = config.bedHeight; - this.minBankHeight = config.minBankHeight; - this.maxBankHeight = config.maxBankHeight; - this.bankAlphaMin = minBankHeight; - this.bankAlphaMax = Math.min(1, minBankHeight + 0.35F); - this.bankAlphaRange = bankAlphaMax - bankAlphaMin; - this.bankVariance = Source.perlin(1234, 150, 1); - this.depthFadeBias = 1 - DEPTH_FADE_STRENGTH; - this.bed = Source.line(bounds.x1(), bounds.y1(), bounds.x2(), bounds.y2(), bedWidth, in, out, 0.1F); - this.banks = Source.line(bounds.x1(), bounds.y1(), bounds.x2(), bounds.y2(), bankWidth, in, out, 0.1F); - this.valley = Source.line(bounds.x1(), bounds.y1(), bounds.x2(), bounds.y2(), valleyWidth, Source.ZERO, Source.ZERO, 0.33F); - } - - @Override - public void apply(Cell cell, float x, float z) { - if (cell.value <= bedHeight) { - return; - } - carve(cell, x, z); - } - - @Override - public void tag(Cell cell, float x, float z) { - if (!terrains.overridesRiver(cell.tag)) { - cell.tag = terrains.river; - } - } - - private void carve(Cell cell, float x, float z) { - float valleyAlpha = valley.getValue(x, z); - if (valleyAlpha == 0) { - return; - } - - // riverMask decreases the closer to the river the position gets - cell.riverMask *= (1 - valleyAlpha); - - float bankHeight = getBankHeight(cell, x, z); - if (!carveValley(cell, valleyAlpha, bankHeight)) { - return; - } - - // is a branching river and x,z is past the connecting point - if (connecting && banks.clipEnd(x, z)) { - return; - } - - float widthModifier = banks.getWidthModifier(x, z); - float banksAlpha = banks.getValue(x, z, widthModifier); - if (banksAlpha == 0) { - return; - } - - float bedHeight = getBedHeight(bankHeight, widthModifier); - if (!carveBanks(cell, banksAlpha, bedHeight)) { - return; - } - - float bedAlpha = bed.getValue(x, z); - if (bedAlpha == 0) { - return; - } - - carveBed(cell, bedHeight); - } - - private float getBankHeight(Cell cell, float x, float z) { - // scale bank height based on elevation of the terrain (higher terrain == taller banks) - float bankHeightAlpha = NoiseUtil.map(cell.value, bankAlphaMin, bankAlphaMax, bankAlphaRange); - // use perlin noise to add a little extra variance to the bank height - float bankHeightVariance = bankVariance.getValue(x, z); - // lerp between the min and max heights - return NoiseUtil.lerp(minBankHeight, maxBankHeight, bankHeightAlpha * bankHeightVariance); - } - - private float getBedHeight(float bankHeight, float widthModifier) { - // scale depth of river by with it's width (wider == deeper) - // depthAlpha changes the river depth up ${DEPTH_FADE_STRENGTH} % - float depthAlpha = depthFadeBias + (DEPTH_FADE_STRENGTH * widthModifier); - return NoiseUtil.lerp(bankHeight, this.bedHeight, depthAlpha); - } - - private boolean carveValley(Cell cell, float valleyAlpha, float bankHeight) { - // lerp the position's height to the riverbank height - if (cell.value > bankHeight) { - cell.value = NoiseUtil.lerp(cell.value, bankHeight, valleyAlpha); - } - return true; - } - - private boolean carveBanks(Cell 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 cell, float bedHeight) { - if (cell.value > bedHeight) { - cell.value = bedHeight; - } - tag(cell, terrains.river); - } - - - private void tag(Cell cell, Terrain tag) { - if (!terrains.overridesRiver(cell.tag)) { - cell.tag = tag; - } - } - - public static boolean validStart(float value) { - return value > (70F / 256F); - } - - public static boolean validEnd(float value) { - return value < (60F / 256F); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverBounds.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverBounds.java deleted file mode 100644 index 9b78bc7..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverBounds.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.river; - -import me.dags.noise.util.Vec2f; - -public class RiverBounds { - - private final int x1; - private final int y1; - private final int x2; - private final int y2; - private final int minX; - private final int minY; - private final int maxX; - private final int maxY; - - public RiverBounds(int x1, int y1, int x2, int y2, int radius) { - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - this.minX = Math.min(x1, x2) - radius; - this.minY = Math.min(y1, y2) - radius; - this.maxX = Math.max(x1, x2) + radius; - this.maxY = Math.max(y1, y2) + radius; - } - - public int x1() { - return x1; - } - - public int y1() { - return y1; - } - - public int x2() { - return x2; - } - - public int y2() { - return y2; - } - - public boolean overlaps(RiverBounds other) { - if (minX > other.maxX || maxX < other.minX) { - return false; - } - if (minY > other.maxY || maxY < other.minY) { - return false; - } - return true; - } - - public Vec2f pos(float distance) { - int dx = x2() - x1(); - int dy = y2() - y1(); - return new Vec2f(x1() + dx * distance, y1() + dy * distance); - } - - public static RiverBounds fromNodes(RiverNode p1, RiverNode p2) { - if (p1.type == RiverNode.Type.START) { - return new RiverBounds(p1.x, p1.z, p2.x, p2.z, 300); - } else { - return new RiverBounds(p2.x, p2.z, p1.x, p1.z, 300); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverConfig.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverConfig.java deleted file mode 100644 index 3f9b70e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverConfig.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.river; - -import com.terraforged.core.world.heightmap.Levels; -import me.dags.noise.util.NoiseUtil; - -public class RiverConfig { - - public final boolean main; - public final int bedWidth; - public final int bankWidth; - public final float bedHeight; - public final float minBankHeight; - public final float maxBankHeight; - public final int length2; - public final double fade; - - private RiverConfig(Builder builder) { - main = builder.main; - bedWidth = builder.bedWidth; - bankWidth = builder.bankWidth; - bedHeight = builder.levels.water(-builder.bedDepth); - minBankHeight = builder.levels.water(builder.minBankHeight); - maxBankHeight = builder.levels.water(builder.maxBankHeight); - length2 = builder.length * builder.length; - fade = builder.fade; - } - - private RiverConfig(boolean main, int bedWidth, int bankWidth, float bedHeight, float minBankHeight, float maxBankHeight, int length2, double fade) { - this.main = main; - this.bedWidth = bedWidth; - this.bankWidth = bankWidth; - this.bedHeight = bedHeight; - this.minBankHeight = minBankHeight; - this.maxBankHeight = maxBankHeight; - this.length2 = length2; - this.fade = fade; - } - - public RiverConfig createFork(float connectWidth) { - if (bankWidth < connectWidth) { - return this; - } - - float scale = bankWidth / connectWidth; - return new RiverConfig( - false, - NoiseUtil.round(bedWidth / scale), - NoiseUtil.round(bankWidth / scale), - bedHeight, - minBankHeight, - maxBankHeight, - length2, - fade - ); - } - - public static Builder builder(Levels levels) { - return new Builder(levels); - } - - public static class Builder { - - private boolean main = false; - private int bedWidth = 4; - private int bankWidth = 15; - private int bedDepth = 5; - private int maxBankHeight = 1; - private int minBankHeight = 1; - private int length = 1000; - private double fade = 0.2; - private final Levels levels; - - private Builder(Levels levels) { - this.levels = levels; - } - - public Builder main(boolean value) { - this.main = value; - return this; - } - - public Builder bedWidth(int value) { - this.bedWidth = value; - return this; - } - - public Builder bankWidth(int value) { - this.bankWidth = value; - return this; - } - - public Builder bedDepth(int depth) { - this.bedDepth = depth; - return this; - } - - public Builder bankHeight(int min, int max) { - this.minBankHeight = Math.min(min, max); - this.maxBankHeight = Math.max(min, max); - return this; - } - - public Builder length(int value) { - this.length = value; - return this; - } - - public Builder fade(double value) { - this.fade = value; - return this; - } - - public RiverConfig build() { - return new RiverConfig(this); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverNode.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverNode.java deleted file mode 100644 index 52b3952..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverNode.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.river; - -public class RiverNode { - - public final int x; - public final int z; - public final Type type; - - public RiverNode(int x, int z, Type type) { - this.x = x; - this.z = z; - this.type = type; - } - - public static Type getType(float value) { - if (River.validStart(value)) { - return Type.START; - } - if (River.validEnd(value)) { - return Type.END; - } - return Type.NONE; - } - - public enum Type { - NONE { - @Override - public Type opposite() { - return this; - } - }, - START { - @Override - public Type opposite() { - return END; - } - }, - END { - @Override - public Type opposite() { - return START; - } - }, - ; - - public abstract Type opposite(); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverRegion.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverRegion.java deleted file mode 100644 index 585a705..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/rivermap/river/RiverRegion.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.rivermap.river; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.concurrent.ObjectPool; -import com.terraforged.core.util.concurrent.cache.ExpiringEntry; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.heightmap.Heightmap; -import com.terraforged.core.world.rivermap.PosGenerator; -import com.terraforged.core.world.rivermap.RiverMapConfig; -import com.terraforged.core.world.rivermap.lake.Lake; -import com.terraforged.core.world.rivermap.lake.LakeConfig; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; -import me.dags.noise.domain.Domain; -import me.dags.noise.util.NoiseUtil; -import me.dags.noise.util.Vec2f; -import me.dags.noise.util.Vec2i; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.concurrent.TimeUnit; - -public class RiverRegion implements ExpiringEntry { - - public static final int SCALE = 12; - private static final double MIN_FORK_ANGLE = 20D; - private static final double MAX_FORK_ANGLE = 60D; - private static final long EXPIRE_TIME = TimeUnit.SECONDS.toMillis(60); - - private final Domain domain; - private final Terrains terrains; - private final LakeConfig lake; - private final RiverConfig primary; - private final RiverConfig secondary; - private final RiverConfig tertiary; - - private final List rivers; - private final List lakes = new LinkedList<>(); - - private final int primaryLimit; - private final int secondaryLimit; - private final int secondaryRelaxedLimit; - private final int forkLimit; - private final int tertiaryLimit; - private final int primaryAttempts; - private final int secondaryAttempts; - private final int secondaryRelaxedAttempts; - private final int forkAttempts; - private final int tertiaryAttempts; - - private final long timestamp = System.currentTimeMillis() + EXPIRE_TIME; - - public RiverRegion(int regionX, int regionZ, Heightmap heightmap, GeneratorContext context, RiverMapConfig riverMapConfig) { - int seed = new Random(NoiseUtil.seed(regionX, regionZ)).nextInt(); - this.lake = riverMapConfig.lakes; - this.primary = riverMapConfig.primary; - this.secondary = riverMapConfig.secondary; - this.tertiary = riverMapConfig.tertiary; - this.terrains = context.terrain; - this.domain = Domain.warp(seed, 400, 1, 400) - .add(Domain.warp(seed + 1, 80, 1, 35)); - - this.primaryLimit = NoiseUtil.round(10 * riverMapConfig.frequency); - this.secondaryLimit = NoiseUtil.round(20 * riverMapConfig.frequency); - this.secondaryRelaxedLimit = NoiseUtil.round(30 * riverMapConfig.frequency); - this.forkLimit = NoiseUtil.round(40 * riverMapConfig.frequency); - this.tertiaryLimit = NoiseUtil.round(50 * riverMapConfig.frequency); - - this.primaryAttempts = NoiseUtil.round(100 * riverMapConfig.frequency); - this.secondaryAttempts = NoiseUtil.round(100 * riverMapConfig.frequency); - this.secondaryRelaxedAttempts = NoiseUtil.round(50 * riverMapConfig.frequency); - this.forkAttempts = NoiseUtil.round(75 * riverMapConfig.frequency); - this.tertiaryAttempts = NoiseUtil.round(50 * riverMapConfig.frequency); - - try (ObjectPool.Item> cell = Cell.pooled()) { - PosGenerator pos = new PosGenerator(heightmap, domain, cell.getValue(),1 << SCALE, River.VALLEY_WIDTH); - this.rivers = generate(regionX, regionZ, pos); - } - } - - @Override - public long getTimestamp() { - return timestamp; - } - - public void apply(Cell cell, float x, float z) { - float px = domain.getX(x, z); - float pz = domain.getY(x, z); - for (River river : rivers) { - river.apply(cell, px, pz); - } - for (Lake lake : lakes) { - lake.apply(cell, px, pz); - } - } - - private List generate(int regionX, int regionZ, PosGenerator pos) { - int x = regionToBlock(regionX); - int z = regionToBlock(regionZ); - long regionSeed = NoiseUtil.seed(regionX, regionZ); - - Random random = new Random(regionSeed); - List rivers = new LinkedList<>(); - - for (int i = 0; rivers.size() < primaryLimit && i < primaryAttempts; i++) { - generateRiver(x, z, pos, primary, random, rivers); - } - - for (int i = 0; rivers.size() < secondaryLimit && i < secondaryAttempts; i++) { - generateRiver(x, z, pos, secondary, random, rivers); - } - - for (int i = 0; rivers.size() < secondaryRelaxedLimit && i < secondaryRelaxedAttempts; i++) { - generateRiverRelaxed(x, z, pos, secondary, random, rivers); - } - - for (int i = 0; rivers.size() < forkLimit && i < forkAttempts; i++) { - generateRiverFork(x, z, pos, tertiary, random, rivers); - } - - for (int i = 0; rivers.size() < tertiaryLimit && i < tertiaryAttempts; i++) { - generateRiver(x, z, pos, tertiary, random, rivers); - } - - Collections.reverse(rivers); - - return rivers; - } - - /** - * Attempts to generate a line that starts inland and reaches the ocean - */ - private boolean generateRiver(int x, int z, PosGenerator pos, RiverConfig config, Random random, List rivers) { - // generate either a river start or end node - RiverNode p1 = pos.next(x, z, random, 50); - if (p1 == null) { - return false; - } - - // generate a node with a min distance from p1 and that has the opposite node type to p1 - RiverNode p2 = pos.nextFrom(x, z, random,50, p1, config.length2); - if (p2 == null) { - return false; - } - - // avoid collisions with existing rivers - RiverBounds bounds = RiverBounds.fromNodes(p1, p2); - for (River river : rivers) { - if (bounds.overlaps(river.bounds)) { - return false; - } - } - - generateLake(bounds, random); - - return rivers.add(new River(bounds, config, terrains, config.fade, 0)); - } - - /** - * Attempts to generate an inland position (p1), finds the nearest river (AB) to it, and tries to connect - * a line from p1 to some position along AB - */ - private boolean generateRiverFork(int x, int z, PosGenerator pos, RiverConfig config, Random random, List rivers) { - // generate a river start node - RiverNode p1 = pos.nextType(x, z, random, 50, RiverNode.Type.START); - if (p1 == null) { - return false; - } - - // find closest river - River closest = null; - float startDist2 = Integer.MAX_VALUE; - for (River river : rivers) { - float d2 = dist2(p1.x, p1.z, river.bounds.x1(), river.bounds.y1()); - if (d2 < startDist2) { - startDist2 = d2; - closest = river; - } - } - - // no close rivers - if (closest == null) { - return false; - } - - // connection should occur no less than 20% along the river length and no greater than 40% - float distance = 0.3F + (random.nextFloat() * 0.3F); - Vec2i fork = closest.bounds.pos(distance).toInt(); - - // connection should not occur in the ocean - float height = pos.getHeight(fork.x, fork.y); - RiverNode.Type type = RiverNode.getType(height); - if (type == RiverNode.Type.END) { - return false; - } - - // calc angle between vector a (AB) & b (CB) - // A - existing river's start - // B - connection point - // C - new river's start - int ax = fork.x - closest.bounds.x1(); - int az = fork.y - closest.bounds.y1(); - int bx = fork.x - p1.x; - int bz = fork.y - p1.z; - - // radians = arccos(AB.BC / |AB||BC|) - int dotAB = ax * bx + az * bz; - double lenA = Math.sqrt(ax * ax + az * az); - double lenB = Math.sqrt(bx * bx + bz * bz); - double radians = Math.acos(dotAB / (lenA * lenB)); - double angle = Math.toDegrees(radians); - if (angle < MIN_FORK_ANGLE || angle > MAX_FORK_ANGLE) { - return false; - } - - RiverBounds bounds = new RiverBounds(p1.x, p1.z, fork.x, fork.y, 300); - // check that the new river does not clash/overlap any other nearby rivers - for (River river : rivers) { - if (river == closest) { - continue; - } - if (river.bounds.overlaps(bounds)) { - return false; - } - } - - generateLake(bounds, random); - - // scale the connecting river's width down so that it's narrower than the one it's connecting to - float forkWidth = closest.config.bankWidth * distance * 0.6F; - RiverConfig forkConfig = config.createFork(forkWidth); - - return rivers.add(new River(bounds, forkConfig, terrains, forkConfig.fade, 0, true)); - } - - private boolean generateRiverRelaxed(int x, int z, PosGenerator pos, RiverConfig config, Random random, List rivers) { - // generate either a river start or end node - RiverNode p1 = pos.nextRelaxed(x, z, random, 50); - if (p1 == null) { - return false; - } - - // generate a node with a min distance from p1 and that has the opposite node type to p1 - RiverNode p2 = pos.nextFromRelaxed(x, z, random,50, p1, config.length2); - if (p2 == null) { - return false; - } - - // avoid collisions with existing rivers - RiverBounds bounds = RiverBounds.fromNodes(p1, p2); - for (River river : rivers) { - if (bounds.overlaps(river.bounds)) { - return false; - } - } - - generateLake(bounds, random); - - return rivers.add(new River(bounds, config, terrains, config.fade, 0)); - } - - private void generateLake(RiverBounds bounds, Random random) { - if (random.nextFloat() < lake.chance) { - float size = lake.sizeMin + (random.nextFloat() * lake.sizeMax); - float distance = lake.distanceMin + (random.nextFloat() * lake.distanceMax); - Vec2f center = bounds.pos(distance); - lakes.add(new Lake(center, size, lake, terrains)); - } - } - - private static float dist2(float x1, float y1, float x2, float y2) { - float dx = x2 - x1; - float dy = y2 - y1; - return dx * dx + dy * dy; - } - - public static int regionToBlock(int value) { - return value << SCALE; - } - - public static int blockToRegion(int value) { - return value >> SCALE; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/LandForms.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/LandForms.java deleted file mode 100644 index f3bb2fa..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/LandForms.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain; - -import com.terraforged.core.settings.TerrainSettings; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.heightmap.Levels; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.func.EdgeFunc; - -public class LandForms { - - private static final int PLAINS_H = 250; - private static final double PLAINS_V = 0.24; - - public static final int PLATEAU_H = 500; - public static final double PLATEAU_V = 0.475; - - private static final int HILLS_H = 500; - private static final double HILLS1_V = 0.6; - private static final double HILLS2_V = 0.55; - - private static final int MOUNTAINS_H = 410; - private static final double MOUNTAINS_V = 0.7; - - private static final int MOUNTAINS2_H = 400; - private static final double MOUNTAINS2_V = 0.645; - - private final TerrainSettings settings; - private final float terrainHorizontalScale; - private final float terrainVerticalScale; - private final float groundLevel; - private final float seaLevel; - - public LandForms(TerrainSettings settings, Levels levels) { - this.settings = settings; - terrainHorizontalScale = settings.globalHorizontalScale; - terrainVerticalScale = settings.globalVerticalScale; - groundLevel = levels.ground; - seaLevel = levels.water; - } - - public Module deepOcean(int seed) { - Module hills = Source.perlin(++seed, 150, 3) - .scale(seaLevel * 0.7) - .bias(Source.perlin(++seed, 200, 1).scale(seaLevel * 0.2F)); - - Module canyons = Source.perlin(++seed, 150, 4) - .powCurve(0.2) - .invert() - .scale(seaLevel * 0.7) - .bias(Source.perlin(++seed, 170, 1).scale(seaLevel * 0.15F)); - - return Source.perlin(++seed, 500, 1) - .blend(hills, canyons, 0.6, 0.65) - .warp(++seed, 50, 2, 50); - } - - public Module steppe(Seed seed) { - int scaleH = Math.round(PLAINS_H * terrainHorizontalScale * settings.steppe.horizontalScale); - - double erosionAmount = 0.45; - - Module erosion = Source.build(seed.next(), scaleH * 2, 3).lacunarity(3.75).perlin().alpha(erosionAmount); - Module warpX = Source.build(seed.next(), scaleH / 4, 3).lacunarity(3).perlin(); - Module warpY = Source.build(seed.next(), scaleH / 4, 3).lacunarity(3).perlin(); - Module module = Source.perlin(seed.next(), scaleH, 1) - .mult(erosion) - .warp(warpX, warpY, Source.constant(scaleH / 4F)) - .warp(seed.next(), 256, 1, 200); - - return settings.steppe.apply(groundLevel, 0.125 * terrainVerticalScale, module); - } - - public Module plains(Seed seed) { - int scaleH = Math.round(PLAINS_H * terrainHorizontalScale * settings.plains.horizontalScale); - - double erosionAmount = 0.45; - - Module erosion = Source.build(seed.next(), scaleH * 2, 3).lacunarity(3.75).perlin().alpha(erosionAmount); - Module warpX = Source.build(seed.next(), scaleH / 4, 3).lacunarity(3.5).perlin(); - Module warpY = Source.build(seed.next(), scaleH / 4, 3).lacunarity(3.5).perlin(); - - Module module = Source.perlin(seed.next(), scaleH, 1) - .mult(erosion) - .warp(warpX, warpY, Source.constant(scaleH / 4F)) - .warp(seed.next(), 256, 1, 256); - - return settings.plains.apply(groundLevel, PLAINS_V * terrainVerticalScale, module); - } - - public Module plateau(Seed seed) { - Module valley = Source.ridge(seed.next(), 500, 1).invert() - .warp(seed.next(), 100, 1, 150) - .warp(seed.next(), 20, 1, 15); - - Module top = Source.build(seed.next(), 150, 3).lacunarity(2.45).ridge() - .warp(seed.next(), 300, 1, 150) - .warp(seed.next(), 40, 2, 20) - .scale(0.15) - .mult(valley.clamp(0.02, 0.1).map(0, 1)); - - Module surface = Source.perlin(seed.next(), 20, 3).scale(0.05) - .warp(seed.next(), 40, 2, 20); - - return settings.plateau.apply(groundLevel, PLATEAU_V * terrainVerticalScale, - valley - .mult(Source.cubic(seed.next(), 500, 1).scale(0.6).bias(0.3)) - .add(top) - .terrace( - Source.perlin(seed.next(), 20, 1).scale(0.3).bias(0.2), - Source.perlin(seed.next(), 20, 2).scale(0.1).bias(0.2), - 4, - 0.4 - ) - .add(surface)); - } - - public Module hills1(Seed seed) { - return settings.hills.apply(groundLevel, HILLS1_V * terrainVerticalScale, Source.perlin(seed.next(), 200, 3) - .mult(Source.billow(seed.next(), 400, 3).alpha(0.5)) - .warp(seed.next(), 30, 3, 20) - .warp(seed.next(), 400, 3, 200)); - } - - public Module hills2(Seed seed) { - return settings.hills.apply(groundLevel, HILLS2_V * terrainVerticalScale, Source.cubic(seed.next(), 128, 2) - .mult(Source.perlin(seed.next(), 32, 4).alpha(0.075)) - .warp(seed.next(), 30, 3, 20) - .warp(seed.next(), 400, 3, 200) - .mult(Source.ridge(seed.next(), 512, 2).alpha(0.8))); - } - - public Module dales(Seed seed) { - Module hills1 = Source.build(seed.next(), 300, 4).gain(0.8).lacunarity(4).billow().powCurve(0.5).scale(0.75); - Module hills2 = Source.build(seed.next(), 350, 3).gain(0.8).lacunarity(4).billow().pow(1.25); - Module combined = Source.perlin(seed.next(), 400, 1).clamp(0.3, 0.6).map(0, 1).blend( - hills1, - hills2, - 0.4, - 0.75 - ); - Module hills = combined - .pow(1.125) - .warp(seed.next(), 300, 1, 100); - - return settings.dales.apply(groundLevel, 0.4, hills); - } - - public Module mountains(Seed seed) { - int scaleH = Math.round(MOUNTAINS_H * terrainHorizontalScale * settings.mountains.horizontalScale); - - Module module = Source.build(seed.next(), scaleH, 4).gain(1.15).lacunarity(2.35).ridge() - .mult(Source.perlin(seed.next(), 24, 4).alpha(0.075)) - .warp(seed.next(), 350, 1, 150); - - return settings.mountains.apply(groundLevel, MOUNTAINS_V * terrainVerticalScale, module); - } - - public Module mountains2(Seed seed) { - double scale = MOUNTAINS2_V * terrainVerticalScale; - Module cell = Source.cellEdge(seed.next(), 360, EdgeFunc.DISTANCE_2).scale(1.2).clamp(0, 1) - .warp(seed.next(), 200, 2, 100); - Module blur = Source.perlin(seed.next(), 10, 1).alpha(0.025); - Module surface = Source.ridge(seed.next(), 125, 4).alpha(0.37); - Module mountains = cell.clamp(0, 1).mult(blur).mult(surface).pow(1.1); - return settings.mountains.apply(groundLevel, scale, mountains); - } - - public Module mountains3(Seed seed) { - double scale = MOUNTAINS2_V * terrainVerticalScale; - - Module cell = Source.cellEdge(seed.next(), MOUNTAINS2_H, EdgeFunc.DISTANCE_2).scale(1.2).clamp(0, 1) - .warp(seed.next(), 200, 2, 100); - Module blur = Source.perlin(seed.next(), 10, 1).alpha(0.025); - Module surface = Source.ridge(seed.next(), 125, 4).alpha(0.37); - Module mountains = cell.clamp(0, 1).mult(blur).mult(surface).pow(1.1); - - Module terraced = mountains.terrace( - Source.perlin(seed.next(), 50, 1).scale(0.5), - Source.perlin(seed.next(), 100, 1).clamp(0.5, 0.95).map(0, 1), - Source.constant(0.45), - 0.2F, - 0.45F, - 24, - 1 - ); - - return settings.mountains.apply(groundLevel, scale, terraced); - } - - public Module badlands(Seed seed) { - Module mask = Source.perlin(seed.next(), 800, 1).clamp(0.35, 0.65).map(0, 1); - Module hills = Source.ridge(seed.next(), 500, 4) - .warp(seed.next(), 400, 2, 100) - .mult(mask); - - double modulation = 0.4; - double alpha = 1 - modulation; - Module mod1 = hills.warp(seed.next(), 100, 1, 50).scale(modulation); - - Module lowFreq = hills.steps(4).scale(alpha).add(mod1); - Module highFreq = hills.steps(10).scale(alpha).add(mod1); - Module detail = lowFreq.add(highFreq); - - Module mod2 = hills.mult(Source.perlin(seed.next(), 400, 3).scale(modulation)); - Module shape = hills.terrace(0.1, 1, 4, 0.01) - .scale(alpha) - .add(mod2) - .scale(alpha); - - return settings.badlands.apply(groundLevel, 0.7, shape.mult(detail.alpha(0.5))); - } - - public Module torridonian(Seed seed) { - Module plains = Source.perlin(seed.next(), 100, 3) - .warp(seed.next(), 300, 1, 150) - .warp(seed.next(), 20, 1, 40) - .scale(0.15); - - Module hills = Source.perlin(seed.next(), 150, 4) - .warp(seed.next(), 300, 1, 200) - .warp(seed.next(), 20, 2, 20) - .boost(); - - Module test = Source.perlin(seed.next(), 200, 3) - .blend(plains, hills, 0.6, 0.6) - .terrace( - Source.perlin(seed.next(), 120, 1).scale(0.25), - Source.perlin(seed.next(), 200, 1).scale(0.5).bias(0.5), - Source.constant(0.5), - 0, - 0.3, - 6, - 1 - ).boost(); - - return settings.torridonian.apply(groundLevel, 0.5, test); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/Terrain.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/Terrain.java deleted file mode 100644 index fb1d3e5..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/Terrain.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain; - -import com.terraforged.core.cell.Tag; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.world.heightmap.Levels; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; - -public class Terrain implements Tag { - - private static final AtomicInteger MAX_ID = new AtomicInteger(0); - private static final Map register = Collections.synchronizedMap(new HashMap<>()); - - public static final int ID_START = 10; - public static final Terrain NONE = new Terrain("none", -1); - - private final String name; - private final int id; - private final float weight; - - public Terrain(String name, int id) { - this(name, id, 1F); - } - - public Terrain(String name, int id, double weight) { - this.name = name; - this.id = id; - this.weight = (float) weight; - register.put(name, this); - MAX_ID.set(Math.max(MAX_ID.get(), id)); - } - - public int getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - public float getMax(float noise) { - return 1F; - } - - public float getWeight() { - return weight; - } - - public float getHue() { - return id / (float) MAX_ID.get(); - } - - @Override - public String toString() { - return getName(); - } - - public static Terrain ocean(Settings settings) { - return new Terrain("ocean", 0) { - - private final float max = new Levels(settings.generator).water; - - @Override - public float getMax(float noise) { - return max; - } - }; - } - - public static Terrain deepOcean(Settings settings) { - return new Terrain("deep_ocean", 1) { - - private final float max = new Levels(settings.generator).water / 2F; - - @Override - public float getMax(float noise) { - return max; - } - }; - } - - public static Terrain coast(Settings settings) { - return new Terrain("coast", 2) { - - private final float max = new Levels(settings.generator).ground(1); - - @Override - public float getMax(float noise) { - return max + (noise * (1 / 255F)); - } - }; - } - - public static Terrain beach(Settings settings) { - return new Terrain("beach", 2) { - - private final float max = new Levels(settings.generator).ground(1); - - @Override - public float getMax(float noise) { - return max + (noise * (1 / 255F)); - } - }; - } - - public static Terrain lake(Settings settings) { - return new Terrain("lake", 3); - } - - public static Terrain river(Settings settings) { - return new Terrain("river", 3); - } - - public static Terrain riverBank(Settings settings) { - return new Terrain("river_banks", 4); - } - - public static Terrain wetlands(Settings settings) { - return new Terrain("wetlands", 5); - } - - public static Terrain steppe(Settings settings) { - return new Terrain("steppe", 6, settings.terrain.steppe.weight); - } - - public static Terrain plains(Settings settings) { - return new Terrain("plains", 7, settings.terrain.plains.weight); - } - - public static Terrain plateau(Settings settings) { - return new Terrain("plateau", 8, settings.terrain.plateau.weight); - } - - public static Terrain badlands(Settings settings) { - return new Terrain("badlands", 9, settings.terrain.badlands.weight); - } - - public static Terrain hills(Settings settings) { - return new Terrain("hills", 10, settings.terrain.hills.weight); - } - - public static Terrain dales(Settings settings) { - return new Terrain("dales", 11, settings.terrain.dales.weight); - } - - public static Terrain torridonian(Settings settings) { - return new Terrain("torridonian_fells", 12, settings.terrain.torridonian.weight); - } - - public static Terrain mountains(Settings settings) { - return new Terrain("mountains", 13, settings.terrain.mountains.weight); - } - - public static Terrain volcano(Settings settings) { - return new Terrain("volcano", 14, settings.terrain.volcano.weight); - } - - public static Terrain volcanoPipe(Settings settings) { - return new Terrain("volcano_pipe", 15, settings.terrain.volcano.weight); - } - - public static Optional get(String name) { - return Optional.ofNullable(register.get(name)); - } - - public static List getRegistered() { - return new ArrayList<>(register.values()); - } -} 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 deleted file mode 100644 index 3d7db53..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/TerrainPopulator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import me.dags.noise.Module; - -public class TerrainPopulator implements Populator { - - private final Terrain type; - private final Module source; - - public TerrainPopulator(Module source, Terrain type) { - this.type = type; - this.source = clamp(source); - } - - public Module getSource() { - return source; - } - - public Terrain getType() { - return type; - } - - @Override - public void apply(Cell cell, float x, float z) { - cell.value = source.getValue(x, z); - cell.tag = type; - } - - @Override - public void tag(Cell cell, float x, float y) { - cell.tag = type; - } - - public static Module clamp(Module module) { - if (module.minValue() < 0 || module.maxValue() > 1) { - return module.clamp(0, 1); - } - return module; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/Terrains.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/Terrains.java deleted file mode 100644 index 3198969..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/Terrains.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain; - -import com.terraforged.core.settings.Settings; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class Terrains { - - public final Terrain ocean; - public final Terrain deepOcean; - public final Terrain coast; - public final Terrain beach; - public final Terrain lake; - public final Terrain river; - public final Terrain riverBanks; - public final Terrain wetlands; - public final Terrain badlands; - public final Terrain steppe; - public final Terrain plains; - public final Terrain plateau; - public final Terrain hills; - public final Terrain dales; - public final Terrain torridonian; - public final Terrain mountains; - public final Terrain volcano; - public final Terrain volcanoPipe; - public final List index; - - private Terrains(Mutable mutable) { - List index = new ArrayList<>(); - Collections.addAll( - index, - ocean = mutable.ocean, - deepOcean = mutable.deepOcean, - coast = mutable.coast, - beach = mutable.beach, - lake = mutable.lake, - river = mutable.river, - torridonian = mutable.torridonian, - riverBanks = mutable.riverbanks, - wetlands = mutable.wetlands, - badlands = mutable.badlands, - plateau = mutable.plateau, - steppe = mutable.steppe, - plains = mutable.plains, - hills = mutable.hills, - dales = mutable.dales, - mountains = mutable.mountains, - volcano = mutable.volcanoes, - volcanoPipe = mutable.volcanoPipe - ); - this.index = Collections.unmodifiableList(index); - } - - public int getId(Terrain landForm) { - return landForm.getId(); - } - - public boolean overridesRiver(Terrain terrain) { - return isOcean(terrain) || terrain == coast; - } - - public boolean isOcean(Terrain terrain) { - return terrain == ocean || terrain == deepOcean; - } - - public boolean isRiver(Terrain terrain) { - return terrain == river || terrain == riverBanks; - } - - public static Terrains create(Settings settings) { - Mutable terrain = new Mutable(); - terrain.ocean = Terrain.ocean(settings); - terrain.deepOcean = Terrain.deepOcean(settings); - terrain.coast = Terrain.coast(settings); - terrain.beach = Terrain.beach(settings); - terrain.lake = Terrain.lake(settings); - terrain.river = Terrain.river(settings); - terrain.riverbanks = Terrain.riverBank(settings); - terrain.wetlands = Terrain.wetlands(settings); - terrain.badlands = Terrain.badlands(settings); - terrain.plateau = Terrain.plateau(settings); - terrain.steppe = Terrain.steppe(settings); - terrain.plains = Terrain.plains(settings); - terrain.hills = Terrain.hills(settings); - terrain.dales = Terrain.dales(settings); - terrain.torridonian = Terrain.torridonian(settings); - terrain.mountains = Terrain.mountains(settings); - terrain.volcanoes = Terrain.volcano(settings); - terrain.volcanoPipe = Terrain.volcanoPipe(settings); - return terrain.create(); - } - - public static final class Mutable { - public Terrain ocean = Terrain.NONE; - public Terrain deepOcean = Terrain.NONE; - public Terrain coast = Terrain.NONE; - public Terrain beach = Terrain.NONE; - public Terrain lake = Terrain.NONE; - public Terrain river = Terrain.NONE; - public Terrain riverbanks = Terrain.NONE; - public Terrain wetlands = Terrain.NONE; - public Terrain badlands = Terrain.NONE; - public Terrain plateau = Terrain.NONE; - public Terrain steppe = Terrain.NONE; - public Terrain plains = Terrain.NONE; - public Terrain hills = Terrain.NONE; - public Terrain dales = Terrain.NONE; - public Terrain torridonian = Terrain.NONE; - public Terrain mountains = Terrain.NONE; - public Terrain volcanoes = Terrain.NONE; - public Terrain volcanoPipe = Terrain.NONE; - public Terrains create() { - return new Terrains(this); - } - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/VolcanoPopulator.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/VolcanoPopulator.java deleted file mode 100644 index 82a93e7..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/VolcanoPopulator.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.heightmap.RegionConfig; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.func.EdgeFunc; - -public class VolcanoPopulator extends TerrainPopulator { - - private static final float throat_value = 0.925F; - - private final Module cone; - private final Module height; - private final Module lowlands; - private final float inversionPoint; - private final float blendLower; - private final float blendUpper; - private final float blendRange; - private final float bias; - - private final Terrain inner; - private final Terrain outer; - - public VolcanoPopulator(Seed seed, RegionConfig region, Levels levels, Terrains terrains) { - super(Source.ZERO, terrains.volcano); - float midpoint = 0.3F; - float range = 0.3F; - - Module heightNoise = Source.perlin(seed.next(), 2, 1).map(0.45, 0.65); - - this.height = Source.cellNoise(region.seed, region.scale, heightNoise) - .warp(region.warpX, region.warpZ, region.warpStrength); - - this.cone = Source.cellEdge(region.seed, region.scale, EdgeFunc.DISTANCE_2_DIV).invert() - .warp(region.warpX, region.warpZ, region.warpStrength) - .powCurve(11) - .clamp(0.475, 1) - .map(0, 1) - .grad(0, 0.5, 0.5) - .warp(seed.next(), 15, 2, 10) - .scale(height); - - this.lowlands = Source.ridge(seed.next(), 150, 3) - .warp(seed.next(), 30, 1, 30) - .scale(0.1); - - this.inversionPoint = 0.94F; - this.blendLower = midpoint - (range / 2F); - this.blendUpper = blendLower + range; - this.blendRange = blendUpper - blendLower; - this.outer = terrains.volcano; - this.inner = terrains.volcanoPipe; - this.bias = levels.ground; - } - - @Override - public void apply(Cell cell, float x, float z) { - float value = cone.getValue(x, z); - float limit = height.getValue(x, z); - float maxHeight = limit * inversionPoint; - - // as value passes the inversion point we start calculating the inner-cone of the volcano - if (value > maxHeight) { - // modifies the steepness of the volcano inner-cone (larger == steeper) - float steepnessModifier = 1F; - - // as alpha approaches 1.0, position is closer to center of volcano - float delta = (value - maxHeight) * steepnessModifier; - float range = (limit - maxHeight); - float alpha = delta / range; - - // calculate height inside volcano - if (alpha > throat_value) { - cell.tag = inner; - } - - value = maxHeight - ((maxHeight / 5F) * alpha); - } else if (value < blendLower) { - value += lowlands.getValue(x, z); - cell.tag = outer; - } else if (value < blendUpper) { - float alpha = 1 - ((value - blendLower) / blendRange); - value += (lowlands.getValue(x, z) * alpha); - cell.tag = outer; - } - - cell.value = bias + value; - } - - @Override - public void tag(Cell cell, float x, float z) { - float value = cone.getValue(x, z); - float limit = height.getValue(x, z); - float maxHeight = limit * inversionPoint; - if (value > maxHeight) { - float steepnessModifier = 1; - - // as alpha approaches 1.0, position is closer to center of volcano - float delta = (value - maxHeight) * steepnessModifier; - float range = (limit - maxHeight); - float alpha = delta / range; - - // calculate height inside volcano - if (alpha > throat_value) { - cell.tag = inner; - } else { - cell.tag = outer; - } - } else { - cell.tag = outer; - } - } -} 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 deleted file mode 100644 index 64419c1..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain.provider; - -import com.terraforged.core.cell.Populator; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.heightmap.RegionConfig; -import com.terraforged.core.world.terrain.LandForms; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.TerrainPopulator; -import com.terraforged.core.world.terrain.VolcanoPopulator; -import me.dags.noise.Module; -import me.dags.noise.Source; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; - -public class StandardTerrainProvider implements TerrainProvider { - - private final List mixable = new ArrayList<>(); - private final List unmixable = new ArrayList<>(); - private final Map populators = new HashMap<>(); - - private final LandForms landForms; - private final RegionConfig config; - private final GeneratorContext context; - private final Populator defaultPopulator; - - public StandardTerrainProvider(GeneratorContext context, RegionConfig config, Populator defaultPopulator) { - this.config = config; - this.context = context; - this.landForms = new LandForms(context.settings.terrain, context.levels); - this.defaultPopulator = defaultPopulator; - init(); - } - - public void init() { - registerMixable(context.terrain.steppe, landForms.steppe(context.seed)); - registerMixable(context.terrain.plains, landForms.plains(context.seed)); - registerMixable(context.terrain.hills, landForms.hills1(context.seed)); - registerMixable(context.terrain.hills, landForms.hills2(context.seed)); - registerMixable(context.terrain.dales, landForms.dales(context.seed)); - registerMixable(context.terrain.badlands, landForms.badlands(context.seed)); - registerMixable(context.terrain.plateau, landForms.plateau(context.seed)); - registerMixable(context.terrain.torridonian, landForms.torridonian(context.seed)); - - registerUnMixable(new VolcanoPopulator(context.seed, config, context.levels, context.terrain)); - registerUnMixable(context.terrain.badlands, landForms.badlands(context.seed)); - registerUnMixable(context.terrain.mountains, landForms.mountains2(context.seed)); - registerUnMixable(context.terrain.mountains, landForms.mountains3(context.seed)); - } - - @Override - public void registerMixable(TerrainPopulator populator) { - populators.putIfAbsent(populator.getType(), populator); - mixable.add(populator); - } - - @Override - public void registerUnMixable(TerrainPopulator populator) { - populators.putIfAbsent(populator.getType(), populator); - unmixable.add(populator); - } - - @Override - public Populator getPopulator(Terrain terrain) { - return populators.getOrDefault(terrain, defaultPopulator); - } - - @Override - public LandForms getLandforms() { - return landForms; - } - - @Override - public List getPopulators() { - List mixed = combine(getMixable(mixable), this::combine); - List result = new ArrayList<>(mixed.size() + unmixable.size()); - result.addAll(mixed); - result.addAll(unmixable); - return result; - } - - protected GeneratorContext getContext() { - return context; - } - - private TerrainPopulator combine(TerrainPopulator tp1, TerrainPopulator tp2) { - return combine(tp1, tp2, context.seed, config.scale / 2); - } - - private static TerrainPopulator combine(TerrainPopulator tp1, TerrainPopulator tp2, Seed seed, int scale) { - 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(); - - 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) - .clamp(0, 1); - - return new TerrainPopulator(combined, type); - } - - private static List combine(List input, BiFunction operator) { - int length = input.size(); - for (int i = 1; i < input.size(); i++) { - length += (input.size() - i); - } - - List result = new ArrayList<>(length); - for (int i = 0; i < length; i++) { - result.add(null); - } - - for (int i = 0, k = input.size(); i < input.size(); i++) { - T t1 = input.get(i); - result.set(i, t1); - for (int j = i + 1; j < input.size(); j++, k++) { - T t2 = input.get(j); - T t3 = operator.apply(t1, t2); - result.set(k, t3); - } - } - - 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/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java deleted file mode 100644 index 58131e6..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain.provider; - -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.terrain.LandForms; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.TerrainPopulator; -import me.dags.noise.Module; - -import java.util.List; - -/** - * Provides the heightmap generator with terrain specific noise generation modules (TerrainPopulators) - */ -public interface TerrainProvider { - - LandForms getLandforms(); - - /** - * Returns the resulting set of TerrainPopulators - */ - List getPopulators(); - - /** - * Returns a populator for the provided Terrain, or the default if not registered - */ - Populator getPopulator(Terrain terrain); - - /** - * Add a TerrainPopulator to world generation. - * - * 'Mixable' TerrainPopulators are used to create additional terrain types, created by blending two - * different mixable TerrainPopulators together (this is in addition to the unmixed version of the populator) - */ - void registerMixable(TerrainPopulator populator); - - /** - * Add a TerrainPopulator to world generation - * - * 'UnMixable' TerrainPopulators are NOT blended together to create additional terrain types - */ - void registerUnMixable(TerrainPopulator populator); - - /** - * Add a TerrainPopulator to world generation. - * - * 'Mixable' TerrainPopulators are used to create additional terrain types, created by blending two - * different mixable TerrainPopulators together (this is in addition to the unmixed version of the populator) - */ - default void registerMixable(Terrain type, Module source) { - registerMixable(new TerrainPopulator(source, type)); - } - - /** - * Add a TerrainPopulator to world generation - * - * 'UnMixable' TerrainPopulators are NOT blended together to create additional terrain types - */ - default void registerUnMixable(Terrain type, Module source) { - registerUnMixable(new TerrainPopulator(source, type)); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProviderFactory.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProviderFactory.java deleted file mode 100644 index 4ff2842..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProviderFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain.provider; - -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.heightmap.RegionConfig; - -public interface TerrainProviderFactory { - - TerrainProvider create(GeneratorContext context, RegionConfig config, Populator defaultPopulator); -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionLerper.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionLerper.java deleted file mode 100644 index 5055e5b..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionLerper.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain.region; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.util.NoiseUtil; - -public class RegionLerper implements Populator { - - private final Populator lower; - private final Populator upper; - - public RegionLerper(Populator lower, Populator upper) { - this.lower = lower; - this.upper = upper; - } - - @Override - public void apply(Cell cell, float x, float y) { - float alpha = cell.regionEdge; - if (alpha == 0) { - lower.apply(cell, x, y); - return; - } - - if (alpha == 1) { - upper.apply(cell, x, y); - return; - } - - lower.apply(cell, x, y); - float lowerValue = cell.value; - - upper.apply(cell, x, y); - float upperValue = cell.value; - - cell.value = NoiseUtil.lerp(lowerValue, upperValue, alpha); - } - - @Override - public void tag(Cell cell, float x, float y) { - if (cell.regionEdge == 0) { - lower.tag(cell, x, y); - return; - } - upper.tag(cell, x, y); - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionModule.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionModule.java deleted file mode 100644 index 739823e..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionModule.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain.region; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.heightmap.RegionConfig; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Source; -import me.dags.noise.domain.Domain; -import me.dags.noise.func.DistanceFunc; -import me.dags.noise.func.EdgeFunc; -import me.dags.noise.util.NoiseUtil; -import me.dags.noise.util.Vec2f; - -public class RegionModule implements Populator { - - private final int seed; - private final float frequency; - - private final float edgeMin; - private final float edgeMax; - private final float edgeRange; - private final Domain warp; - - public RegionModule(RegionConfig regionConfig) { - seed = regionConfig.seed; - edgeMin = 0F; - edgeMax = 0.5F; - edgeRange = edgeMax - edgeMin; - frequency = 1F / regionConfig.scale; - warp = Domain.warp(regionConfig.warpX, regionConfig.warpZ, Source.constant(regionConfig.warpStrength)); - } - - @Override - public void apply(Cell cell, float x, float y) { - float ox = warp.getOffsetX(x, y); - float oz = warp.getOffsetY(x, y); - - float px = x + ox; - float py = y + oz; - - px *= frequency; - py *= frequency; - - int cellX = 0; - int cellY = 0; - - int xr = NoiseUtil.round(px); - int yr = NoiseUtil.round(py); - float edgeDistance = 999999.0F; - float edgeDistance2 = 999999.0F; - float valueDistance = 3.4028235E38F; - DistanceFunc dist = DistanceFunc.NATURAL; - - for (int dy = -1; dy <= 1; dy++) { - for (int dx = -1; dx <= 1; dx++) { - int xi = xr + dx; - int yi = yr + dy; - Vec2f vec = NoiseUtil.CELL_2D[NoiseUtil.hash2D(seed, xi, yi) & 255]; - - float vecX = xi - px + vec.x; - float vecY = yi - py + vec.y; - float distance = dist.apply(vecX, vecY); - - if (distance < valueDistance) { - valueDistance = distance; - cellX = xi; - cellY = yi; - } - - if (distance < edgeDistance2) { - edgeDistance2 = Math.max(edgeDistance, distance); - } else { - edgeDistance2 = Math.max(edgeDistance, edgeDistance2); - } - - edgeDistance = Math.min(edgeDistance, distance); - } - } - - cell.region = cellValue(seed, cellX, cellY); - cell.regionEdge = edgeValue(edgeDistance, edgeDistance2); - } - - @Override - public void tag(Cell cell, float x, float y) { - - } - - private float cellValue(int seed, int cellX, int cellY) { - float value = NoiseUtil.valCoord2D(seed, cellX, cellY); - return NoiseUtil.map(value, -1, 1, 2); - } - - private float edgeValue(float distance, float distance2) { - EdgeFunc edge = EdgeFunc.DISTANCE_2_DIV; - float value = edge.apply(distance, distance2); - float edgeValue = 1 - NoiseUtil.map(value, edge.min(), edge.max(), edge.range()); - - edgeValue = NoiseUtil.pow(edgeValue, 1.5F); - - if (edgeValue < edgeMin) { - return 0F; - } - if (edgeValue > edgeMax) { - return 1F; - } - - return (edgeValue - edgeMin) / edgeRange; - } -} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionSelector.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionSelector.java deleted file mode 100644 index d967663..0000000 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/region/RegionSelector.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.core.world.terrain.region; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.TerrainPopulator; -import me.dags.noise.util.NoiseUtil; - -import java.util.LinkedList; -import java.util.List; - -public class RegionSelector implements Populator { - - private final int maxIndex; - private final Populator[] nodes; - - public RegionSelector(List populators) { - this.nodes = getWeightedArray(populators); - this.maxIndex = nodes.length - 1; - } - - @Override - public void apply(Cell cell, float x, float y) { - get(cell.region).apply(cell, x, y); - } - - @Override - public void tag(Cell cell, float x, float y) { - get(cell.region).tag(cell, x, y); - } - - public Populator get(float identity) { - int index = NoiseUtil.round(identity * maxIndex); - return nodes[index]; - } - - private static Populator[] getWeightedArray(List modules) { - float smallest = Float.MAX_VALUE; - for (Populator p : modules) { - if (p instanceof TerrainPopulator) { - TerrainPopulator tp = (TerrainPopulator) p; - if (tp.getType().getWeight() == 0F) { - continue; - } - smallest = Math.min(smallest, tp.getType().getWeight()); - } else { - smallest = Math.min(smallest, 1); - } - } - - if (smallest == Float.MAX_VALUE) { - return modules.toArray(new Populator[0]); - } - - List result = new LinkedList<>(); - for (Populator p : modules) { - int count; - if (p instanceof TerrainPopulator) { - TerrainPopulator tp = (TerrainPopulator) p; - if (tp.getType().getWeight() == 0F) { - continue; - } - count = Math.round(tp.getType().getWeight() / smallest); - } else { - count = Math.round(1 / smallest); - } - while (count-- > 0) { - result.add(p); - } - } - - if (result.isEmpty()) { - return modules.toArray(new Populator[0]); - } - - return result.toArray(new Populator[0]); - } -} diff --git a/TerraForgedCore/src/main/resources/biomes.png b/TerraForgedCore/src/main/resources/biomes.png deleted file mode 100644 index 131a9bf..0000000 Binary files a/TerraForgedCore/src/main/resources/biomes.png and /dev/null differ diff --git a/TerraForgedCore/src/main/resources/biomes.txt b/TerraForgedCore/src/main/resources/biomes.txt deleted file mode 100644 index 9622c92..0000000 --- a/TerraForgedCore/src/main/resources/biomes.txt +++ /dev/null @@ -1,13 +0,0 @@ -#TerraForgedCore BiomeType Hex Colors (do not include hash/pound character) -#Fri Jan 10 23:15:10 GMT 2020 -ALPINE=a078aa -TAIGA=5b8f52 -TEMPERATE_RAINFOREST=0aa041 -TUNDRA=93a7ac -TROPICAL_RAINFOREST=075330 -SAVANNA=97a527 -GRASSLAND=64dc3c -TEMPERATE_FOREST=32c850 -STEPPE=c8c878 -DESERT=c87137 -COLD_STEPPE=afb496 \ No newline at end of file diff --git a/TerraForgedCore/src/main/resources/license.txt b/TerraForgedCore/src/main/resources/license.txt deleted file mode 100644 index 0b31935..0000000 --- a/TerraForgedCore/src/main/resources/license.txt +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 TerraForged - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/TerraForgedCore/src/main/resources/terraforged.png b/TerraForgedCore/src/main/resources/terraforged.png deleted file mode 100644 index ecedcf8..0000000 Binary files a/TerraForgedCore/src/main/resources/terraforged.png and /dev/null differ diff --git a/TerraForgedMod/README.md b/TerraForgedMod/README.md deleted file mode 100644 index 7f0dcfb..0000000 --- a/TerraForgedMod/README.md +++ /dev/null @@ -1,56 +0,0 @@ -![TerraForged Social](https://terraforged.com/curse/header.jpg) - -#### About: -TerraForged is an ambitious new terrain generator mod for Minecraft (Java Edition) attempting to - create more immersive, inspiring worlds to explore and build in. Featuring an overhaul of the - vanilla generation system, custom terrain shapes, simulated erosion, better rivers, custom - decorations, tonnes of configuration options, and more! - -#### Website(s): -[https://terraforged.com](https://terraforged.com) -[https://github.com/TerraForged](https://github.com/TerraForged) -[https://curseforge.com/../TerraForged](https://www.curseforge.com/minecraft/mc-mods/terraforged) - -#### Installation: -1. Install forge for the target version of Minecraft (ie 1.15.2) -2. Add the TerraForged mod jar to your profile's mods folder -3. Select the '`TerraForged`' world-type when creating a new world - -#### Features: -- Varied and immersive terrain -- Erosion and improved rivers -- Custom features and decoration -- Extensive configuration options & in-game GUI - -![TerraForged Gallery](https://terraforged.com/curse/gallery.jpg) - -#### FAQ: -1) "Is this compatible with mod xyz?" -_Probably! (to some degree) - TerraForged is designed to work with many of the same world-gen systems -that the majority of block & biome providing mods use. Certain biomes' terrain may not always look -exactly as their author designed but should otherwise be compatible. Feel free to report any other -compatibility issues on the issue tracker._ - -2) "How can I use this on my server?" -_When Forge supports it, you can simply set level-type=terraforged in your server.properties file. In -the meantime, you will need to create the world in single player and then copy that to your server -directory. (In both cases, TerraForged must be installed on the client and the server)._ - -3) "Will I need a super-computer to run this?!" -_No, not really - while this world generator will be a bit slower than vanilla's (on account of it -doing more work to make things look nice), it would only be apparent when first generating a chunk - -they might load in slower when moving to new parts of the world, but game performance should -otherwise be normal. A 4-core CPU should be able to handle this just fine._ - -4) "Can this be ported Fabric/Bukkit/Spigot/Sponge?" -_If someone would like to take this task on, yes - a large part of the TerraForged codebase is already -platform independent. There are certain client-side features in the forge-mod that would not translate -onto server-only APIs, but the core experience could certainly be ported. I don't intend to work on -this directly but others are very welcome._ - -5) "Will this be back-ported to older Forge versions?" -_Not by myself, no - My aim is to keep current with Forge. I'm simply not prolific enough a modder to -write and maintain for multiple versions (hats off to those who do!). Again though, others are welcome -to back-port it, if inclined to do so._ - -[View more questions on Github](https://github.com/TerraForged/TerraForged/issues?q=label:question) \ No newline at end of file diff --git a/TerraForgedMod/build.gradle b/TerraForgedMod/build.gradle deleted file mode 100644 index b165533..0000000 --- a/TerraForgedMod/build.gradle +++ /dev/null @@ -1,103 +0,0 @@ -buildscript { - repositories { - jcenter() - mavenCentral() - maven { url "https://files.minecraftforge.net/maven" } - } - dependencies { - classpath group: "net.minecraftforge.gradle", name: "ForgeGradle", version: "3.+", changing: true - } -} - -apply plugin: "net.minecraftforge.gradle" -apply plugin: "maven-publish" -apply plugin: "eclipse" - -version = "${mc_version}-${mod_version}${getClassifier()}" -archivesBaseName = "TerraForged" - -repositories { - jcenter() - mavenCentral() -} - -dependencies { - minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" - compile project(":Noise2D") - compile(project(":TerraForgedCore")) { transitive false } - compile(project(":FeatureManager")) { transitive false } - compile(project(":TerraForgedAPI")) { transitive false } -} - -minecraft { - mappings channel: mcp_channel, version: mcp_version - runs { - client { - workingDirectory project.file("run/client") - property "forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP" - property "forge.logging.console.level", "debug" - jvmArgs "-Xmx8G", "-Xms6G", "-Ddev" - mods { - terraforged { - source sourceSets.main - } - } - } - server { - workingDirectory project.file("run/server") - property "forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP" - property "forge.logging.console.level", "debug" - jvmArgs "-Xmx8G", "-Xms6G", "-Ddev" - mods { - terraforged { - source sourceSets.main - } - } - } - } -} - -task collectClasses(type: Copy) { - configurations.collectMany { it.allDependencies }.findAll { it instanceof ProjectDependency }.each { - ProjectDependency project = (ProjectDependency) it - from("$project.dependencyProject.buildDir/classes/java/main") - } - into("build/classes/java/main") -} - -task collectResources(type: Copy) { - configurations.collectMany { it.allDependencies }.findAll { it instanceof ProjectDependency }.each { - ProjectDependency project = (ProjectDependency) it - from("$project.dependencyProject.buildDir/resources/main") - } - into("build/resources/main") -} - -processResources { - dependsOn(collectResources) - filesMatching("**/mods.toml") { - expand( - "version": "${mod_version}${getClassifier()}", - "mc_version": mc_version - ) - } -} - -classes { - dependsOn(collectClasses) -} - -publish { - dependsOn("reobfJar") -} - -static def getClassifier() { - if (System.getenv("GIT_TAG_NAME") != null) { - return "" - } - def buildNumber = System.getenv("BUILD_NUMBER") - if (buildNumber != null) { - return "-${buildNumber}" - } - return "" -} \ No newline at end of file diff --git a/TerraForgedMod/gradlew b/TerraForgedMod/gradlew deleted file mode 100644 index cccdd3d..0000000 --- a/TerraForgedMod/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/TerraForgedMod/gradlew.bat b/TerraForgedMod/gradlew.bat deleted file mode 100644 index f955316..0000000 --- a/TerraForgedMod/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/TerraForgedMod/psd/biomes.psd b/TerraForgedMod/psd/biomes.psd deleted file mode 100644 index eedc297..0000000 Binary files a/TerraForgedMod/psd/biomes.psd and /dev/null differ diff --git a/TerraForgedMod/psd/icon.png b/TerraForgedMod/psd/icon.png deleted file mode 100644 index ecedcf8..0000000 Binary files a/TerraForgedMod/psd/icon.png and /dev/null differ diff --git a/TerraForgedMod/psd/terraforged.psd b/TerraForgedMod/psd/terraforged.psd deleted file mode 100644 index 8034e6d..0000000 Binary files a/TerraForgedMod/psd/terraforged.psd and /dev/null differ diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/AbstractBiomeMap.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/AbstractBiomeMap.java deleted file mode 100644 index aa6bb9a..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/AbstractBiomeMap.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.map; - -import com.google.common.collect.Sets; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.mod.biome.ModBiomes; -import com.terraforged.mod.biome.provider.BiomeHelper; -import me.dags.noise.util.NoiseUtil; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.Biomes; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public abstract class AbstractBiomeMap implements BiomeMap { - - private final Biome[][] beach; - private final Biome[][] river; - private final Biome[][] wetland; - private final Biome[][] ocean; - private final Biome[][] deepOcean; - - protected final DefaultBiome defaultLand = this::defaultBiome; - protected final DefaultBiome defaultBeach = this::defaultBeach; - protected final DefaultBiome defaultRiver = this::defaultRiver; - protected final DefaultBiome defaultWetland = this::defaultWetland; - protected final DefaultBiome defaultOcean = this::defaultOcean; - protected final DefaultBiome defaultDeepOcean = this::defaultDeepOcean; - - protected AbstractBiomeMap(BiomeMapBuilder builder) { - river = builder.rivers(); - beach = builder.beaches(); - ocean = builder.oceans(); - wetland = builder.wetlands(); - deepOcean = builder.deepOceans(); - } - - @Override - public Biome getBeach(float temperature, float moisture, float shape) { - return get(beach, getCategory(temperature), shape, temperature, defaultBeach); - } - - @Override - public Biome getRiver(float temperature, float moisture, float shape) { - return get(river, getCategory(temperature), shape, temperature, defaultRiver); - } - - @Override - public Biome getWetland(float temperature, float moisture, float shape) { - return get(wetland, getCategory(temperature), shape, temperature, defaultWetland); - } - - @Override - public Biome getOcean(float temperature, float moisture, float shape) { - return get(ocean, getCategory(temperature), shape, temperature, defaultOcean); - } - - @Override - public Biome getDeepOcean(float temperature, float moisture, float shape) { - return get(deepOcean, getCategory(temperature), shape, temperature, defaultDeepOcean); - } - - @Override - public Set getOceanBiomes(Biome.TempCategory temp) { - return Sets.newHashSet(ocean[temp.ordinal() - 1]); - } - - @Override - public Set getDeepOceanBiomes(Biome.TempCategory temp) { - return Sets.newHashSet(deepOcean[temp.ordinal() - 1]); - } - - @Override - public Set getRivers(Biome.TempCategory temp) { - return Sets.newHashSet(river[temp.ordinal() - 1]); - } - - @Override - public JsonObject toJson() { - JsonObject root = new JsonObject(); - root.add("rivers", collect(river)); - root.add("wetland", collect(wetland)); - root.add("beaches", collect(beach)); - root.add("oceans", collect(ocean)); - root.add("deepOceans", collect(deepOcean)); - return root; - } - - private JsonObject collect(Biome[][] biomes) { - JsonObject root = new JsonObject(); - for (Biome.TempCategory temp : Biome.TempCategory.values()) { - if (temp == Biome.TempCategory.OCEAN) { - continue; - } - JsonArray array = new JsonArray(); - Biome[] group = biomes[temp.ordinal() - 1]; - if (group != null) { - Set set = new HashSet<>(); - Collections.addAll(set, group); - set.stream().map(BiomeHelper::getId).sorted().forEach(array::add); - } - root.add(temp.name(), array); - } - return root; - } - - - protected Biome.TempCategory getCategory(float value) { - if (value < 0.25) { - return Biome.TempCategory.COLD; - } - if (value > 0.75) { - return Biome.TempCategory.WARM; - } - return Biome.TempCategory.MEDIUM; - } - - protected Biome defaultBeach(float temperature) { - if (temperature < 0.25) { - return Biomes.SNOWY_BEACH; - } - if (temperature > 0.75) { - return ModBiomes.WARM_BEACH; - } - return Biomes.BEACH; - } - - protected Biome defaultRiver(float temperature) { - if (temperature < 0.15) { - return Biomes.FROZEN_RIVER; - } - return Biomes.RIVER; - } - - protected Biome defaultWetland(float temperature) { - if (temperature < 0.15) { - return ModBiomes.TAIGA_SCRUB; - } - return ModBiomes.MARSHLAND; - } - - protected Biome defaultOcean(float temperature) { - if (temperature < 0.3) { - return Biomes.FROZEN_OCEAN; - } - if (temperature > 0.7) { - return Biomes.WARM_OCEAN; - } - return Biomes.OCEAN; - } - - protected Biome defaultDeepOcean(float temperature) { - if (temperature < 0.3) { - return Biomes.DEEP_FROZEN_OCEAN; - } - if (temperature > 0.7) { - return Biomes.DEEP_WARM_OCEAN; - } - return Biomes.DEEP_OCEAN; - } - - protected Biome defaultBiome(float temperature) { - if (temperature < 0.3) { - return ModBiomes.TAIGA_SCRUB; - } - if (temperature > 0.7) { - return ModBiomes.SAVANNA_SCRUB; - } - return Biomes.PLAINS; - } - - protected Biome get(Biome[][] group, Biome.TempCategory category, float shape, float temp, DefaultBiome def) { - return get(group, category.ordinal() - 1, shape, temp, def); - } - - protected Biome get(Biome[][] group, BiomeType type, float shape, float temp, DefaultBiome def) { - return get(group, type.ordinal(), shape, temp, def); - } - - protected Biome get(Biome[][] group, int ordinal, float shape, float temp, DefaultBiome def) { - if (ordinal >= group.length) { - return def.getDefaultBiome(temp); - } - - Biome[] biomes = group[ordinal]; - if (biomes == null || biomes.length == 0) { - return def.getDefaultBiome(temp); - } - - int index = NoiseUtil.round((biomes.length - 1) * shape); - return biomes[index]; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BasicBiomeMap.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BasicBiomeMap.java deleted file mode 100644 index 37f62e8..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BasicBiomeMap.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.map; - -import com.google.common.collect.Sets; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.mod.biome.provider.BiomeHelper; -import net.minecraft.world.biome.Biome; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -public class BasicBiomeMap extends AbstractBiomeMap { - - private final Biome[][] biomeTypes; - - public BasicBiomeMap(BiomeMapBuilder builder) { - super(builder); - biomeTypes = builder.biomeList(); - } - - @Override - public List getAllBiomes(BiomeType type) { - if (type.ordinal() >= biomeTypes.length) { - return Collections.emptyList(); - } - return Arrays.asList(biomeTypes[type.ordinal()]); - } - - @Override - public Set getBiomes(BiomeType type) { - if (type.ordinal() >= biomeTypes.length) { - return Collections.emptySet(); - } - return Sets.newHashSet(biomeTypes[type.ordinal()]); - } - - @Override - public Biome getBiome(BiomeType type, float temperature, float moisture, float shape) { - return get(biomeTypes, type, shape, temperature, defaultLand); - } - - @Override - public JsonObject toJson() { - JsonObject groups = new JsonObject(); - for (BiomeType type : BiomeType.values()) { - JsonArray group = new JsonArray(); - getBiomes(type).stream().map(BiomeHelper::getId).sorted().forEach(group::add); - groups.add(type.name(), group); - } - JsonObject root = super.toJson(); - root.add("biomes", groups); - return root; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeGroup.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeGroup.java deleted file mode 100644 index 98fd7cc..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeGroup.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.map; - -import com.terraforged.core.util.grid.FixedGrid; -import net.minecraft.world.biome.Biome; - -public class BiomeGroup { - - public final FixedGrid biomes; - - public BiomeGroup(FixedGrid biomes) { - this.biomes = biomes; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeMapBuilder.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeMapBuilder.java deleted file mode 100644 index c4c2ee5..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeMapBuilder.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.map; - -import com.terraforged.core.util.grid.FixedGrid; -import com.terraforged.core.world.biome.BiomeData; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.mod.biome.provider.BiomeHelper; -import com.terraforged.mod.util.ListUtils; -import net.minecraft.world.biome.Biome; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; - -public class BiomeMapBuilder implements BiomeMap.Builder { - - private final Map> rivers = new HashMap<>(); - private final Map> wetlands = new HashMap<>(); - private final Map> beaches = new HashMap<>(); - private final Map> oceans = new HashMap<>(); - private final Map> deepOceans = new HashMap<>(); - private final Map> map = new EnumMap<>(BiomeType.class); - private final Map dataMap = new HashMap<>(); - - private final int gridSize; - private final Function constructor; - - BiomeMapBuilder(Function constructor, int gridSize, List biomes) { - this.constructor = constructor; - this.gridSize = gridSize; - - for (BiomeData data : biomes) { - dataMap.put((Biome) data.reference, data); - } - } - - @Override - public BiomeMapBuilder addOcean(Biome biome, int count) { - Biome.TempCategory category = BiomeHelper.getTempCategory(biome); - if (biome.getDepth() < -1) { - add(deepOceans.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); - } else { - add(oceans.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); - } - return this; - } - - @Override - public BiomeMap.Builder addBeach(Biome biome, int count) { - Biome.TempCategory category = BiomeHelper.getTempCategory(biome); - add(beaches.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); - return this; - } - - @Override - public BiomeMapBuilder addRiver(Biome biome, int count) { - Biome.TempCategory category = BiomeHelper.getTempCategory(biome); - add(rivers.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); - return this; - } - - @Override - public BiomeMapBuilder addWetland(Biome biome, int count) { - Biome.TempCategory category = BiomeHelper.getTempCategory(biome); - add(wetlands.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); - return this; - } - - @Override - public BiomeMapBuilder addBiome(BiomeType type, Biome biome, int count) { - add(map.computeIfAbsent(type, t -> new ArrayList<>()), biome, count); - return this; - } - - @Override - public BiomeMap build() { - return constructor.apply(this); - } - - Biome[][] rivers() { - return collectTemps(rivers); - } - - Biome[][] wetlands() { - return collectTemps(wetlands); - } - - Biome[][] beaches() { - return collectTemps(beaches); - } - - Biome[][] oceans() { - return collectTemps(oceans); - } - - Biome[][] deepOceans() { - return collectTemps(deepOceans); - } - - Biome[][] biomeList() { - return collectTypes(map); - } - - BiomeGroup[] biomeGroups() { - BiomeGroup[] biomes = new BiomeGroup[BiomeType.values().length]; - - Function moisture = b -> dataMap.get(b).rainfall; - Function temperature = b -> dataMap.get(b).temperature; - for (BiomeType type : BiomeType.values()) { - List list = map.getOrDefault(type, Collections.emptyList()); - if (list.isEmpty()) { - continue; - } - FixedGrid grid = FixedGrid.generate(gridSize, list, moisture, temperature); - biomes[type.ordinal()] = new BiomeGroup(grid); - } - - return biomes; - } - - private void add(List list, Biome biome, int count) { - for (int i = 0; i < count; i++) { - list.add(biome); - } - } - - private Biome[][] collectTemps(Map> map) { - Biome[][] biomes = new Biome[3][]; - for (Biome.TempCategory category : Biome.TempCategory.values()) { - if (category == Biome.TempCategory.OCEAN) { - continue; - } - List list = map.getOrDefault(category, Collections.emptyList()); - list = ListUtils.minimize(list); - list.sort(Comparator.comparing(BiomeHelper::getId)); - biomes[category.ordinal() - 1] = list.toArray(new Biome[0]); - } - return biomes; - } - - private Biome[][] collectTypes(Map> map) { - Biome[][] biomes = new Biome[BiomeType.values().length][]; - for (BiomeType type : BiomeType.values()) { - List list = map.getOrDefault(type, Collections.emptyList()); - list = ListUtils.minimize(list); - list.sort(Comparator.comparing(BiomeHelper::getId)); - biomes[type.ordinal()] = list.toArray(new Biome[0]); - } - return biomes; - } - - public static BiomeMap.Builder basic(List biomes) { - return new BiomeMapBuilder(BasicBiomeMap::new, 0, biomes); - } - - public static BiomeMap.Builder grid(int size, List biomes) { - return new BiomeMapBuilder(GridBiomeMap::new, size, biomes); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/GridBiomeMap.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/GridBiomeMap.java deleted file mode 100644 index eb0a02f..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/GridBiomeMap.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.map; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.terraforged.core.util.grid.FixedList; -import com.terraforged.core.util.grid.MappedList; -import com.terraforged.core.world.biome.BiomeType; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.Biomes; - -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -public class GridBiomeMap extends AbstractBiomeMap { - - private final BiomeGroup[] biomeTypes; - - GridBiomeMap(BiomeMapBuilder builder) { - super(builder); - biomeTypes = builder.biomeGroups(); - } - - @Override - public Biome getBiome(BiomeType type, float temperature, float moisture, float shape) { - BiomeGroup group = biomeTypes[type.ordinal()]; - if (group == null) { - return Biomes.NETHER; - } - return group.biomes.get(moisture, temperature, shape); - } - - @Override - public List getAllBiomes(BiomeType type) { - BiomeGroup group = biomeTypes[type.ordinal()]; - if (group == null) { - return Collections.emptyList(); - } - List biomes = new LinkedList<>(); - for (MappedList> row : group.biomes) { - for (FixedList cell : row) { - for (Biome biome : cell) { - biomes.add(biome); - } - } - } - return biomes; - } - - @Override - public Set getBiomes(BiomeType type) { - BiomeGroup group = biomeTypes[type.ordinal()]; - if (group == null) { - return Collections.emptySet(); - } - Set biomes = new HashSet<>(); - for (MappedList> row : group.biomes) { - for (FixedList cell : row) { - for (Biome biome : cell) { - biomes.add(biome); - } - } - } - return biomes; - } - - @Override - public JsonObject toJson() { - JsonObject root = new JsonObject(); - for (BiomeType type : BiomeType.values()) { - BiomeGroup group = biomeTypes[type.ordinal()]; - JsonObject grid = new JsonObject(); - if (group != null) { - int rowCount = 0; - float maxRow = group.biomes.size() - 1; - for (MappedList> row : group.biomes) { - int colCount = 0; - float maxCol = row.size() - 1; - - JsonObject rowJson = new JsonObject(); - for (FixedList cell : row) { - JsonArray colJson = new JsonArray(); - for (Biome biome : cell.uniqueValues()) { - colJson.add(biome.getRegistryName() + ""); - } - float colId = colCount / maxCol; - rowJson.add("" + colId, colJson); - colCount++; - } - - float rowId = rowCount / maxRow; - grid.add("" + rowId, rowJson); - rowCount++; - } - } - root.add(type.name(), grid); - } - return root; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java deleted file mode 100644 index bd5279b..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.modifier; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.mod.material.MaterialHelper; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.Biomes; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Set; -import java.util.stream.Collectors; - -// prevents deserts forming at high levels -public class SandBiomeModifier extends AbstractMaxHeightModifier { - - private final Set biomes; - - public SandBiomeModifier(Seed seed, Climate climate, Levels levels) { - super(seed, climate, 50, 2, levels.scale(8), levels.ground(5), levels.ground(25)); - this.biomes = ForgeRegistries.BIOMES.getValues().stream() - .filter(biome -> MaterialHelper.isSand(biome.getSurfaceBuilderConfig().getTop().getBlock())) - .collect(Collectors.toSet()); - } - - @Override - public int priority() { - return 1; - } - - @Override - public boolean test(Biome biome) { - return biome.getCategory() == Biome.Category.DESERT || biomes.contains(biome); - } - - @Override - protected Biome getModifiedBiome(Biome in, Cell cell, int x, int z, float ox, float oz) { - return Biomes.BADLANDS; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java deleted file mode 100644 index 99cb204..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/AbstractBiomeProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.provider; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.biome.Biome; -import net.minecraftforge.common.BiomeDictionary; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.stream.Collectors; - -public abstract class AbstractBiomeProvider extends net.minecraft.world.biome.provider.BiomeProvider { - - public AbstractBiomeProvider() { - super(getOverworldBiomes()); - } - - public Set getAvailableBiomes() { - return super.field_226837_c_; - } - - @Override - public final Set func_225530_a_(int x, int y, int z, int size) { - return getBiomesInSquare(x, y, z, size); - } - - @Override - public final BlockPos func_225531_a_(int centerX, int centerY, int centerZ, int range, List biomes, Random random) { - return findBiomePosition(centerX, centerY, centerZ, range, biomes, random); - } - - public abstract Set getBiomesInSquare(int x, int y, int z, int size); - - public abstract BlockPos findBiomePosition(int centerX, int centerY, int centerZ, int range, List biomes, Random random); - - private static Set getOverworldBiomes() { - return ForgeRegistries.BIOMES.getValues().stream() - .map(biome -> biome.delegate.get()) - .filter(biome -> BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.OVERWORLD)) - .collect(Collectors.toSet()); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/TerraBiomeRegistry.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/TerraBiomeRegistry.java deleted file mode 100644 index 68219be..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/TerraBiomeRegistry.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.biome.provider; - -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.Biome; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; - -public class TerraBiomeRegistry { - - private static final TerraBiomeRegistry instance = new TerraBiomeRegistry(); - - public Optional getBiome(ResourceLocation name) { - if (ForgeRegistries.BIOMES.containsKey(name)) { - return Optional.ofNullable(ForgeRegistries.BIOMES.getValue(name)); - } - return Optional.empty(); - } - - public Collection getAll(Predicate filter) { - List combined = new LinkedList<>(ForgeRegistries.BIOMES.getValues()); - combined.removeIf(filter); - return combined; - } - - public static TerraBiomeRegistry getInstance() { - return instance; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/spawn/SpawnHandler.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/spawn/SpawnHandler.java deleted file mode 100644 index 188dca9..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/spawn/SpawnHandler.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.terraforged.mod.biome.spawn; - -import com.terraforged.mod.Log; -import com.terraforged.mod.biome.provider.BiomeProvider; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.gen.feature.ConfiguredFeature; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.IFeatureConfig; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) -public class SpawnHandler { - - @SubscribeEvent - public static void createSpawn(WorldEvent.CreateSpawnPosition event) { - if (event.getWorld() instanceof ServerWorld) { - ServerWorld world =(ServerWorld) event.getWorld(); - if (world.getChunkProvider().getChunkGenerator().getBiomeProvider() instanceof BiomeProvider) { - Log.info("Searching for world spawn position"); - BiomeProvider provider = (BiomeProvider) world.getChunkProvider().getChunkGenerator().getBiomeProvider(); - SpawnSearch search = new SpawnSearch(BlockPos.ZERO, provider); - BlockPos spawn = search.get(); - - Log.info("Setting world spawn: {}", spawn); - event.setCanceled(true); - event.getWorld().getWorldInfo().setSpawn(spawn); - - if (event.getSettings().isBonusChestEnabled()) { - Log.info("Generating bonus chest"); - createBonusChest(world, spawn); - } - } - } - } - - private static void createBonusChest(ServerWorld world, BlockPos pos) { - ConfiguredFeature chest = Feature.BONUS_CHEST.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG); - chest.place(world, world.getChunkProvider().getChunkGenerator(), world.rand, pos); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ChunkProcessor.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ChunkProcessor.java deleted file mode 100644 index e9df107..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ChunkProcessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.terraforged.mod.chunk; - -import com.terraforged.api.chunk.column.DecoratorContext; -import com.terraforged.core.region.chunk.ChunkReader; -import net.minecraft.util.math.ChunkPos; - -public interface ChunkProcessor { - - void preProcess(ChunkPos pos, ChunkReader chunk, TerraContainer container); - - void postProcess(ChunkReader chunk, TerraContainer container, DecoratorContext context); -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ObfHelperChunkGenerator.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ObfHelperChunkGenerator.java deleted file mode 100644 index 5c9843c..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ObfHelperChunkGenerator.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.chunk; - -import com.terraforged.mod.chunk.fix.SpawnFix; -import com.terraforged.mod.util.annotation.Name; -import com.terraforged.mod.util.annotation.Ref; -import net.minecraft.entity.EntityClassification; -import net.minecraft.util.SharedSeedRandom; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.provider.BiomeProvider; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.GenerationSettings; -import net.minecraft.world.gen.Heightmap; -import net.minecraft.world.gen.INoiseGenerator; -import net.minecraft.world.gen.NoiseChunkGenerator; -import net.minecraft.world.gen.OverworldChunkGenerator; -import net.minecraft.world.gen.PerlinNoiseGenerator; -import net.minecraft.world.gen.WorldGenRegion; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.CatSpawner; -import net.minecraft.world.spawner.PatrolSpawner; -import net.minecraft.world.spawner.PhantomSpawner; -import net.minecraft.world.spawner.WorldEntitySpawner; - -import java.util.List; - -@Ref({OverworldChunkGenerator.class, NoiseChunkGenerator.class, ChunkGenerator.class}) -public abstract class ObfHelperChunkGenerator extends ChunkGenerator { - - private final CatSpawner catSpawner = new CatSpawner(); - private final PatrolSpawner patrolSpawner = new PatrolSpawner(); - private final PhantomSpawner phantomSpawner = new PhantomSpawner(); - private final INoiseGenerator surfaceNoise; - - public ObfHelperChunkGenerator(IWorld world, BiomeProvider biomeProvider, T settings) { - super(world, biomeProvider, settings); - SharedSeedRandom random = new SharedSeedRandom(world.getSeed()); - this.surfaceNoise = new PerlinNoiseGenerator(random, 3, 0); - } - - @Override - public final void generateStructureStarts(IWorld world, IChunk chunk) { - try { - super.generateStructureStarts(world, chunk); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - @Override - public final void makeBase(IWorld world, IChunk chunk) { - generateBase(world, chunk); - } - - @Override - public final void func_225551_a_(WorldGenRegion world, IChunk chunk) { - generateSurface(world, chunk); - } - - @Override - public final List getPossibleCreatures(EntityClassification type, BlockPos pos) { - if (Feature.SWAMP_HUT.func_202383_b(this.world, pos)) { - if (type == EntityClassification.MONSTER) { - return Feature.SWAMP_HUT.getSpawnList(); - } - - if (type == EntityClassification.CREATURE) { - return Feature.SWAMP_HUT.getCreatureSpawnList(); - } - } else if (type == EntityClassification.MONSTER) { - if (Feature.PILLAGER_OUTPOST.isPositionInStructure(this.world, pos)) { - return Feature.PILLAGER_OUTPOST.getSpawnList(); - } - - if (Feature.OCEAN_MONUMENT.isPositionInStructure(this.world, pos)) { - return Feature.OCEAN_MONUMENT.getSpawnList(); - } - } - return super.getPossibleCreatures(type, pos); - } - - @Override - public final void spawnMobs(WorldGenRegion region) { - // vanilla does NOT check the mobSpawning gamerule before calling this - if (SpawnFix.canSpawnMobs()) { - int chunkX = region.getMainChunkX(); - int chunkZ = region.getMainChunkZ(); - Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0); - SharedSeedRandom sharedseedrandom = new SharedSeedRandom(); - sharedseedrandom.setDecorationSeed(region.getSeed(), chunkX << 4, chunkZ << 4); - WorldEntitySpawner.performWorldGenSpawning(region, biome, chunkX, chunkZ, sharedseedrandom); - } - } - - @Override - public final void spawnMobs(ServerWorld worldIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs) { - // vanilla does check the mobSpawning gamerule before calling this - phantomSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs); - patrolSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs); - catSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs); - } - - @Override - @Name("getSurfaceLevel") - public final int func_222529_a(int x, int z, Heightmap.Type type) { - int level = getTopBlockY(x, z, type) + 1; - if (type == Heightmap.Type.OCEAN_FLOOR || type == Heightmap.Type.OCEAN_FLOOR_WG) { - return level; - } - return Math.max(getSeaLevel(), level); - } - - public final double getSurfaceNoise(int x, int z) { - double scale = 0.0625D; - double noiseX = x * scale; - double noiseZ = z * scale; - double unusedValue1 = scale; - double unusedValue2 = (x & 15) * scale; - return surfaceNoise.noiseAt(noiseX, noiseZ, unusedValue1, unusedValue2); - } - - public abstract int getTopBlockY(int x, int z, Heightmap.Type type); - - public abstract void generateBase(IWorld world, IChunk chunk); - - public abstract void generateSurface(WorldGenRegion world, IChunk chunk); -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java deleted file mode 100644 index 45465db..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java +++ /dev/null @@ -1,407 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.chunk; - -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.chunk.surface.SurfaceContext; -import com.terraforged.api.chunk.surface.SurfaceManager; -import com.terraforged.api.material.layer.LayerManager; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.Size; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.core.region.gen.RegionCache; -import com.terraforged.core.region.gen.RegionGenerator; -import com.terraforged.core.util.concurrent.ThreadPool; -import com.terraforged.core.world.decorator.Decorator; -import com.terraforged.feature.FeatureManager; -import com.terraforged.feature.matcher.dynamic.DynamicMatcher; -import com.terraforged.feature.matcher.feature.FeatureMatcher; -import com.terraforged.feature.modifier.FeatureModifierLoader; -import com.terraforged.feature.modifier.FeatureModifiers; -import com.terraforged.feature.predicate.DeepWater; -import com.terraforged.feature.predicate.FeaturePredicate; -import com.terraforged.feature.predicate.MinDepth; -import com.terraforged.feature.predicate.MinHeight; -import com.terraforged.feature.template.type.FeatureTypes; -import com.terraforged.mod.Log; -import com.terraforged.mod.biome.provider.BiomeProvider; -import com.terraforged.mod.chunk.fix.ChunkCarverFix; -import com.terraforged.mod.chunk.fix.RegionFix; -import com.terraforged.mod.decorator.ChunkPopulator; -import com.terraforged.mod.decorator.base.BedrockDecorator; -import com.terraforged.mod.decorator.base.CoastDecorator; -import com.terraforged.mod.decorator.base.ErosionDecorator; -import com.terraforged.mod.decorator.base.GeologyDecorator; -import com.terraforged.mod.decorator.feature.LayerDecorator; -import com.terraforged.mod.decorator.feature.SnowEroder; -import com.terraforged.mod.decorator.surface.FrozenOcean; -import com.terraforged.mod.feature.Matchers; -import com.terraforged.mod.feature.TerrainHelper; -import com.terraforged.mod.feature.predicate.TreeLine; -import com.terraforged.mod.material.Materials; -import com.terraforged.mod.material.geology.GeoManager; -import com.terraforged.mod.util.Environment; -import com.terraforged.mod.util.setup.SetupHooks; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.IWorld; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.BiomeManager; -import net.minecraft.world.biome.Biomes; -import net.minecraft.world.chunk.ChunkPrimer; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.GenerationSettings; -import net.minecraft.world.gen.GenerationStage; -import net.minecraft.world.gen.Heightmap; -import net.minecraft.world.gen.WorldGenRegion; -import net.minecraft.world.gen.feature.AbstractTreeFeature; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.template.TemplateManager; - -import java.util.ArrayList; -import java.util.List; - -public class TerraChunkGenerator extends ObfHelperChunkGenerator implements ChunkProcessor { - - private final TerraContext context; - private final BiomeProvider biomeProvider; - private final TerrainHelper terrainHelper; - - private final GeoManager geologyManager; - private final FeatureManager featureManager; - private final SurfaceManager surfaceManager; - private final List baseDecorators; - private final List postProcessors; - - private final RegionCache regionCache; - - public TerraChunkGenerator(TerraContext context, BiomeProvider biomeProvider, GenerationSettings settings) { - super(context.world, biomeProvider, settings); - this.context = context; - this.biomeProvider = biomeProvider; - this.surfaceManager = SetupHooks.setup(createSurfaceManager(), context.copy()); - this.geologyManager = SetupHooks.setup(createGeologyManager(context), context.copy()); - this.baseDecorators = createBaseDecorators(context); - this.postProcessors = createFeatureDecorators(context); - this.terrainHelper = new TerrainHelper(0.75F); - this.featureManager = createFeatureManager(context); - this.regionCache = createRegionCache(context); - SetupHooks.setup(getLayerManager(), context.copy()); - SetupHooks.setup(baseDecorators, postProcessors, context.copy()); - } - - @Override - public void generateStructures(BiomeManager biomes, IChunk chunk, ChunkGenerator generator, TemplateManager templates) { - ChunkPos pos = chunk.getPos(); - int regionX = regionCache.chunkToRegion(pos.x); - int regionZ = regionCache.chunkToRegion(pos.z); - // start generating the heightmap as early as possible - regionCache.queueRegion(regionX, regionZ); - super.generateStructures(biomes, chunk, this, templates); - } - - @Override - public final void generateBiomes(IChunk chunk) { - ChunkPos pos = chunk.getPos(); - ChunkReader reader = getChunkReader(pos.x, pos.z); - TerraContainer container = getBiomeProvider().createBiomeContainer(reader); - ((ChunkPrimer) chunk).func_225548_a_(container); - // apply chunk-local heightmap modifications - preProcess(pos, reader, container); - } - - @Override - public final void preProcess(ChunkPos pos, ChunkReader chunk, TerraContainer container) { - chunk.iterate((cell, dx, dz) -> { - Biome biome = container.getBiome(dx, dz); - for (Decorator decorator : getBiomeProvider().getDecorators(biome)) { - if (decorator.apply(cell, pos.getXStart() + dx, pos.getZStart() + dz)) { - return; - } - } - }); - } - - @Override - public final void generateBase(IWorld world, IChunk chunk) { - TerraContainer container = getBiomeContainer(chunk); - DecoratorContext context = new DecoratorContext(FastChunk.wrap(chunk), getContext().levels, getContext().terrain, getContext().factory.getClimate()); - container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> { - int px = ctx.blockX + dx; - int pz = ctx.blockZ + dz; - int py = ctx.levels.scale(cell.value); - ctx.cell = cell; - ctx.biome = container.getBiome(dx, dz); - ChunkPopulator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz); - }); - terrainHelper.flatten(world, chunk); - } - - @Override - public final void generateSurface(WorldGenRegion world, IChunk chunk) { - TerraContainer container = getBiomeContainer(chunk); - ChunkSurfaceBuffer buffer = new ChunkSurfaceBuffer(FastChunk.wrap(chunk)); - SurfaceContext context = getContext().surface(buffer, getSettings()); - - container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> { - int px = ctx.blockX + dx; - int pz = ctx.blockZ + dz; - int top = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, dx, dz) + 1; - - ctx.buffer.setSurfaceLevel(top); - - ctx.cell = cell; - ctx.biome = container.getBiome(dx, dz); - ctx.noise = getSurfaceNoise(px, pz) * 15D; - - getSurfaceManager().getSurface(ctx).buildSurface(px, pz, top, ctx); - - int py = ctx.levels.scale(cell.value); - for (ColumnDecorator processor : getBaseDecorators()) { - processor.decorate(ctx.buffer, ctx, px, py, pz); - } - }); - - FastChunk.updateWGHeightmaps(chunk, context.pos); - } - - @Override - public final void func_225550_a_(BiomeManager biomeManager, IChunk chunk, GenerationStage.Carving carving) { - - // World carvers have hardcoded 'carvable' blocks which can be problematic with modded blocks - // AirCarverFix shims the actual blockstates to an equivalent carvable type - super.func_225550_a_(biomeManager, new ChunkCarverFix(chunk, context.materials), carving); - } - - @Override - public void decorate(WorldGenRegion region) { - int chunkX = region.getMainChunkX(); - int chunkZ = region.getMainChunkZ(); - IChunk chunk = region.getChunk(chunkX, chunkZ); - TerraContainer container = getBiomeContainer(chunk); - Biome biome = container.getFeatureBiome(); - DecoratorContext context = getContext().decorator(chunk); - - IWorld regionFix = new RegionFix(region, this); - BlockPos pos = new BlockPos(context.blockX, 0, context.blockZ); - - // place biome features - featureManager.decorate(this, regionFix, chunk, biome, pos); - - // run post processes on chunk - postProcess(container.getChunkReader(), container, context); - - // bake biome array & discard gen data - ((ChunkPrimer) chunk).func_225548_a_(container.bakeBiomes(Environment.isVanillaBiomes())); - - // marks the heightmap data for this chunk for removal - container.getChunkReader().dispose(); - } - - @Override - public final void postProcess(ChunkReader chunk, TerraContainer container, DecoratorContext context) { - chunk.iterate(context, (cell, dx, dz, ctx) -> { - int px = ctx.blockX + dx; - int pz = ctx.blockZ + dz; - int py = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, dx, dz); - ctx.cell = cell; - ctx.biome = container.getBiome(dx, dz); - for (ColumnDecorator decorator : getPostProcessors()) { - decorator.decorate(ctx.chunk, ctx, px, py, pz); - } - }); - } - - @Override - public int getTopBlockY(int x, int z, Heightmap.Type type) { - int chunkX = Size.blockToChunk(x); - int chunkZ = Size.blockToChunk(z); - ChunkReader chunk = getChunkReader(chunkX, chunkZ); - Cell cell = chunk.getCell(x, z); - return context.levels.scale(cell.value); - } - - @Override - public BiomeProvider getBiomeProvider() { - return biomeProvider; - } - - @Override - public final int getMaxHeight() { - return getContext().levels.worldHeight; - } - - @Override - public final int getSeaLevel() { - return getContext().levels.waterLevel; - } - - @Override - public final int getGroundHeight() { - return getContext().levels.groundLevel; - } - - public final TerraContext getContext() { - return context; - } - - public final Materials getMaterials() { - return context.materials; - } - - public final GeoManager getGeologyManager() { - return geologyManager; - } - - public final LayerManager getLayerManager() { - return context.materials.getLayerManager(); - } - - public final SurfaceManager getSurfaceManager() { - return surfaceManager; - } - - public final List getBaseDecorators() { - return baseDecorators; - } - - public final List getPostProcessors() { - return postProcessors; - } - - protected TerraContainer getBiomeContainer(IChunk chunk) { - if (chunk.getBiomes() instanceof TerraContainer) { - return (TerraContainer) chunk.getBiomes(); - } - - ChunkReader view = getChunkReader(chunk.getPos().x, chunk.getPos().z); - TerraContainer container = getBiomeProvider().createBiomeContainer(view); - if (chunk instanceof ChunkPrimer) { - ((ChunkPrimer) chunk).func_225548_a_(container); - } else if (chunk instanceof FastChunk) { - ((FastChunk) chunk).setBiomes(container); - } - - return container; - } - - protected FeatureManager createFeatureManager(TerraContext context) { - FeatureModifiers modifiers; - if (context.terraSettings.features.customBiomeFeatures) { - Log.info(" - Custom biome features enabled"); - modifiers = FeatureModifierLoader.load(); - } else { - modifiers = new FeatureModifiers(); - } - - if (context.terraSettings.features.strataDecorator) { - // block stone blobs if strata enabled - modifiers.getPredicates().add(Matchers.stoneBlobs(), FeaturePredicate.DENY); - } - - if (!context.terraSettings.features.vanillaWaterFeatures) { - // block lakes and springs if not enabled - modifiers.getPredicates().add(FeatureMatcher.of(Feature.LAKE), FeaturePredicate.DENY); - modifiers.getPredicates().add(FeatureMatcher.of(Feature.SPRING_FEATURE), FeaturePredicate.DENY); - } - - // block ugly features - modifiers.getPredicates().add(Matchers.sedimentDisks(), FeaturePredicate.DENY); - - // limit to deep oceans - modifiers.getPredicates().add(FeatureMatcher.of(Feature.SHIPWRECK), MinDepth.DEPTH55); - modifiers.getPredicates().add(FeatureMatcher.of(Feature.OCEAN_RUIN), DeepWater.INSTANCE); - modifiers.getPredicates().add(FeatureMatcher.of(Feature.OCEAN_MONUMENT), DeepWater.INSTANCE); - - // prevent mineshafts above ground - modifiers.getPredicates().add(FeatureMatcher.of(Feature.MINESHAFT), MinHeight.HEIGHT80); - - // prevent trees/bamboo growing too high up - TreeLine treeLine = new TreeLine(context); - modifiers.getPredicates().add(FeatureTypes.TREE.matcher(), treeLine); - modifiers.getPredicates().add(FeatureMatcher.of(Feature.BAMBOO), treeLine); - modifiers.getDynamic().add(DynamicMatcher.feature(AbstractTreeFeature.class), treeLine); - - return FeatureManager.create(context.world, SetupHooks.setup(modifiers, context.copy())); - } - - protected GeoManager createGeologyManager(TerraContext context) { - return new GeoManager(context); - } - - protected SurfaceManager createSurfaceManager() { - SurfaceManager manager = new SurfaceManager(); - manager.replace(Biomes.FROZEN_OCEAN, new FrozenOcean(context, 20, 15)); - manager.replace(Biomes.DEEP_FROZEN_OCEAN, new FrozenOcean(context, 30, 30)); - return manager; - } - - protected List createBaseDecorators(TerraContext context) { - List processors = new ArrayList<>(); - if (context.terraSettings.features.strataDecorator) { - Log.info(" - Geology decorator enabled"); - processors.add(new GeologyDecorator(geologyManager)); - } - - if (context.terraSettings.features.erosionDecorator) { - Log.info(" - Erosion decorator enabled"); - processors.add(new ErosionDecorator(context)); - } - processors.add(new CoastDecorator(context)); - processors.add(new BedrockDecorator(context)); - return processors; - } - - protected List createFeatureDecorators(TerraContext context) { - List processors = new ArrayList<>(); - if (context.terraSettings.features.naturalSnowDecorator) { - Log.info(" - Natural snow decorator enabled"); - processors.add(new SnowEroder(context)); - } - if (context.terraSettings.features.smoothLayerDecorator) { - Log.info(" - Smooth layer decorator enabled"); - processors.add(new LayerDecorator(context.materials.getLayerManager())); - } - return processors; - } - - protected RegionCache createRegionCache(TerraContext context) { - return RegionGenerator.builder() - .legacy(context.terraSettings.version == 0) - .pool(ThreadPool.getPool()) - .factory(context.factory) - .size(3, 2) - .build() - .toCache(false); - } - - public ChunkReader getChunkReader(int chunkX, int chunkZ) { - return regionCache.getChunk(chunkX, chunkZ); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraContainer.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraContainer.java deleted file mode 100644 index b9f0651..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraContainer.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.chunk; - -import com.terraforged.api.biome.BiomeVariant; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.core.util.PosIterator; -import com.terraforged.core.world.terrain.Terrain; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.BiomeContainer; - -// holds a 1:1 map of biomes in the chunk -// also holds the chunk's view on the heightmap for convenience -public class TerraContainer extends BiomeContainer { - - private static final int BITS_WIDTH = (int) Math.round(Math.log(16.0D) / Math.log(2.0D)) - 2; - private static final int ZOOM_VERT = (int) Math.round(Math.log(256.0D) / Math.log(2.0D)) - 2; - public static final int SIZE = 1 << BITS_WIDTH + BITS_WIDTH + ZOOM_VERT; - public static final int MASK_HORIZ = (1 << BITS_WIDTH) - 1; - public static final int MASK_VERT = (1 << ZOOM_VERT) - 1; - - private final Biome[] biomes; - private final Biome[] surface; - private final ChunkReader chunkReader; - - public TerraContainer(Builder builder, ChunkReader chunkReader) { - super(builder.biomes); - this.chunkReader = chunkReader; - this.biomes = builder.biomes; - this.surface = builder.surfaceBiomeCache; - } - - public Biome getBiome(int x, int z) { - return surface[indexOf(x, z)]; - } - - @Override - public Biome getNoiseBiome(int x, int y, int z) { - return super.getNoiseBiome(x, y, z); - } - - public Biome getFeatureBiome() { - PosIterator iterator = PosIterator.area(0, 0, 16, 16); - while (iterator.next()) { - Cell cell = chunkReader.getCell(iterator.x(), iterator.z()); - if (cell.biomeType.isExtreme()) { - return getBiome(iterator.x(), iterator.z()); - } - } - return getBiome(8, 8); - } - - public BiomeContainer bakeBiomes(boolean convertToVanilla) { - if (convertToVanilla) { - Biome[] biomeArray = new Biome[biomes.length]; - for (int i = 0; i < biomes.length; i++) { - Biome biome = biomes[i]; - if (biome instanceof BiomeVariant) { - biome = ((BiomeVariant) biome).getBase(); - } - biomeArray[i] = biome; - } - return new BiomeContainer(biomeArray); - } - return new BiomeContainer(biomes); - } - - public ChunkReader getChunkReader() { - return chunkReader; - } - - private static int indexOf(int x, int z) { - x &= 15; - z &= 15; - return (z << 4) + x; - } - - private static int indexOf(int x, int y, int z) { - x &= MASK_HORIZ; - y = MathHelper.clamp(y, 0, MASK_VERT); - z &= MASK_HORIZ; - return y << BITS_WIDTH + BITS_WIDTH | z << BITS_WIDTH | x; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private final Biome[] biomes = new Biome[SIZE]; - private final Biome[] surfaceBiomeCache = new Biome[256]; - - public void set(int x, int z, Biome biome) { - surfaceBiomeCache[indexOf(x, z)] = biome; - } - - public TerraContainer build(ChunkReader chunkReader) { - // biome storage format is 1 biome pos == 4x4x4 blocks, stored in an 4x64x4 (xyz) array - // sample the 1:1 surfaceBiomeCache every 4 blocks with a 2 block offset (roughly center of the 4x4 area) - for (int dy = 0; dy < 64; dy++) { - for (int dz = 0; dz < 4; dz++) { - for (int dx = 0; dx < 4; dx++) { - int x = dx * 4; - int z = dz * 4; - int index = indexOf(dx, dy, dz); - biomes[index] = surfaceBiomeCache[indexOf(x, z)]; - } - } - } - return new TerraContainer(this, chunkReader); - } - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraGenSettings.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraGenSettings.java deleted file mode 100644 index b2c034a..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraGenSettings.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.chunk; - -import com.terraforged.mod.settings.StructureSettings; -import net.minecraft.world.gen.OverworldGenSettings; - -public class TerraGenSettings extends OverworldGenSettings { - - public TerraGenSettings(StructureSettings settings) { - super.villageDistance *= settings.villageDistance; - super.mansionDistance *= settings.mansionDistance; - super.strongholdDistance *= settings.strongholdDistance; - super.strongholdSpread *= settings.strongholdSpread; - super.biomeFeatureDistance *= settings.biomeStructureDistance; - super.oceanMonumentSpacing *= settings.oceanMonumentSpacing; - super.oceanMonumentSeparation *= settings.oceanMonumentSeparation; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java deleted file mode 100644 index 19e5459..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.terraforged.mod.chunk.fix; - -import net.minecraft.world.GameRules; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -import java.util.concurrent.atomic.AtomicBoolean; - -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) -public class SpawnFix { - - private static final AtomicBoolean MOB_SPAWNING = new AtomicBoolean(); - - @SubscribeEvent - public static void tick(TickEvent.WorldTickEvent event) { - if (event.phase == TickEvent.Phase.START && event.side.isServer()) { - boolean mobSpawning = event.world.getGameRules().get(GameRules.DO_MOB_SPAWNING).get(); - MOB_SPAWNING.set(mobSpawning); - } - } - - public static boolean canSpawnMobs() { - return MOB_SPAWNING.get(); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/TestChunkGenerator.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/TestChunkGenerator.java deleted file mode 100644 index f823aa6..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/TestChunkGenerator.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.chunk.test; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.cell.Populator; -import com.terraforged.core.region.gen.RegionCache; -import com.terraforged.core.region.gen.RegionGenerator; -import com.terraforged.core.util.concurrent.ThreadPool; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.heightmap.WorldHeightmap; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.mod.biome.provider.BiomeProvider; -import com.terraforged.mod.chunk.TerraChunkGenerator; -import com.terraforged.mod.chunk.TerraContext; -import net.minecraft.world.gen.GenerationSettings; - -public class TestChunkGenerator extends TerraChunkGenerator { - - private final BiomeProvider biomeProvider; - - public TestChunkGenerator(TerraContext context, BiomeProvider biomeProvider, GenerationSettings settings) { - super(context, biomeProvider, settings); - this.biomeProvider = new TestBiomeProvider(context); - } - - @Override - protected RegionCache createRegionCache(TerraContext context) { - return RegionGenerator.builder() - .factory(new WorldGeneratorFactory(context, new TestHeightMap(context))) - .pool(ThreadPool.getPool()) - .size(3, 2) - .build() - .toCache(false); - } - - @Override - public BiomeProvider getBiomeProvider() { - return biomeProvider; - } - - private static class TestHeightMap extends WorldHeightmap { - - private final Populator populator; - - public TestHeightMap(GeneratorContext context) { - super(context); - this.populator = getPopulator(Test.getTerrainType(context.terrain)); - } - - @Override - public void apply(Cell cell, float x, float y) { - super.apply(cell, x, y); - populator.apply(cell, x, y); - } - - @Override - public void tag(Cell cell, float x, float y) { - populator.tag(cell, x, y); - } - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/Permissions.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/Permissions.java deleted file mode 100644 index a8a6926..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/Permissions.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.terraforged.mod.command; - -public class Permissions { - - public static final String QUERY = "terraforged.command.terra.query"; - public static final String DEBUG = "terraforged.command.terra.debug"; - public static final String DATA = "terraforged.command.terra.data"; - public static final String DEFAULTS = "terraforged.command.terra.defaults"; - public static final String LOCATE = "terraforged.command.terra.locate"; -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/BiomeSearchTask.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/BiomeSearchTask.java deleted file mode 100644 index 4a83c12..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/BiomeSearchTask.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.terraforged.mod.command.search; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorldReader; -import net.minecraft.world.biome.Biome; - -public class BiomeSearchTask extends Search { - - private final Biome biome; - private final IWorldReader reader; - - public BiomeSearchTask(BlockPos center, IWorldReader reader, Biome biome) { - super(center, 128); - this.reader = reader; - this.biome = biome; - } - - @Override - public int getSpacing() { - return 10; - } - - @Override - public boolean test(BlockPos pos) { - return reader.getNoiseBiomeRaw(pos.getX() >> 2, pos.getY(), pos.getZ() >> 2) == biome; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/TerrainSearchTask.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/TerrainSearchTask.java deleted file mode 100644 index a48e45c..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/TerrainSearchTask.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.terraforged.mod.command.search; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.WorldGenerator; -import com.terraforged.core.world.terrain.Terrain; -import net.minecraft.util.math.BlockPos; - -public class TerrainSearchTask extends Search { - - private final Terrain type; - private final WorldGenerator generator; - private final Cell cell = new Cell<>(); - - public TerrainSearchTask(BlockPos center, WorldGenerator generator, Terrain type) { - super(center, 256); - this.type = type; - this.generator = generator; - } - - @Override - public int getSpacing() { - return 20; - } - - @Override - public boolean test(BlockPos pos) { - generator.getHeightmap().apply(cell, pos.getX(), pos.getZ()); - return cell.tag == type; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenFeatures.java b/TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenFeatures.java deleted file mode 100644 index 4c1d082..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenFeatures.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.data; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mojang.datafixers.Dynamic; -import com.mojang.datafixers.types.JsonOps; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.GenerationStage; -import net.minecraft.world.gen.feature.ConfiguredFeature; -import net.minecraft.world.gen.feature.IFeatureConfig; -import net.minecraft.world.gen.feature.jigsaw.JigsawManager; -import net.minecraft.world.gen.feature.jigsaw.JigsawPattern; -import net.minecraft.world.gen.feature.jigsaw.JigsawPatternRegistry; -import net.minecraft.world.gen.feature.jigsaw.JigsawPiece; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraftforge.registries.ForgeRegistries; - -import java.io.File; -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Random; - -public class WorldGenFeatures extends DataGen { - - public static void genBiomeFeatures(File dataDir) { - if (dataDir.exists() || dataDir.mkdirs()) { - for (Biome biome : ForgeRegistries.BIOMES) { - genBiomeFeatures(dataDir, biome); - genBiomeStructures(dataDir, biome); - } - genBiomeJigsaws(dataDir); - } - } - - private static void genBiomeFeatures(File dir, Biome biome) { - write(new File(dir, getJsonPath("features", biome.getRegistryName())), writer -> { - JsonObject root = new JsonObject(); - for (GenerationStage.Decoration type : GenerationStage.Decoration.values()) { - JsonArray features = new JsonArray(); - for (ConfiguredFeature feature : biome.getFeatures(type)) { - try { - Dynamic dynamic = feature.serialize(JsonOps.INSTANCE); - features.add(dynamic.getValue()); - } catch (NullPointerException e) { - new NullPointerException("Badly written feature: " + feature.feature.getRegistryName()).printStackTrace(); - } - } - root.add(type.getName(), features); - } - write(root, writer); - }); - } - - private static void genBiomeStructures(File dir, Biome biome) { - write(new File(dir, getJsonPath("structures", biome.getRegistryName())), writer -> { - JsonObject root = new JsonObject(); - for (Map.Entry> e : Structure.STRUCTURES.entrySet()) { - JsonArray array = new JsonArray(); - IFeatureConfig config = biome.getStructureConfig(e.getValue()); - if (config == null) { - continue; - } - JsonElement element = config.serialize(JsonOps.INSTANCE).getValue(); - JsonObject object = new JsonObject(); - object.addProperty("structure", e.getValue().getRegistryName() + ""); - object.add("config", element); - array.add(object); - } - write(root, writer); - }); - } - - private static void genBiomeJigsaws(File dir) { - Random random = new Random(); - write(new File(dir, "jigsaws.json"), writer -> { - JsonObject root = new JsonObject(); - for (Map.Entry e : getJigsawRegistry().entrySet()) { - JsonArray array = new JsonArray(); - List pieces = e.getValue().getShuffledPieces(random); - for (JigsawPiece piece : pieces) { - JsonElement element = piece.serialize(JsonOps.INSTANCE).getValue(); - array.add(element); - } - root.add(e.getKey().toString(), array); - } - write(root, writer); - }); - } - - private static Map getJigsawRegistry() { - try { - for (Field field : JigsawPatternRegistry.class.getDeclaredFields()) { - if (field.getType() == Map.class) { - field.setAccessible(true); - Object value = field.get(JigsawManager.REGISTRY); - return (Map) value; - } - } - } catch (Throwable t) { - t.printStackTrace(); - } - return Collections.emptyMap(); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/BiomeVariance.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/BiomeVariance.java deleted file mode 100644 index a54c154..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/BiomeVariance.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.terraforged.mod.feature.decorator.poisson; - -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.mod.chunk.TerraContainer; -import com.terraforged.mod.chunk.fix.RegionDelegate; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; -import net.minecraft.world.IWorld; -import net.minecraft.world.biome.BiomeContainer; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.gen.WorldGenRegion; - -public class BiomeVariance implements Module { - - public static float MIN_FADE = 0.05F; - - private final ChunkReader chunk; - private final float fade; - private final float range; - - public BiomeVariance(ChunkReader chunk, float fade) { - this.chunk = chunk; - this.fade = fade; - this.range = fade - MIN_FADE; - } - - @Override - public float getValue(float x, float y) { - Cell cell = chunk.getCell((int) x, (int) y); - return NoiseUtil.map(1 - cell.biomeEdge, MIN_FADE, fade, range); - } - - public static Module of(IWorld world, float fade) { - if (world instanceof RegionDelegate) { - WorldGenRegion region = ((RegionDelegate) world).getRegion(); - IChunk chunk = region.getChunk(region.getMainChunkX(), region.getMainChunkZ()); - return of(chunk, fade); - } - return Source.ONE; - } - - public static Module of(IChunk chunk, float fade) { - BiomeContainer container = chunk.getBiomes(); - if (container instanceof TerraContainer) { - ChunkReader reader = ((TerraContainer) container).getChunkReader(); - return new BiomeVariance(reader, fade); - } - return Source.ONE; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/Poisson.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/Poisson.java deleted file mode 100644 index 09d36ff..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/Poisson.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.terraforged.mod.feature.decorator.poisson; - -import com.terraforged.core.util.concurrent.ObjectPool; -import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; -import me.dags.noise.util.Vec2f; - -import javax.swing.*; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.util.Arrays; -import java.util.Random; -import java.util.function.BiConsumer; - -public class Poisson { - - private static final int SAMPLES = 50; - - private final int radius; - private final int radius2; - private final float halfRadius; - private final int maxDistance; - private final int regionSize; - private final int gridSize; - private final float cellSize; - private final ObjectPool pool; - - public Poisson(int radius) { - int size = 48; - this.radius = radius; - this.radius2 = radius * radius; - this.halfRadius = radius / 2F; - this.maxDistance = radius * 2; - this.regionSize = size - radius; - this.cellSize = radius / NoiseUtil.SQRT2; - this.gridSize = (int) Math.ceil(regionSize / cellSize); - this.pool = new ObjectPool<>(3, () -> new Vec2f[gridSize][gridSize]); - } - - public int getRadius() { - return radius; - } - - public void visit(int chunkX, int chunkZ, PoissonContext context, BiConsumer consumer) { - try (ObjectPool.Item grid = pool.get()) { - clear(grid.getValue()); - context.startX = (chunkX << 4); - context.startZ = (chunkZ << 4); - context.endX = context.startX + 16; - context.endZ = context.startZ + 16; - int regionX = (context.startX >> 5); - int regionZ = (context.startZ >> 5); - context.offsetX = regionX << 5; - context.offsetZ = regionZ << 5; - context.random.setSeed(NoiseUtil.hash2D(context.seed, regionX, regionZ)); - int x = context.random.nextInt(regionSize); - int z = context.random.nextInt(regionSize); - visit(x, z, grid.getValue(), SAMPLES, context, consumer); - } - } - - private void visit(float px, float pz, Vec2f[][] grid, int samples, PoissonContext context, BiConsumer consumer) { - for (int i = 0; i < samples; i++) { - float angle = context.random.nextFloat() * NoiseUtil.PI2; - float distance = radius + (context.random.nextFloat() * maxDistance); - float x = halfRadius + px + NoiseUtil.sin(angle) * distance; - float z = halfRadius + pz + NoiseUtil.cos(angle) * distance; - if (valid(x, z, grid, context)) { - Vec2f vec = new Vec2f(x, z); - visit(vec, context, consumer); - int cellX = (int) (x / cellSize); - int cellZ = (int) (z / cellSize); - grid[cellZ][cellX] = vec; - visit(vec.x, vec.y, grid, samples, context, consumer); - } - } - } - - private void visit(Vec2f pos, PoissonContext context, BiConsumer consumer) { - int dx = context.offsetX + (int) pos.x; - int dz = context.offsetZ + (int) pos.y; - if (dx >= context.startX && dx < context.endX && dz >= context.startZ && dz < context.endZ) { - consumer.accept(dx, dz); - } - } - - private boolean valid(float x, float z, Vec2f[][] grid, PoissonContext context) { - if (x < 0 || x >= regionSize || z < 0 || z >= regionSize) { - return false; - } - - int cellX = (int) (x / cellSize); - int cellZ = (int) (z / cellSize); - if (grid[cellZ][cellX] != null) { - return false; - } - - float noise = context.density.getValue(context.offsetX + x, context.offsetZ + z); - float radius2 = noise * this.radius2; - - int searchRadius = 2; - int minX = Math.max(0, cellX - searchRadius); - int maxX = Math.min(grid[0].length - 1, cellX + searchRadius); - int minZ = Math.max(0, cellZ - searchRadius); - int maxZ = Math.min(grid.length - 1, cellZ + searchRadius); - - for (int dz = minZ; dz <= maxZ; dz++) { - for (int dx = minX; dx <= maxX; dx++) { - Vec2f vec = grid[dz][dx]; - if (vec == null) { - continue; - } - - float dist2 = vec.dist2(x, z); - if (dist2 < radius2) { - return false; - } - } - } - return true; - } - - private static void clear(Vec2f[][] grid) { - for (Vec2f[] row : grid) { - Arrays.fill(row, null); - } - } - - public static void main(String[] args) { - int size = 512; - int radius = 6; - - int chunkSize = 16; - int chunks = size / chunkSize; - - BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); - Poisson poisson = new Poisson(radius); - PoissonContext context = new PoissonContext(213, new Random()); - context.density = Source.simplex(213, 100, 1).scale(2).bias(0); - - long time = 0L; - long count = 0L; - - int chunkX = 342; - int chunkZ = 546; - for (int cz = 0; cz < chunks; cz++) { - for (int cx = 0; cx < chunks; cx++) { - long start = System.nanoTime(); - poisson.visit(chunkX + cx, chunkZ + cz, context, (x, z) -> { - x -= chunkX << 4; - z -= chunkZ << 4; - if (x < 0 || x >= image.getWidth() || z < 0 || z >= image.getHeight()) { - return; - } - image.setRGB(x, z, Color.WHITE.getRGB()); - }); - time += (System.nanoTime() - start); - count++; - } - } - - double avg = (double) (time / count) / 1000000; - System.out.println(avg + "ms"); - - JFrame frame = new JFrame(); - frame.add(new JLabel(new ImageIcon(image))); - frame.setVisible(true); - frame.pack(); - frame.setResizable(false); - frame.setLocationRelativeTo(null); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonConfig.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonConfig.java deleted file mode 100644 index 5f62f0b..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.terraforged.mod.feature.decorator.poisson; - -import com.google.common.collect.ImmutableMap; -import com.mojang.datafixers.Dynamic; -import com.mojang.datafixers.types.DynamicOps; -import net.minecraft.world.gen.placement.IPlacementConfig; - -public class PoissonConfig implements IPlacementConfig { - - public final int radius; - public final float biomeFade; - public final int variance; - public final float min; - public final float max; - - public PoissonConfig(int radius, float biomeFade, int variance, float min, float max) { - this.radius = radius; - this.biomeFade = biomeFade; - this.variance = variance; - this.min = min; - this.max = max; - } - - @Override - public Dynamic serialize(DynamicOps ops) { - return new Dynamic<>(ops, ops.createMap( - ImmutableMap.of( - ops.createString("radius"), ops.createInt(radius), - ops.createString("fade"), ops.createFloat(biomeFade), - ops.createString("scale"), ops.createInt(variance), - ops.createString("min"), ops.createFloat(min), - ops.createString("max"), ops.createFloat(max) - )) - ); - } - - public static PoissonConfig deserialize(Dynamic dynamic) { - int radius = dynamic.get("radius").asInt(4); - float biomeFade = dynamic.get("fade").asFloat(0.2F); - int variance = dynamic.get("scale").asInt(0); - float min = dynamic.get("min").asFloat(0F); - float max = dynamic.get("max").asFloat(1F); - return new PoissonConfig(radius, biomeFade, variance, min, max); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonContext.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonContext.java deleted file mode 100644 index 7c6c512..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonContext.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.terraforged.mod.feature.decorator.poisson; - -import me.dags.noise.Module; -import me.dags.noise.Source; - -import java.util.Random; - -public class PoissonContext { - - public int offsetX; - public int offsetZ; - public int startX; - public int startZ; - public int endX; - public int endZ; - public Module density = Source.ONE; - - public final int seed; - public final Random random; - - public PoissonContext(long seed, Random random) { - this.seed = (int) seed; - this.random = random; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/predicate/TreeLine.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/predicate/TreeLine.java deleted file mode 100644 index fd9f6d6..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/predicate/TreeLine.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.predicate; - -import com.terraforged.core.world.climate.Climate; -import com.terraforged.feature.predicate.FeaturePredicate; -import com.terraforged.mod.chunk.TerraContext; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.gen.Heightmap; - -public class TreeLine implements FeaturePredicate { - - private final int worldHeight; - private final Climate climate; - - public TreeLine(TerraContext context) { - this.worldHeight = context.levels.worldHeight; - this.climate = context.heightmap.getClimate(); - } - - @Override - public boolean test(IChunk chunk, Biome biome) { - int x = chunk.getPos().getXStart() + 8; - int z = chunk.getPos().getZStart() + 8; - int treeline = getTreeline(x, z); - int y = chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, 8, 8); - return y < treeline; - } - - private int getTreeline(int x, int z) { - return (int) (climate.getTreeLine(x, z) * worldHeight); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingConfig.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingConfig.java deleted file mode 100644 index 70b4333..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingConfig.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.tree; - -import com.google.gson.reflect.TypeToken; -import com.mojang.datafixers.types.DynamicOps; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.NoFeatureConfig; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class SaplingConfig { - - private static final TypeToken> TOKEN = new TypeToken>() { - }; - - private final Map normal; - private final Map giant; - - public SaplingConfig() { - normal = new HashMap<>(); - giant = new HashMap<>(); - } - - public SaplingConfig(T config, DynamicOps ops) { - this.normal = getSection("normal", config, ops); - this.giant = getSection("giant", config, ops); - } - - public SaplingConfig addNormal(ResourceLocation name, int weight) { - normal.put(name, weight); - return this; - } - - public SaplingConfig addNormal(String name, int weight) { - normal.put(new ResourceLocation(name), weight); - return this; - } - - public SaplingConfig addGiant(ResourceLocation name, int weight) { - giant.put(name, weight); - return this; - } - - public SaplingConfig addGiant(String name, int weight) { - giant.put(new ResourceLocation(name), weight); - return this; - } - - private Map getSection(String key, T config, DynamicOps ops) { - return ops.get(config, key).flatMap(ops::getMapValues).map(map -> { - Map backing = new HashMap<>(); - - for (Map.Entry entry : map.entrySet()) { - String name = ops.getStringValue(entry.getKey()).orElse(""); - int weight = ops.getNumberValue(entry.getValue()).orElse(0).intValue(); - if (name.isEmpty() || weight == 0) { - continue; - } - - ResourceLocation loc = new ResourceLocation(name); - backing.put(loc, weight); - } - - return backing; - }).orElse(Collections.emptyMap()); - } - - public List> getNormal() { - return build(normal); - } - - public List> getGiant() { - return build(giant); - } - - @SuppressWarnings("unchecked") - public static List> build(Map map) { - List> list = new LinkedList<>(); - for (Map.Entry entry : map.entrySet()) { - Feature feature = ForgeRegistries.FEATURES.getValue(entry.getKey()); - if (feature == null) { - continue; - } - - if (TOKEN.getRawType().isAssignableFrom(feature.getClass())) { - Feature noConfFeature = (Feature) feature; - list.add(noConfFeature); - } - } - return list; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingFeature.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingFeature.java deleted file mode 100644 index b8204ff..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingFeature.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.tree; - -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.NoFeatureConfig; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class SaplingFeature { - - private final List> normal; - private final List> giant; - - public SaplingFeature(SaplingConfig config) { - this.normal = new ArrayList<>(config.getNormal()); - this.giant = new ArrayList<>(config.getGiant()); - } - - public Feature nextNormal(Random random) { - if (normal.isEmpty()) { - return null; - } - return normal.get(random.nextInt(normal.size())); - } - - public Feature nextGiant(Random random) { - if (giant.isEmpty()) { - return null; - } - return giant.get(random.nextInt(giant.size())); - } - - public int getNormalCount() { - return normal.size(); - } - - public int getGiantCount() { - return giant.size(); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java deleted file mode 100644 index 7836573..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.tree; - -import com.terraforged.mod.TerraWorld; -import com.terraforged.mod.chunk.TerraChunkGenerator; -import com.terraforged.mod.chunk.TerraContext; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.SaplingBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.IWorld; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.NoFeatureConfig; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.event.world.SaplingGrowTreeEvent; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) -public class SaplingListener { - - private static final BlockPos[] NONE = {BlockPos.ZERO}; - - private static final Vec3i[][] DIRECTIONS = { - {new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(1, 0, 0)}, - {new Vec3i(1, 0, 0), new Vec3i(1, 0, -1), new Vec3i(0, 0, -1)}, - {new Vec3i(0, 0, -1), new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0)}, - {new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1)}, - }; - - @SubscribeEvent(priority = EventPriority.LOWEST) - public static void onTreeGrow(SaplingGrowTreeEvent event) { - // ignore if client - if (event.getWorld().isRemote()) { - return; - } - // ignore other world types - if (!TerraWorld.isTerraWorld(event.getWorld())) { - return; - } - // has user disabled custom trees? - if (!areCustomTreesEnabled(event.getWorld())) { - return; - } - - IWorld world = event.getWorld(); - BlockPos pos = event.getPos(); - Block block = world.getBlockState(pos).getBlock(); - if (block instanceof SaplingBlock) { - // get the sapling feature for the given block type - SaplingFeature tree = SaplingManager.getSapling(block.getRegistryName()); - - // tree is null if the sapling type hasn't been configured - if (tree == null) { - return; - } - - // check for a 2x2 arrangement of sapling blocks around the position - Vec3i[] directions = getNeighbourDirections(world, block, pos); - - // length is 1 if a full 2x2 arrangement could not be found - if (directions.length == 1) { - placeNormal(tree, event, directions); - } else { - placeGiant(tree, event, block, directions); - } - } - } - - private static void placeNormal(SaplingFeature tree, SaplingGrowTreeEvent event, Vec3i[] directions) { - SaplingPlacer.placeTree(tree.nextNormal(event.getRand()), event, directions); - } - - private static void placeGiant(SaplingFeature tree, SaplingGrowTreeEvent event, Block type, Vec3i[] directions) { - Feature feature = tree.nextGiant(event.getRand()); - - // if no giant tree exists for this sapling type try and place a normal one instead - if (feature == null) { - placeNormal(tree, event, directions); - return; - } - - // do not continue if unable to place the tree - if (!SaplingPlacer.placeTree(feature, event, directions)) { - return; - } - - // iterate through the contributing saplings and remove any that were not destroyed during tree creation - BlockPos pos = event.getPos(); - for (Vec3i dir : directions) { - BlockPos blockPos = pos.add(dir); - BlockState state = event.getWorld().getBlockState(blockPos); - if (state.getBlock() == type) { - event.getWorld().removeBlock(blockPos, false); - } - } - } - - private static Vec3i[] getNeighbourDirections(IWorld world, Block block, BlockPos pos) { - for (Vec3i[] dirs : DIRECTIONS) { - boolean match = true; - for (Vec3i dir : dirs) { - BlockState state = world.getBlockState(pos.add(dir)); - if (state.getBlock() != block) { - match = false; - break; - } - } - if (match) { - return dirs; - } - } - return NONE; - } - - private static boolean areCustomTreesEnabled(IWorld world) { - if (world instanceof ServerWorld) { - ServerWorld serverWorld = (ServerWorld) world; - ChunkGenerator generator = serverWorld.getChunkProvider().generator; - if (generator instanceof TerraChunkGenerator) { - TerraContext context = ((TerraChunkGenerator) generator).getContext(); - return context.terraSettings.features.customBiomeFeatures; - } - } - return false; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingManager.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingManager.java deleted file mode 100644 index 9335703..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingManager.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.tree; - -import com.mojang.datafixers.types.DynamicOps; -import com.terraforged.mod.Log; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.util.ResourceLocation; - -import java.util.HashMap; -import java.util.Map; - -public class SaplingManager { - - private static final Map saplings = new HashMap<>(); - - public static SaplingFeature getSapling(ResourceLocation name) { - return saplings.get(name); - } - - public static void register(Block block, SaplingConfig config) { - register(block.getRegistryName(), config); - } - - public static void register(ResourceLocation location, T config, DynamicOps ops) { - register(location, new SaplingConfig(config, ops)); - } - - public static void register(ResourceLocation location, SaplingConfig config) { - saplings.put(location, new SaplingFeature(config)); - } - - public static void init() { - register(Blocks.OAK_SAPLING, new SaplingConfig() - .addNormal("terraforged:oak_small", 4) - .addNormal("terraforged:oak_forest", 3) - .addNormal("terraforged:oak_large", 2) - .addGiant("terraforged:oak_huge", 1)); - - register(Blocks.BIRCH_SAPLING, new SaplingConfig() - .addNormal("terraforged:birch_small", 4) - .addNormal("terraforged:birch_forest", 3) - .addNormal("terraforged:birch_large", 1)); - - register(Blocks.JUNGLE_SAPLING, new SaplingConfig() - .addNormal("terraforged:jungle_small", 4) - .addGiant("terraforged:jungle_large", 1)); - - register( - Blocks.SPRUCE_SAPLING, - new SaplingConfig() - .addNormal("terraforged:spruce_small", 4) - .addNormal("terraforged:spruce_large", 1) - .addGiant("terraforged:redwood_huge", 1)); - - register(Blocks.DARK_OAK_SAPLING, new SaplingConfig() - .addNormal("terraforged:dark_oak_small", 4) - .addNormal("terraforged:dark_oak_large", 1)); - - register(Blocks.ACACIA_SAPLING, new SaplingConfig() - .addNormal("terraforged:acacia_small", 2) - .addNormal("terraforged:acacia_large", 1)); - - Log.info("Registered saplings"); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingPlacer.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingPlacer.java deleted file mode 100644 index 5c335ab..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingPlacer.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.tree; - -import com.terraforged.feature.template.decorator.DecoratedFeature; -import com.terraforged.feature.template.decorator.DecoratorWorld; -import com.terraforged.feature.template.feature.TemplateFeature; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.IWorld; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.NoFeatureConfig; -import net.minecraft.world.server.ServerChunkProvider; -import net.minecraftforge.event.world.SaplingGrowTreeEvent; -import net.minecraftforge.eventbus.api.Event; - -public class SaplingPlacer { - - public static boolean placeTree(Feature feature, SaplingGrowTreeEvent event, Vec3i[] dirs) { - if (feature == null) { - return false; - } - - event.setResult(Event.Result.DENY); - - if (feature instanceof DecoratedFeature) { - return placeDecorated((DecoratedFeature) feature, event, dirs); - } - - return placeNormal(feature, event, dirs); - } - - private static boolean placeDecorated(DecoratedFeature feature, SaplingGrowTreeEvent event, Vec3i[] dirs) { - if (!(event.getWorld().getChunkProvider() instanceof ServerChunkProvider)) { - return false; - } - - TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos()); - W world = feature.wrap(buffer); - - ChunkGenerator generator = ((ServerChunkProvider) event.getWorld().getChunkProvider()).getChunkGenerator(); - feature.placeFeature(world, generator, event.getRand(), event.getPos(), NoFeatureConfig.NO_FEATURE_CONFIG); - - // check that the tree can grow here - if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) { - return false; - } - - BlockPos translation = buffer.getBaseMin().add(getMin(dirs)); - - // apply buffer to world with translation - applyBuffer(buffer, event.getWorld(), translation); - - // translate the decoration positions and apply in the world - world.setDelegate(event.getWorld()); - world.translate(translation); - feature.decorate(world, event.getRand()); - return true; - } - - private static boolean placeNormal(Feature feature, SaplingGrowTreeEvent event, Vec3i[] dirs) { - // apply the feature to a buffer - TreeGrowBuffer buffer = new TreeGrowBuffer(event.getWorld(), event.getPos()); - buffer.placeFeature(feature, event.getPos(), event.getRand()); - - // check that the tree can grow here - if (overheadIsSolid(event.getWorld(), event.getPos(), buffer.getTopY())) { - return false; - } - - // get the min position in the 2x2 grid - BlockPos translation = buffer.getBaseMin().add(getMin(dirs)); - - // copy the feature from the buffer to the world while translating each block - applyBuffer(buffer, event.getWorld(), translation); - return true; - } - - private static void applyBuffer(TreeGrowBuffer buffer, IWorld world, BlockPos translation) { - try (BlockPos.PooledMutable pos = BlockPos.PooledMutable.retain()) { - for (TemplateFeature.BlockInfo block : buffer.getChanges()) { - int x = block.getPos().getX() + translation.getX(); - int y = block.getPos().getY(); - int z = block.getPos().getZ() + translation.getZ(); - - pos.setPos(x, y, z); - - BlockState current = world.getBlockState(pos); - if (current.isSolid()) { - continue; - } - - world.setBlockState(pos, block.getState(), 2); - } - } - } - - private static boolean overheadIsSolid(IWorld world, BlockPos pos, int topY) { - try (BlockPos.PooledMutable blockPos = BlockPos.PooledMutable.retain()) { - for (int y = pos.getY(); y <= topY; y++) { - blockPos.setPos(pos.getX(), y, pos.getZ()); - BlockState state = world.getBlockState(pos); - if (state.isSolid()) { - return true; - } - } - return false; - } - } - - private static Vec3i getMin(Vec3i[] dirs) { - Vec3i min = Vec3i.NULL_VECTOR; - for (Vec3i dir : dirs) { - if (dir.getX() < min.getX() && dir.getZ() <= min.getZ()) { - min = dir; - continue; - } - if (dir.getZ() < min.getZ() && dir.getX() <= min.getX()) { - min = dir; - } - } - return min; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/TreeGrowBuffer.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/TreeGrowBuffer.java deleted file mode 100644 index 27a5371..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/TreeGrowBuffer.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.feature.tree; - -import com.terraforged.feature.template.feature.TemplateFeature; -import com.terraforged.feature.util.WorldDelegate; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.IWorld; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.IFeatureConfig; -import net.minecraft.world.gen.feature.NoFeatureConfig; -import net.minecraft.world.server.ServerChunkProvider; - -import java.util.LinkedList; -import java.util.List; -import java.util.Random; - -public class TreeGrowBuffer extends WorldDelegate { - - private int topY = 0; - private final BlockPos pos; - private final MutableVec3i baseMin = new MutableVec3i(0); - private final MutableVec3i baseMax = new MutableVec3i(0); - private final List changes = new LinkedList<>(); - - public TreeGrowBuffer(IWorld delegate, BlockPos pos) { - super(delegate); - this.pos = pos; - } - - public int getTopY() { - return topY; - } - - public BlockPos getBaseMin() { - return new BlockPos(-baseMin.x, baseMin.y, -baseMin.z); - } - - public BlockPos getBaseMax() { - return new BlockPos(baseMax.x, baseMax.y, baseMax.z); - } - - public Iterable getChanges() { - return changes; - } - - @Override - public boolean setBlockState(BlockPos pos, BlockState state, int i) { - if (pos.getY() < this.pos.getY()) { - return false; - } - if (state.isSolid()) { - recordPos(pos); - } - changes.add(new TemplateFeature.BlockInfo(pos, state)); - return true; - } - - public void placeFeature(Feature feature, BlockPos pos, Random random) { - placeFeature(feature, pos, random, NoFeatureConfig.NO_FEATURE_CONFIG); - } - - public void placeFeature(Feature feature, BlockPos pos, Random random, T config) { - if (getChunkProvider() instanceof ServerChunkProvider) { - ServerChunkProvider chunkProvider = (ServerChunkProvider) getChunkProvider(); - feature.place(this, chunkProvider.getChunkGenerator(), random, pos, config); - } - } - - private void recordPos(BlockPos pos) { - if (pos.getY() > topY) { - topY = pos.getY(); - baseMax.max(pos.subtract(this.pos)); - } else if (pos.getY() == this.pos.getY()) { - baseMin.min(pos.subtract(this.pos)); - } - } - - private static class MutableVec3i { - - private int x, y, z; - - private MutableVec3i(int start) { - x = start; - y = start; - z = start; - } - - private void min(Vec3i vec) { - x = Math.min(x, vec.getX()); - y = Math.min(y, vec.getY()); - z = Math.min(z, vec.getZ()); - } - - private void max(Vec3i vec) { - x = Math.max(x, vec.getX()); - y = Math.max(y, vec.getY()); - z = Math.max(z, vec.getZ()); - } - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/ClimatePage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/ClimatePage.java deleted file mode 100644 index 940c15e..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/ClimatePage.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.preview.PreviewPage; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class ClimatePage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT climateSettings; - - public ClimatePage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.climateSettings = NBTHelper.serialize(settings.climate); - } - - @Override - public String getTitle() { - return "Climate Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(climateSettings, settings.climate); - } - - @Override - public void init(OverlayScreen parent) { - Column center = getColumn(0); - center.scrollPane.setScrollAmount(0D); - addElements(0, 0, center, climateSettings, true, center.scrollPane::addButton, this::update); - } - - @Override - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(climateSettings, settings.climate)); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java deleted file mode 100644 index 0fece56..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/DimensionsPage.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.terraforged.mod.gui.page; - -import com.terraforged.mod.TerraWorld; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.element.TerraTextInput; -import com.terraforged.mod.settings.TerraSettings; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.client.gui.widget.Widget; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.nbt.StringNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.WorldType; -import net.minecraftforge.registries.ForgeRegistries; - -public class DimensionsPage extends BasePage { - - private final TerraSettings settings; - private final CompoundNBT dimensionSettings; - - public DimensionsPage(TerraSettings settings) { - this.settings = settings; - this.dimensionSettings = NBTHelper.serialize(settings.dimensions); - - CompoundNBT generators = dimensionSettings.getCompound("dimensionGenerators").getCompound("value"); - for (String name : generators.keySet()) { - CompoundNBT setting = generators.getCompound(name); - setting.put("#options", getWorldTypes()); - } - } - - @Override - public String getTitle() { - return "Dimension Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(dimensionSettings, settings.dimensions); - } - - @Override - public void init(OverlayScreen parent) { - Column left = getColumn(0); - addElements(left.left, left.top, left, dimensionSettings, true, left.scrollPane::addButton, this::update); - } - - @Override - public void onAddWidget(Widget widget) { - if (widget instanceof TerraTextInput) { - TerraTextInput input = (TerraTextInput) widget; - input.setColorValidator(string -> ForgeRegistries.BLOCKS.containsKey(new ResourceLocation(string))); - } - } - - private static ListNBT getWorldTypes() { - ListNBT options = new ListNBT(); - for (WorldType type : WorldType.WORLD_TYPES) { - if (type == null || (type.getId() >= 1 && type.getId() <= 6) || type.getId() == 8) { - continue; - } - if (!TerraWorld.isTerraType(type)) { - options.add(StringNBT.valueOf(type.getName())); - } - } - return options; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/FeaturePage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/FeaturePage.java deleted file mode 100644 index 2f32b62..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/FeaturePage.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.settings.TerraSettings; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class FeaturePage extends BasePage { - - private final TerraSettings settings; - private final CompoundNBT featureSettings; - - public FeaturePage(TerraSettings settings) { - this.settings = settings; - this.featureSettings = NBTHelper.serialize(settings.features); - } - - @Override - public String getTitle() { - return "Feature Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(featureSettings, settings.features); - } - - @Override - public void init(OverlayScreen parent) { - Column left = getColumn(0); - addElements(left.left, left.top, left, featureSettings, false, left.scrollPane::addButton, this::update); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/FilterPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/FilterPage.java deleted file mode 100644 index 9d48767..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/FilterPage.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.preview.PreviewPage; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class FilterPage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT filterSettings; - - public FilterPage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.filterSettings = NBTHelper.serialize(settings.filters); - } - - @Override - public String getTitle() { - return "Filter Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(filterSettings, settings.filters); - } - - @Override - public void init(OverlayScreen parent) { - Column column = getColumn(0); - addElements(0, 0, column, filterSettings, true, column.scrollPane::addButton, this::update); - } - - @Override - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(filterSettings, settings.filters)); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/GeneratorPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/GeneratorPage.java deleted file mode 100644 index ff979a1..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/GeneratorPage.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.preview.PreviewPage; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class GeneratorPage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT generatorSettings; - - public GeneratorPage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.generatorSettings = NBTHelper.serialize(settings.generator); - } - - @Override - public String getTitle() { - return "Generator Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(generatorSettings, settings.generator); - } - - @Override - public void init(OverlayScreen parent) { - Column left = getColumn(0); - addElements(left.left, left.top, left, generatorSettings, true, left.scrollPane::addButton, this::update); - } - - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(generatorSettings, settings.generator)); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/RiverPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/RiverPage.java deleted file mode 100644 index f19fc4f..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/RiverPage.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.preview.PreviewPage; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class RiverPage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT riverSettings; - - public RiverPage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.riverSettings = NBTHelper.serialize(settings.rivers); - } - - @Override - public String getTitle() { - return "River Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(riverSettings, settings.rivers); - } - - @Override - public void init(OverlayScreen parent) { - Column center = getColumn(0); - center.scrollPane.setScrollAmount(0D); - addElements(0, 0, center, riverSettings, true, center.scrollPane::addButton, this::update); - } - - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(riverSettings, settings.rivers)); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/StructurePage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/StructurePage.java deleted file mode 100644 index e0a8278..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/StructurePage.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.settings.TerraSettings; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class StructurePage extends BasePage { - - private final TerraSettings settings; - private final CompoundNBT structureSettings; - - public StructurePage(TerraSettings settings) { - this.settings = settings; - this.structureSettings = NBTHelper.serialize(settings.structures); - } - - @Override - public String getTitle() { - return "Structure Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(structureSettings, settings.structures); - } - - @Override - public void init(OverlayScreen parent) { - Column left = getColumn(0); - addElements(left.left, left.top, left, structureSettings, true, left.scrollPane::addButton, this::update); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/TerrainPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/TerrainPage.java deleted file mode 100644 index d1e951d..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/TerrainPage.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.gui.page; - -import com.terraforged.core.settings.Settings; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.preview.PreviewPage; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; - -public class TerrainPage extends BasePage { - - private final Settings settings; - private final PreviewPage preview; - private final CompoundNBT terrainSettings; - - public TerrainPage(Settings settings, PreviewPage preview) { - this.settings = settings; - this.preview = preview; - this.terrainSettings = NBTHelper.serialize(settings.terrain); - } - - @Override - public String getTitle() { - return "Terrain Settings"; - } - - @Override - public void save() { - NBTHelper.deserialize(terrainSettings, settings.terrain); - } - - @Override - public void init(OverlayScreen parent) { - Column center = getColumn(0); - center.scrollPane.setScrollAmount(0D); - addElements(0, 0, center, terrainSettings, true, center.scrollPane::addButton, this::update); - } - - protected void update() { - super.update(); - preview.apply(settings -> NBTHelper.deserialize(terrainSettings, settings.terrain)); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/material/MaterialHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/material/MaterialHelper.java deleted file mode 100644 index fdc1360..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/material/MaterialHelper.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.material; - -import com.google.common.collect.Sets; -import com.terraforged.core.util.concurrent.ObjectPool; -import com.terraforged.mod.util.DummyBlockReader; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.ConcretePowderBlock; -import net.minecraft.block.material.Material; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.gen.feature.ConfiguredFeature; -import net.minecraft.world.gen.feature.DecoratedFeatureConfig; -import net.minecraft.world.gen.feature.OreFeatureConfig; -import net.minecraftforge.common.Tags; -import net.minecraftforge.registries.IForgeRegistryEntry; - -import java.util.Set; - -public class MaterialHelper { - - private static final Set BLACKLIST = Sets.newHashSet( - Blocks.INFESTED_CHISELED_STONE_BRICKS, - Blocks.INFESTED_COBBLESTONE, - Blocks.INFESTED_CRACKED_STONE_BRICKS, - Blocks.INFESTED_MOSSY_STONE_BRICKS, - Blocks.INFESTED_STONE, - Blocks.INFESTED_STONE_BRICKS, - Blocks.SLIME_BLOCK, - Blocks.RED_SAND, - Blocks.SOUL_SAND, - // honey etc - Blocks.HONEY_BLOCK, - Blocks.HONEYCOMB_BLOCK, - Blocks.BEE_NEST, - Blocks.BEEHIVE, - Blocks.COMPOSTER - ); - - public static boolean isAir(Block block) { - return block == Blocks.AIR || block == Blocks.CAVE_AIR || block == Blocks.VOID_AIR; - } - - public static boolean isGrass(Block block) { - return block == Blocks.GRASS_BLOCK || block == Blocks.MYCELIUM; - } - - public static boolean isStone(Block block) { - return Tags.Blocks.STONE.contains(block) - && !isBlacklisted(block) - && !("" + block.getRegistryName()).contains("polished_"); - } - - public static boolean isDirt(Block block) { - return Tags.Blocks.DIRT.contains(block) - && !isBlacklisted(block); - } - - public static boolean isClay(Block block) { - return block.getDefaultState().getMaterial() == Material.CLAY - && !isBlacklisted(block); - } - - public static boolean isSand(Block block) { - return BlockTags.SAND.contains(block) - && !isBlacklisted(block) - && !(block instanceof ConcretePowderBlock); - } - - public static boolean isSediment(Block block) { - return (isSand(block) || isGravel(block)) - && !isBlacklisted(block) - && !(block instanceof ConcretePowderBlock); - } - - public static boolean isGravel(Block block) { - return getName(block).contains("gravel"); - } - - public static boolean isOre(Block block) { - return Tags.Blocks.ORES.contains(block) - && !isBlacklisted(block); - } - - public static boolean isBlacklisted(Block block) { - return BLACKLIST.contains(block); - } - - public static String getName(IForgeRegistryEntry entry) { - return "" + entry.getRegistryName(); - } - - public static String getNamespace(IForgeRegistryEntry entry) { - ResourceLocation name = entry.getRegistryName(); - if (name == null) { - return "unknown"; - } - return name.getNamespace(); - } - - public static float getHardness(BlockState state) { - try (ObjectPool.Item reader = DummyBlockReader.pooled()) { - reader.getValue().set(state); - return state.getBlockHardness(reader.getValue(), BlockPos.ZERO); - } - } - - public static boolean isCube(BlockState state) { - try (ObjectPool.Item reader = DummyBlockReader.pooled()) { - reader.getValue().set(state); - return state.isNormalCube(reader.getValue(), BlockPos.ZERO); - } - } - - public static OreFeatureConfig getOreConfig(ConfiguredFeature feature) { - if (feature.config instanceof DecoratedFeatureConfig) { - DecoratedFeatureConfig config = (DecoratedFeatureConfig) feature.config; - if (config.feature.config instanceof OreFeatureConfig) { - return (OreFeatureConfig) config.feature.config; - } - } - return null; - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/material/Materials.java b/TerraForgedMod/src/main/java/com/terraforged/mod/material/Materials.java deleted file mode 100644 index 151450d..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/material/Materials.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.material; - -import com.terraforged.api.material.WGTags; -import com.terraforged.api.material.layer.LayerManager; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.tags.Tag; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Predicate; - -@Deprecated -public class Materials { - - private final Set stone = create(WGTags.STONE); - private final Set dirt = create(WGTags.DIRT); - private final Set clay = create(WGTags.CLAY); - private final Set sediment = create(WGTags.SEDIMENT); - private final Set erodible = create(WGTags.ERODIBLE); - private final LayerManager layerManager = new LayerManager(); - - public Materials() { - Predicate filter = getTagFilter(); - for (Block block : ForgeRegistries.BLOCKS) { - if (filter.test(block)) { - continue; - } - - if (!MaterialHelper.isCube(block.getDefaultState())) { - continue; - } - - if (MaterialHelper.isStone(block)) { - stone.add(block); - } else if (MaterialHelper.isDirt(block)) { - dirt.add(block); - } else if (MaterialHelper.isClay(block)) { - clay.add(block); - } else if (MaterialHelper.isSediment(block)) { - sediment.add(block); - } - } - - if (stone.isEmpty()) { - stone.add(Blocks.STONE); - } - } - - public LayerManager getLayerManager() { - return layerManager; - } - - public boolean isStone(Block block) { - return stone.contains(block); - } - - public boolean isEarth(Block block) { - return dirt.contains(block); - } - - public boolean isClay(Block block) { - return clay.contains(block); - } - - public boolean isSediment(Block block) { - return sediment.contains(block); - } - - public boolean isErodible(Block block) { - return erodible.contains(block); - } - - private static Set create(Tag tag) { - return new HashSet<>(tag.getAllElements()); - } - - private static Predicate getTagFilter() { - Set namespaces = new HashSet<>(); - collectNamespace(namespaces, WGTags.STONE.getAllElements()); - collectNamespace(namespaces, WGTags.DIRT.getAllElements()); - collectNamespace(namespaces, WGTags.DIRT.getAllElements()); - collectNamespace(namespaces, WGTags.SEDIMENT.getAllElements()); - return b -> namespaces.contains(MaterialHelper.getNamespace(b)); - } - - private static void collectNamespace(Set set, Collection blocks) { - for (Block block : blocks) { - set.add(MaterialHelper.getNamespace(block)); - } - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java deleted file mode 100644 index 86af287..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.terraforged.mod.settings; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.terraforged.mod.Log; -import com.terraforged.mod.TerraWorld; -import com.terraforged.mod.util.nbt.NBTHelper; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.storage.WorldInfo; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.nio.file.Files; - -public class SettingsHelper { - - public static final String SETTINGS_FILE_NAME = "terraforged-generator.json"; - public static final File SETTINGS_DIR = new File("config", "terraforged"); - public static final File SETTINGS_FILE= new File(SETTINGS_DIR, SETTINGS_FILE_NAME); - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - - public static int getVersion(WorldInfo info) { - if (info.getGeneratorOptions().isEmpty()) { - // if options have not been set then the world has been created - // during the current runtime .: is not legacy - return TerraWorld.VERSION; - } - - CompoundNBT version = info.getGeneratorOptions().getCompound("version"); - if (version.isEmpty()) { - // version tag is absent in legacy worlds .: is legacy - return 0; - } - - return version.getInt("value"); - } - - public static void clearDefaults() { - if (SETTINGS_FILE.exists() && SETTINGS_FILE.delete()) { - Log.info("Deleted generator defaults"); - } - } - - public static void exportDefaults(TerraSettings settings) { - CompoundNBT tag = NBTHelper.serializeCompact(settings); - JsonElement json = NBTHelper.toJson(tag); - try (Writer writer = new BufferedWriter(new FileWriter(SETTINGS_FILE))) { - GSON.toJson(json, writer); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void applyDefaults(CompoundNBT options, TerraSettings dest) { - if (options.isEmpty()) { - try (Reader reader = new BufferedReader(new FileReader(SETTINGS_FILE))) { - JsonElement json = new JsonParser().parse(reader); - options = NBTHelper.fromJson(json); - } catch (IOException ignored) { - - } - } - NBTHelper.deserialize(options, dest); - } - - public static TerraSettings getSettings(WorldInfo info) { - TerraSettings settings = new TerraSettings(); - if (info.getGeneratorOptions().isEmpty()) { - if (SETTINGS_FILE.exists()) { - try (Reader reader = new BufferedReader(new FileReader(SETTINGS_FILE))) { - Log.info("Loading generator settings from json"); - JsonElement json = new JsonParser().parse(reader); - CompoundNBT root = NBTHelper.fromJson(json); - NBTHelper.deserialize(root, settings); - } catch (Throwable t) { - t.printStackTrace(); - } - } - } else { - Log.info("Loading generator settings from level.dat"); - NBTHelper.deserialize(info.getGeneratorOptions(), settings); - } - return settings; - } - - public static void syncSettings(WorldInfo info, TerraSettings settings, int version) { - settings.version = version; - settings.generator.seed = info.getSeed(); - CompoundNBT options = NBTHelper.serialize(settings); - info.setGeneratorOptions(options); - } - - public static void initSettings() { - if (SETTINGS_FILE.exists()) { - return; - } - - File src = new File("config", SETTINGS_FILE_NAME); - if (src.exists()) { - if (SETTINGS_DIR.exists() || SETTINGS_DIR.mkdirs()) { - try { - Files.copy(src.toPath(), SETTINGS_FILE.toPath()); - if (src.delete()) { - Log.info("Moved settings file to new location: {}", SETTINGS_FILE.getAbsoluteFile()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } else { - DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> exportDefaults(new TerraSettings())); - } - } - - private static void initServerSettings() { - DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> exportDefaults(new TerraSettings())); - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/StructureSettings.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/StructureSettings.java deleted file mode 100644 index 866fe53..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/StructureSettings.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.settings; - -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; - -@Serializable -public class StructureSettings { - - @Range(min = 1, max = 10) - @Comment("Controls the distance between villages") - public int villageDistance = 2; - - @Range(min = 1, max = 10) - @Comment("Controls the distance between mansions") - public int mansionDistance = 3; - - @Range(min = 1, max = 10) - @Comment("Controls the distance between strongholds") - public int strongholdDistance = 3; - - @Range(min = 1, max = 10) - @Comment("Controls the distance between strongholds") - public int strongholdSpread = 3; - - @Range(min = 1, max = 10) - @Comment("Controls the distance between biome structures") - public int biomeStructureDistance = 4; - - @Range(min = 1, max = 10) - @Comment("Controls the distance between ocean monuments") - public int oceanMonumentSpacing = 3; - - @Range(min = 1, max = 10) - @Comment("Controls the separation between ocean monuments") - public int oceanMonumentSeparation = 3; -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTWriter.java b/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTWriter.java deleted file mode 100644 index a2a0550..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTWriter.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * MIT License - * - * Copyright (c) 2020 TerraForged - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.terraforged.mod.util.nbt; - -import com.terraforged.core.util.serialization.serializer.Writer; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.FloatNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.nbt.IntNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.nbt.StringNBT; - -public class NBTWriter implements Writer { - - private final Context root = new Context(null); - - private String name = ""; - private Context context = root; - - public NBTWriter() { - - } - - public INBT root() { - return root.value; - } - - public CompoundNBT compound() { - return (CompoundNBT) root(); - } - - public ListNBT list() { - return (ListNBT) root(); - } - - private NBTWriter begin(INBT value) { - if (root.value == null) { - root.value = value; - context.value = value; - } else { - append(value); - context = new Context(context); - context.value = value; - } - return this; - } - - private NBTWriter append(INBT value) { - if (context.value instanceof CompoundNBT) { - ((CompoundNBT) context.value).put(name, value); - } else if (context.value instanceof ListNBT) { - ((ListNBT) context.value).add(value); - } - return this; - } - - @Override - public NBTWriter name(String name) { - this.name = name; - return this; - } - - @Override - public NBTWriter beginObject() { - return begin(new CompoundNBT()); - } - - @Override - public NBTWriter endObject() { - context = context.parent; - return this; - } - - @Override - public NBTWriter beginArray() { - return begin(new ListNBT()); - } - - @Override - public NBTWriter endArray() { - context = context.parent; - return this; - } - - @Override - public NBTWriter value(String value) { - return append(StringNBT.valueOf(value)); - } - - @Override - public NBTWriter value(float value) { - return append(FloatNBT.valueOf(value)); - } - - @Override - public NBTWriter value(int value) { - return append(IntNBT.valueOf(value)); - } - - private static class Context { - - private final Context parent; - private INBT value; - - private Context(Context root) { - this.parent = root; - } - } -} diff --git a/TerraForgedMod/src/main/resources/assets/terraforged/lang/en_us.json b/TerraForgedMod/src/main/resources/assets/terraforged/lang/en_us.json deleted file mode 100644 index 529f20c..0000000 --- a/TerraForgedMod/src/main/resources/assets/terraforged/lang/en_us.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "generator.terraforged": "TerraForged", - "generator.terratest": "TerraTest", - "biome.terraforged.cold_steppe": "Cold Steppe", - "biome.terraforged.marshland": "Marshland", - "biome.terraforged.savanna_scrub": "Savanna Scrub", - "biome.terraforged.shattered_savanna_scrub": "Shattered Savanna Scrub", - "biome.terraforged.snowy_taiga_scrub": "Snowy Taiga Scrub", - "biome.terraforged.steppe": "Steppe", - "biome.terraforged.taiga_scrub": "Taiga Scrub", - "biome.terraforged.warm_beach": "Warm Beach" -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/birch.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/birch.json deleted file mode 100644 index fea9e44..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/birch.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "biomes": [ - "minecraft:birch*", - "minecraft:tall_birch*" - ], - "match": [ - [ - "minecraft:birch_log", - "minecraft:birch_leaves" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:birch_forest", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:birch_large", - "config": {}, - "chance": 0.2 - } - ], - "default": { - "name": "terraforged:birch_forest", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 21, - "extra_chance": 0.1, - "extra_count": 1 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/birch_oak.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/birch_oak.json deleted file mode 100644 index e9ffca8..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/birch_oak.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "biomes": [ - "minecraft:wooded_hills" - ], - "match": [ - [ - "minecraft:birch_log", - "minecraft:birch_leaves", - "minecraft:oak_log", - "minecraft:oak_leaves" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:birch_forest", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:birch_large", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:oak_forest", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:oak_large", - "config": {}, - "chance": 0.2 - } - ], - "default": { - "name": "terraforged:birch_forest", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 20, - "extra_chance": 0.1, - "extra_count": 1 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/flower_forest.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/flower_forest.json deleted file mode 100644 index d399328..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/flower_forest.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "biomes": [ - "minecraft:flower_forest" - ], - "match": [ - [ - "minecraft:oak_log", - "minecraft:oak_leaves" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:birch_forest", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:birch_large", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:oak_forest", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:oak_large", - "config": {}, - "chance": 0.2 - } - ], - "default": { - "name": "terraforged:birch_forest", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 2, - "extra_chance": 0.1, - "extra_count": 2 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle_edge.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle_edge.json deleted file mode 100644 index 638dfc5..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle_edge.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "biomes": [ - "minecraft:jungle_edge", - "minecraft:modified_jungle_edge" - ], - "match": [ - [ - "minecraft:fancy_tree" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:jungle_small", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:jungle_large", - "config": {}, - "chance": 0.3 - } - ], - "default": { - "name": "terraforged:jungle_small", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 3, - "extra_chance": 0.25, - "extra_count": 1 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_forest.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_forest.json deleted file mode 100644 index dd1ff71..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_forest.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "biomes": [ - "minecraft:forest" - ], - "match": [ - [ - "minecraft:oak_log", - "minecraft:oak_leaves" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:oak_forest", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:oak_large", - "config": {}, - "chance": 0.3 - } - ], - "default": { - "name": "terraforged:oak_forest", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 10, - "extra_chance": 0.1, - "extra_count": 2 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json deleted file mode 100644 index e9fb356..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/redwood.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "biomes": [ - "minecraft:*" - ], - "match": [ - [ - "minecraft:mega_spruce_tree" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:redwood_huge", - "config": {}, - "chance": 0.025641026 - }, - { - "name": "terraforged:pine", - "config": {}, - "chance": 0.15 - }, - { - "name": "terraforged:redwood_large", - "config": {}, - "chance": 0.33333334 - } - ], - "default": { - "name": "terraforged:redwood_large", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 10, - "extra_chance": 0.1, - "extra_count": 1 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/spruce_tundra.json b/TerraForgedMod/src/main/resources/data/terraforged/features/trees/spruce_tundra.json deleted file mode 100644 index b746237..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/spruce_tundra.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "biomes": [ - "minecraft:snowy_tundra", - "minecraft:wooded_mountains" - ], - "match": [ - [ - "minecraft:normal_tree", - "minecraft:spruce_log", - "minecraft:spruce_leaves" - ] - ], - "replace": { - "name": "minecraft:decorated", - "config": { - "feature": { - "name": "minecraft:random_selector", - "config": { - "features": [ - { - "name": "terraforged:pine", - "config": {}, - "chance": 0.3 - } - ], - "default": { - "name": "terraforged:pine", - "config": {} - } - } - }, - "decorator": { - "name": "minecraft:count_extra_heightmap", - "config": { - "count": 0, - "extra_chance": 0.02, - "extra_count": 1 - } - } - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_forest.json b/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_forest.json deleted file mode 100644 index 8e2334f..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_forest.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "tree", - "base": 3, - "name": "terraforged:birch_forest", - "paths": [ - "terraforged:trees/birch/forest" - ], - "decorators": { - "minecraft:beehive": { - "probability": 0.002 - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_large.json b/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_large.json deleted file mode 100644 index 517da81..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_large.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "tree", - "base": 3, - "name": "terraforged:birch_large", - "paths": [ - "terraforged:trees/birch/large" - ], - "decorators": { - "minecraft:beehive": { - "probability": 0.002 - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_forest.json b/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_forest.json deleted file mode 100644 index eacbf1f..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_forest.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "tree", - "base": 3, - "name": "terraforged:oak_forest", - "paths": [ - "terraforged:trees/oak/forest" - ], - "decorators": { - "minecraft:beehive": { - "probability": 0.002 - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_huge.json b/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_huge.json deleted file mode 100644 index 15704e9..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_huge.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "tree", - "base": 3, - "name": "terraforged:oak_huge", - "paths": [ - "terraforged:trees/oak/huge" - ], - "decorators": { - "minecraft:beehive": { - "probability": 0.002 - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_large.json b/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_large.json deleted file mode 100644 index dd11f3e..0000000 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_large.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "tree", - "base": 3, - "name": "terraforged:oak_large", - "paths": [ - "terraforged:trees/oak/large" - ], - "decorators": { - "minecraft:beehive": { - "probability": 0.002 - } - } -} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/license.txt b/TerraForgedMod/src/main/resources/license.txt deleted file mode 100644 index 0b31935..0000000 --- a/TerraForgedMod/src/main/resources/license.txt +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 TerraForged - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/TerraForgedMod/src/main/resources/terraforged.png b/TerraForgedMod/src/main/resources/terraforged.png deleted file mode 100644 index 0d649c9..0000000 Binary files a/TerraForgedMod/src/main/resources/terraforged.png and /dev/null differ diff --git a/build.gradle b/build.gradle index 04634f8..b1ae38e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,129 @@ -allprojects { - apply plugin: "java" - group = "com.terraforged" - version = mod_version +buildscript { + repositories { + jcenter() + mavenCentral() + maven { url "https://files.minecraftforge.net/maven" } + } + dependencies { + classpath group: "net.minecraftforge.gradle", name: "ForgeGradle", version: "3.+", changing: true + } } -jar.enabled(false) \ No newline at end of file +apply plugin: "net.minecraftforge.gradle" +apply plugin: "maven-publish" +apply plugin: "eclipse" + +sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 + +version = "${mc_version}-${mod_version}${getClassifier()}" + +allprojects { + apply plugin: "java" +} + +configurations { + lib + compile.extendsFrom lib +} + +repositories { + jcenter() + mavenCentral() + maven { url "https://io.terraforged.com/repository/maven/" } +} + +dependencies { + minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" + lib (project(":FeatureManager")) { transitive false } + lib project(":Engine") +} + +minecraft { + mappings channel: mcp_channel, version: mcp_version + runs { + client { + workingDirectory project.file("run/client") + property "forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP" + property "forge.logging.console.level", "debug" + jvmArgs "-Xmx8G", "-Xms6G", "-Ddev" + mods { + terraforged { + source sourceSets.main + } + } + } + server { + workingDirectory project.file("run/server") + property "forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP" + property "forge.logging.console.level", "debug" + jvmArgs "-Xmx8G", "-Xms6G", "-Ddev" + mods { + terraforged { + source sourceSets.main + } + } + } + data { + workingDirectory project.file("run/data") + property "forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP" + property "forge.logging.console.level", "debug" + property "fml.earlyprogresswindow", "false" + args "--mod", "terraforged", "--server", "--output", file("generated/resources/") + jvmArgs "-Xmx4G", "-Xms2G" + mods { + terraforged { + source sourceSets.main + } + } + } + } +} + +sourceSets { + main.resources { + srcDirs += "generated/resources/" + exclude ".cache" + } +} + +task collectLibs(type: Copy) { + dependsOn(dependsOn: subprojects.tasks["jar"]) + from { configurations.lib.collect { it.isDirectory() ? it : zipTree(it) } } + into("build/classes/java/main") + duplicatesStrategy = "EXCLUDE" +} + +task apiJar(type: Jar) { + from { zipTree(tasks.jar.archivePath) } + include "com/terraforged/fm/**" + include "com/terraforged/api/**" + include "com/terraforged/core/**" + include "com/terraforged/n2d/**" + include "com/terraforged/world/**" + classifier "api" +} + +processResources { + filesMatching("**/mods.toml") { + expand("version": "${mod_version}${getClassifier()}", "mc_version": mc_version) + } +} + +classes { + dependsOn(collectLibs) +} + +build { + finalizedBy(apiJar) +} + +static def getClassifier() { + if (System.getenv("GIT_TAG_NAME") != null) { + return "" + } + def buildNumber = System.getenv("BUILD_NUMBER") + if (buildNumber != null) { + return "-${buildNumber}" + } + return "" +} \ No newline at end of file diff --git a/generated/resources/assets/terraforged/lang/en_us.json b/generated/resources/assets/terraforged/lang/en_us.json new file mode 100644 index 0000000..dc49c69 --- /dev/null +++ b/generated/resources/assets/terraforged/lang/en_us.json @@ -0,0 +1,331 @@ +{ + "biome.terraforged.bryce": "Bryce", + "biome.terraforged.cold_steppe": "Cold Steppe", + "biome.terraforged.fir_forest": "Fir Forest", + "biome.terraforged.flower_plains": "Flower Plains", + "biome.terraforged.frozen_lake": "Frozen Lake", + "biome.terraforged.lake": "Lake", + "biome.terraforged.marshland": "Marshland", + "biome.terraforged.savanna_scrub": "Savanna Scrub", + "biome.terraforged.shattered_savanna_scrub": "Shattered Savanna Scrub", + "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", + "display.terraforged.climate.biome_edge_shape": "Biome Edge Shape", + "display.terraforged.climate.biome_edge_shape.gain": "Gain", + "display.terraforged.climate.biome_edge_shape.lacunarity": "Lacunarity", + "display.terraforged.climate.biome_edge_shape.octaves": "Octaves", + "display.terraforged.climate.biome_edge_shape.scale": "Scale", + "display.terraforged.climate.biome_edge_shape.strength": "Strength", + "display.terraforged.climate.biome_edge_shape.type": "Type", + "display.terraforged.climate.biome_shape": "Biome Shape", + "display.terraforged.climate.biome_shape.biome_size": "Biome Size", + "display.terraforged.climate.biome_shape.biome_warp_scale": "Biome Warp Scale", + "display.terraforged.climate.biome_shape.biome_warp_strength": "Biome Warp Strength", + "display.terraforged.climate.biome_shape.macro_noise_size": "Macro Noise Size", + "display.terraforged.climate.moisture": "Moisture", + "display.terraforged.climate.moisture.bias": "Bias", + "display.terraforged.climate.moisture.falloff": "Falloff", + "display.terraforged.climate.moisture.max": "Max", + "display.terraforged.climate.moisture.min": "Min", + "display.terraforged.climate.moisture.scale": "Scale", + "display.terraforged.climate.temperature": "Temperature", + "display.terraforged.climate.temperature.bias": "Bias", + "display.terraforged.climate.temperature.falloff": "Falloff", + "display.terraforged.climate.temperature.max": "Max", + "display.terraforged.climate.temperature.min": "Min", + "display.terraforged.climate.temperature.scale": "Scale", + "display.terraforged.climate.title": "Climate Settings", + "display.terraforged.dimensions": "Dimensions", + "display.terraforged.dimensions.bedrock_layer": "Bedrock Layer", + "display.terraforged.dimensions.bedrock_layer.material": "Material", + "display.terraforged.dimensions.bedrock_layer.min_depth": "Min Depth", + "display.terraforged.dimensions.bedrock_layer.variance": "Variance", + "display.terraforged.dimensions.dimensions": "Dimensions", + "display.terraforged.dimensions.dimensions.end": "End", + "display.terraforged.dimensions.dimensions.nether": "Nether", + "display.terraforged.filters": "Filters", + "display.terraforged.filters.erosion": "Erosion", + "display.terraforged.filters.erosion.deposite_rate": "Deposite Rate", + "display.terraforged.filters.erosion.droplet_lifetime": "Droplet Lifetime", + "display.terraforged.filters.erosion.droplet_velocity": "Droplet Velocity", + "display.terraforged.filters.erosion.droplet_volume": "Droplet Volume", + "display.terraforged.filters.erosion.erosion_rate": "Erosion Rate", + "display.terraforged.filters.erosion.iterations": "Iterations", + "display.terraforged.filters.smoothing": "Smoothing", + "display.terraforged.filters.smoothing.iterations": "Iterations", + "display.terraforged.filters.smoothing.smoothing_radius": "Smoothing Radius", + "display.terraforged.filters.smoothing.smoothing_rate": "Smoothing Rate", + "display.terraforged.filters.title": "Filter Settings", + "display.terraforged.general.cancel": "Cancel", + "display.terraforged.general.done": "Done", + "display.terraforged.miscellaneous": "Miscellaneous", + "display.terraforged.miscellaneous.custom_biome_features": "Custom Biome Features", + "display.terraforged.miscellaneous.erosion_decorator": "Erosion Decorator", + "display.terraforged.miscellaneous.mountain_biome_usage": "Mountain Biome Usage", + "display.terraforged.miscellaneous.natural_snow_decorator": "Natural Snow Decorator", + "display.terraforged.miscellaneous.smooth_layer_decorator": "Smooth Layer Decorator", + "display.terraforged.miscellaneous.strata_decorator": "Strata Decorator", + "display.terraforged.miscellaneous.title": "Miscellaneous Settings", + "display.terraforged.miscellaneous.vanilla_water_features": "Vanilla Water Features", + "display.terraforged.preset.create": "Create", + "display.terraforged.preset.default": "Make Default", + "display.terraforged.preset.delete": "Delete", + "display.terraforged.preset.load": "Load", + "display.terraforged.preset.reset": "Reset", + "display.terraforged.preset.save": "Save", + "display.terraforged.presets.title": "Presets & Defaults", + "display.terraforged.preview": "Preview", + "display.terraforged.preview.area": "Area: ", + "display.terraforged.preview.biome": "Biome: ", + "display.terraforged.preview.display": "Display", + "display.terraforged.preview.seed": "New Seed", + "display.terraforged.preview.terrain": "Terrain: ", + "display.terraforged.preview.zoom": "Zoom", + "display.terraforged.river.title": "River Settings", + "display.terraforged.rivers": "Rivers", + "display.terraforged.rivers.primary_rivers": "Primary Rivers", + "display.terraforged.rivers.primary_rivers.bank_width": "Bank Width", + "display.terraforged.rivers.primary_rivers.bed_depth": "Bed Depth", + "display.terraforged.rivers.primary_rivers.bed_width": "Bed Width", + "display.terraforged.rivers.primary_rivers.fade": "Fade", + "display.terraforged.rivers.primary_rivers.max_bank_height": "Max Bank Height", + "display.terraforged.rivers.primary_rivers.min_bank_height": "Min Bank Height", + "display.terraforged.rivers.river_count": "River Count", + "display.terraforged.rivers.secondary_river": "Secondary River", + "display.terraforged.rivers.secondary_river.bank_width": "Bank Width", + "display.terraforged.rivers.secondary_river.bed_depth": "Bed Depth", + "display.terraforged.rivers.secondary_river.bed_width": "Bed Width", + "display.terraforged.rivers.secondary_river.fade": "Fade", + "display.terraforged.rivers.secondary_river.max_bank_height": "Max Bank Height", + "display.terraforged.rivers.secondary_river.min_bank_height": "Min Bank Height", + "display.terraforged.rivers.tertiary_rivers": "Tertiary Rivers", + "display.terraforged.rivers.tertiary_rivers.bank_width": "Bank Width", + "display.terraforged.rivers.tertiary_rivers.bed_depth": "Bed Depth", + "display.terraforged.rivers.tertiary_rivers.bed_width": "Bed Width", + "display.terraforged.rivers.tertiary_rivers.fade": "Fade", + "display.terraforged.rivers.tertiary_rivers.max_bank_height": "Max Bank Height", + "display.terraforged.rivers.tertiary_rivers.min_bank_height": "Min Bank Height", + "display.terraforged.structures": "Structures", + "display.terraforged.structures.mansions": "Mansions", + "display.terraforged.structures.mansions.distance": "Distance", + "display.terraforged.structures.mansions.separation": "Separation", + "display.terraforged.structures.ocean_monuments": "Ocean Monuments", + "display.terraforged.structures.ocean_monuments.distance": "Distance", + "display.terraforged.structures.ocean_monuments.separation": "Separation", + "display.terraforged.structures.ocean_ruins": "Ocean Ruins", + "display.terraforged.structures.ocean_ruins.distance": "Distance", + "display.terraforged.structures.ocean_ruins.separation": "Separation", + "display.terraforged.structures.other_structures": "Other Structures", + "display.terraforged.structures.other_structures.distance": "Distance", + "display.terraforged.structures.other_structures.separation": "Separation", + "display.terraforged.structures.shipwrecks": "Shipwrecks", + "display.terraforged.structures.shipwrecks.distance": "Distance", + "display.terraforged.structures.shipwrecks.separation": "Separation", + "display.terraforged.structures.strongholds": "Strongholds", + "display.terraforged.structures.strongholds.distance": "Distance", + "display.terraforged.structures.strongholds.separation": "Separation", + "display.terraforged.structures.title": "Structure Settings", + "display.terraforged.structures.villages": "Villages", + "display.terraforged.structures.villages.distance": "Distance", + "display.terraforged.structures.villages.separation": "Separation", + "display.terraforged.terrain": "Terrain", + "display.terraforged.terrain.badlands": "Badlands", + "display.terraforged.terrain.badlands.base_scale": "Base Scale", + "display.terraforged.terrain.badlands.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.badlands.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.badlands.weight": "Weight", + "display.terraforged.terrain.dales": "Dales", + "display.terraforged.terrain.dales.base_scale": "Base Scale", + "display.terraforged.terrain.dales.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.dales.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.dales.weight": "Weight", + "display.terraforged.terrain.general": "General", + "display.terraforged.terrain.general.global_horizontal_scale": "Global Horizontal Scale", + "display.terraforged.terrain.general.global_vertical_scale": "Global Vertical Scale", + "display.terraforged.terrain.general.terrain_region_size": "Terrain Region Size", + "display.terraforged.terrain.hills": "Hills", + "display.terraforged.terrain.hills.base_scale": "Base Scale", + "display.terraforged.terrain.hills.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.hills.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.hills.weight": "Weight", + "display.terraforged.terrain.mountains": "Mountains", + "display.terraforged.terrain.mountains.base_scale": "Base Scale", + "display.terraforged.terrain.mountains.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.mountains.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.mountains.weight": "Weight", + "display.terraforged.terrain.plains": "Plains", + "display.terraforged.terrain.plains.base_scale": "Base Scale", + "display.terraforged.terrain.plains.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.plains.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.plains.weight": "Weight", + "display.terraforged.terrain.plateau": "Plateau", + "display.terraforged.terrain.plateau.base_scale": "Base Scale", + "display.terraforged.terrain.plateau.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.plateau.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.plateau.weight": "Weight", + "display.terraforged.terrain.steppe": "Steppe", + "display.terraforged.terrain.steppe.base_scale": "Base Scale", + "display.terraforged.terrain.steppe.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.steppe.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.steppe.weight": "Weight", + "display.terraforged.terrain.title": "Terrain Settings", + "display.terraforged.terrain.torridonian": "Torridonian", + "display.terraforged.terrain.torridonian.base_scale": "Base Scale", + "display.terraforged.terrain.torridonian.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.torridonian.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.torridonian.weight": "Weight", + "display.terraforged.terrain.volcano": "Volcano", + "display.terraforged.terrain.volcano.base_scale": "Base Scale", + "display.terraforged.terrain.volcano.horizontal_scale": "Horizontal Scale", + "display.terraforged.terrain.volcano.vertical_scale": "Vertical Scale", + "display.terraforged.terrain.volcano.weight": "Weight", + "display.terraforged.world": "World", + "display.terraforged.world.continent": "Continent", + "display.terraforged.world.continent.continent_mode": "Continent Mode", + "display.terraforged.world.continent.continent_scale": "Continent Scale", + "display.terraforged.world.continent.continent_shape": "Continent Shape", + "display.terraforged.world.continent.ocean_scale": "Ocean Scale", + "display.terraforged.world.properties": "Properties", + "display.terraforged.world.properties.sea_level": "Sea Level", + "display.terraforged.world.properties.spawn_type": "Spawn Type", + "display.terraforged.world.properties.world_height": "World Height", + "display.terraforged.world.title": "World Settings", + "display.terraforged.world.transition_points": "Transition Points", + "display.terraforged.world.transition_points.beach": "Beach", + "display.terraforged.world.transition_points.coast": "Coast", + "display.terraforged.world.transition_points.deep_ocean": "Deep Ocean", + "display.terraforged.world.transition_points.inland": "Inland", + "display.terraforged.world.transition_points.shallow_ocean": "Shallow Ocean", + "generator.terraforged": "TerraForged", + "generator.terratest": "TerraTest", + "tooltip.terraforged.climate.biome_edge_shape.gain": "Controls the gain subsequent noise octaves", + "tooltip.terraforged.climate.biome_edge_shape.lacunarity": "Controls the lacunarity of subsequent noise octaves", + "tooltip.terraforged.climate.biome_edge_shape.octaves": "Controls the number of noise octaves", + "tooltip.terraforged.climate.biome_edge_shape.scale": "Controls the scale of the noise", + "tooltip.terraforged.climate.biome_edge_shape.strength": "Controls the strength of the noise", + "tooltip.terraforged.climate.biome_edge_shape.type": "The noise type", + "tooltip.terraforged.climate.biome_shape.biome_size": "Controls the size of individual biomes", + "tooltip.terraforged.climate.biome_shape.biome_warp_scale": "Controls the scale of shape distortion for biomes", + "tooltip.terraforged.climate.biome_shape.biome_warp_strength": "Controls the strength of shape distortion for biomes", + "tooltip.terraforged.climate.biome_shape.macro_noise_size": "Macro noise is used to group large areas of biomes into a single type (such as deserts)", + "tooltip.terraforged.climate.moisture.bias": "The bias towards either end of the range", + "tooltip.terraforged.climate.moisture.falloff": "How quickly values transition from an extremity", + "tooltip.terraforged.climate.moisture.max": "The upper limit of the range", + "tooltip.terraforged.climate.moisture.min": "The lower limit of the range", + "tooltip.terraforged.climate.moisture.scale": "The horizontal scale", + "tooltip.terraforged.climate.temperature.bias": "The bias towards either end of the range", + "tooltip.terraforged.climate.temperature.falloff": "How quickly values transition from an extremity", + "tooltip.terraforged.climate.temperature.max": "The upper limit of the range", + "tooltip.terraforged.climate.temperature.min": "The lower limit of the range", + "tooltip.terraforged.climate.temperature.scale": "The horizontal scale", + "tooltip.terraforged.dimensions.bedrock_layer.material": "Controls the material that should be used in the world's base layer", + "tooltip.terraforged.dimensions.bedrock_layer.min_depth": "Controls the minimum height of the world's base layer", + "tooltip.terraforged.dimensions.bedrock_layer.variance": "Controls the amount of height randomness of the world's base layer", + "tooltip.terraforged.dimensions.dimensions.end": "Select the end generator", + "tooltip.terraforged.dimensions.dimensions.nether": "Select the nether generator", + "tooltip.terraforged.filters.erosion.deposite_rate": "Controls how quickly material is deposited (during erosion)", + "tooltip.terraforged.filters.erosion.droplet_lifetime": "Controls the number of iterations that a single water droplet is simulated for", + "tooltip.terraforged.filters.erosion.droplet_velocity": "Controls the starting velocity of the simulated water droplet", + "tooltip.terraforged.filters.erosion.droplet_volume": "Controls the starting volume of water that a simulated water droplet carries", + "tooltip.terraforged.filters.erosion.erosion_rate": "Controls how quickly material dissolves (during erosion)", + "tooltip.terraforged.filters.erosion.iterations": "Controls the number of erosion iterations", + "tooltip.terraforged.filters.smoothing.iterations": "Controls the number of smoothing iterations", + "tooltip.terraforged.filters.smoothing.smoothing_radius": "Controls the smoothing radius", + "tooltip.terraforged.filters.smoothing.smoothing_rate": "Controls how strongly smoothing is applied", + "tooltip.terraforged.miscellaneous.custom_biome_features": "Use custom biome features in place of vanilla ones (such as trees)", + "tooltip.terraforged.miscellaneous.erosion_decorator": "Replace surface materials where erosion has occurred", + "tooltip.terraforged.miscellaneous.mountain_biome_usage": "The probability that mountainous terrain will be set to a mountain biome type.\nThis may help improve compatibility with mods that rely exclusively on mountain biomes.", + "tooltip.terraforged.miscellaneous.natural_snow_decorator": "Removes snow from the terrain where it shouldn't naturally settle", + "tooltip.terraforged.miscellaneous.smooth_layer_decorator": "Modifies layer block levels (ie snow) to fit the terrain", + "tooltip.terraforged.miscellaneous.strata_decorator": "Generates strata (rock layers) instead of just stone", + "tooltip.terraforged.miscellaneous.vanilla_water_features": "Controls whether vanilla lakes & springs should generate", + "tooltip.terraforged.rivers.primary_rivers.bank_width": "Controls the river-banks width", + "tooltip.terraforged.rivers.primary_rivers.bed_depth": "Controls the depth of the river", + "tooltip.terraforged.rivers.primary_rivers.bed_width": "Controls the river-bed width", + "tooltip.terraforged.rivers.primary_rivers.fade": "Controls how much rivers taper", + "tooltip.terraforged.rivers.primary_rivers.max_bank_height": "Controls the height of river banks", + "tooltip.terraforged.rivers.primary_rivers.min_bank_height": "Controls the height of river banks", + "tooltip.terraforged.rivers.river_count": "Controls the number of major rivers per continent", + "tooltip.terraforged.rivers.secondary_river.bank_width": "Controls the river-banks width", + "tooltip.terraforged.rivers.secondary_river.bed_depth": "Controls the depth of the river", + "tooltip.terraforged.rivers.secondary_river.bed_width": "Controls the river-bed width", + "tooltip.terraforged.rivers.secondary_river.fade": "Controls how much rivers taper", + "tooltip.terraforged.rivers.secondary_river.max_bank_height": "Controls the height of river banks", + "tooltip.terraforged.rivers.secondary_river.min_bank_height": "Controls the height of river banks", + "tooltip.terraforged.rivers.tertiary_rivers.bank_width": "Controls the river-banks width", + "tooltip.terraforged.rivers.tertiary_rivers.bed_depth": "Controls the depth of the river", + "tooltip.terraforged.rivers.tertiary_rivers.bed_width": "Controls the river-bed width", + "tooltip.terraforged.rivers.tertiary_rivers.fade": "Controls how much rivers taper", + "tooltip.terraforged.rivers.tertiary_rivers.max_bank_height": "Controls the height of river banks", + "tooltip.terraforged.rivers.tertiary_rivers.min_bank_height": "Controls the height of river banks", + "tooltip.terraforged.structures.mansions.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.mansions.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.structures.ocean_monuments.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.ocean_monuments.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.structures.ocean_ruins.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.ocean_ruins.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.structures.other_structures.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.other_structures.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.structures.shipwrecks.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.shipwrecks.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.structures.strongholds.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.strongholds.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.structures.villages.distance": "The distance (in chunks) between placements of this feature", + "tooltip.terraforged.structures.villages.separation": "The separation (in chunks) between placements of this feature", + "tooltip.terraforged.terrain.badlands.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.badlands.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.badlands.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.badlands.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.dales.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.dales.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.dales.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.dales.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.general.global_horizontal_scale": "Globally controls the horizontal scaling of terrain", + "tooltip.terraforged.terrain.general.global_vertical_scale": "Globally controls the vertical scaling of terrain", + "tooltip.terraforged.terrain.general.terrain_region_size": "Controls the size of terrain regions", + "tooltip.terraforged.terrain.hills.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.hills.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.hills.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.hills.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.mountains.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.mountains.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.mountains.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.mountains.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.plains.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.plains.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.plains.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.plains.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.plateau.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.plateau.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.plateau.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.plateau.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.steppe.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.steppe.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.steppe.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.steppe.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.torridonian.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.torridonian.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.torridonian.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.torridonian.weight": "Controls how common this terrain type is", + "tooltip.terraforged.terrain.volcano.base_scale": "Controls the base height of this terrain", + "tooltip.terraforged.terrain.volcano.horizontal_scale": "Stretches or compresses the terrain horizontally", + "tooltip.terraforged.terrain.volcano.vertical_scale": "Stretches or compresses the terrain vertically", + "tooltip.terraforged.terrain.volcano.weight": "Controls how common this terrain type is", + "tooltip.terraforged.world.continent.continent_mode": "Controls the continent generator type", + "tooltip.terraforged.world.continent.continent_scale": "Controls the size of continents", + "tooltip.terraforged.world.continent.continent_shape": "Controls how continent shapes are calculated", + "tooltip.terraforged.world.continent.ocean_scale": "Controls the amount of ocean between continents", + "tooltip.terraforged.world.properties.sea_level": "Controls the sea level", + "tooltip.terraforged.world.properties.spawn_type": "Set whether spawn should be close to x=0,z=0 or the centre of the nearest continent", + "tooltip.terraforged.world.properties.world_height": "Controls the world height", + "tooltip.terraforged.world.transition_points.beach": "The beach transition point", + "tooltip.terraforged.world.transition_points.coast": "The coast transition point", + "tooltip.terraforged.world.transition_points.deep_ocean": "The deep ocean transition point", + "tooltip.terraforged.world.transition_points.inland": "The inland transition point", + "tooltip.terraforged.world.transition_points.shallow_ocean": "The shallow ocean transition point" +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 01967c6..aaa9637 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ -mod_version=0.0.14 +mod_version=0.1.0-BETA mc_version=1.15.2 -forge_version=31.1.77 +forge_version=31.2.27 mcp_channel=snapshot -mcp_version=20200225-1.15.1 +mcp_version=20200514-1.15.1 org.gradle.jvmargs=-Xmx4G org.gradle.daemon=false \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 5e95ef4..d66aaef 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,3 @@ rootProject.name = "TerraForged" -include ":Noise2D" -include ":TerraForgedMod" -include ":TerraForgedAPI" -include ":TerraForgedCore" -include ":FeatureManager" -include ":TerraForgedApp" \ No newline at end of file +include ":Engine" +include ":FeatureManager" \ No newline at end of file diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java b/src/main/java/com/terraforged/api/biome/BiomeTags.java similarity index 98% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java rename to src/main/java/com/terraforged/api/biome/BiomeTags.java index e411af3..4d9db20 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java +++ b/src/main/java/com/terraforged/api/biome/BiomeTags.java @@ -25,7 +25,7 @@ package com.terraforged.api.biome; -import com.terraforged.core.world.biome.BiomeType; +import com.terraforged.world.biome.BiomeType; import net.minecraft.tags.Tag; import net.minecraft.tags.TagCollection; import net.minecraft.util.ResourceLocation; diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeVariant.java b/src/main/java/com/terraforged/api/biome/BiomeVariant.java similarity index 80% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeVariant.java rename to src/main/java/com/terraforged/api/biome/BiomeVariant.java index b98d854..d6a90ee 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeVariant.java +++ b/src/main/java/com/terraforged/api/biome/BiomeVariant.java @@ -25,6 +25,7 @@ package com.terraforged.api.biome; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; public abstract class BiomeVariant extends Biome { @@ -33,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); @@ -49,4 +55,9 @@ public abstract class BiomeVariant extends Biome { } public abstract Biome getBase(); + + protected static float getTemperatureNoise(BlockPos pos) { + float value = (float) (TEMPERATURE_NOISE.noiseAt(pos.getX() / 8F, pos.getZ() / 8F, false) * 4F); + return (value + pos.getY() - 64F) * 0.05F / 30F; + } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java b/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java similarity index 84% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java rename to src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java index 773b321..c5cd9fc 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java +++ b/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java @@ -25,12 +25,11 @@ package com.terraforged.api.biome.modifier; +import com.terraforged.core.Seed; import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.world.climate.Climate; import net.minecraft.world.biome.Biome; public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { @@ -49,7 +48,7 @@ public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { } @Override - protected final Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz) { + protected final Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz) { float var = variance.getValue(x, z); float value = cell.value + var; if (value < minHeight) { @@ -63,5 +62,5 @@ public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { return in; } - protected abstract Biome getModifiedBiome(Biome in, Cell cell, int x, int z, float ox, float oz); + protected abstract Biome getModifiedBiome(Biome in, Cell cell, int x, int z, float ox, float oz); } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java b/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java similarity index 85% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java rename to src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java index d0a6a43..6727c52 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java +++ b/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java @@ -26,8 +26,7 @@ package com.terraforged.api.biome.modifier; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.terrain.Terrain; +import com.terraforged.world.climate.Climate; import net.minecraft.world.biome.Biome; public abstract class AbstractOffsetModifier implements BiomeModifier { @@ -39,11 +38,11 @@ public abstract class AbstractOffsetModifier implements BiomeModifier { } @Override - public Biome modify(Biome in, Cell cell, int x, int z) { + public Biome modify(Biome in, Cell cell, int x, int z) { float dx = climate.getOffsetX(x, z, 50); float dz = climate.getOffsetX(x, z, 50); return modify(in, cell, x, z, x + dx, z + dz); } - protected abstract Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz); + protected abstract Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz); } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java b/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java similarity index 90% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java rename to src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java index 2d81330..adb2460 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java +++ b/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java @@ -26,16 +26,19 @@ package com.terraforged.api.biome.modifier; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; import net.minecraft.world.biome.Biome; public interface BiomeModifier extends Comparable { int priority(); - boolean test(Biome biome); + boolean test(Biome biome, Cell cell); - Biome modify(Biome in, Cell cell, int x, int z); + Biome modify(Biome in, Cell cell, int x, int z); + + default boolean exitEarly() { + return false; + } @Override default int compareTo(BiomeModifier other) { diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java b/src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java rename to src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java b/src/main/java/com/terraforged/api/biome/surface/CachedSurface.java similarity index 96% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java rename to src/main/java/com/terraforged/api/biome/surface/CachedSurface.java index 8bda7b8..12cd9d6 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java +++ b/src/main/java/com/terraforged/api/biome/surface/CachedSurface.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.api.chunk.surface; +package com.terraforged.api.biome.surface; import net.minecraft.world.biome.Biome; diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/ChunkSurfaceBuffer.java b/src/main/java/com/terraforged/api/biome/surface/ChunkSurfaceBuffer.java similarity index 98% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/ChunkSurfaceBuffer.java rename to src/main/java/com/terraforged/api/biome/surface/ChunkSurfaceBuffer.java index bbc3888..29d4833 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/ChunkSurfaceBuffer.java +++ b/src/main/java/com/terraforged/api/biome/surface/ChunkSurfaceBuffer.java @@ -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; diff --git a/src/main/java/com/terraforged/api/biome/surface/MaskedSurface.java b/src/main/java/com/terraforged/api/biome/surface/MaskedSurface.java new file mode 100644 index 0000000..700f47f --- /dev/null +++ b/src/main/java/com/terraforged/api/biome/surface/MaskedSurface.java @@ -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); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java b/src/main/java/com/terraforged/api/biome/surface/Surface.java similarity index 94% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java rename to src/main/java/com/terraforged/api/biome/surface/Surface.java index 2fd3ede..c3efb73 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java +++ b/src/main/java/com/terraforged/api/biome/surface/Surface.java @@ -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; diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java b/src/main/java/com/terraforged/api/biome/surface/SurfaceContext.java similarity index 85% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java rename to src/main/java/com/terraforged/api/biome/surface/SurfaceContext.java index 923351a..e9e69fd 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java +++ b/src/main/java/com/terraforged/api/biome/surface/SurfaceContext.java @@ -23,19 +23,18 @@ * SOFTWARE. */ -package com.terraforged.api.chunk.surface; +package com.terraforged.api.biome.surface; import com.terraforged.api.chunk.column.DecoratorContext; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrains; +import com.terraforged.world.climate.Climate; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.Terrains; import net.minecraft.block.BlockState; import net.minecraft.world.gen.GenerationSettings; -public class SurfaceContext extends DecoratorContext { +public class SurfaceContext extends DecoratorContext implements AutoCloseable { public final long seed; - public final int seaLevel; public final BlockState solid; public final BlockState fluid; public final ChunkSurfaceBuffer buffer; @@ -48,7 +47,6 @@ public class SurfaceContext extends DecoratorContext { this.solid = settings.getDefaultBlock(); this.fluid = settings.getDefaultFluid(); this.buffer = buffer; - this.seaLevel = levels.waterLevel; this.seed = seed; } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java b/src/main/java/com/terraforged/api/biome/surface/SurfaceManager.java similarity index 51% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java rename to src/main/java/com/terraforged/api/biome/surface/SurfaceManager.java index e0578de..4665908 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java +++ b/src/main/java/com/terraforged/api/biome/surface/SurfaceManager.java @@ -23,28 +23,76 @@ * 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; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; public class SurfaceManager { - private final Map surfaces = new HashMap<>(); + private final ReadWriteLock lock = new ReentrantReadWriteLock(); + private final Map surfaces = new HashMap<>(); + + public Surface getSurface(Biome biome) { + lock.readLock().lock(); + Surface surface = surfaces.get(biome.getRegistryName()); + lock.readLock().unlock(); + return surface; + } + + public Surface getOrCreateSurface(Biome biome) { + Surface surface = getSurface(biome); + if (surface == null) { + surface = Delegate.FUNC.apply(biome); + replace(biome, surface); + } + return surface; + } public SurfaceManager replace(Biome biome, Surface surface) { - surfaces.put(biome, surface); + lock.writeLock().lock(); + surfaces.put(biome.getRegistryName(), surface); + lock.writeLock().unlock(); return this; } - public SurfaceManager extend(Biome biome, Surface surface) { + public SurfaceManager replace(Surface surface, Biome... biomes) { + for (Biome biome : biomes) { + replace(biome, surface); + } + return this; + } + + public SurfaceManager prepend(Biome biome, Surface surface) { + Surface result = surface.then(getOrCreateSurface(biome)); + return replace(biome, result); + } + + public SurfaceManager prepend(Surface surface, Biome... biomes) { + for (Biome biome : biomes) { + prepend(biome, surface); + } + return this; + } + + public SurfaceManager append(Biome biome, Surface surface) { Surface result = getOrCreateSurface(biome).then(surface); return replace(biome, result); } + public SurfaceManager append(Surface surface, Biome... biomes) { + for (Biome biome : biomes) { + append(biome, surface); + } + return this; + } + public Surface getSurface(SurfaceContext context) { if (context.biome == context.cached.biome) { return context.cached.surface; @@ -53,8 +101,4 @@ public class SurfaceManager { context.cached.surface = getOrCreateSurface(context.biome); return context.cached.surface; } - - public Surface getOrCreateSurface(Biome biome) { - return surfaces.computeIfAbsent(biome, Delegate.FUNC); - } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java b/src/main/java/com/terraforged/api/biome/surface/builder/Combiner.java similarity index 90% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java rename to src/main/java/com/terraforged/api/biome/surface/builder/Combiner.java index fdc7015..ea54e60 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java +++ b/src/main/java/com/terraforged/api/biome/surface/builder/Combiner.java @@ -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 { diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java b/src/main/java/com/terraforged/api/biome/surface/builder/Delegate.java similarity index 87% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java rename to src/main/java/com/terraforged/api/biome/surface/builder/Delegate.java index 2f9034d..2972db4 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java +++ b/src/main/java/com/terraforged/api/biome/surface/builder/Delegate.java @@ -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; @@ -38,11 +38,11 @@ public class Delegate implements Surface { private final ConfiguredSurfaceBuilder surfaceBuilder; - private Delegate(Biome biome) { + public Delegate(Biome biome) { this(biome.getSurfaceBuilder()); } - private Delegate(ConfiguredSurfaceBuilder surfaceBuilder) { + public Delegate(ConfiguredSurfaceBuilder surfaceBuilder) { this.surfaceBuilder = surfaceBuilder; } @@ -60,7 +60,7 @@ public class Delegate implements Surface { context.noise, context.solid, context.fluid, - context.seaLevel, + context.levels.waterLevel, context.seed ); } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkContext.java b/src/main/java/com/terraforged/api/chunk/ChunkContext.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkContext.java rename to src/main/java/com/terraforged/api/chunk/ChunkContext.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java b/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java rename to src/main/java/com/terraforged/api/chunk/ChunkDelegate.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java b/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java similarity index 94% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java rename to src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java index e1d0dbf..b26a718 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java +++ b/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java @@ -25,9 +25,9 @@ package com.terraforged.api.chunk.column; -import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer; -import me.dags.noise.Source; -import me.dags.noise.source.FastSource; +import com.terraforged.api.biome.surface.ChunkSurfaceBuffer; +import com.terraforged.n2d.Source; +import com.terraforged.n2d.source.FastSource; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.IChunk; diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java b/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java similarity index 70% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java rename to src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java index 2181348..b305eeb 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java +++ b/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java @@ -27,30 +27,42 @@ package com.terraforged.api.chunk.column; import com.terraforged.api.chunk.ChunkContext; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.geology.DepthBuffer; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; +import com.terraforged.core.concurrent.Resource; +import com.terraforged.world.climate.Climate; +import com.terraforged.world.geology.DepthBuffer; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.Terrains; import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.IChunk; -public class DecoratorContext extends ChunkContext { +public class DecoratorContext extends ChunkContext implements AutoCloseable { public final Levels levels; public final Climate climate; public final Terrains terrains; - public final DepthBuffer depthBuffer = new DepthBuffer(); + public final Resource depthBuffer; public final BlockPos.Mutable pos = new BlockPos.Mutable(); public Biome biome; - public Cell cell; + public Cell cell; public DecoratorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate) { + this(chunk, levels, terrain, climate, true); + } + + public DecoratorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate, boolean depthBuffer) { super(chunk); this.levels = levels; this.climate = climate; this.terrains = terrain; + this.depthBuffer = depthBuffer ? DepthBuffer.get() : null; + } + + @Override + public void close() { + if (depthBuffer != null) { + depthBuffer.close(); + } } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java b/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java rename to src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java b/src/main/java/com/terraforged/api/event/SetupEvent.java similarity index 88% rename from TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java rename to src/main/java/com/terraforged/api/event/SetupEvent.java index e05a98c..f9333e8 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java +++ b/src/main/java/com/terraforged/api/event/SetupEvent.java @@ -27,12 +27,13 @@ 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.core.world.GeneratorContext; -import com.terraforged.core.world.terrain.provider.TerrainProvider; -import com.terraforged.feature.modifier.FeatureModifiers; +import com.terraforged.fm.modifier.FeatureModifiers; +import com.terraforged.fm.structure.StructureManager; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.terrain.provider.TerrainProvider; import net.minecraftforge.eventbus.api.Event; public abstract class SetupEvent extends Event { @@ -109,6 +110,16 @@ public abstract class SetupEvent extends Event { } } + /** + * Register custom FeatureModifiers + */ + public static class Structures extends SetupEvent { + + public Structures(StructureManager manager, GeneratorContext context) { + super(manager, context); + } + } + /** * Register custom Terrain Populators */ diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java b/src/main/java/com/terraforged/api/material/WGTags.java similarity index 91% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java rename to src/main/java/com/terraforged/api/material/WGTags.java index f2c741a..9cf6f76 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/WGTags.java +++ b/src/main/java/com/terraforged/api/material/WGTags.java @@ -25,7 +25,6 @@ package com.terraforged.api.material; -import com.terraforged.api.material.state.StateTagPredicate; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.tags.BlockTags; @@ -51,6 +50,10 @@ public class WGTags { } public static Predicate stone() { - return new StateTagPredicate(STONE); + return toStatePredicate(STONE); + } + + private static Predicate toStatePredicate(Tag tag) { + return state -> tag.contains(state.getBlock()); } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java b/src/main/java/com/terraforged/api/material/geology/GeologyManager.java similarity index 95% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java rename to src/main/java/com/terraforged/api/material/geology/GeologyManager.java index dd46b94..b8a7c72 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java +++ b/src/main/java/com/terraforged/api/material/geology/GeologyManager.java @@ -25,8 +25,8 @@ package com.terraforged.api.material.geology; -import com.terraforged.core.world.geology.Geology; -import com.terraforged.core.world.geology.Strata; +import com.terraforged.world.geology.Geology; +import com.terraforged.world.geology.Strata; import net.minecraft.block.BlockState; import net.minecraft.world.biome.Biome; diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java b/src/main/java/com/terraforged/api/material/geology/StrataConfig.java similarity index 98% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java rename to src/main/java/com/terraforged/api/material/geology/StrataConfig.java index 58ee8b2..8078601 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java +++ b/src/main/java/com/terraforged/api/material/geology/StrataConfig.java @@ -25,7 +25,7 @@ package com.terraforged.api.material.geology; -import me.dags.noise.util.NoiseUtil; +import com.terraforged.n2d.util.NoiseUtil; public class StrataConfig { diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java b/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java similarity index 96% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java rename to src/main/java/com/terraforged/api/material/geology/StrataGenerator.java index ae712f4..f553a38 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java +++ b/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java @@ -25,7 +25,7 @@ package com.terraforged.api.material.geology; -import com.terraforged.core.world.geology.Strata; +import com.terraforged.world.geology.Strata; import net.minecraft.block.BlockState; public interface StrataGenerator { diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerManager.java b/src/main/java/com/terraforged/api/material/layer/LayerManager.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerManager.java rename to src/main/java/com/terraforged/api/material/layer/LayerManager.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java b/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java similarity index 96% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java rename to src/main/java/com/terraforged/api/material/layer/LayerMaterial.java index 70a7fee..eae3c01 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java +++ b/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java @@ -25,7 +25,7 @@ package com.terraforged.api.material.layer; -import me.dags.noise.util.NoiseUtil; +import com.terraforged.n2d.util.NoiseUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -34,7 +34,7 @@ import net.minecraft.state.properties.BlockStateProperties; public class LayerMaterial { - private static final BlockState AIR = Blocks.AIR.getDefaultState(); + public static final BlockState NONE = Blocks.AIR.getDefaultState(); private final int min; private final int max; @@ -64,7 +64,7 @@ public class LayerMaterial { public BlockState getState(int level) { if (level < min) { - return LayerMaterial.AIR; + return LayerMaterial.NONE; } if (level >= max) { return fullState; diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/CachedState.java b/src/main/java/com/terraforged/api/material/state/CachedState.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/state/CachedState.java rename to src/main/java/com/terraforged/api/material/state/CachedState.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/DefaultState.java b/src/main/java/com/terraforged/api/material/state/DefaultState.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/state/DefaultState.java rename to src/main/java/com/terraforged/api/material/state/DefaultState.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateSupplier.java b/src/main/java/com/terraforged/api/material/state/StateSupplier.java similarity index 100% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateSupplier.java rename to src/main/java/com/terraforged/api/material/state/StateSupplier.java diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java b/src/main/java/com/terraforged/api/material/state/States.java similarity index 91% rename from TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java rename to src/main/java/com/terraforged/api/material/state/States.java index c3e2e85..4399e80 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java +++ b/src/main/java/com/terraforged/api/material/state/States.java @@ -35,9 +35,9 @@ public class States { public static final StateSupplier GRAVEL = DefaultState.of("minecraft:gravel").cache(); public static final StateSupplier LAVA = DefaultState.of("minecraft:lava").cache(); public static final StateSupplier PACKED_ICE = DefaultState.of("minecraft:packed_ice").cache(); - public static final StateSupplier RED_SANDSTONE = DefaultState.of("minecraft:red_sandstone").cache(); public static final StateSupplier SAND = DefaultState.of("minecraft:sand").cache(); - public static final StateSupplier SANDSTONE = DefaultState.of("minecraft:sandstone").cache(); + public static final StateSupplier SMOOTH_SANDSTONE = DefaultState.of("minecraft:smooth_sandstone").cache(); + public static final StateSupplier SMOOTH_RED_SANDSTONE = DefaultState.of("minecraft:smooth_red_sandstone").cache(); public static final StateSupplier SNOW_BLOCK = DefaultState.of("minecraft:snow_block").cache(); public static final StateSupplier STONE = DefaultState.of("minecraft:stone").cache(); public static final StateSupplier WATER = DefaultState.of("minecraft:water").cache(); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/Log.java b/src/main/java/com/terraforged/mod/Log.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/Log.java rename to src/main/java/com/terraforged/mod/Log.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java b/src/main/java/com/terraforged/mod/TerraForgedMod.java similarity index 83% rename from TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java rename to src/main/java/com/terraforged/mod/TerraForgedMod.java index 83f36db..1413f1d 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java +++ b/src/main/java/com/terraforged/mod/TerraForgedMod.java @@ -26,13 +26,16 @@ package com.terraforged.mod; import com.terraforged.api.material.WGTags; -import com.terraforged.feature.FeatureManager; -import com.terraforged.mod.command.TerraCommand; +import com.terraforged.mod.chunk.settings.SettingsHelper; +import com.terraforged.mod.server.command.TerraCommand; +import com.terraforged.mod.config.ConfigManager; import com.terraforged.mod.data.DataGen; +import com.terraforged.mod.feature.context.ContextSelectorFeature; import com.terraforged.mod.feature.decorator.poisson.PoissonAtSurface; +import com.terraforged.mod.feature.feature.BushFeature; import com.terraforged.mod.feature.feature.DiskFeature; -import com.terraforged.mod.feature.tree.SaplingManager; -import com.terraforged.mod.settings.SettingsHelper; +import com.terraforged.mod.feature.feature.FreezeLayer; +import com.terraforged.fm.template.TemplateManager; import com.terraforged.mod.util.DataPackFinder; import com.terraforged.mod.util.Environment; import net.minecraft.world.biome.Biomes; @@ -61,16 +64,15 @@ public class TerraForgedMod { Log.info("Common setup"); WGTags.init(); TerraWorld.init(); - SaplingManager.init(); TerraCommand.init(); - SettingsHelper.initSettings(); + ConfigManager.init(); + SettingsHelper.init(); // temp fix BiomeDictionary.addTypes(Biomes.BAMBOO_JUNGLE, BiomeDictionary.Type.OVERWORLD); BiomeDictionary.addTypes(Biomes.BAMBOO_JUNGLE_HILLS, BiomeDictionary.Type.OVERWORLD); - // allows ores to replace any world-gen stone type - OreFeatureConfig.FillerBlockType.create("WG_STONE", "wg_stone", WGTags.stone()); + OreFeatureConfig.FillerBlockType.create("wg_stone", "wg_stone", WGTags.stone()); } @SubscribeEvent @@ -83,8 +85,11 @@ public class TerraForgedMod { @SubscribeEvent public static void registerFeatures(RegistryEvent.Register> event) { Log.info("Registering features"); - FeatureManager.registerTemplates(event); + TemplateManager.register(event); event.getRegistry().register(DiskFeature.INSTANCE); + event.getRegistry().register(FreezeLayer.INSTANCE); + event.getRegistry().register(BushFeature.INSTANCE); + event.getRegistry().register(ContextSelectorFeature.INSTANCE); } @SubscribeEvent diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java b/src/main/java/com/terraforged/mod/TerraWorld.java similarity index 88% rename from TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java rename to src/main/java/com/terraforged/mod/TerraWorld.java index 0c7d479..0c94f11 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java +++ b/src/main/java/com/terraforged/mod/TerraWorld.java @@ -25,19 +25,19 @@ package com.terraforged.mod; -import com.terraforged.core.world.terrain.Terrains; -import com.terraforged.mod.biome.provider.BiomeProvider; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; import com.terraforged.mod.chunk.ChunkGeneratorFactory; import com.terraforged.mod.chunk.TerraChunkGenerator; import com.terraforged.mod.chunk.TerraContext; import com.terraforged.mod.chunk.TerraGenSettings; +import com.terraforged.mod.chunk.settings.DimesionSettings; +import com.terraforged.mod.chunk.settings.SettingsHelper; +import com.terraforged.mod.chunk.settings.TerraSettings; import com.terraforged.mod.chunk.test.TestChunkGenerator; -import com.terraforged.mod.gui.SettingsScreen; -import com.terraforged.mod.settings.DimesionSettings; -import com.terraforged.mod.settings.SettingsHelper; -import com.terraforged.mod.settings.TerraSettings; +import com.terraforged.mod.client.gui.SettingsScreen; import com.terraforged.mod.util.Environment; import com.terraforged.mod.util.nbt.NBTHelper; +import com.terraforged.world.terrain.Terrains; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.CreateWorldScreen; import net.minecraft.world.IWorld; @@ -53,10 +53,10 @@ import net.minecraftforge.api.distmarker.OnlyIn; import java.util.HashSet; import java.util.Set; +import java.util.function.Consumer; public class TerraWorld extends WorldType { - public static final int VERSION = 1; private static final Set types = new HashSet<>(); private final ChunkGeneratorFactory factory; @@ -72,10 +72,9 @@ public class TerraWorld extends WorldType { public ChunkGenerator createChunkGenerator(World world) { if (world.getDimension().getType() == DimensionType.OVERWORLD) { WorldInfo info = world.getWorldInfo(); - int version = SettingsHelper.getVersion(info); TerraSettings settings = SettingsHelper.getSettings(info); - SettingsHelper.syncSettings(world.getWorldInfo(), settings, version); - settings.dimensions.dimensionGenerators.apply(world.getWorldInfo()); + settings.world.seed = world.getSeed(); + settings.dimensions.dimensions.apply(world.getWorldInfo()); Terrains terrains = Terrains.create(settings); @@ -85,7 +84,7 @@ public class TerraWorld extends WorldType { world.getWorldInfo().setGeneratorOptions(NBTHelper.serializeCompact(settings)); TerraContext context = new TerraContext(world, terrains, settings); - BiomeProvider biomeProvider = new BiomeProvider(context); + TerraBiomeProvider biomeProvider = new TerraBiomeProvider(context); Log.debug("Creating Terra {} generator", world.getDimension().getType().getRegistryName()); return factory.create(context, biomeProvider, genSettings); @@ -125,12 +124,17 @@ public class TerraWorld extends WorldType { public static void init() { Log.info("Registered world type"); new TerraWorld("terraforged", TerraChunkGenerator::new); + if (Environment.isDev()) { Log.info("Registered developer world type"); new TerraWorld("terratest", TestChunkGenerator::new); } } + public static void forEach(Consumer consumer) { + types.forEach(consumer); + } + public static boolean isTerraType(WorldType type) { return types.contains(type); } diff --git a/src/main/java/com/terraforged/mod/biome/Bryce.java b/src/main/java/com/terraforged/mod/biome/Bryce.java new file mode 100644 index 0000000..6192ac4 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/Bryce.java @@ -0,0 +1,56 @@ +package com.terraforged.mod.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 Bryce extends BiomeVariant { + + public Bryce() { + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.BADLANDS, SurfaceBuilder.RED_SAND_WHITE_TERRACOTTA_GRAVEL_CONFIG).precipitation(Biome.RainType.NONE).category(Biome.Category.MESA).depth(0.1F).scale(0.2F).temperature(2.0F).downfall(0.0F).waterColor(4159204).waterFogColor(329011).parent((String)null)); + setRegistryName("terraforged", "bryce"); + this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.MESA))); + 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.addExtraGoldOre(this); + DefaultBiomeFeatures.addSedimentDisks(this); + DefaultBiomeFeatures.addGrassAndDeadBushes(this); + DefaultBiomeFeatures.addMushrooms(this); + DefaultBiomeFeatures.addReedsPumpkinsCactus(this); + DefaultBiomeFeatures.addSprings(this); + DefaultBiomeFeatures.addFreezeTopLayer(this); + 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)); + } + + @Override + public void registerWeights() { + BiomeManager.addBiome(BiomeManager.BiomeType.WARM, new BiomeManager.BiomeEntry(this, 2)); + } + + @Override + public Biome getBase() { + return Biomes.BADLANDS; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ColdSteppe.java b/src/main/java/com/terraforged/mod/biome/ColdSteppe.java similarity index 92% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/ColdSteppe.java rename to src/main/java/com/terraforged/mod/biome/ColdSteppe.java index e114c54..36d348b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ColdSteppe.java +++ b/src/main/java/com/terraforged/mod/biome/ColdSteppe.java @@ -29,7 +29,6 @@ import com.terraforged.api.biome.BiomeVariant; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorldReader; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.DefaultBiomeFeatures; @@ -42,8 +41,10 @@ import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; public class ColdSteppe extends BiomeVariant { + private static final float DEFAULT_TEMPERATURE = 0.4F; + public ColdSteppe() { - super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.GIANT_TREE_TAIGA, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(RainType.SNOW).category(Biome.Category.TAIGA).depth(0.2F).scale(0.25F).temperature(0.2F).downfall(0.1F).waterColor(4159204).waterFogColor(329011).parent((String) null)); + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.GIANT_TREE_TAIGA, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(RainType.SNOW).category(Biome.Category.TAIGA).depth(0.2F).scale(0.25F).temperature(0.2F).downfall(0.05F).waterColor(4159204).waterFogColor(329011).parent((String) null)); this.addStructure(Feature.VILLAGE.withConfiguration(new VillageConfig("village/taiga/town_centers", 6))); this.addStructure(Feature.PILLAGER_OUTPOST.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG)); this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.NORMAL))); @@ -58,7 +59,6 @@ public class ColdSteppe extends BiomeVariant { DefaultBiomeFeatures.addGrass(this); DefaultBiomeFeatures.addVeryDenseGrass(this); DefaultBiomeFeatures.addBerryBushes(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)); @@ -80,13 +80,12 @@ public class ColdSteppe extends BiomeVariant { } @Override - public boolean doesSnowGenerate(IWorldReader worldIn, BlockPos pos) { - return false; - } - - @Override - public boolean doesWaterFreeze(IWorldReader worldIn, BlockPos pos) { - return false; + public float getTemperatureRaw(BlockPos pos) { + if (pos.getY() > 64) { + return DEFAULT_TEMPERATURE - getTemperatureNoise(pos); + } else { + return DEFAULT_TEMPERATURE; + } } @Override diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/FirForest.java b/src/main/java/com/terraforged/mod/biome/FirForest.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/FirForest.java rename to src/main/java/com/terraforged/mod/biome/FirForest.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/FlowerPlains.java b/src/main/java/com/terraforged/mod/biome/FlowerPlains.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/FlowerPlains.java rename to src/main/java/com/terraforged/mod/biome/FlowerPlains.java diff --git a/src/main/java/com/terraforged/mod/biome/FrozenLake.java b/src/main/java/com/terraforged/mod/biome/FrozenLake.java new file mode 100644 index 0000000..fc44c9d --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/FrozenLake.java @@ -0,0 +1,75 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.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.structure.MineshaftConfig; +import net.minecraft.world.gen.feature.structure.MineshaftStructure; +import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; + +public class FrozenLake extends BiomeVariant { + + protected FrozenLake() { + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.DEFAULT, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(Biome.RainType.SNOW).category(Biome.Category.RIVER).depth(-0.5F).scale(0.0F).temperature(0.0F).downfall(0.5F).waterColor(3750089).waterFogColor(329011).parent((String)null)); + this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.NORMAL))); + DefaultBiomeFeatures.addCarvers(this); + DefaultBiomeFeatures.addStructures(this); + DefaultBiomeFeatures.addMonsterRooms(this); + DefaultBiomeFeatures.addStoneVariants(this); + DefaultBiomeFeatures.addOres(this); + DefaultBiomeFeatures.addSedimentDisks(this); + DefaultBiomeFeatures.addDefaultFlowers(this); + DefaultBiomeFeatures.addSparseGrass(this); + DefaultBiomeFeatures.addMushrooms(this); + DefaultBiomeFeatures.addReedsAndPumpkins(this); + DefaultBiomeFeatures.addSprings(this); + DefaultBiomeFeatures.addFreezeTopLayer(this); + this.addSpawn(EntityClassification.WATER_CREATURE, new Biome.SpawnListEntry(EntityType.SQUID, 2, 1, 4)); + this.addSpawn(EntityClassification.WATER_CREATURE, new Biome.SpawnListEntry(EntityType.SALMON, 5, 1, 5)); + 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.DROWNED, 1, 1, 1)); + 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)); + setRegistryName("terraforged", "frozen_lake"); + } + + @Override + public Biome getBase() { + return Biomes.FROZEN_RIVER; + } +} diff --git a/src/main/java/com/terraforged/mod/biome/Lake.java b/src/main/java/com/terraforged/mod/biome/Lake.java new file mode 100644 index 0000000..1cc1d03 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/Lake.java @@ -0,0 +1,80 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.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.GenerationStage; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.SeaGrassConfig; +import net.minecraft.world.gen.feature.structure.MineshaftConfig; +import net.minecraft.world.gen.feature.structure.MineshaftStructure; +import net.minecraft.world.gen.placement.IPlacementConfig; +import net.minecraft.world.gen.placement.Placement; +import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; + +public class Lake extends BiomeVariant { + + protected Lake() { + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.DEFAULT, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(Biome.RainType.RAIN).category(Biome.Category.RIVER).depth(-0.5F).scale(0.0F).temperature(0.5F).downfall(0.5F).waterColor(4159204).waterFogColor(329011).parent((String)null)); + this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.NORMAL))); + DefaultBiomeFeatures.addCarvers(this); + DefaultBiomeFeatures.addStructures(this); + DefaultBiomeFeatures.addMonsterRooms(this); + DefaultBiomeFeatures.addStoneVariants(this); + DefaultBiomeFeatures.addOres(this); + DefaultBiomeFeatures.addSedimentDisks(this); + DefaultBiomeFeatures.addDefaultFlowers(this); + DefaultBiomeFeatures.addSparseGrass(this); + DefaultBiomeFeatures.addMushrooms(this); + DefaultBiomeFeatures.addReedsAndPumpkins(this); + DefaultBiomeFeatures.addSprings(this); + this.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Feature.SEAGRASS.withConfiguration(new SeaGrassConfig(48, 0.4D)).withPlacement(Placement.TOP_SOLID_HEIGHTMAP.configure(IPlacementConfig.NO_PLACEMENT_CONFIG))); + DefaultBiomeFeatures.addFreezeTopLayer(this); + this.addSpawn(EntityClassification.WATER_CREATURE, new Biome.SpawnListEntry(EntityType.SQUID, 2, 1, 4)); + this.addSpawn(EntityClassification.WATER_CREATURE, new Biome.SpawnListEntry(EntityType.SALMON, 5, 1, 5)); + 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.DROWNED, 100, 1, 1)); + 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)); + setRegistryName("terraforged", "lake"); + } + + @Override + public Biome getBase() { + return Biomes.RIVER; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/Marshland.java b/src/main/java/com/terraforged/mod/biome/Marshland.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/Marshland.java rename to src/main/java/com/terraforged/mod/biome/Marshland.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java b/src/main/java/com/terraforged/mod/biome/ModBiomes.java similarity index 78% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java rename to src/main/java/com/terraforged/mod/biome/ModBiomes.java index d2ded1b..a5503bd 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ModBiomes.java +++ b/src/main/java/com/terraforged/mod/biome/ModBiomes.java @@ -39,16 +39,21 @@ public class ModBiomes { private static final ArrayList biomes = new ArrayList<>(); + 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()); + public static final Biome LAKE = register(new Lake()); + public static final Biome MARSHLAND = register(new Marshland()); public static final Biome SAVANNA_SCRUB = register(new SavannaScrub()); public static final Biome SHATTERED_SAVANNA_SCRUB = register(new ShatteredSavannaScrub()); + public static final Biome SNOWY_FIR_FOREST = register(new SnowyFirForest()); public static final Biome SNOWY_TAIGA_SCRUB = register(new SnowyTaigaScrub()); public static final Biome STEPPE = register(new Steppe()); public static final Biome TAIGA_SCRUB = register(new TaigaScrub()); public static final Biome WARM_BEACH = register(new WarmBeach()); - public static final Biome MARSHLAND = register(new Marshland()); -// public static final Biome FIR_FOREST = register(new FirForest()); -// public static final Biome FLOWER_PLAINS = register(new FlowerPlains()); private static Biome register(BiomeVariant biome) { biomes.add(biome); @@ -59,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/TerraForgedMod/src/main/java/com/terraforged/mod/biome/SavannaScrub.java b/src/main/java/com/terraforged/mod/biome/SavannaScrub.java similarity index 99% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/SavannaScrub.java rename to src/main/java/com/terraforged/mod/biome/SavannaScrub.java index 3ce4ee9..9ac7079 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/SavannaScrub.java +++ b/src/main/java/com/terraforged/mod/biome/SavannaScrub.java @@ -63,8 +63,8 @@ public class SavannaScrub extends BiomeVariant { DefaultBiomeFeatures.addSedimentDisks(this); DefaultBiomeFeatures.addExtraDefaultFlowers(this); // func_222339_L - add grasses - add this a few times since there are no trees - DefaultBiomeFeatures.addGrass(this); DefaultBiomeFeatures.addVeryDenseGrass(this); + DefaultBiomeFeatures.addDeadBushes(this); DefaultBiomeFeatures.addMushrooms(this); DefaultBiomeFeatures.addReedsAndPumpkins(this); this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.SHEEP, 12, 4, 4)); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ShatteredSavannaScrub.java b/src/main/java/com/terraforged/mod/biome/ShatteredSavannaScrub.java similarity index 98% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/ShatteredSavannaScrub.java rename to src/main/java/com/terraforged/mod/biome/ShatteredSavannaScrub.java index 2121706..aac48de 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/ShatteredSavannaScrub.java +++ b/src/main/java/com/terraforged/mod/biome/ShatteredSavannaScrub.java @@ -59,6 +59,8 @@ public class ShatteredSavannaScrub extends BiomeVariant { DefaultBiomeFeatures.addDefaultFlowers(this); DefaultBiomeFeatures.addGrass(this); DefaultBiomeFeatures.addVeryDenseGrass(this); + DefaultBiomeFeatures.addPlainsTallGrass(this); + DefaultBiomeFeatures.addDeadBushes(this); DefaultBiomeFeatures.addMushrooms(this); DefaultBiomeFeatures.addReedsAndPumpkins(this); DefaultBiomeFeatures.addFreezeTopLayer(this); diff --git a/src/main/java/com/terraforged/mod/biome/SnowyFirForest.java b/src/main/java/com/terraforged/mod/biome/SnowyFirForest.java new file mode 100644 index 0000000..421f49b --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/SnowyFirForest.java @@ -0,0 +1,60 @@ +package com.terraforged.mod.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; + +public class SnowyFirForest extends BiomeVariant { + + public SnowyFirForest() { + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.DEFAULT, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(Biome.RainType.SNOW).category(Biome.Category.TAIGA).depth(0.2F).scale(0.2F).temperature(-0.5F).downfall(0.4F).waterColor(4020182).waterFogColor(329011).parent((String)null)); + this.addStructure(Feature.IGLOO.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG)); + 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.addMonsterRooms(this); + DefaultBiomeFeatures.addTaigaLargeFerns(this); + DefaultBiomeFeatures.addStoneVariants(this); + DefaultBiomeFeatures.addOres(this); + DefaultBiomeFeatures.addSedimentDisks(this); + DefaultBiomeFeatures.addTaigaConifers(this); + DefaultBiomeFeatures.addDefaultFlowers(this); + DefaultBiomeFeatures.addTaigaGrassAndMushrooms(this); + DefaultBiomeFeatures.addMushrooms(this); + DefaultBiomeFeatures.addReedsAndPumpkins(this); + DefaultBiomeFeatures.addSprings(this); + DefaultBiomeFeatures.addSparseBerryBushes(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.WOLF, 8, 4, 4)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.RABBIT, 4, 2, 3)); + this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.FOX, 8, 2, 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.setRegistryName("terraforged", "snowy_fir_forest"); + } + + @Override + public Biome getBase() { + return Biomes.SNOWY_TAIGA; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/SnowyTaigaScrub.java b/src/main/java/com/terraforged/mod/biome/SnowyTaigaScrub.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/SnowyTaigaScrub.java rename to src/main/java/com/terraforged/mod/biome/SnowyTaigaScrub.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/Steppe.java b/src/main/java/com/terraforged/mod/biome/Steppe.java similarity index 89% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/Steppe.java rename to src/main/java/com/terraforged/mod/biome/Steppe.java index e85f77d..742d870 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/Steppe.java +++ b/src/main/java/com/terraforged/mod/biome/Steppe.java @@ -29,7 +29,6 @@ import com.terraforged.api.biome.BiomeVariant; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorldReader; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.DefaultBiomeFeatures; @@ -42,8 +41,10 @@ import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; public class Steppe extends BiomeVariant { + private static final float DEFAULT_TEMPERATURE = 1F; + protected Steppe() { - super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.GIANT_TREE_TAIGA, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(RainType.SNOW).category(Category.SAVANNA).depth(0.2F).scale(0.2F).temperature(0.7F).downfall(0.1F).waterColor(4159204).waterFogColor(329011).parent((String) null)); + super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.GIANT_TREE_TAIGA, SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG).precipitation(RainType.RAIN).category(Category.SAVANNA).depth(0.2F).scale(0.2F).temperature(0.7F).downfall(0.05F).waterColor(4159204).waterFogColor(329011).parent((String) null)); this.addStructure(Feature.VILLAGE.withConfiguration(new VillageConfig("village/savanna/town_centers", 6))); this.addStructure(Feature.PILLAGER_OUTPOST.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG)); this.addStructure(Feature.MINESHAFT.withConfiguration(new MineshaftConfig(0.004D, MineshaftStructure.Type.NORMAL))); @@ -54,8 +55,9 @@ public class Steppe extends BiomeVariant { DefaultBiomeFeatures.addStoneVariants(this); DefaultBiomeFeatures.addOres(this); DefaultBiomeFeatures.addSedimentDisks(this); - DefaultBiomeFeatures.addGrass(this); DefaultBiomeFeatures.addVeryDenseGrass(this); + DefaultBiomeFeatures.addPlainsTallGrass(this); + DefaultBiomeFeatures.addDeadBushes(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)); @@ -72,18 +74,16 @@ public class Steppe extends BiomeVariant { 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)); - setRegistryName("terraforged", "steppe"); } @Override - public boolean doesSnowGenerate(IWorldReader worldIn, BlockPos pos) { - return false; - } - - @Override - public boolean doesWaterFreeze(IWorldReader worldIn, BlockPos pos) { - return false; + public float getTemperatureRaw(BlockPos pos) { + if (pos.getY() > 64) { + return DEFAULT_TEMPERATURE - getTemperatureNoise(pos); + } else { + return DEFAULT_TEMPERATURE; + } } @Override diff --git a/src/main/java/com/terraforged/mod/biome/StoneForest.java b/src/main/java/com/terraforged/mod/biome/StoneForest.java new file mode 100644 index 0000000..9e4b56a --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/StoneForest.java @@ -0,0 +1,67 @@ +package com.terraforged.mod.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, 2)); + } + + @Override + public Biome getBase() { + return Biomes.JUNGLE; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/TaigaScrub.java b/src/main/java/com/terraforged/mod/biome/TaigaScrub.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/TaigaScrub.java rename to src/main/java/com/terraforged/mod/biome/TaigaScrub.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/WarmBeach.java b/src/main/java/com/terraforged/mod/biome/WarmBeach.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/WarmBeach.java rename to src/main/java/com/terraforged/mod/biome/WarmBeach.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeMap.java b/src/main/java/com/terraforged/mod/biome/map/BiomeMap.java similarity index 61% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeMap.java rename to src/main/java/com/terraforged/mod/biome/map/BiomeMap.java index 7fa0f1a..ccaa9fe 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomeMap.java +++ b/src/main/java/com/terraforged/mod/biome/map/BiomeMap.java @@ -27,58 +27,57 @@ package com.terraforged.mod.biome.map; import com.google.gson.JsonElement; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; +import com.terraforged.world.biome.BiomeType; +import com.terraforged.world.heightmap.Levels; import net.minecraft.world.biome.Biome; +import javax.annotation.Nullable; import java.util.List; -import java.util.Set; public interface BiomeMap { - Biome getBeach(float temperature, float moisture, float shape); + Biome getBeach(Cell cell); - Biome getRiver(float temperature, float moisture, float shape); + Biome getCoast(Cell cell, Biome current); - Biome getWetland(float temperature, float moisture, float shape); + Biome getRiver(Cell cell); - Biome getOcean(float temperature, float moisture, float shape); + Biome getLake(Cell cell); - Biome getDeepOcean(float temperature, float moisture, float shape); + Biome getWetland(Cell cell); - Biome getBiome(BiomeType type, float temperature, float moisture, float shape); + Biome getShallowOcean(Cell cell); - default Biome getBiome(Cell cell) { - return getBiome(cell.biomeType, cell.temperature, cell.moisture, cell.biome); - } + Biome getDeepOcean(Cell cell); + + Biome getLand(Cell cell); + + @Nullable + Biome getMountain(Cell cell); + + Biome provideBiome(Cell cell, Levels levels); List getAllBiomes(BiomeType type); - Set getBiomes(BiomeType type); - - Set getRivers(Biome.TempCategory temp); - - Set getOceanBiomes(Biome.TempCategory temp); - - Set getDeepOceanBiomes(Biome.TempCategory temp); - JsonElement toJson(); - static Biome getBiome(Biome biome) { - return biome.delegate.get(); - } - interface Builder { + Builder addOcean(Biome biome, int count); + Builder addBeach(Biome biome, int count); + Builder addCoast(Biome biome, int count); + Builder addRiver(Biome biome, int count); + Builder addLake(Biome biome, int count); + Builder addWetland(Biome biome, int count); - Builder addOcean(Biome biome, int count); + Builder addMountain(Biome biome, int count); - Builder addBiome(BiomeType type, Biome biome, int count); + Builder addLand(BiomeType type, Biome biome, int count); BiomeMap build(); } diff --git a/src/main/java/com/terraforged/mod/biome/map/BiomeMapBuilder.java b/src/main/java/com/terraforged/mod/biome/map/BiomeMapBuilder.java new file mode 100644 index 0000000..6c1d1a0 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/BiomeMapBuilder.java @@ -0,0 +1,130 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.biome.map; + +import com.terraforged.mod.biome.provider.BiomeHelper; +import com.terraforged.world.biome.BiomeType; +import net.minecraft.world.biome.Biome; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +public class BiomeMapBuilder implements BiomeMap.Builder { + + protected final Map> rivers = new HashMap<>(); + protected final Map> lakes = new HashMap<>(); + protected final Map> wetlands = new HashMap<>(); + protected final Map> coasts = new HashMap<>(); + protected final Map> beaches = new HashMap<>(); + protected final Map> oceans = new HashMap<>(); + protected final Map> deepOceans = new HashMap<>(); + protected final Map> mountains = new HashMap<>(); + protected final Map> map = new EnumMap<>(BiomeType.class); + + private final Function constructor; + + BiomeMapBuilder(Function constructor) { + this.constructor = constructor; + } + + @Override + public BiomeMapBuilder addOcean(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getTempCategory(biome); + if (biome.getDepth() < -1) { + add(deepOceans.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + } else { + add(oceans.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + } + return this; + } + + @Override + public BiomeMap.Builder addBeach(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getTempCategory(biome); + add(beaches.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMap.Builder addCoast(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getTempCategory(biome); + add(coasts.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMapBuilder addRiver(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getTempCategory(biome); + add(rivers.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMapBuilder addLake(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getTempCategory(biome); + add(lakes.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMapBuilder addWetland(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getTempCategory(biome); + add(wetlands.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMapBuilder addMountain(Biome biome, int count) { + Biome.TempCategory category = BiomeHelper.getMountainCategory(biome); + add(mountains.computeIfAbsent(category, c -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMapBuilder addLand(BiomeType type, Biome biome, int count) { + add(map.computeIfAbsent(type, t -> new ArrayList<>()), biome, count); + return this; + } + + @Override + public BiomeMap build() { + return constructor.apply(this); + } + + private void add(List list, Biome biome, int count) { + for (int i = 0; i < count; i++) { + list.add(biome); + } + } + + public static BiomeMap.Builder create() { + return new BiomeMapBuilder(SimpleBiomeMap::new); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java b/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java similarity index 92% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java rename to src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java index 30e3fcd..cea6122 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java +++ b/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java @@ -25,8 +25,8 @@ package com.terraforged.mod.biome.map; -import com.terraforged.core.world.biome.BiomeData; import com.terraforged.mod.biome.provider.BiomeHelper; +import com.terraforged.world.biome.BiomeData; import net.minecraft.world.biome.Biome; import java.util.function.BiPredicate; @@ -84,18 +84,21 @@ public interface BiomePredicate { return false; } - BiomePredicate COAST = type(Biome.Category.BEACH, Biome.Category.MUSHROOM).or(name("shore")).or(name("beach")); - BiomePredicate WETLAND = type(Biome.Category.SWAMP); - BiomePredicate DESERT = type(Biome.Category.DESERT).or(temp(0.9, 2).and(rain(-1, 0.2))); - BiomePredicate SAVANNA = type(Biome.Category.SAVANNA).or(temp(0.8, 2).and(rain(-1, 0.4))); - BiomePredicate MESA = type(Biome.Category.MESA); - BiomePredicate STEPPE = name("steppe").and(temp(0.3, 1)); + BiomePredicate BEACH = type(Biome.Category.BEACH).or(name("beach")); + BiomePredicate COAST = type(Biome.Category.MUSHROOM).or(name("coast")); BiomePredicate COLD_STEPPE = name("steppe").and(temp(-1, 0.3)); + BiomePredicate DESERT = type(Biome.Category.DESERT).or(temp(0.9, 2).and(rain(-1, 0.2))); BiomePredicate GRASSLAND = type(Biome.Category.PLAINS); + BiomePredicate LAKE = type(Biome.Category.RIVER).and(name("lake")); + BiomePredicate MESA = type(Biome.Category.MESA); + BiomePredicate MOUNTAIN = type(Biome.Category.EXTREME_HILLS).or(name("mountain")); + BiomePredicate RIVER = type(Biome.Category.RIVER).not(name("lake")); + BiomePredicate SAVANNA = type(Biome.Category.SAVANNA).or(temp(0.8, 2).and(rain(-1, 0.4))); + BiomePredicate STEPPE = name("steppe").and(temp(0.3, 1)); + BiomePredicate TAIGA = type(Biome.Category.TAIGA).or(temp(0.19, 0.35)).not(rainType(Biome.RainType.SNOW)); BiomePredicate TEMPERATE_FOREST = type(Biome.Category.FOREST).and(rain(-1, 0.81)); BiomePredicate TEMPERATE_RAINFOREST = type(Biome.Category.FOREST).and(rain(0.8, 2)); BiomePredicate TROPICAL_RAINFOREST = type(Biome.Category.JUNGLE); - BiomePredicate TAIGA = type(Biome.Category.TAIGA).or(temp(0.19, 0.35)).not(rainType(Biome.RainType.SNOW)); BiomePredicate TUNDRA = type(Biome.Category.ICY).or(temp(-1, 0.21).and(rainType(Biome.RainType.SNOW))); - BiomePredicate MOUNTAIN = type(Biome.Category.EXTREME_HILLS).or(name("mountain")); + BiomePredicate WETLAND = type(Biome.Category.SWAMP); } diff --git a/src/main/java/com/terraforged/mod/biome/map/SimpleBiomeMap.java b/src/main/java/com/terraforged/mod/biome/map/SimpleBiomeMap.java new file mode 100644 index 0000000..974d2f1 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/SimpleBiomeMap.java @@ -0,0 +1,148 @@ +package com.terraforged.mod.biome.map; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.terraforged.mod.biome.map.defaults.DefaultBiomes; +import com.terraforged.mod.biome.map.set.BiomeSet; +import com.terraforged.mod.biome.map.set.BiomeTypeSet; +import com.terraforged.mod.biome.map.set.RiverSet; +import com.terraforged.mod.biome.map.set.TemperatureSet; +import com.terraforged.core.cell.Cell; +import com.terraforged.n2d.util.NoiseUtil; +import com.terraforged.world.biome.BiomeType; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.TerrainType; +import net.minecraft.world.biome.Biome; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class SimpleBiomeMap implements BiomeMap { + + private final BiomeSet deepOcean; + private final BiomeSet shallowOcean; + private final BiomeSet beach; + private final BiomeSet coast; + private final BiomeSet river; + private final BiomeSet lake; + private final BiomeSet wetland; + private final BiomeSet land; + private final BiomeSet mountains; + private final BiomeSet[] terrainBiomes; + + public SimpleBiomeMap(BiomeMapBuilder builder) { + deepOcean = new TemperatureSet(builder.deepOceans, DefaultBiomes::defaultDeepOcean); + shallowOcean = new TemperatureSet(builder.oceans, DefaultBiomes::defaultOcean); + beach = new TemperatureSet(builder.beaches, DefaultBiomes::defaultBeach); + coast = new TemperatureSet(builder.coasts, DefaultBiomes::defaultBiome); + river = new RiverSet(builder.rivers, DefaultBiomes::defaultRiver, this); + lake = new TemperatureSet(builder.lakes, DefaultBiomes::defaultLake); + wetland = new TemperatureSet(builder.wetlands, DefaultBiomes::defaultWetland); + mountains = new TemperatureSet(builder.mountains, DefaultBiomes::defaultMountain); + land = new BiomeTypeSet(builder.map, DefaultBiomes::defaultBiome); + terrainBiomes = new BiomeSet[TerrainType.values().length]; + terrainBiomes[TerrainType.SHALLOW_OCEAN.ordinal()] = shallowOcean; + terrainBiomes[TerrainType.DEEP_OCEAN.ordinal()] = deepOcean; + terrainBiomes[TerrainType.WETLAND.ordinal()] = wetland; + terrainBiomes[TerrainType.RIVER.ordinal()] = river; + terrainBiomes[TerrainType.LAKE.ordinal()] = lake; + for (TerrainType type : TerrainType.values()) { + if (terrainBiomes[type.ordinal()] == null) { + terrainBiomes[type.ordinal()] = land; + } + } + } + + public Biome provideBiome(Cell cell, Levels levels) { + TerrainType type = cell.terrain.getType(); + if (type.isSubmerged() && cell.value > levels.water) { + return land.getBiome(cell); + } + return terrainBiomes[cell.terrain.getType().ordinal()].getBiome(cell); + } + + @Override + public Biome getDeepOcean(Cell cell) { + return deepOcean.getBiome(cell); + } + + @Override + public Biome getShallowOcean(Cell cell) { + return shallowOcean.getBiome(cell); + } + + @Override + public Biome getBeach(Cell cell) { + return beach.getBiome(cell); + } + + @Override + public Biome getCoast(Cell cell, Biome current) { + int inland = land.getSize(cell); + Biome[] coastal = coast.getSet(cell); + int total = inland + coastal.length; + int index = NoiseUtil.round((total - 1) * cell.biome); + if (index >= inland) { + return coastal[index - inland]; + } + return current; + } + + @Override + public Biome getRiver(Cell cell) { + return river.getBiome(cell); + } + + @Override + public Biome getLake(Cell cell) { + return lake.getBiome(cell); + } + + @Override + public Biome getWetland(Cell cell) { + return wetland.getBiome(cell); + } + + @Override + public Biome getMountain(Cell cell) { + return mountains.getBiome(cell); + } + + @Override + public Biome getLand(Cell cell) { + return land.getBiome(cell); + } + + @Override + public List getAllBiomes(BiomeType type) { + if (type == BiomeType.ALPINE) { + return Collections.emptyList(); + } + int size = land.getSize(type.ordinal()); + if (size == 0) { + return Collections.emptyList(); + } + return Arrays.asList(land.getSet(type.ordinal())); + } + + @Override + public JsonElement toJson() { + JsonObject root = new JsonObject(); + root.add("DEEP_OCEAN", deepOcean.toJson()); + root.add("SHALLOW_OCEAN", shallowOcean.toJson()); + root.add("BEACH", beach.toJson()); + root.add("COAST", coast.toJson()); + root.add("RIVER", river.toJson()); + root.add("LAKE", lake.toJson()); + root.add("WETLAND", wetland.toJson()); + root.add("LAND", landToJson()); + return root; + } + + private JsonElement landToJson() { + JsonObject root = land.toJson().getAsJsonObject(); + root.add(BiomeType.ALPINE.name(), mountains.toJson()); + return root; + } +} diff --git a/src/main/java/com/terraforged/mod/biome/map/defaults/BiomeTemps.java b/src/main/java/com/terraforged/mod/biome/map/defaults/BiomeTemps.java new file mode 100644 index 0000000..99c2efb --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/defaults/BiomeTemps.java @@ -0,0 +1,7 @@ +package com.terraforged.mod.biome.map.defaults; + +public class BiomeTemps { + + public static final float COLD = 0.25F; + public static final float HOT = 0.75F; +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/DefaultBiome.java b/src/main/java/com/terraforged/mod/biome/map/defaults/DefaultBiome.java similarity index 57% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/DefaultBiome.java rename to src/main/java/com/terraforged/mod/biome/map/defaults/DefaultBiome.java index 857ffb4..15105df 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/DefaultBiome.java +++ b/src/main/java/com/terraforged/mod/biome/map/defaults/DefaultBiome.java @@ -1,9 +1,12 @@ -package com.terraforged.mod.biome.map; +package com.terraforged.mod.biome.map.defaults; import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.OceanBiome; public interface DefaultBiome { + Biome NONE = new OceanBiome().setRegistryName("terraforged", "none"); + Biome getBiome(float temperature); default Biome getDefaultBiome(float temperature) { diff --git a/src/main/java/com/terraforged/mod/biome/map/defaults/DefaultBiomes.java b/src/main/java/com/terraforged/mod/biome/map/defaults/DefaultBiomes.java new file mode 100644 index 0000000..44a3d9d --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/defaults/DefaultBiomes.java @@ -0,0 +1,83 @@ +package com.terraforged.mod.biome.map.defaults; + +import com.terraforged.mod.biome.ModBiomes; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; + +public class DefaultBiomes { + + public static Biome defaultBeach(float temperature) { + if (temperature < 0.25) { + return Biomes.SNOWY_BEACH; + } + if (temperature > 0.75) { + return ModBiomes.WARM_BEACH; + } + return Biomes.BEACH; + } + + public static Biome defaultRiver(float temperature) { + if (temperature < 0.15) { + return Biomes.FROZEN_RIVER; + } + return Biomes.RIVER; + } + + public static Biome defaultLake(float temperature) { + if (temperature < 0.15) { + return ModBiomes.FROZEN_LAKE; + } + return ModBiomes.LAKE; + } + + public static Biome defaultWetland(float temperature) { + if (temperature < 0.15) { + return ModBiomes.TAIGA_SCRUB; + } + return ModBiomes.MARSHLAND; + } + + public static Biome defaultOcean(float temperature) { + if (temperature < 0.3) { + return Biomes.FROZEN_OCEAN; + } + if (temperature > 0.7) { + return Biomes.WARM_OCEAN; + } + return Biomes.OCEAN; + } + + public static Biome defaultDeepOcean(float temperature) { + if (temperature < 0.3) { + return Biomes.DEEP_FROZEN_OCEAN; + } + if (temperature > 0.7) { + return Biomes.DEEP_WARM_OCEAN; + } + return Biomes.DEEP_OCEAN; + } + + public static Biome defaultMountain(float temperature) { + if (temperature < 0.25) { + return Biomes.SNOWY_MOUNTAINS; + } + if (temperature > 0.75) { + return DefaultBiome.NONE; + } + return Biomes.MOUNTAINS; + } + + public static Biome defaultBiome(float temperature) { + if (temperature < 0.3) { + return ModBiomes.TAIGA_SCRUB; + } + if (temperature > 0.7) { + return ModBiomes.SAVANNA_SCRUB; + } + return Biomes.PLAINS; + } + + public static boolean overridesRiver(Biome biome) { + return biome.getCategory() == Biome.Category.SWAMP || biome.getCategory() == Biome.Category.JUNGLE; + } +} diff --git a/src/main/java/com/terraforged/mod/biome/map/set/BiomeSet.java b/src/main/java/com/terraforged/mod/biome/map/set/BiomeSet.java new file mode 100644 index 0000000..32774a1 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/set/BiomeSet.java @@ -0,0 +1,76 @@ +package com.terraforged.mod.biome.map.set; + +import com.google.gson.JsonElement; +import com.terraforged.mod.biome.map.defaults.DefaultBiome; +import com.terraforged.mod.biome.provider.BiomeHelper; +import com.terraforged.core.cell.Cell; +import com.terraforged.n2d.util.NoiseUtil; +import com.terraforged.mod.util.ListUtils; +import net.minecraft.world.biome.Biome; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +public abstract class BiomeSet { + + private static final Biome[] EMPTY = new Biome[0]; + + private final Biome[][] biomes; + private final DefaultBiome defaultBiome; + + public BiomeSet(Biome[][] biomes, DefaultBiome defaultBiome) { + this.biomes = biomes; + this.defaultBiome = defaultBiome; + } + + public int getSize(int index) { + return biomes[index].length; + } + + public int getSize(Cell cell) { + return biomes[getIndex(cell)].length; + } + + public Biome[] getSet(int index) { + return biomes[index]; + } + + public Biome[] getSet(Cell cell) { + return biomes[getIndex(cell)]; + } + + public Biome getBiome(Cell cell) { + Biome[] set = biomes[getIndex(cell)]; + if (set.length == 0) { + return defaultBiome.getDefaultBiome(cell.temperature); + } + return set[NoiseUtil.round((set.length - 1) * cell.biome)]; + } + + public abstract int getIndex(Cell cell); + + public abstract JsonElement toJson(); + + protected static Biome[][] collect(Map, List> map, int size, Function, Integer> indexer) { + Biome[][] biomes = new Biome[size][]; + for (Enum type : map.keySet()) { + int index = indexer.apply(type); + if (index < 0 || index >= size) { + continue; + } + List list = map.getOrDefault(type, Collections.emptyList()); + list = ListUtils.minimize(list); + list.sort(Comparator.comparing(BiomeHelper::getId)); + biomes[index] = list.toArray(new Biome[0]); + } + for (int i = 0; i < size; i++) { + if (biomes[i] == null) { + biomes[i] = EMPTY; + } + } + return biomes; + } +} diff --git a/src/main/java/com/terraforged/mod/biome/map/set/BiomeTypeSet.java b/src/main/java/com/terraforged/mod/biome/map/set/BiomeTypeSet.java new file mode 100644 index 0000000..c02dc84 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/set/BiomeTypeSet.java @@ -0,0 +1,37 @@ +package com.terraforged.mod.biome.map.set; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.terraforged.mod.biome.map.defaults.DefaultBiome; +import com.terraforged.core.cell.Cell; +import com.terraforged.world.biome.BiomeType; +import net.minecraft.world.biome.Biome; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Stream; + +public class BiomeTypeSet extends BiomeSet { + + public BiomeTypeSet(Map> map, DefaultBiome defaultBiome) { + super(BiomeSet.collect(map, BiomeType.values().length, Enum::ordinal), defaultBiome); + } + + @Override + public int getIndex(Cell cell) { + return cell.biomeType.ordinal(); + } + + @Override + public JsonElement toJson() { + JsonObject root = new JsonObject(); + for (BiomeType type : BiomeType.values()) { + JsonArray array = new JsonArray(); + root.add(type.name(), array); + Stream.of(getSet(type.ordinal())).distinct().map(Biome::getRegistryName).map(Objects::toString).forEach(array::add); + } + return root; + } +} diff --git a/src/main/java/com/terraforged/mod/biome/map/set/RiverSet.java b/src/main/java/com/terraforged/mod/biome/map/set/RiverSet.java new file mode 100644 index 0000000..49628bf --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/set/RiverSet.java @@ -0,0 +1,29 @@ +package com.terraforged.mod.biome.map.set; + +import com.terraforged.mod.biome.map.BiomeMap; +import com.terraforged.mod.biome.map.defaults.DefaultBiome; +import com.terraforged.mod.biome.map.defaults.DefaultBiomes; +import com.terraforged.core.cell.Cell; +import net.minecraft.world.biome.Biome; + +import java.util.List; +import java.util.Map; + +public class RiverSet extends TemperatureSet { + + private final BiomeMap biomes; + + public RiverSet(Map> map, DefaultBiome defaultBiome, BiomeMap biomes) { + super(map, defaultBiome); + this.biomes = biomes; + } + + @Override + public Biome getBiome(Cell cell) { + Biome biome = biomes.getLand(cell); + if (DefaultBiomes.overridesRiver(biome)) { + return biome; + } + return super.getBiome(cell); + } +} diff --git a/src/main/java/com/terraforged/mod/biome/map/set/TemperatureSet.java b/src/main/java/com/terraforged/mod/biome/map/set/TemperatureSet.java new file mode 100644 index 0000000..6a152c2 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/map/set/TemperatureSet.java @@ -0,0 +1,46 @@ +package com.terraforged.mod.biome.map.set; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.terraforged.mod.biome.map.defaults.BiomeTemps; +import com.terraforged.mod.biome.map.defaults.DefaultBiome; +import com.terraforged.core.cell.Cell; +import net.minecraft.world.biome.Biome; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Stream; + +public class TemperatureSet extends BiomeSet { + + public TemperatureSet(Map> map, DefaultBiome defaultBiome) { + super(BiomeSet.collect(map, 3, e -> e.ordinal() - 1), defaultBiome); + } + + @Override + public int getIndex(Cell cell) { + if (cell.temperature < BiomeTemps.COLD) { + return 0; + } + if (cell.temperature > BiomeTemps.HOT) { + return 2; + } + return 1; + } + + @Override + public JsonElement toJson() { + JsonObject root = new JsonObject(); + for (Biome.TempCategory temp : Biome.TempCategory.values()) { + int index = temp.ordinal() - 1; + if (index >= 0 && index < 3) { + JsonArray array = new JsonArray(); + root.add(temp.name(), array); + Stream.of(getSet(index)).distinct().map(Biome::getRegistryName).map(Objects::toString).forEach(array::add); + } + } + return root; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/AbstractMaxHeightModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/AbstractMaxHeightModifier.java similarity index 84% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/AbstractMaxHeightModifier.java rename to src/main/java/com/terraforged/mod/biome/modifier/AbstractMaxHeightModifier.java index 8915c6d..7a62baf 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/AbstractMaxHeightModifier.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/AbstractMaxHeightModifier.java @@ -25,12 +25,11 @@ package com.terraforged.mod.biome.modifier; +import com.terraforged.core.Seed; import com.terraforged.core.cell.Cell; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.Module; -import me.dags.noise.Source; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.world.climate.Climate; import net.minecraft.world.biome.Biome; public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { @@ -49,7 +48,7 @@ public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { } @Override - protected final Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz) { + protected final Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz) { float var = variance.getValue(x, z); float value = cell.value + var; if (value < minHeight) { @@ -63,5 +62,5 @@ public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { return in; } - protected abstract Biome getModifiedBiome(Biome in, Cell cell, int x, int z, float ox, float oz); + protected abstract Biome getModifiedBiome(Biome in, Cell cell, int x, int z, float ox, float oz); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/AbstractOffsetModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/AbstractOffsetModifier.java similarity index 86% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/AbstractOffsetModifier.java rename to src/main/java/com/terraforged/mod/biome/modifier/AbstractOffsetModifier.java index 0f9031a..5ba1157 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/AbstractOffsetModifier.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/AbstractOffsetModifier.java @@ -27,8 +27,7 @@ package com.terraforged.mod.biome.modifier; import com.terraforged.api.biome.modifier.BiomeModifier; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.climate.Climate; -import com.terraforged.core.world.terrain.Terrain; +import com.terraforged.world.climate.Climate; import net.minecraft.world.biome.Biome; public abstract class AbstractOffsetModifier implements BiomeModifier { @@ -40,11 +39,11 @@ public abstract class AbstractOffsetModifier implements BiomeModifier { } @Override - public Biome modify(Biome in, Cell cell, int x, int z) { + public Biome modify(Biome in, Cell cell, int x, int z) { float dx = climate.getOffsetX(x, z, 50); float dz = climate.getOffsetX(x, z, 50); return modify(in, cell, x, z, x + dx, z + dz); } - protected abstract Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz); + protected abstract Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz); } diff --git a/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java new file mode 100644 index 0000000..7dc1d6e --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java @@ -0,0 +1,46 @@ +package com.terraforged.mod.biome.modifier; + +import com.terraforged.api.biome.modifier.BiomeModifier; +import com.terraforged.mod.biome.map.BiomeMap; +import com.terraforged.core.cell.Cell; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.biome.BiomeType; +import com.terraforged.world.terrain.TerrainType; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; + +public class BeachModifier implements BiomeModifier { + + private final float height; + private final Module noise; + private final BiomeMap biomes; + + public BeachModifier(BiomeMap biomeMap, GeneratorContext context) { + this.biomes = biomeMap; + this.height = context.levels.water(6); + this.noise = Source.perlin(context.seed.next(), 10, 1).scale(context.levels.scale(5)); + } + + @Override + public int priority() { + return 9; + } + + @Override + public boolean test(Biome biome, Cell cell) { + return cell.terrain.getType() == TerrainType.BEACH && cell.biomeType != BiomeType.DESERT; + } + + @Override + public Biome modify(Biome in, Cell cell, int x, int z) { + if (cell.value + noise.getValue(x, z) < height) { + if (in == Biomes.MUSHROOM_FIELDS) { + return Biomes.MUSHROOM_FIELD_SHORE; + } + return biomes.getBeach(cell); + } + return in; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java b/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java similarity index 81% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java rename to src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java index 5cbf385..59e9fbe 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java @@ -27,12 +27,12 @@ package com.terraforged.mod.biome.modifier; import com.terraforged.api.biome.modifier.BiomeModifier; import com.terraforged.api.biome.modifier.ModifierManager; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.biome.BiomeType; -import com.terraforged.core.world.terrain.Terrain; import com.terraforged.mod.biome.map.BiomeMap; import com.terraforged.mod.biome.provider.DesertBiomes; import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.cell.Cell; +import com.terraforged.world.biome.BiomeType; +import com.terraforged.world.terrain.ITerrain; import net.minecraft.world.biome.Biome; import java.util.ArrayList; @@ -47,42 +47,46 @@ public class BiomeModifierManager implements BiomeModifier, ModifierManager { public BiomeModifierManager(TerraContext context, BiomeMap biomes) { desertBiomes = new DesertBiomes(context.materials, biomes.getAllBiomes(BiomeType.DESERT)); List modifiers = new ArrayList<>(); - modifiers.add(new BeachModifier(biomes, context.terrain)); + modifiers.add(new CoastModifier(biomes, context)); modifiers.add(new DesertColorModifier(desertBiomes)); - modifiers.add(new SandBiomeModifier( - context.seed, - context.factory.getClimate(), - context.levels - )); + modifiers.add(new BeachModifier(biomes, context)); + modifiers.add(new MountainModifier(context, biomes)); Collections.sort(modifiers); this.biomeModifiers = modifiers; } + public boolean hasModifiers(ITerrain type) { + return type.isOverground(); + } + + public DesertBiomes getDesertBiomes() { + return desertBiomes; + } + @Override public void register(BiomeModifier modifier) { biomeModifiers.add(modifier); Collections.sort(biomeModifiers); } - public DesertBiomes getDesertBiomes() { - return desertBiomes; - } - @Override public int priority() { return -1; } @Override - public boolean test(Biome biome) { + public boolean test(Biome biome, Cell cell) { return true; } @Override - public Biome modify(Biome biome, Cell cell, int x, int z) { + public Biome modify(Biome biome, Cell cell, int x, int z) { for (BiomeModifier modifier : biomeModifiers) { - if (modifier.test(biome)) { + if (modifier.test(biome, cell)) { biome = modifier.modify(biome, cell, x, z); + if (modifier.exitEarly()) { + return biome; + } } } return biome; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/CoastModifier.java similarity index 73% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java rename to src/main/java/com/terraforged/mod/biome/modifier/CoastModifier.java index 31abce2..341b4c2 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/BeachModifier.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/CoastModifier.java @@ -26,36 +26,38 @@ package com.terraforged.mod.biome.modifier; import com.terraforged.api.biome.modifier.BiomeModifier; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; import com.terraforged.mod.biome.map.BiomeMap; +import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.cell.Cell; +import com.terraforged.world.terrain.Terrains; import net.minecraft.world.biome.Biome; -public class BeachModifier implements BiomeModifier { +public class CoastModifier implements BiomeModifier { + private final float height; private final Terrains terrain; private final BiomeMap biomeMap; - public BeachModifier(BiomeMap biomeMap, Terrains terrain) { - this.terrain = terrain; + public CoastModifier(BiomeMap biomeMap, TerraContext context) { + this.terrain = context.terrain; this.biomeMap = biomeMap; + this.height = context.levels.water(8); } @Override public int priority() { - return 0; + return 10; } @Override - public boolean test(Biome biome) { - return true; + public boolean test(Biome biome, Cell cell) { + return cell.terrain.isCoast(); } @Override - public Biome modify(Biome in, Cell cell, int x, int z) { - if (cell.tag == terrain.beach) { - return biomeMap.getBeach(cell.temperature, cell.moisture, cell.biome); + public Biome modify(Biome in, Cell cell, int x, int z) { + if (cell.terrain.isCoast()) { + return biomeMap.getCoast(cell, in); } return in; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/DesertColorModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/DesertColorModifier.java similarity index 76% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/DesertColorModifier.java rename to src/main/java/com/terraforged/mod/biome/modifier/DesertColorModifier.java index d941f23..f2c4614 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/modifier/DesertColorModifier.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/DesertColorModifier.java @@ -26,9 +26,8 @@ package com.terraforged.mod.biome.modifier; import com.terraforged.api.biome.modifier.BiomeModifier; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; import com.terraforged.mod.biome.provider.DesertBiomes; +import com.terraforged.core.cell.Cell; import net.minecraft.world.biome.Biome; public class DesertColorModifier implements BiomeModifier { @@ -39,24 +38,33 @@ public class DesertColorModifier implements BiomeModifier { this.biomes = biomes; } + @Override + public boolean exitEarly() { + return true; + } + @Override public int priority() { - return 0; + return 5; } @Override - public boolean test(Biome biome) { - return biome.getCategory() == Biome.Category.DESERT; + public boolean test(Biome biome, Cell cell) { + return biome.getCategory() == Biome.Category.DESERT + || biome.getCategory() == Biome.Category.MESA + || biomes.isDesert(biome); } @Override - public Biome modify(Biome in, Cell cell, int x, int z) { + public Biome modify(Biome in, Cell cell, int x, int z) { if (biomes.isRedDesert(in)) { - if (cell.continent <= 0.5F) { + if (cell.macroNoise <= 0.5F) { return biomes.getWhiteDesert(cell.biome); } - } else if (cell.continent > 0.5F) { - return biomes.getRedDesert(cell.biome); + } else { + if (cell.macroNoise > 0.5F) { + return biomes.getRedDesert(cell.biome); + } } return in; } diff --git a/src/main/java/com/terraforged/mod/biome/modifier/MountainModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/MountainModifier.java new file mode 100644 index 0000000..eed4c34 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/modifier/MountainModifier.java @@ -0,0 +1,46 @@ +package com.terraforged.mod.biome.modifier; + +import com.terraforged.api.biome.modifier.BiomeModifier; +import com.terraforged.mod.biome.map.BiomeMap; +import com.terraforged.mod.biome.map.defaults.DefaultBiome; +import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.cell.Cell; +import net.minecraft.world.biome.Biome; + +public class MountainModifier implements BiomeModifier { + + // the probability that mountain terrain will get upgraded to a mountain biome + public static final float MOUNTAIN_CHANCE = 0.4F; + + private final float chance; + private final BiomeMap biomes; + + public MountainModifier(TerraContext context, BiomeMap biomes) { + this.biomes = biomes; + this.chance = context.terraSettings.miscellaneous.mountainBiomeUsage; + } + + @Override + public int priority() { + return 0; + } + + @Override + public boolean exitEarly() { + return true; + } + + @Override + public boolean test(Biome biome, Cell cell) { + return cell.terrain.isMountain() && cell.macroNoise < chance; + } + + @Override + public Biome modify(Biome in, Cell cell, int x, int z) { + Biome mountain = biomes.getMountain(cell); + if (mountain != DefaultBiome.NONE) { + return mountain; + } + return in; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java b/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java similarity index 68% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java rename to src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java index 121472a..042f095 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java +++ b/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java @@ -25,14 +25,13 @@ package com.terraforged.mod.biome.provider; -import com.terraforged.core.settings.BiomeSettings; -import com.terraforged.core.world.biome.BiomeData; -import com.terraforged.core.world.biome.BiomeType; import com.terraforged.mod.biome.ModBiomes; import com.terraforged.mod.biome.map.BiomeMap; import com.terraforged.mod.biome.map.BiomeMapBuilder; import com.terraforged.mod.biome.map.BiomePredicate; -import me.dags.noise.util.Vec2f; +import com.terraforged.n2d.util.Vec2f; +import com.terraforged.world.biome.BiomeData; +import com.terraforged.world.biome.BiomeType; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biomes; @@ -50,100 +49,69 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; public class BiomeHelper { 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)); - put(BiomeType.DESERT, BiomePredicate.DESERT.or(BiomePredicate.MESA).not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN).not(BiomePredicate.WETLAND)); - put(BiomeType.TEMPERATE_RAINFOREST, BiomePredicate.TEMPERATE_RAINFOREST.not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN)); - put(BiomeType.TEMPERATE_FOREST, BiomePredicate.TEMPERATE_FOREST.not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN).not(BiomePredicate.WETLAND)); - put(BiomeType.GRASSLAND, BiomePredicate.GRASSLAND.not(BiomePredicate.WETLAND).not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN)); - put(BiomeType.COLD_STEPPE, BiomePredicate.COLD_STEPPE.not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN)); - put(BiomeType.STEPPE, BiomePredicate.STEPPE.not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN)); - put(BiomeType.TAIGA, BiomePredicate.TAIGA.not(BiomePredicate.TUNDRA).not(BiomePredicate.COLD_STEPPE).not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN)); - put(BiomeType.TUNDRA, BiomePredicate.TUNDRA.not(BiomePredicate.TAIGA).not(BiomePredicate.COAST).not(BiomePredicate.MOUNTAIN)); + put(BiomeType.SAVANNA, BiomePredicate.SAVANNA.or(BiomePredicate.MESA).not(BiomePredicate.DESERT).not(BiomePredicate.STEPPE).not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN).not(BiomePredicate.WETLAND)); + put(BiomeType.DESERT, BiomePredicate.DESERT.or(BiomePredicate.MESA).not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN).not(BiomePredicate.WETLAND)); + put(BiomeType.TEMPERATE_RAINFOREST, BiomePredicate.TEMPERATE_RAINFOREST.not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN)); + put(BiomeType.TEMPERATE_FOREST, BiomePredicate.TEMPERATE_FOREST.not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN).not(BiomePredicate.WETLAND)); + put(BiomeType.GRASSLAND, BiomePredicate.GRASSLAND.not(BiomePredicate.WETLAND).not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN)); + put(BiomeType.COLD_STEPPE, BiomePredicate.COLD_STEPPE.not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN)); + put(BiomeType.STEPPE, BiomePredicate.STEPPE.not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN)); + put(BiomeType.TAIGA, BiomePredicate.TAIGA.not(BiomePredicate.TUNDRA).not(BiomePredicate.COLD_STEPPE).not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN)); + put(BiomeType.TUNDRA, BiomePredicate.TUNDRA.not(BiomePredicate.TAIGA).not(BiomePredicate.BEACH).not(BiomePredicate.MOUNTAIN)); put(BiomeType.ALPINE, BiomePredicate.MOUNTAIN); }}; - public static BiomeMap.Builder getBuilder(List biomes) { - return BiomeMapBuilder.basic(biomes); - } - - public static BiomeMap getDefaultBiomeMap() { + public static BiomeMap createBiomeMap() { List biomes = getAllBiomeData(); - BiomeMap.Builder builder = getBuilder(biomes); + BiomeWeights weights = new BiomeWeights(); + BiomeMap.Builder builder = BiomeMapBuilder.create(); for (BiomeData data : biomes) { - int weight = 10; Biome biome = (Biome) data.reference; - if (biome.isMutation() && getId(biome).contains("hills")) { continue; } - if (biome.getCategory() == Biome.Category.FOREST) { - weight = 5; - } - - // don't use BiomeDictionary with transient biomes - if (ForgeRegistries.BIOMES.containsKey(biome.getRegistryName())) { - if (BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.RARE)) { - weight = 1; - } - } - - if (BiomePredicate.COAST.test(data)) { + int weight = weights.getWeight(biome); + if (BiomePredicate.BEACH.test(data)) { builder.addBeach(biome, weight); + } else if (BiomePredicate.COAST.test(data)) { + builder.addCoast(biome, weight); } else if (biome.getCategory() == Biome.Category.OCEAN) { builder.addOcean(biome, weight); - } else if (biome.getCategory() == Biome.Category.RIVER) { + } else if (BiomePredicate.RIVER.test(data)) { builder.addRiver(biome, weight); - } else if (biome.getCategory() == Biome.Category.SWAMP) { + } else if (BiomePredicate.LAKE.test(data)) { + builder.addLake(biome, weight); + } else if (BiomePredicate.WETLAND.test(data)) { builder.addWetland(biome, weight); + } else if (BiomePredicate.MOUNTAIN.test(data)) { + builder.addMountain(biome, weight); } else { Collection types = getTypes(data, biome); for (BiomeType type : types) { - builder.addBiome(type, biome, weight); + // shouldn't happen + if (type == BiomeType.ALPINE) { + continue; + } + builder.addLand(type, biome, weight); } } } - builder.addBiome(BiomeType.TEMPERATE_RAINFOREST, Biomes.PLAINS, 10); - builder.addBiome(BiomeType.TEMPERATE_FOREST, Biomes.FLOWER_FOREST, 3); - builder.addBiome(BiomeType.TEMPERATE_FOREST, Biomes.PLAINS, 10); - builder.addBiome(BiomeType.TUNDRA, ModBiomes.SNOWY_TAIGA_SCRUB, 5); - builder.addBiome(BiomeType.TAIGA, ModBiomes.TAIGA_SCRUB, 5); + builder.addLand(BiomeType.TEMPERATE_RAINFOREST, Biomes.PLAINS, 5); + builder.addLand(BiomeType.TEMPERATE_FOREST, Biomes.FLOWER_FOREST, 2); + builder.addLand(BiomeType.TEMPERATE_FOREST, Biomes.PLAINS, 5); + builder.addLand(BiomeType.TUNDRA, ModBiomes.SNOWY_TAIGA_SCRUB, 2); + builder.addLand(BiomeType.TAIGA, ModBiomes.TAIGA_SCRUB, 2); return builder.build(); } - public static BiomeMap getBiomeMap(BiomeSettings settings) { - List biomes = getAllBiomeData(); - BiomeMap.Builder builder = getBuilder(biomes); - Map biomeMap = biomes.stream().collect(Collectors.toMap(d -> d.name, d -> d)); - Map groupMap = settings.asMap(); - for (Map.Entry e : groupMap.entrySet()) { - for (BiomeSettings.BiomeWeight biomeWeight : e.getValue().biomes) { - BiomeData data = biomeMap.get(biomeWeight.id); - if (data == null) { - continue; - } - builder.addBiome(e.getKey(), (Biome) data.reference, biomeWeight.weight); - } - } - for (BiomeData data : biomes) { - Biome biome = (Biome) data.reference; - if (biome.getCategory() == Biome.Category.OCEAN) { - builder.addOcean(biome, 10); - } else if (biome.getCategory() == Biome.Category.RIVER) { - builder.addRiver(biome, 10); - } - } - return builder.build(); - } - public static Biome.TempCategory getTempCategory(Biome biome) { // vanilla ocean biome properties are not at all helpful for determining temperature if (biome.getCategory() == Biome.Category.OCEAN) { @@ -167,6 +135,16 @@ public class BiomeHelper { return biome.getTempCategory(); } + public static Biome.TempCategory getMountainCategory(Biome biome) { + if (biome.getDefaultTemperature() < 0.2) { + return Biome.TempCategory.COLD; + } + if (biome.getDefaultTemperature() > 0.4) { + return Biome.TempCategory.WARM; + } + return Biome.TempCategory.MEDIUM; + } + public static String getId(Biome biome) { ResourceLocation name = biome.getRegistryName(); if (name == null) { @@ -186,7 +164,7 @@ public class BiomeHelper { } public static List getAllBiomeData() { - Collection biomes = TerraBiomeRegistry.getInstance().getAll(BiomeHelper::filter); + Collection biomes = getAllBiomes(); Vec2f tempRange = getRange(biomes, Biome::getDefaultTemperature); Vec2f moistRange = getRange(biomes, Biome::getDownfall); List list = new LinkedList<>(); @@ -200,6 +178,17 @@ public class BiomeHelper { return list; } + public static Set getAllBiomes() { + Set biomes = new HashSet<>(); + for (Biome biome : ForgeRegistries.BIOMES) { + if (filter(biome)) { + continue; + } + biomes.add(biome.delegate.get()); + } + return biomes; + } + private static boolean filter(Biome biome) { if (biome.getCategory() == Biome.Category.NONE) { return true; @@ -210,6 +199,9 @@ public class BiomeHelper { if (biome.getCategory() == Biome.Category.NETHER) { return true; } + if (biome == Biomes.MUSHROOM_FIELD_SHORE || biome == Biomes.MOUNTAIN_EDGE) { + return true; + } return !BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.OVERWORLD); } diff --git a/src/main/java/com/terraforged/mod/biome/provider/BiomeWeights.java b/src/main/java/com/terraforged/mod/biome/provider/BiomeWeights.java new file mode 100644 index 0000000..847d0fb --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/provider/BiomeWeights.java @@ -0,0 +1,79 @@ +package com.terraforged.mod.biome.provider; + +import com.electronwill.nightconfig.core.CommentedConfig; +import com.terraforged.mod.Log; +import com.terraforged.mod.config.ConfigManager; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.common.BiomeManager; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BiomeWeights { + + private final int standardWeight; + private final int forestWeight; + private final int rareWeight; + private final Map biomes = new HashMap<>(); + + public BiomeWeights() { + this(10, 5, 1); + } + + public BiomeWeights(int standard, int forest, int rare) { + this.standardWeight = standard; + this.forestWeight = forest; + this.rareWeight = rare; + + // Get biome weights from Forge + for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values()) { + List entries = BiomeManager.getBiomes(type); + if (entries == null) { + continue; + } + for (BiomeManager.BiomeEntry entry : entries) { + biomes.put(entry.biome.getRegistryName(), entry.itemWeight); + } + } + + // TF config gets final say + readWeights(); + } + + public int getWeight(Biome biome) { + Integer value = biomes.get(biome.getRegistryName()); + if (value != null) { + return value; + } + if (BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.RARE)) { + return rareWeight; + } + if (biome.getCategory() == Biome.Category.FOREST) { + return forestWeight; + } + return standardWeight; + } + + private void readWeights() { + CommentedConfig config = ConfigManager.BIOME_WEIGHTS.get(); + + for (String key : config.valueMap().keySet()) { + int weight = config.getInt(key); + if (weight < 0) { + continue; + } + + ResourceLocation name = new ResourceLocation(key); + if (!ForgeRegistries.BIOMES.containsKey(name)) { + continue; + } + + biomes.put(name, weight); + Log.debug("Loaded custom biome weight: %s=%s", name, weight); + } + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/DesertBiomes.java b/src/main/java/com/terraforged/mod/biome/provider/DesertBiomes.java similarity index 92% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/DesertBiomes.java rename to src/main/java/com/terraforged/mod/biome/provider/DesertBiomes.java index 18941d9..a29588a 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/DesertBiomes.java +++ b/src/main/java/com/terraforged/mod/biome/provider/DesertBiomes.java @@ -27,11 +27,10 @@ package com.terraforged.mod.biome.provider; import com.terraforged.api.material.layer.LayerManager; import com.terraforged.api.material.layer.LayerMaterial; -import com.terraforged.core.util.concurrent.ObjectPool; +import com.terraforged.core.concurrent.Resource; import com.terraforged.mod.material.Materials; import com.terraforged.mod.util.DummyBlockReader; import com.terraforged.mod.util.ListUtils; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.material.MaterialColor; @@ -51,6 +50,7 @@ public class DesertBiomes { private final Set reds; private final Set whites; + private final Set deserts; private final List redSand; private final List whiteSand; private final LayerManager layerManager; @@ -61,10 +61,10 @@ public class DesertBiomes { public DesertBiomes(Materials materials, List deserts) { List white = new LinkedList<>(); List red = new LinkedList<>(); - try (ObjectPool.Item reader = DummyBlockReader.pooled()) { + try (Resource reader = DummyBlockReader.pooled()) { for (Biome biome : deserts) { BlockState top = biome.getSurfaceBuilderConfig().getTop(); - MaterialColor color = top.getMaterialColor(reader.getValue().set(top), BlockPos.ZERO); + MaterialColor color = top.getMaterialColor(reader.get().set(top), BlockPos.ZERO); int whiteDist2 = distance2(color, MaterialColor.SAND); int redDist2 = distance2(color, MaterialColor.ADOBE); if (whiteDist2 < redDist2) { @@ -77,6 +77,7 @@ public class DesertBiomes { this.layerManager = materials.getLayerManager(); this.whiteSand = new ArrayList<>(white); this.redSand = new ArrayList<>(red); + this.deserts = new HashSet<>(deserts); this.whites = new HashSet<>(white); this.reds = new HashSet<>(red); this.whiteSand.sort(Comparator.comparing(BiomeHelper::getId)); @@ -84,6 +85,9 @@ public class DesertBiomes { this.maxRedIndex = red.size() - 1; this.maxWhiteIndex = white.size() - 1; } + public boolean isDesert(Biome biome) { + return deserts.contains(biome); + } public boolean isRedDesert(Biome biome) { return reds.contains(biome); @@ -102,7 +106,6 @@ public class DesertBiomes { } public LayerMaterial getSandLayers(Biome biome) { - Block top = biome.getSurfaceBuilderConfig().getTop().getBlock(); return layerManager.getMaterial(Blocks.SAND); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java b/src/main/java/com/terraforged/mod/biome/provider/TerraBiomeProvider.java similarity index 53% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java rename to src/main/java/com/terraforged/mod/biome/provider/TerraBiomeProvider.java index 5e7bc4f..48e6fc0 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeProvider.java +++ b/src/main/java/com/terraforged/mod/biome/provider/TerraBiomeProvider.java @@ -26,20 +26,19 @@ package com.terraforged.mod.biome.provider; import com.google.common.collect.Sets; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.chunk.ChunkReader; -import com.terraforged.core.world.decorator.Decorator; -import com.terraforged.core.world.heightmap.WorldLookup; -import com.terraforged.core.world.terrain.Terrain; import com.terraforged.mod.biome.map.BiomeMap; import com.terraforged.mod.biome.modifier.BiomeModifierManager; -import com.terraforged.mod.chunk.TerraContainer; import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.concurrent.Resource; import com.terraforged.mod.util.setup.SetupHooks; -import net.minecraft.block.BlockState; +import com.terraforged.world.heightmap.WorldLookup; +import com.terraforged.world.terrain.decorator.Decorator; import net.minecraft.util.math.BlockPos; import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.world.biome.BiomeManager; +import net.minecraft.world.biome.ColumnFuzzedBiomeMagnifier; +import net.minecraft.world.biome.provider.BiomeProvider; import java.util.Collections; import java.util.HashMap; @@ -48,46 +47,39 @@ import java.util.Map; import java.util.Random; import java.util.Set; -public class BiomeProvider extends AbstractBiomeProvider { +public class TerraBiomeProvider extends BiomeProvider { + private final long seed; private final BiomeMap biomeMap; private final TerraContext context; private final WorldLookup worldLookup; private final BiomeModifierManager modifierManager; private final Map> decorators = new HashMap<>(); - public BiomeProvider(TerraContext context) { + public TerraBiomeProvider(TerraContext context) { + super(BiomeHelper.getAllBiomes()); this.context = context; - this.biomeMap = BiomeHelper.getDefaultBiomeMap(); + this.seed = context.terraSettings.world.seed; + this.biomeMap = BiomeHelper.createBiomeMap(); this.worldLookup = new WorldLookup(context.factory, context); this.modifierManager = SetupHooks.setup(new BiomeModifierManager(context, biomeMap), context.copy()); } - public TerraContext getContext() { - return context; - } - - public void lookupPos(int x, int z, Cell cell) { - worldLookup.applyCell(cell, x, z); - } - - public Cell lookupPos(int x, int z) { - return worldLookup.getCell(x, z); - } - - public boolean canSpawnAt(Cell cell) { - return cell.tag != context.terrain.ocean && cell.tag != context.terrain.deepOcean && cell.value > context.levels.ground; + public Resource lookupPos(int x, int z) { + return getWorldLookup().getCell(x, z); } @Override public Biome getNoiseBiome(int x, int y, int z) { x = (x << 2); z = (z << 2); - return getBiome(lookupPos(x, z), x, z); + try (Resource cell = lookupPos(x, z)) { + return getBiome(cell.get(), x, z); + } } @Override - public Set getBiomesInSquare(int centerX, int centerY, int centerZ, int radius) { + public Set getBiomes(int centerX, int centerY, int centerZ, int radius) { int minX = centerX - radius >> 2; int minZ = centerZ - radius >> 2; int maxX = centerX + radius >> 2; @@ -95,7 +87,7 @@ public class BiomeProvider extends AbstractBiomeProvider { int rangeX = maxX - minX + 1; int rangeZ = maxZ - minZ + 1; Set set = Sets.newHashSet(); - Cell cell = new Cell<>(); + Cell cell = new Cell(); for(int dz = 0; dz < rangeZ; ++dz) { for(int dx = 0; dx < rangeX; ++dx) { int x = (minX + dx) << 2; @@ -110,7 +102,7 @@ public class BiomeProvider extends AbstractBiomeProvider { } @Override - public BlockPos findBiomePosition(int centerX, int centerY, int centerZ, int range, List biomes, Random random) { + public BlockPos func_225531_a_(int centerX, int centerY, int centerZ, int range, List biomes, Random random) { int minX = centerX - range >> 2; int minZ = centerZ - range >> 2; int maxX = centerX + range >> 2; @@ -121,7 +113,7 @@ public class BiomeProvider extends AbstractBiomeProvider { BlockPos blockpos = null; int attempts = 0; - Cell cell = new Cell<>(); + Cell cell = new Cell(); for(int dz = 0; dz < rangeZ; ++dz) { for(int dx = 0; dx < rangeX; ++dx) { int x = (minX + dx) << 2; @@ -138,26 +130,16 @@ public class BiomeProvider extends AbstractBiomeProvider { return blockpos; } - @Override - public boolean hasStructure(Structure structure) { - return this.hasStructureCache.computeIfAbsent(structure, (name) -> { - for (Biome biome : getAvailableBiomes()) { - if (biome.hasStructure(name)) { - return true; - } - } - return false; - }); + public Biome getSurfaceBiome(int x, int z, BiomeManager.IBiomeReader reader) { + return ColumnFuzzedBiomeMagnifier.INSTANCE.getBiome(seed, x, 0, z, reader); } - @Override - public Set getSurfaceBlocks() { - if (this.topBlocksCache.isEmpty()) { - for (Biome biome : getAvailableBiomes()) { - this.topBlocksCache.add(biome.getSurfaceBuilderConfig().getTop()); - } - } - return this.topBlocksCache; + public WorldLookup getWorldLookup() { + return worldLookup; + } + + public TerraContext getContext() { + return context; } public BiomeModifierManager getModifierManager() { @@ -168,47 +150,15 @@ public class BiomeProvider extends AbstractBiomeProvider { return decorators.getOrDefault(biome, Collections.emptyList()); } - public TerraContainer createBiomeContainer(ChunkReader chunkReader) { - TerraContainer.Builder builder = TerraContainer.builder(); - chunkReader.iterate((cell, dx, dz) -> { - Biome biome = getBiome(cell, chunkReader.getBlockX() + dx, chunkReader.getBlockZ() + dz); - builder.set(dx, dz, biome); - }); - return builder.build(chunkReader); + public Biome getBiome(Cell cell, int x, int z) { + Biome biome = biomeMap.provideBiome(cell, context.levels); + if (modifierManager.hasModifiers(cell.terrain)) { + return modifierManager.modify(biome, cell, x, z); + } + return biome; } - public Biome getBiome(Cell cell, int x, int z) { - if (cell.tag == context.terrain.wetlands) { - return biomeMap.getWetland(cell.temperature, cell.moisture, cell.biome); - } - - if (cell.value > context.levels.water) { - return getModifierManager().modify(biomeMap.getBiome(cell), cell, x, z); - } - - if (cell.tag == context.terrain.river || cell.tag == context.terrain.riverBanks || cell.tag == context.terrain.lake) { - Biome biome = biomeMap.getBiome(cell); - if (overridesRiver(biome)) { - return biome; - } - return biomeMap.getRiver(cell.temperature, cell.moisture, cell.biome); - } - - if (cell.tag == context.terrain.ocean) { - return biomeMap.getOcean(cell.temperature, cell.moisture, cell.biome); - } - - return biomeMap.getDeepOcean(cell.temperature, cell.moisture, cell.biome); - } - - private static boolean overridesRiver(Biome biome) { - return biome.getCategory() == Biome.Category.SWAMP || biome.getCategory() == Biome.Category.JUNGLE; - } - - private static class SearchContext { - - private int count = 0; - private boolean first = true; - private final BlockPos.Mutable pos = new BlockPos.Mutable(); + public boolean canSpawnAt(Cell cell) { + return cell.terrain != context.terrain.ocean && cell.terrain != context.terrain.deepOcean; } } diff --git a/src/main/java/com/terraforged/mod/biome/spawn/SpawnHandler.java b/src/main/java/com/terraforged/mod/biome/spawn/SpawnHandler.java new file mode 100644 index 0000000..5ca37f8 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/spawn/SpawnHandler.java @@ -0,0 +1,69 @@ +package com.terraforged.mod.biome.spawn; + +import com.terraforged.mod.Log; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import com.terraforged.world.continent.MutableVeci; +import com.terraforged.world.continent.SpawnType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.IFeatureConfig; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) +public class SpawnHandler { + + @SubscribeEvent + public static void createSpawn(WorldEvent.CreateSpawnPosition event) { + if (event.getWorld() instanceof ServerWorld) { + ServerWorld world =(ServerWorld) event.getWorld(); + ChunkGenerator generator = world.getChunkProvider().getChunkGenerator(); + if (generator.getBiomeProvider() instanceof TerraBiomeProvider) { + Log.info("Searching for world spawn position"); + TerraBiomeProvider provider = (TerraBiomeProvider) generator.getBiomeProvider(); + BlockPos center = getSearchCenter(provider); + SpawnSearch search = new SpawnSearch(center, provider); + + // SpawnSearch uses a rough look-up that does not account for the effects of erosion which + // can add or remove from the heightmap depending on location. Use the chunk generator's + // surface lookup function to obtain the actual height + BlockPos spawn = getSurface(generator, search.get()); + + Log.info("Setting world spawn: {}", spawn); + event.setCanceled(true); + event.getWorld().getWorldInfo().setSpawn(spawn); + + if (event.getSettings().isBonusChestEnabled()) { + Log.info("Generating bonus chest"); + createBonusChest(world, spawn); + } + } + } + } + + private static BlockPos getSearchCenter(TerraBiomeProvider provider) { + SpawnType spawnType = provider.getContext().terraSettings.world.properties.spawnType; + if (spawnType == SpawnType.WORLD_ORIGIN) { + return BlockPos.ZERO; + } else { + MutableVeci pos = new MutableVeci(); + provider.getContext().heightmap.getContinent().getNearestCenter(0, 0, pos); + return new BlockPos(pos.x, 0, pos.z); + } + } + + private static BlockPos getSurface(ChunkGenerator generator, BlockPos pos) { + int surface = generator.func_222529_a(pos.getX(), pos.getZ(), Heightmap.Type.WORLD_SURFACE_WG); + return new BlockPos(pos.getX(), surface, pos.getZ()); + } + + private static void createBonusChest(ServerWorld world, BlockPos pos) { + ConfiguredFeature chest = Feature.BONUS_CHEST.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG); + chest.place(world, world.getChunkProvider().getChunkGenerator(), world.rand, pos); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/spawn/SpawnSearch.java b/src/main/java/com/terraforged/mod/biome/spawn/SpawnSearch.java similarity index 62% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/spawn/SpawnSearch.java rename to src/main/java/com/terraforged/mod/biome/spawn/SpawnSearch.java index be5b8cc..f57b08a 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/spawn/SpawnSearch.java +++ b/src/main/java/com/terraforged/mod/biome/spawn/SpawnSearch.java @@ -1,18 +1,17 @@ package com.terraforged.mod.biome.spawn; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; import com.terraforged.mod.Log; -import com.terraforged.mod.biome.provider.BiomeProvider; -import com.terraforged.mod.command.search.Search; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import com.terraforged.mod.server.command.search.Search; +import com.terraforged.core.cell.Cell; import net.minecraft.util.math.BlockPos; public class SpawnSearch extends Search { - private final BiomeProvider biomeProvider; - private final Cell cell = new Cell<>(); + private final TerraBiomeProvider biomeProvider; + private final Cell cell = new Cell(); - public SpawnSearch(BlockPos center, BiomeProvider biomeProvider) { + public SpawnSearch(BlockPos center, TerraBiomeProvider biomeProvider) { super(center, 0, 2048); this.biomeProvider = biomeProvider; } @@ -24,19 +23,19 @@ public class SpawnSearch extends Search { @Override public boolean test(BlockPos pos) { - biomeProvider.lookupPos(pos.getX(), pos.getZ(), cell); + biomeProvider.getWorldLookup().applyCell(cell, pos.getX(), pos.getZ()); return biomeProvider.canSpawnAt(cell); } @Override - protected BlockPos success(BlockPos.Mutable pos) { + public BlockPos success(BlockPos.Mutable pos) { pos.setY(biomeProvider.getContext().levels.scale(cell.value)); Log.info("Found valid spawn position: {}", pos); return super.success(pos); } @Override - protected BlockPos fail(BlockPos pos) { + public BlockPos fail(BlockPos pos) { Log.info("Unable to find valid spawn position, defaulting x=0, z=0"); return new BlockPos(0, biomeProvider.getContext().levels.groundLevel, 0); } diff --git a/src/main/java/com/terraforged/mod/biome/surface/BriceSurface.java b/src/main/java/com/terraforged/mod/biome/surface/BriceSurface.java new file mode 100644 index 0000000..941d9ea --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/surface/BriceSurface.java @@ -0,0 +1,57 @@ +package com.terraforged.mod.biome.surface; + +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.world.geology.Strata; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; + +import java.util.Random; + +public class BriceSurface implements MaskedSurface { + + private final Module module; + private final Strata stackStrata; + + public BriceSurface(Seed seed) { + Random random = new Random(seed.next()); + Variance variance = Variance.of(0.1, 0.2); + + module = Source.ridge(123, 60, 4) + .clamp(0.8, 0.95).map(0, 1) + .terrace(1, 0.25, 4, 1) + .mult(Source.perlin(1234, 4, 1).alpha(0.05)); + + stackStrata = Strata.builder(seed.next(), Source.build(seed.next(), 30, 3)) + .add(Blocks.ORANGE_TERRACOTTA.getDefaultState(), variance.next(random)) + .add(Blocks.TERRACOTTA.getDefaultState(), variance.next(random)) + .add(Blocks.YELLOW_TERRACOTTA.getDefaultState(), variance.next(random)) + .add(Blocks.WHITE_TERRACOTTA.getDefaultState(), variance.next(random)) + .add(Blocks.BROWN_TERRACOTTA.getDefaultState(), variance.next(random)) + .add(Blocks.RED_TERRACOTTA.getDefaultState(), variance.next(random)) + .build(); + } + + @Override + 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) { + return false; + } + ctx.chunk.setBlockState(ctx.pos.setPos(x, height + y, z), material, false); + return true; + }); + } +} diff --git a/src/main/java/com/terraforged/mod/biome/surface/DesertSurface.java b/src/main/java/com/terraforged/mod/biome/surface/DesertSurface.java new file mode 100644 index 0000000..8d36295 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/surface/DesertSurface.java @@ -0,0 +1,62 @@ +package com.terraforged.mod.biome.surface; + +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; +import com.terraforged.world.GeneratorContext; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; + +public class DesertSurface implements Surface { + + private final float min; + private final float level; + private final Module noise; + private final BlockState sandstone = States.SMOOTH_SANDSTONE.get(); + private final BlockState low = Blocks.TERRACOTTA.delegate.get().getDefaultState(); + private final BlockState mid = Blocks.ORANGE_TERRACOTTA.delegate.get().getDefaultState(); + private final BlockState high = Blocks.BROWN_TERRACOTTA.delegate.get().getDefaultState(); + + public DesertSurface(GeneratorContext context) { + min = context.levels.ground(10); + + level = context.levels.ground(40); + + noise = Source.perlin(context.seed.next(), 8, 1) + .scale(context.levels.scale(16)); + } + + @Override + public void buildSurface(int x, int z, int height, SurfaceContext ctx) { + if (ctx.cell.steepness < 0.15) { + return; + } + + if (ctx.cell.value < min) { + return; + } + + float value = ctx.cell.value + noise.getValue(x, z); + if (ctx.cell.steepness > 0.3 || value > level) { + BlockState state = sandstone; + + if (value > level) { + if (ctx.cell.steepness > 0.975) { + state = low; + } else if (ctx.cell.steepness > 0.85) { + state = high; + } else if (ctx.cell.steepness > 0.75) { + state = mid; + } else if (ctx.cell.steepness > 0.65) { + state = low; + } + } + + for (int dy = 0; dy < 4; dy++) { + ctx.buffer.setBlockState(ctx.pos.setPos(x, height - dy, z), state, false); + } + } + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/DesertDunes.java b/src/main/java/com/terraforged/mod/biome/surface/DunesSurface.java similarity index 66% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/DesertDunes.java rename to src/main/java/com/terraforged/mod/biome/surface/DunesSurface.java index 7089486..db1b026 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/DesertDunes.java +++ b/src/main/java/com/terraforged/mod/biome/surface/DunesSurface.java @@ -23,25 +23,28 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.surface; +package com.terraforged.mod.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.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; -import com.terraforged.mod.biome.provider.BiomeProvider; import com.terraforged.mod.biome.provider.DesertBiomes; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; import com.terraforged.mod.chunk.TerraContext; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.func.CellFunc; +import com.terraforged.core.cell.Cell; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.n2d.func.CellFunc; +import com.terraforged.n2d.util.NoiseUtil; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.Terrains; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.gen.Heightmap; -public class DesertDunes implements Surface { +public class DunesSurface implements MaskedSurface { private final int maxHeight; private final Levels levels; @@ -50,7 +53,7 @@ public class DesertDunes implements Surface { private final DesertBiomes deserts; private final BlockPos.Mutable pos = new BlockPos.Mutable(); - public DesertDunes(TerraContext context, int maxHeight, DesertBiomes deserts) { + public DunesSurface(TerraContext context, int maxHeight, DesertBiomes deserts) { Module dunes = Source.cell(context.seed.next(), 80, CellFunc.DISTANCE) .warp(context.seed.next(), 70, 1, 70); this.terrains = context.terrain; @@ -61,18 +64,24 @@ public class DesertDunes implements Surface { } @Override - public void buildSurface(int x, int z, int surface, SurfaceContext ctx) { - float value = module.getValue(x, z) * getMask(ctx.cell); - float baseHeight = ctx.cell.value * levels.worldHeight; + 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; - int duneTop = (int) duneHeight; + int duneTop = (int) duneHeight + 1; if (duneTop < levels.waterLevel || duneTop <= baseHeight) { return; } LayerMaterial material = deserts.getSandLayers(ctx.biome); if (material == null) { + fill(x, z, duneBase - 4, duneTop, ctx, ctx.chunk, Blocks.SAND.getDefaultState()); return; } @@ -84,15 +93,11 @@ public class DesertDunes implements Surface { ctx.chunk.setBlockState(pos.setPos(x, duneTop, z), top, false); } - public static Surface create(TerraContext context, BiomeProvider provider) { + public static Surface create(TerraContext context, TerraBiomeProvider provider) { return create(context, provider.getModifierManager().getDesertBiomes()); } public static Surface create(TerraContext context, DesertBiomes desertBiomes) { - return new DesertDunes(context, 25, desertBiomes); - } - - private static float getMask(Cell cell) { - return cell.biomeMask(0F, 0.75F) * cell.mask(0.4F, 0.5F, 0F, 0.8F); + return new DunesSurface(context, 25, desertBiomes); } } diff --git a/src/main/java/com/terraforged/mod/biome/surface/ForestSurface.java b/src/main/java/com/terraforged/mod/biome/surface/ForestSurface.java new file mode 100644 index 0000000..b5a93e5 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/surface/ForestSurface.java @@ -0,0 +1,39 @@ +package com.terraforged.mod.biome.surface; + +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; +import com.terraforged.world.GeneratorContext; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.world.gen.Heightmap; + +public class ForestSurface implements Surface { + + private final Module noise; + + public ForestSurface(GeneratorContext context) { + noise = Source.simplex(context.seed.next(), 40, 2).warp(Source.RAND, context.seed.next(), 2, 1, 4); + } + + @Override + public void buildSurface(int x, int z, int height, SurfaceContext ctx) { + if (ctx.buffer.getTopBlockY(Heightmap.Type.OCEAN_FLOOR_WG, x, z) == height) { + BlockState state = getMaterial(x, z); + ctx.buffer.setBlockState(ctx.pos.setPos(x, height, z), state, false); + } + } + + private BlockState getMaterial(int x, int z) { + float value = noise.getValue(x, z); + if (value > 0.6) { + if (value < 0.75) { + return Blocks.PODZOL.getDefaultState(); + } + return States.DIRT.get(); + } + return States.GRASS_BLOCK.get(); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java b/src/main/java/com/terraforged/mod/biome/surface/IcebergsSurface.java similarity index 86% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java rename to src/main/java/com/terraforged/mod/biome/surface/IcebergsSurface.java index 68d2929..7096b57 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java +++ b/src/main/java/com/terraforged/mod/biome/surface/IcebergsSurface.java @@ -23,22 +23,22 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.surface; +package com.terraforged.mod.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.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; import com.terraforged.mod.chunk.TerraContext; -import me.dags.noise.Module; -import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; +import com.terraforged.core.cell.Cell; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.n2d.util.NoiseUtil; +import com.terraforged.world.heightmap.Levels; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; -public class FrozenOcean implements Surface { +public class IcebergsSurface implements MaskedSurface { private final Module up; private final Module down; @@ -50,7 +50,7 @@ public class FrozenOcean implements Surface { private final float minDepth; private final float depthRange; - public FrozenOcean(TerraContext context, int height, int depth) { + public IcebergsSurface(TerraContext context, int height, int depth) { Levels levels = context.levels; Module shape = Source.perlin(context.seed.next(), 65, 3) .warp(context.seed.next(), 15, 1, 10) @@ -85,13 +85,28 @@ public class FrozenOcean 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 FrozenOcean 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); - } } diff --git a/src/main/java/com/terraforged/mod/biome/surface/SteppeSurface.java b/src/main/java/com/terraforged/mod/biome/surface/SteppeSurface.java new file mode 100644 index 0000000..09547cb --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/surface/SteppeSurface.java @@ -0,0 +1,30 @@ +package com.terraforged.mod.biome.surface; + +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; +import com.terraforged.n2d.func.CellFunc; +import net.minecraft.block.BlockState; + +public class SteppeSurface implements Surface { + + @Override + public void buildSurface(int x, int z, int height, SurfaceContext ctx) { + Module module = Source.cell(123, 4, CellFunc.DISTANCE).warp(214, 80, 1, 40); + float value = module.getValue(x, z); + + BlockState state = States.SAND.get(); + + if (value > 0.275F) { + state = States.GRASS_BLOCK.get(); + } else if (value > 0.225F) { + state = States.DIRT.get(); + } + + ctx.chunk.setBlockState(ctx.pos.setPos(x, height, z), state, false); + ctx.chunk.setBlockState(ctx.pos.setPos(x, height-1, z), state, false); + ctx.chunk.setBlockState(ctx.pos.setPos(x, height-2, z), state, false); + } +} diff --git a/src/main/java/com/terraforged/mod/biome/surface/StoneForestSurface.java b/src/main/java/com/terraforged/mod/biome/surface/StoneForestSurface.java new file mode 100644 index 0000000..e5e9a57 --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/surface/StoneForestSurface.java @@ -0,0 +1,44 @@ +package com.terraforged.mod.biome.surface; + +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 net.minecraft.block.BlockState; + +public class StoneForestSurface implements MaskedSurface { + + 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, 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); + } + + 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/mod/biome/surface/SwampSurface.java b/src/main/java/com/terraforged/mod/biome/surface/SwampSurface.java new file mode 100644 index 0000000..5054c0d --- /dev/null +++ b/src/main/java/com/terraforged/mod/biome/surface/SwampSurface.java @@ -0,0 +1,34 @@ +package com.terraforged.mod.biome.surface; + +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; + +public class SwampSurface implements Surface { + + private final SurfaceBuilderConfig config = SurfaceBuilder.GRASS_DIRT_GRAVEL_CONFIG; + + @Override + public void buildSurface(int x, int z, int height, SurfaceContext ctx) { + double noise = Biome.INFO_NOISE.noiseAt(x * 0.25D, z * 0.25D, false); + if (noise > 0.0D) { + int dx = x & 15; + int dz = z & 15; + for (int y = height; y >= height - 10; --y) { + ctx.pos.setPos(dx, y, dz); + if (ctx.buffer.getBlockState(ctx.pos).isAir()) { + continue; + } + + if (y == ctx.levels.waterY && ctx.buffer.getBlockState(ctx.pos).getBlock() != ctx.fluid.getBlock()) { + ctx.buffer.setBlockState(ctx.pos, ctx.fluid, false); + } + break; + } + } + + SurfaceBuilder.DEFAULT.buildSurface(ctx.random, ctx.buffer, ctx.biome, x, z, height, noise, ctx.solid, ctx.fluid, ctx.levels.waterLevel, ctx.seed, config); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/tag/BiomeTagManager.java b/src/main/java/com/terraforged/mod/biome/tag/BiomeTagManager.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/biome/tag/BiomeTagManager.java rename to src/main/java/com/terraforged/mod/biome/tag/BiomeTagManager.java index 26e5ac8..f870efc 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/tag/BiomeTagManager.java +++ b/src/main/java/com/terraforged/mod/biome/tag/BiomeTagManager.java @@ -25,8 +25,8 @@ package com.terraforged.mod.biome.tag; -import com.terraforged.api.biome.BiomeTags; import com.terraforged.mod.Log; +import com.terraforged.api.biome.BiomeTags; import net.minecraft.profiler.IProfiler; import net.minecraft.resources.IFutureReloadListener; import net.minecraft.resources.IResourceManager; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ChunkGeneratorFactory.java b/src/main/java/com/terraforged/mod/chunk/ChunkGeneratorFactory.java similarity index 89% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ChunkGeneratorFactory.java rename to src/main/java/com/terraforged/mod/chunk/ChunkGeneratorFactory.java index 9b4d1f6..ba7e7ba 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/ChunkGeneratorFactory.java +++ b/src/main/java/com/terraforged/mod/chunk/ChunkGeneratorFactory.java @@ -25,11 +25,11 @@ package com.terraforged.mod.chunk; -import com.terraforged.mod.biome.provider.BiomeProvider; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.OverworldGenSettings; public interface ChunkGeneratorFactory> { - T create(TerraContext context, BiomeProvider biomeProvider, OverworldGenSettings settings); + T create(TerraContext context, TerraBiomeProvider biomeProvider, OverworldGenSettings settings); } diff --git a/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java b/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java new file mode 100644 index 0000000..1436c0a --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java @@ -0,0 +1,281 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.chunk; + +import com.terraforged.api.chunk.column.ColumnDecorator; +import com.terraforged.api.biome.surface.SurfaceManager; +import com.terraforged.api.material.layer.LayerManager; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import com.terraforged.mod.chunk.generator.BiomeGenerator; +import com.terraforged.mod.chunk.generator.FeatureGenerator; +import com.terraforged.mod.chunk.generator.Generator; +import com.terraforged.mod.chunk.generator.MobGenerator; +import com.terraforged.mod.chunk.generator.StructureGenerator; +import com.terraforged.mod.chunk.generator.SurfaceGenerator; +import com.terraforged.mod.chunk.generator.TerrainCarver; +import com.terraforged.mod.chunk.generator.TerrainGenerator; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.tile.Size; +import com.terraforged.core.tile.Tile; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.core.tile.gen.TileCache; +import com.terraforged.mod.feature.BlockDataManager; +import com.terraforged.fm.FeatureManager; +import com.terraforged.fm.data.DataManager; +import com.terraforged.fm.structure.StructureManager; +import com.terraforged.mod.material.Materials; +import com.terraforged.mod.material.geology.GeoManager; +import com.terraforged.mod.util.setup.SetupHooks; +import net.minecraft.entity.EntityClassification; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeManager; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.GenerationSettings; +import net.minecraft.world.gen.GenerationStage; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.WorldGenRegion; +import net.minecraft.world.gen.feature.template.TemplateManager; +import net.minecraft.world.server.ServerWorld; + +import java.util.List; + +public class TerraChunkGenerator extends ChunkGenerator { + + private final TerraContext context; + private final TerraBiomeProvider biomeProvider; + + private final Generator.Mobs mobGenerator; + private final Generator.Biomes biomeGenerator; + private final Generator.Carvers terrainCarver; + private final Generator.Terrain terrainGenerator; + private final Generator.Surfaces surfaceGenerator; + private final Generator.Features featureGenerator; + private final Generator.Structures structureGenerator; + + private final GeoManager geologyManager; + private final FeatureManager featureManager; + private final StructureManager structureManager; + private final SurfaceManager surfaceManager; + private final BlockDataManager blockDataManager; + private final List baseDecorators; + private final List postProcessors; + + private final TileCache tileCache; + + public TerraChunkGenerator(TerraContext context, TerraBiomeProvider biomeProvider, GenerationSettings settings) { + super(context.world, biomeProvider, settings); + this.context = context; + this.biomeProvider = biomeProvider; + this.mobGenerator = new MobGenerator(this); + this.biomeGenerator = new BiomeGenerator(this); + this.terrainCarver = new TerrainCarver(this); + this.terrainGenerator = new TerrainGenerator(this); + this.surfaceGenerator = new SurfaceGenerator(this); + this.featureGenerator = new FeatureGenerator(this); + this.structureGenerator = new StructureGenerator(this); + + this.surfaceManager = TerraSetupFactory.createSurfaceManager(context); + this.structureManager = TerraSetupFactory.createStructureManager(context); + this.geologyManager = TerraSetupFactory.createGeologyManager(context); + this.baseDecorators = TerraSetupFactory.createBaseDecorators(geologyManager, context); + this.postProcessors = TerraSetupFactory.createFeatureDecorators(context); + this.tileCache = context.cache; + + try (DataManager data = TerraSetupFactory.createDataManager()) { + FeatureManager.initData(data); + this.featureManager = TerraSetupFactory.createFeatureManager(data, context); + this.blockDataManager = TerraSetupFactory.createBlockDataManager(data, context); + FeatureManager.clearData(); + } + + SetupHooks.setup(getLayerManager(), context.copy()); + SetupHooks.setup(baseDecorators, postProcessors, context.copy()); + } + + @Override + public final void generateStructures(BiomeManager biomes, IChunk chunk, ChunkGenerator generator, TemplateManager templates) { + structureGenerator.generateStructureStarts(biomes, chunk, templates); + } + + @Override + public final void generateStructureStarts(IWorld world, IChunk chunk) { + structureGenerator.generateStructureReferences(world, chunk); + } + + @Override + public final void generateBiomes(IChunk chunk) { + biomeGenerator.generateBiomes(chunk); + } + + @Override + public final void makeBase(IWorld world, IChunk chunk) { + terrainGenerator.generateTerrain(world, chunk); + } + + @Override + public final void generateSurface(WorldGenRegion world, IChunk chunk) { + surfaceGenerator.generateSurface(world, chunk); + } + + @Override + public final void decorate(WorldGenRegion region) { + featureGenerator.generateFeatures(region); + } + + @Override + public final void func_225550_a_(BiomeManager biomes, IChunk chunk, GenerationStage.Carving type) { + terrainCarver.carveTerrain(biomes, chunk, type); + } + + @Override + public final void spawnMobs(WorldGenRegion region) { + mobGenerator.generateMobs(region); + } + + @Override + public final void spawnMobs(ServerWorld worldIn, boolean hostile, boolean peaceful) { + mobGenerator.tickSpawners(worldIn, hostile, peaceful); + } + + @Override + public final List getPossibleCreatures(EntityClassification type, BlockPos pos) { + return mobGenerator.getSpawns(world, type, pos); + } + + @Override + public Biome getBiome(BiomeManager manager, BlockPos pos) { + return super.getBiome(manager, pos); + } + + @Override + public final int func_222529_a(int x, int z, Heightmap.Type type) { + int chunkX = Size.blockToChunk(x); + int chunkZ = Size.blockToChunk(z); + try (ChunkReader chunk = getChunkReader(chunkX, chunkZ)) { + Cell cell = chunk.getCell(x, z); + int level = context.levels.scale(cell.value) + 1; + if (type == Heightmap.Type.OCEAN_FLOOR || type == Heightmap.Type.OCEAN_FLOOR_WG) { + return level; + } + return Math.max(getSeaLevel(), level); + } + } + + @Override + public TerraBiomeProvider getBiomeProvider() { + return biomeProvider; + } + + @Override + public final int getMaxHeight() { + return getContext().levels.worldHeight; + } + + @Override + public final int getSeaLevel() { + return getContext().levels.waterLevel; + } + + @Override + public final int getGroundHeight() { + return getContext().levels.groundLevel; + } + + public final TerraContext getContext() { + return context; + } + + public final Materials getMaterials() { + return context.materials; + } + + public final FeatureManager getFeatureManager() { + return featureManager; + } + + public final StructureManager getStructureManager() { + return structureManager; + } + + public final GeoManager getGeologyManager() { + return geologyManager; + } + + public final LayerManager getLayerManager() { + return context.materials.getLayerManager(); + } + + public final SurfaceManager getSurfaceManager() { + return surfaceManager; + } + + public final BlockDataManager getBlockDataManager() { + return blockDataManager; + } + + public final List getBaseDecorators() { + return baseDecorators; + } + + public final List getPostProcessors() { + return postProcessors; + } + + public final void queueChunk(int chunkX, int chunkZ) { + int rx = tileCache.chunkToRegion(chunkX); + int rz = tileCache.chunkToRegion(chunkZ); + tileCache.queueRegion(rx, rz); + } + + public final Tile getTile(int chunkX, int chunkZ) { + int rx = tileCache.chunkToRegion(chunkX); + int rz = tileCache.chunkToRegion(chunkZ); + return tileCache.getRegion(rx, rz); + } + + public final ChunkReader getChunkReader(int chunkX, int chunkZ) { + return tileCache.getChunk(chunkX, chunkZ); + } + + public static ChunkReader getChunk(IWorld world, ChunkGenerator generator) { + if (generator instanceof TerraChunkGenerator) { + TerraChunkGenerator terra = (TerraChunkGenerator) generator; + if (world instanceof IChunk) { + IChunk chunk = (IChunk) world; + return terra.getChunkReader(chunk.getPos().x, chunk.getPos().z); + } + + if (world instanceof WorldGenRegion) { + WorldGenRegion region = (WorldGenRegion) world; + return terra.getChunkReader(region.getMainChunkX(), region.getMainChunkZ()); + } + } + return null; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraContext.java b/src/main/java/com/terraforged/mod/chunk/TerraContext.java similarity index 54% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraContext.java rename to src/main/java/com/terraforged/mod/chunk/TerraContext.java index aacd5e8..092406d 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraContext.java +++ b/src/main/java/com/terraforged/mod/chunk/TerraContext.java @@ -25,17 +25,20 @@ package com.terraforged.mod.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.core.world.GeneratorContext; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.heightmap.Heightmap; -import com.terraforged.core.world.terrain.Terrains; +import com.terraforged.api.biome.surface.ChunkSurfaceBuffer; +import com.terraforged.api.biome.surface.SurfaceContext; +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.config.PerfDefaults; +import com.terraforged.core.concurrent.thread.ThreadPools; +import com.terraforged.core.tile.gen.TileCache; +import com.terraforged.core.tile.gen.TileGenerator; import com.terraforged.mod.material.Materials; -import com.terraforged.mod.settings.TerraSettings; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.WorldGeneratorFactory; +import com.terraforged.world.heightmap.Heightmap; +import com.terraforged.world.terrain.Terrains; import net.minecraft.world.IWorld; import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.GenerationSettings; @@ -45,25 +48,43 @@ public class TerraContext extends GeneratorContext { public final IWorld world; public final Heightmap heightmap; public final Materials materials; - public final WorldGeneratorFactory factory; public final TerraSettings terraSettings; + public TerraContext(TerraContext other) { + super(other.terrain, other.settings, other.terrainFactory, TerraContext::createCache); + this.world = other.world; + this.materials = other.materials; + this.terraSettings = other.terraSettings; + this.heightmap = factory.getHeightmap(); + } + public TerraContext(IWorld world, Terrains terrain, TerraSettings settings) { - super(terrain, settings, TerraTerrainProvider::new); + super(terrain, settings, TerraTerrainProvider::new, TerraContext::createCache); this.world = world; this.materials = new Materials(); this.terraSettings = settings; - this.factory = new WorldGeneratorFactory(this); this.heightmap = factory.getHeightmap(); - ItemStack stack = new ItemStack(Items.COBBLESTONE); - stack.getMaxStackSize(); } public DecoratorContext decorator(IChunk chunk) { - return new DecoratorContext(chunk, levels, terrain, factory.getClimate()); + return new DecoratorContext(chunk, levels, terrain, factory.getClimate(), false); } public SurfaceContext surface(ChunkSurfaceBuffer buffer, GenerationSettings settings) { return new SurfaceContext(buffer, levels, terrain, factory.getClimate(), settings, world.getSeed()); } + + public static TileCache createCache(WorldGeneratorFactory factory) { + CommentedConfig config = PerfDefaults.getAndPrintPerfSettings(); + boolean batching = config.getOrElse("batching", false); + int tileSize = Math.min(PerfDefaults.MAX_TILE_SIZE, Math.max(2, config.getInt("tile_size"))); + int batchCount = Math.min(PerfDefaults.MAX_BATCH_COUNT, Math.max(1, config.getInt("batch_count"))); + int threadCount = Math.min(PerfDefaults.MAX_THREAD_COUNT, Math.max(1, config.getInt("thread_count"))); + return TileGenerator.builder() + .pool(ThreadPools.create(threadCount, batching)) + .size(tileSize, 2) + .batch(batchCount) + .factory(factory) + .build().toCache(); + } } diff --git a/src/main/java/com/terraforged/mod/chunk/TerraGenSettings.java b/src/main/java/com/terraforged/mod/chunk/TerraGenSettings.java new file mode 100644 index 0000000..c0b2fbc --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/TerraGenSettings.java @@ -0,0 +1,92 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.chunk; + +import com.terraforged.mod.chunk.settings.StructureSettings; +import net.minecraft.world.gen.OverworldGenSettings; + +public class TerraGenSettings extends OverworldGenSettings { + + private final int villageSeparation; + private final int mansionSeparation; + private final int biomeFeatureSeparation; + private final int shipwreckDistance; + private final int shipwreckSeparation; + private final int oceanRuinDistance; + private final int oceanRuinSeparation; + + public TerraGenSettings(StructureSettings settings) { + super.villageDistance = settings.villages.distance; + this.villageSeparation = settings.villages.separation; + super.mansionDistance = settings.mansions.distance; + this.mansionSeparation = settings.mansions.separation; + super.strongholdDistance = settings.strongholds.distance; + super.strongholdSpread = settings.strongholds.separation; + super.oceanMonumentSpacing = settings.oceanMonuments.distance; + super.oceanMonumentSeparation = settings.oceanMonuments.separation; + super.biomeFeatureDistance = settings.otherStructures.distance; + this.biomeFeatureSeparation = settings.otherStructures.separation; + this.shipwreckDistance = settings.shipwrecks.distance; + this.shipwreckSeparation = settings.shipwrecks.separation; + this.oceanRuinDistance = settings.oceanRuins.distance; + this.oceanRuinSeparation = settings.oceanRuins.separation; + } + + @Override + public int getVillageSeparation() { + return villageSeparation; + } + + @Override + public int getMansionSeparation() { + return mansionSeparation; + } + + @Override + public int getBiomeFeatureSeparation() { + return biomeFeatureSeparation; + } + + @Override + public int getOceanRuinDistance() { + return oceanRuinDistance; + } + + @Override + public int getOceanRuinSeparation() { + return oceanRuinSeparation; + } + + @Override + public int getShipwreckDistance() { + return shipwreckDistance; + } + + @Override + public int getShipwreckSeparation() { + return shipwreckSeparation; + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/TerraSetupFactory.java b/src/main/java/com/terraforged/mod/chunk/TerraSetupFactory.java new file mode 100644 index 0000000..d73f64b --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/TerraSetupFactory.java @@ -0,0 +1,149 @@ +package com.terraforged.mod.chunk; + +import com.terraforged.mod.Log; +import com.terraforged.api.chunk.column.ColumnDecorator; +import com.terraforged.api.biome.surface.SurfaceManager; +import com.terraforged.mod.biome.ModBiomes; +import com.terraforged.mod.biome.surface.BriceSurface; +import com.terraforged.mod.biome.surface.DesertSurface; +import com.terraforged.mod.biome.surface.StoneForestSurface; +import com.terraforged.mod.biome.surface.ForestSurface; +import com.terraforged.mod.biome.surface.IcebergsSurface; +import com.terraforged.mod.biome.surface.SwampSurface; +import com.terraforged.mod.chunk.column.BedrockDecorator; +import com.terraforged.mod.chunk.column.ErosionDecorator; +import com.terraforged.mod.chunk.column.GeologyDecorator; +import com.terraforged.mod.chunk.column.post.LayerDecorator; +import com.terraforged.mod.chunk.column.post.SnowEroder; +import com.terraforged.mod.feature.BlockDataManager; +import com.terraforged.mod.feature.Matchers; +import com.terraforged.mod.feature.feature.FreezeLayer; +import com.terraforged.fm.FeatureManager; +import com.terraforged.fm.data.DataManager; +import com.terraforged.fm.matcher.biome.BiomeMatcher; +import com.terraforged.fm.matcher.feature.FeatureMatcher; +import com.terraforged.fm.modifier.FeatureModifiers; +import com.terraforged.fm.predicate.DeepWater; +import com.terraforged.fm.predicate.FeaturePredicate; +import com.terraforged.fm.predicate.MinHeight; +import com.terraforged.fm.structure.StructureManager; +import com.terraforged.fm.transformer.FeatureTransformer; +import com.terraforged.mod.material.geology.GeoManager; +import com.terraforged.mod.util.setup.SetupHooks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.structure.Structure; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class TerraSetupFactory { + + public static DataManager createDataManager() { + return FeatureManager.data(new File("config/terraforged/datapacks")); + } + + public static List createBaseDecorators(GeoManager geoManager, TerraContext context) { + List processors = new ArrayList<>(); + if (context.terraSettings.miscellaneous.strataDecorator) { + Log.info(" - Geology decorator enabled"); + processors.add(new GeologyDecorator(geoManager)); + } + if (context.terraSettings.miscellaneous.erosionDecorator) { + Log.info(" - Erosion decorator enabled"); + processors.add(new ErosionDecorator(context)); + } + processors.add(new BedrockDecorator(context)); + return processors; + } + + public static List createFeatureDecorators(TerraContext context) { + List processors = new ArrayList<>(); + if (context.terraSettings.miscellaneous.naturalSnowDecorator) { + Log.info(" - Natural snow decorator enabled"); + processors.add(new SnowEroder(context)); + } + if (context.terraSettings.miscellaneous.smoothLayerDecorator) { + Log.info(" - Smooth layer decorator enabled"); + processors.add(new LayerDecorator(context.materials.getLayerManager())); + } + return processors; + } + + public static BlockDataManager createBlockDataManager(DataManager data, TerraContext context) { + return new BlockDataManager(data); + } + + public static FeatureManager createFeatureManager(DataManager data, TerraContext context) { + FeatureModifiers modifiers = FeatureManager.modifiers(data, context.terraSettings.miscellaneous.customBiomeFeatures); + + if (context.terraSettings.miscellaneous.strataDecorator) { + // block stone blobs if strata enabled + modifiers.getPredicates().add(Matchers.stoneBlobs(), FeaturePredicate.DENY); + } + + if (!context.terraSettings.miscellaneous.vanillaWaterFeatures) { + // block lakes and springs if not enabled + modifiers.getPredicates().add(FeatureMatcher.of(Feature.LAKE), FeaturePredicate.DENY); + modifiers.getPredicates().add(FeatureMatcher.of(Feature.SPRING_FEATURE), FeaturePredicate.DENY); + } + + if (context.terraSettings.miscellaneous.customBiomeFeatures) { + // remove default trees from river biomes since forests can go up to the edge of rivers + modifiers.getPredicates().add(BiomeMatcher.of(Biome.Category.RIVER), Matchers.tree(), FeaturePredicate.DENY); + + // places snow layers below and on top of trees + modifiers.getTransformers().add( + BiomeMatcher.ANY, + FeatureMatcher.of(Feature.FREEZE_TOP_LAYER), + FeatureTransformer.replace(Feature.FREEZE_TOP_LAYER, FreezeLayer.INSTANCE) + ); + } + + // block ugly features + modifiers.getPredicates().add(Matchers.sedimentDisks(), FeaturePredicate.DENY); + modifiers.getPredicates().add(FeatureMatcher.of(Feature.MINESHAFT), new MinHeight(context.levels.waterY + 20)); + + return FeatureManager.create(SetupHooks.setup(modifiers, context.copy())); + } + + public static SurfaceManager createSurfaceManager(TerraContext context) { + SurfaceManager manager = new SurfaceManager(); + 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, + Biomes.DESERT_HILLS, + Biomes.DESERT_LAKES + ); + manager.replace( + new SwampSurface(), + Biomes.SWAMP.delegate.get(), + ModBiomes.MARSHLAND + ); + manager.append( + new ForestSurface(context), + Biomes.FOREST, + Biomes.WOODED_HILLS, + Biomes.DARK_FOREST, + Biomes.DARK_FOREST_HILLS + ); + return SetupHooks.setup(manager, context); + } + + public static StructureManager createStructureManager(TerraContext context) { + StructureManager manager = new StructureManager(); + manager.register(Structure.OCEAN_MONUMENT, DeepWater.INSTANCE); + manager.register(Structure.OCEAN_RUIN, DeepWater.INSTANCE); + return SetupHooks.setup(manager, context); + } + + public static GeoManager createGeologyManager(TerraContext context) { + return new GeoManager(context); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraTerrainProvider.java b/src/main/java/com/terraforged/mod/chunk/TerraTerrainProvider.java similarity index 89% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraTerrainProvider.java rename to src/main/java/com/terraforged/mod/chunk/TerraTerrainProvider.java index a6365df..319ed6b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraTerrainProvider.java +++ b/src/main/java/com/terraforged/mod/chunk/TerraTerrainProvider.java @@ -26,10 +26,10 @@ package com.terraforged.mod.chunk; import com.terraforged.core.cell.Populator; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.heightmap.RegionConfig; -import com.terraforged.core.world.terrain.provider.StandardTerrainProvider; import com.terraforged.mod.util.setup.SetupHooks; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.heightmap.RegionConfig; +import com.terraforged.world.terrain.provider.StandardTerrainProvider; public class TerraTerrainProvider extends StandardTerrainProvider { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/ChunkPopulator.java b/src/main/java/com/terraforged/mod/chunk/column/BaseDecorator.java similarity index 87% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/ChunkPopulator.java rename to src/main/java/com/terraforged/mod/chunk/column/BaseDecorator.java index 87e826f..267de15 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/ChunkPopulator.java +++ b/src/main/java/com/terraforged/mod/chunk/column/BaseDecorator.java @@ -23,20 +23,20 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator; +package com.terraforged.mod.chunk.column; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.material.state.States; import net.minecraft.world.chunk.IChunk; -public class ChunkPopulator implements ColumnDecorator { +public class BaseDecorator implements ColumnDecorator { - public static final ChunkPopulator INSTANCE = new ChunkPopulator(); + public static final BaseDecorator INSTANCE = new BaseDecorator(); @Override public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.tag == context.terrains.volcanoPipe && context.cell.riverMask > 0.25F) { + if (context.cell.terrain == context.terrains.volcanoPipe && context.cell.riverMask > 0.5F) { int lavaStart = Math.max(context.levels.waterY + 10, y - 30); int lavaEnd = Math.max(5, context.levels.waterY - 10); fillDown(context, chunk, x, z, lavaStart, lavaEnd, States.LAVA.get()); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/BedrockDecorator.java b/src/main/java/com/terraforged/mod/chunk/column/BedrockDecorator.java similarity index 90% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/BedrockDecorator.java rename to src/main/java/com/terraforged/mod/chunk/column/BedrockDecorator.java index 9e52080..b76c087 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/BedrockDecorator.java +++ b/src/main/java/com/terraforged/mod/chunk/column/BedrockDecorator.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.base; +package com.terraforged.mod.chunk.column; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; @@ -44,9 +44,9 @@ public class BedrockDecorator implements ColumnDecorator { private final BlockState material; public BedrockDecorator(TerraContext context) { - minDepth = context.terraSettings.dimensions.baseLayer.minDepth; - variance = context.terraSettings.dimensions.baseLayer.variance; - material = getState(context.terraSettings.dimensions.baseLayer.material); + minDepth = context.terraSettings.dimensions.bedrockLayer.minDepth; + variance = context.terraSettings.dimensions.bedrockLayer.variance; + material = getState(context.terraSettings.dimensions.bedrockLayer.material); } @Override diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/CoastDecorator.java b/src/main/java/com/terraforged/mod/chunk/column/CoastDecorator.java similarity index 94% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/CoastDecorator.java rename to src/main/java/com/terraforged/mod/chunk/column/CoastDecorator.java index 686d4b8..86327a8 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/CoastDecorator.java +++ b/src/main/java/com/terraforged/mod/chunk/column/CoastDecorator.java @@ -23,14 +23,14 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.base; +package com.terraforged.mod.chunk.column; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.material.state.States; -import com.terraforged.core.util.VariablePredicate; -import com.terraforged.core.world.terrain.Terrains; import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.util.VariablePredicate; +import com.terraforged.world.terrain.Terrains; import net.minecraft.block.BlockState; import net.minecraft.world.chunk.IChunk; @@ -59,7 +59,7 @@ public class CoastDecorator implements ColumnDecorator { @Override public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.tag != terrains.beach) { + if (context.cell.terrain != terrains.beach) { return; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/ErosionDecorator.java b/src/main/java/com/terraforged/mod/chunk/column/ErosionDecorator.java similarity index 94% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/ErosionDecorator.java rename to src/main/java/com/terraforged/mod/chunk/column/ErosionDecorator.java index e72cd23..2055448 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/ErosionDecorator.java +++ b/src/main/java/com/terraforged/mod/chunk/column/ErosionDecorator.java @@ -23,14 +23,14 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.base; +package com.terraforged.mod.chunk.column; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.material.state.States; -import com.terraforged.core.world.terrain.Terrains; import com.terraforged.mod.chunk.TerraContext; import com.terraforged.mod.material.Materials; +import com.terraforged.world.terrain.Terrains; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.material.Material; @@ -69,17 +69,17 @@ public class ErosionDecorator implements ColumnDecorator { this.seed1 = context.seed.next(); this.seed2 = context.seed.next(); this.seed3 = context.seed.next(); - this.minY = context.levels.ground(4); + this.minY = context.levels.water; this.materials = context.materials; } @Override public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.value < minY || context.cell.tag == terrain.river || context.cell.tag == terrain.riverBanks) { + if (context.cell.value < minY || context.cell.terrain.isRiver() || context.cell.terrain.isWetland()) { return; } - if (context.cell.tag == terrain.volcanoPipe) { + if (context.cell.terrain == terrain.volcanoPipe) { return; } @@ -179,10 +179,10 @@ public class ErosionDecorator implements ColumnDecorator { } if (state.getMaterial() == Material.SAND) { if (state.getBlock() == Blocks.SAND) { - return States.SANDSTONE.get(); + return States.SMOOTH_SANDSTONE.get(); } if (state.getBlock() == Blocks.RED_SAND) { - return States.RED_SANDSTONE.get(); + return States.SMOOTH_RED_SANDSTONE.get(); } } return States.COARSE_DIRT.get(); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/GeologyDecorator.java b/src/main/java/com/terraforged/mod/chunk/column/GeologyDecorator.java similarity index 92% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/GeologyDecorator.java rename to src/main/java/com/terraforged/mod/chunk/column/GeologyDecorator.java index 2d5a2f1..13d8943 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/GeologyDecorator.java +++ b/src/main/java/com/terraforged/mod/chunk/column/GeologyDecorator.java @@ -23,11 +23,11 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.base; +package com.terraforged.mod.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.mod.material.geology.GeoManager; import net.minecraft.world.chunk.IChunk; @@ -47,7 +47,7 @@ public class GeologyDecorator implements ColumnDecorator { @Override public void decorate(ChunkSurfaceBuffer buffer, DecoratorContext context, int x, int y, int z) { int top = buffer.getSurfaceBottom(); - geology.getGeology(context.biome).getStrata(x, z).downwards(x, top, z, context.depthBuffer, (py, state) -> { + geology.getGeology(context.biome).getStrata(x, z).downwards(x, top, z, context.depthBuffer.get(), (py, state) -> { context.pos.setPos(x, py, z); buffer.getDelegate().setBlockState(context.pos, state, false); return true; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java b/src/main/java/com/terraforged/mod/chunk/column/post/LayerDecorator.java similarity index 70% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java rename to src/main/java/com/terraforged/mod/chunk/column/post/LayerDecorator.java index 5467be8..f8ca7e8 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java +++ b/src/main/java/com/terraforged/mod/chunk/column/post/LayerDecorator.java @@ -23,15 +23,14 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.feature; +package com.terraforged.mod.chunk.column.post; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.material.layer.LayerManager; import com.terraforged.api.material.layer.LayerMaterial; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.mod.material.MaterialHelper; +import com.terraforged.world.heightmap.Levels; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.IChunk; @@ -48,37 +47,30 @@ public class LayerDecorator implements ColumnDecorator { public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { context.pos.setPos(x, y + 1, z); - // if block is already a layer-type then simply set the layer property BlockState state = chunk.getBlockState(context.pos); - LayerMaterial material = layerManager.getMaterial(state.getBlock()); - if (material != null) { - setLayer(chunk, context.pos, material, context.cell, context.levels, 0F); - return; - } - - if (MaterialHelper.isAir(state.getBlock())) { - return; - } - - // block is non-solid (grass/flower etc) - if (!state.getMaterial().blocksMovement()) { - // block below is solid - if (chunk.getBlockState(context.pos.setPos(x, y, z)).getMaterial().blocksMovement()) { - // block above is air - if (MaterialHelper.isAir(chunk.getBlockState(context.pos.setPos(x, y + 2, z)).getBlock())) { -// setLayer(chunk, pos.setPos(x, y + 1, z), context.cell, context.levels, 0.25F); - } + if (state.isAir(chunk, context.pos)) { + context.pos.setPos(x, y, z); + state = chunk.getBlockState(context.pos); + if (state.isAir(chunk, context.pos)) { + return; } } + + LayerMaterial material = layerManager.getMaterial(state.getBlock()); + if (material == null) { + return; + } + + setLayer(chunk, context.pos, material, context.cell, context.levels, 0F); } - private void setLayer(IChunk chunk, BlockPos pos, LayerMaterial material, Cell cell, Levels levels, float min) { + private void setLayer(IChunk chunk, BlockPos pos, LayerMaterial material, Cell cell, Levels levels, float min) { float height = cell.value * levels.worldHeight; float depth = material.getDepth(height); if (depth > min) { int level = material.getLevel(depth); BlockState layer = material.getState(level); - if (MaterialHelper.isAir(layer.getBlock())) { + if (layer == LayerMaterial.NONE) { return; } chunk.setBlockState(pos, layer, false); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/feature/SnowEroder.java b/src/main/java/com/terraforged/mod/chunk/column/post/SnowEroder.java similarity index 94% rename from TerraForgedMod/src/main/java/com/terraforged/mod/decorator/feature/SnowEroder.java rename to src/main/java/com/terraforged/mod/chunk/column/post/SnowEroder.java index 829a6d9..fa14591 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/feature/SnowEroder.java +++ b/src/main/java/com/terraforged/mod/chunk/column/post/SnowEroder.java @@ -23,13 +23,13 @@ * SOFTWARE. */ -package com.terraforged.mod.decorator.feature; +package com.terraforged.mod.chunk.column.post; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.mod.chunk.TerraContext; -import com.terraforged.mod.decorator.base.ErosionDecorator; -import me.dags.noise.source.Rand; +import com.terraforged.mod.chunk.column.ErosionDecorator; +import com.terraforged.n2d.source.Rand; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.GrassBlock; @@ -71,7 +71,7 @@ public class SnowEroder extends ErosionDecorator { float var = -ColumnDecorator.getNoise(x, z, seed1, 16, 0); float hNoise = rand.getValue(x, z, seed2) * HEIGHT_MODIFIER; float sNoise = rand.getValue(x, z, seed3) * SLOPE_MODIFIER; - float vModifier = context.cell.tag == context.terrains.volcano ? 0.15F : 0F; + float vModifier = context.cell.terrain == context.terrains.volcano ? 0.15F : 0F; float height = context.cell.value + var + hNoise + vModifier; float steepness = context.cell.steepness + var + sNoise + vModifier; if (snowErosion(x, z, steepness, height)) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java b/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java similarity index 93% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java rename to src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java index dc12300..0792eae 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java +++ b/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java @@ -27,7 +27,6 @@ package com.terraforged.mod.chunk.fix; import com.terraforged.api.chunk.ChunkDelegate; import com.terraforged.api.material.state.States; -import com.terraforged.mod.material.MaterialHelper; import com.terraforged.mod.material.Materials; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; @@ -51,10 +50,10 @@ public class ChunkCarverFix implements ChunkDelegate { @Override public BlockState getBlockState(BlockPos pos) { BlockState state = getDelegate().getBlockState(pos); - if (MaterialHelper.isAir(state.getBlock())) { + if (materials.isAir(state.getBlock())) { return state; } - if (MaterialHelper.isGrass(state.getBlock())) { + if (materials.isGrass(state.getBlock())) { return States.GRASS_BLOCK.get(); } if (materials.isStone(state.getBlock())) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/RegionDelegate.java b/src/main/java/com/terraforged/mod/chunk/fix/RegionDelegate.java similarity index 90% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/RegionDelegate.java rename to src/main/java/com/terraforged/mod/chunk/fix/RegionDelegate.java index 446ef98..d373d53 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/RegionDelegate.java +++ b/src/main/java/com/terraforged/mod/chunk/fix/RegionDelegate.java @@ -129,8 +129,8 @@ public class RegionDelegate extends WorldGenRegion { } @Override - public boolean func_225521_a_(BlockPos p_225521_1_, boolean p_225521_2_, @Nullable Entity p_225521_3_) { - return region.func_225521_a_(p_225521_1_, p_225521_2_, p_225521_3_); + public boolean destroyBlock(BlockPos p_225521_1_, boolean p_225521_2_, @Nullable Entity p_225521_3_) { + return region.destroyBlock(p_225521_1_, p_225521_2_, p_225521_3_); } @Override @@ -308,8 +308,8 @@ public class RegionDelegate extends WorldGenRegion { } @Override - public List func_225316_b(Class p_225316_1_, AxisAlignedBB p_225316_2_, @Nullable Predicate p_225316_3_) { - return region.func_225316_b(p_225316_1_, p_225316_2_, p_225316_3_); + public List getLoadedEntitiesWithinAABB(Class p_225316_1_, AxisAlignedBB p_225316_2_, @Nullable Predicate p_225316_3_) { + return region.getLoadedEntitiesWithinAABB(p_225316_1_, p_225316_2_, p_225316_3_); } @Override @@ -323,8 +323,8 @@ public class RegionDelegate extends WorldGenRegion { } @Override - public List func_225317_b(Class p_225317_1_, AxisAlignedBB p_225317_2_) { - return region.func_225317_b(p_225317_1_, p_225317_2_); + public List getLoadedEntitiesWithinAABB(Class p_225317_1_, AxisAlignedBB p_225317_2_) { + return region.getLoadedEntitiesWithinAABB(p_225317_1_, p_225317_2_); } @Override @@ -451,8 +451,8 @@ public class RegionDelegate extends WorldGenRegion { @Override @Nullable - public IBlockReader getBlockReader(int p_225522_1_, int p_225522_2_) { - return region.getBlockReader(p_225522_1_, p_225522_2_); + public IBlockReader getBlockReader(int chunkX, int chunkZ) { + return region.getBlockReader(chunkX, chunkZ); } @Override @@ -545,38 +545,38 @@ public class RegionDelegate extends WorldGenRegion { } @Override - public boolean func_226668_i_(Entity p_226668_1_) { - return region.func_226668_i_(p_226668_1_); + public boolean checkNoEntityCollision(Entity p_226668_1_) { + return region.checkNoEntityCollision(p_226668_1_); } @Override - public boolean func_226664_a_(AxisAlignedBB p_226664_1_) { - return region.func_226664_a_(p_226664_1_); + public boolean hasNoCollisions(AxisAlignedBB p_226664_1_) { + return region.hasNoCollisions(p_226664_1_); } @Override - public boolean func_226669_j_(Entity p_226669_1_) { - return region.func_226669_j_(p_226669_1_); + public boolean hasNoCollisions(Entity p_226669_1_) { + return region.hasNoCollisions(p_226669_1_); } @Override - public boolean func_226665_a__(Entity p_226665_1_, AxisAlignedBB p_226665_2_) { - return region.func_226665_a__(p_226665_1_, p_226665_2_); + public boolean hasNoCollisions(Entity p_226665_1_, AxisAlignedBB p_226665_2_) { + return region.hasNoCollisions(p_226665_1_, p_226665_2_); } @Override - public boolean func_226662_a_(@Nullable Entity p_226662_1_, AxisAlignedBB p_226662_2_, Set p_226662_3_) { - return region.func_226662_a_(p_226662_1_, p_226662_2_, p_226662_3_); + public boolean hasNoCollisions(@Nullable Entity p_226662_1_, AxisAlignedBB p_226662_2_, Set p_226662_3_) { + return region.hasNoCollisions(p_226662_1_, p_226662_2_, p_226662_3_); } @Override - public Stream func_226667_c_(@Nullable Entity p_226667_1_, AxisAlignedBB p_226667_2_, Set p_226667_3_) { - return region.func_226667_c_(p_226667_1_, p_226667_2_, p_226667_3_); + public Stream getCollisionShapes(@Nullable Entity p_226667_1_, AxisAlignedBB p_226667_2_, Set p_226667_3_) { + return region.getCollisionShapes(p_226667_1_, p_226667_2_, p_226667_3_); } @Override - public Stream func_226666_b_(@Nullable Entity p_226666_1_, AxisAlignedBB p_226666_2_) { - return region.func_226666_b_(p_226666_1_, p_226666_2_); + public Stream getCollisionShapes(@Nullable Entity p_226666_1_, AxisAlignedBB p_226666_2_) { + return region.getCollisionShapes(p_226666_1_, p_226666_2_); } @Override diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/RegionFix.java b/src/main/java/com/terraforged/mod/chunk/fix/RegionFix.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/fix/RegionFix.java rename to src/main/java/com/terraforged/mod/chunk/fix/RegionFix.java diff --git a/src/main/java/com/terraforged/mod/chunk/generator/BiomeGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/BiomeGenerator.java new file mode 100644 index 0000000..b2a4978 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/BiomeGenerator.java @@ -0,0 +1,42 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.util.TerraContainer; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.world.terrain.decorator.Decorator; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.IChunk; + +public class BiomeGenerator implements Generator.Biomes { + + private final TerraChunkGenerator generator; + private final TerraBiomeProvider biomeProvider; + + public BiomeGenerator(TerraChunkGenerator generator) { + this.generator = generator; + this.biomeProvider = generator.getBiomeProvider(); + } + + @Override + public void generateBiomes(IChunk chunk) { + ChunkPos pos = chunk.getPos(); + try (ChunkReader reader = generator.getChunkReader(pos.x, pos.z)) { + TerraContainer container = TerraContainer.create(reader, generator.getBiomeProvider()); + // apply chunk-local heightmap modifications + preProcess(reader, container); + } + } + + private void preProcess(ChunkReader reader, TerraContainer biomes) { + reader.iterate((cell, dx, dz) -> { + Biome biome = biomes.getBiome(dx, dz); + for (Decorator decorator : generator.getBiomeProvider().getDecorators(biome)) { + if (decorator.apply(cell, reader.getBlockX() + dx, reader.getBlockZ() + dz)) { + return; + } + } + }); + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/FeatureGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/FeatureGenerator.java new file mode 100644 index 0000000..0c4bcc0 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/FeatureGenerator.java @@ -0,0 +1,72 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.api.chunk.column.ColumnDecorator; +import com.terraforged.api.chunk.column.DecoratorContext; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.fix.RegionFix; +import com.terraforged.mod.chunk.util.TerraContainer; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.mod.util.Environment; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.ChunkPrimer; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.WorldGenRegion; + +import java.util.List; + +public class FeatureGenerator implements Generator.Features { + + private final TerraChunkGenerator generator; + + public FeatureGenerator(TerraChunkGenerator generator) { + this.generator = generator; + } + + @Override + public final void generateFeatures(WorldGenRegion region) { + int chunkX = region.getMainChunkX(); + int chunkZ = region.getMainChunkZ(); + IChunk chunk = region.getChunk(chunkX, chunkZ); + + ChunkReader reader = generator.getChunkReader(chunkX, chunkZ); + TerraContainer container = TerraContainer.getOrCreate(chunk, reader, generator.getBiomeProvider()); + + Biome biome = container.getFeatureBiome(reader); + DecoratorContext context = generator.getContext().decorator(chunk); + + IWorld regionFix = new RegionFix(region, generator); + BlockPos pos = new BlockPos(context.blockX, 0, context.blockZ); + + // place biome features + generator.getFeatureManager().decorate(generator, regionFix, chunk, biome, pos); + + // run post processes on chunk + postProcess(reader, container, context); + + // bake biome array + ((ChunkPrimer) chunk).func_225548_a_(container.bakeBiomes(Environment.isVanillaBiomes())); + + // close the current chunk reader + reader.close(); + + // mark chunk disposed as this is the last usage of the reader + reader.dispose(); + } + + private void postProcess(ChunkReader reader, TerraContainer container, DecoratorContext context) { + List decorators = generator.getPostProcessors(); + reader.iterate(context, (cell, dx, dz, ctx) -> { + int px = ctx.blockX + dx; + int pz = ctx.blockZ + dz; + int py = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, dx, dz); + ctx.cell = cell; + ctx.biome = container.getBiome(dx, dz); + for (ColumnDecorator decorator : decorators) { + decorator.decorate(ctx.chunk, ctx, px, py, pz); + } + }); + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/Generator.java b/src/main/java/com/terraforged/mod/chunk/generator/Generator.java new file mode 100644 index 0000000..ecfca40 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/Generator.java @@ -0,0 +1,89 @@ +package com.terraforged.mod.chunk.generator; + +import net.minecraft.entity.EntityClassification; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeManager; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.GenerationStage; +import net.minecraft.world.gen.WorldGenRegion; +import net.minecraft.world.gen.feature.template.TemplateManager; +import net.minecraft.world.server.ServerWorld; + +import java.util.List; + +public interface Generator { + + interface Biomes { + + /** + * Generates the biomes for this chunk + */ + void generateBiomes(IChunk chunk); + } + + interface Terrain { + + /** + * Generates the basic heightmap and populates with stone/water/bedrock accordinly + */ + void generateTerrain(IWorld world, IChunk chunk); + } + + interface Features { + + /** + * Places biome specific features into the center-chunk of the world gen region + * The region consists of the center chunk (the chunk being generated) and it's 8 neighbouring chunks (citation needed) + */ + void generateFeatures(WorldGenRegion region); + } + + interface Structures { + + /** + * Determines where structures will be placed during chunk gen + */ + void generateStructureStarts(BiomeManager biomes, IChunk chunk, TemplateManager templates); + + /** + * Determines where individual structure pieces will be placed based on the start positions + */ + void generateStructureReferences(IWorld world, IChunk chunk); + } + + interface Surfaces { + + /** + * Applies biome specific surface generation during chunk gen + */ + void generateSurface(WorldGenRegion world, IChunk chunk); + } + + interface Carvers { + + /** + * Cuts caves/ravines during chunk gen according to the carving stage + */ + void carveTerrain(BiomeManager biomes, IChunk chunk, GenerationStage.Carving type); + } + + interface Mobs { + + /** + * Spawns mobs during chunk gen + */ + void generateMobs(WorldGenRegion region); + + /** + * Ticks the worlds mob spawners post chunk gen + */ + void tickSpawners(ServerWorld world, boolean hostile, boolean peaceful); + + /** + * Gets a list of possible spawns at the given position + */ + List getSpawns(IWorld world, EntityClassification type, BlockPos pos); + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/MobGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/MobGenerator.java new file mode 100644 index 0000000..c86de9f --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/MobGenerator.java @@ -0,0 +1,86 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.mod.chunk.TerraChunkGenerator; +import net.minecraft.entity.EntityClassification; +import net.minecraft.util.SharedSeedRandom; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.GameRules; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.WorldGenRegion; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.server.ServerWorld; +import net.minecraft.world.spawner.CatSpawner; +import net.minecraft.world.spawner.PatrolSpawner; +import net.minecraft.world.spawner.PhantomSpawner; +import net.minecraft.world.spawner.WorldEntitySpawner; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +import java.util.List; + +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) +public class MobGenerator implements Generator.Mobs { + + // may be accessed cross-thread + private static volatile boolean mobSpawning = true; + + private final CatSpawner catSpawner = new CatSpawner(); + private final PatrolSpawner patrolSpawner = new PatrolSpawner(); + private final PhantomSpawner phantomSpawner = new PhantomSpawner(); + private final TerraChunkGenerator generator; + + public MobGenerator(TerraChunkGenerator generator) { + this.generator = generator; + } + + @Override + public final void generateMobs(WorldGenRegion region) { + // vanilla does NOT check the mobSpawning gamerule before calling this + if (MobGenerator.mobSpawning) { + int chunkX = region.getMainChunkX(); + int chunkZ = region.getMainChunkZ(); + Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0); + SharedSeedRandom sharedseedrandom = new SharedSeedRandom(); + sharedseedrandom.setDecorationSeed(region.getSeed(), chunkX << 4, chunkZ << 4); + WorldEntitySpawner.performWorldGenSpawning(region, biome, chunkX, chunkZ, sharedseedrandom); + } + } + + @Override + public final void tickSpawners(ServerWorld world, boolean hostile, boolean peaceful) { + phantomSpawner.tick(world, hostile, peaceful); + patrolSpawner.tick(world, hostile, peaceful); + catSpawner.tick(world, hostile, peaceful); + } + + @Override + public final List getSpawns(IWorld world, EntityClassification type, BlockPos pos) { + if (Feature.SWAMP_HUT.func_202383_b(world, pos)) { + if (type == EntityClassification.MONSTER) { + return Feature.SWAMP_HUT.getSpawnList(); + } + + if (type == EntityClassification.CREATURE) { + return Feature.SWAMP_HUT.getCreatureSpawnList(); + } + } else if (type == EntityClassification.MONSTER) { + if (Feature.PILLAGER_OUTPOST.isPositionInStructure(world, pos)) { + return Feature.PILLAGER_OUTPOST.getSpawnList(); + } + + if (Feature.OCEAN_MONUMENT.isPositionInStructure(world, pos)) { + return Feature.OCEAN_MONUMENT.getSpawnList(); + } + } + return world.getBiome(pos).getSpawns(type); + } + + @SubscribeEvent + public static void tick(TickEvent.WorldTickEvent event) { + if (event.phase == TickEvent.Phase.START && event.side.isServer()) { + mobSpawning = event.world.getGameRules().get(GameRules.DO_MOB_SPAWNING).get(); + } + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/StructureGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/StructureGenerator.java new file mode 100644 index 0000000..7cae36a --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/StructureGenerator.java @@ -0,0 +1,92 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.fm.predicate.FeaturePredicate; +import net.minecraft.network.DebugPacketSender; +import net.minecraft.util.SharedSeedRandom; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.MutableBoundingBox; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeManager; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.world.gen.feature.structure.StructureStart; +import net.minecraft.world.gen.feature.template.TemplateManager; + +import java.util.Map; + +public class StructureGenerator implements Generator.Structures { + + private final TerraChunkGenerator generator; + + public StructureGenerator(TerraChunkGenerator generator) { + this.generator = generator; + } + + @Override + public void generateStructureStarts(BiomeManager biomes, IChunk chunk, TemplateManager templates) { + ChunkPos chunkpos = chunk.getPos(); + generator.queueChunk(chunkpos.x, chunkpos.z); + + BlockPos biomePos = new BlockPos(chunkpos.getXStart() + 9, 0, chunkpos.getZStart() + 9); + Biome biome = biomes.getBiome(biomePos); + + for (Structure structure : Feature.STRUCTURES.values()) { + if (generator.getBiomeProvider().hasStructure(structure)) { + FeaturePredicate predicate = generator.getStructureManager().getPredicate(structure); + if (!predicate.test(chunk, biome)) { + continue; + } + + StructureStart existingStart = chunk.getStructureStart(structure.getStructureName()); + int refCount = existingStart != null ? existingStart.getRefCount() : 0; + + SharedSeedRandom random = new SharedSeedRandom(); + StructureStart start = StructureStart.DUMMY; + + if (structure.canBeGenerated(biomes, generator, random, chunkpos.x, chunkpos.z, biome)) { + StructureStart altStart = structure.getStartFactory().create(structure, chunkpos.x, chunkpos.z, MutableBoundingBox.getNewBoundingBox(), refCount, generator.getSeed()); + altStart.init(generator, templates, chunkpos.x, chunkpos.z, biome); + start = altStart.isValid() ? altStart : StructureStart.DUMMY; + } + + chunk.putStructureStart(structure.getStructureName(), start); + } + } + } + + public void generateStructureReferences(IWorld world, IChunk chunk) { + try { + int radius = 8; + + int chunkX = chunk.getPos().x; + int chunkZ = chunk.getPos().z; + + int minX = chunkX << 4; + int minZ = chunkZ << 4; + int maxX = minX + 15; + int maxZ = minZ + 15; + + for (int dx = -radius; dx <= radius; ++dx) { + for (int dz = -radius; dz <= radius; ++dz) { + int cx = chunkX + dx; + int cz = chunkZ + dz; + long chunkSeed = ChunkPos.asLong(cx, cz); + IChunk c = world.getChunk(cx, cz); + for (Map.Entry entry : c.getStructureStarts().entrySet()) { + StructureStart start = entry.getValue(); + if (start != StructureStart.DUMMY && start.getBoundingBox().intersectsWith(minX, minZ, maxX, maxZ)) { + chunk.addStructureReference(entry.getKey(), chunkSeed); + DebugPacketSender.sendStructureStart(world, start); + } + } + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/SurfaceGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/SurfaceGenerator.java new file mode 100644 index 0000000..55b5e63 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/SurfaceGenerator.java @@ -0,0 +1,66 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.api.chunk.column.ColumnDecorator; +import com.terraforged.api.biome.surface.ChunkSurfaceBuffer; +import com.terraforged.api.biome.surface.SurfaceContext; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.util.FastChunk; +import com.terraforged.mod.chunk.util.TerraContainer; +import com.terraforged.core.tile.chunk.ChunkReader; +import net.minecraft.util.SharedSeedRandom; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.INoiseGenerator; +import net.minecraft.world.gen.PerlinNoiseGenerator; +import net.minecraft.world.gen.WorldGenRegion; + +public class SurfaceGenerator implements Generator.Surfaces { + + private final TerraChunkGenerator generator; + private final INoiseGenerator surfaceNoise; + + public SurfaceGenerator(TerraChunkGenerator generator) { + this.generator = generator; + this.surfaceNoise = new PerlinNoiseGenerator(new SharedSeedRandom(generator.getSeed()), 3, 0); + } + + @Override + public final void generateSurface(WorldGenRegion world, IChunk chunk) { + try (ChunkReader reader = generator.getChunkReader(chunk.getPos().x, chunk.getPos().z)) { + TerraContainer container = TerraContainer.getOrCreate(chunk, reader, generator.getBiomeProvider()); + ChunkSurfaceBuffer buffer = new ChunkSurfaceBuffer(FastChunk.wrap(chunk)); + + try (SurfaceContext context = generator.getContext().surface(buffer, generator.getSettings())) { + reader.iterate(context, (cell, dx, dz, ctx) -> { + int px = ctx.blockX + dx; + int pz = ctx.blockZ + dz; + int top = ctx.chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE_WG, dx, dz); + + ctx.buffer.setSurfaceLevel(top); + + ctx.cell = cell; + ctx.biome = container.getBiome(dx, dz); + ctx.noise = getSurfaceNoise(px, pz) * 15D; + + generator.getSurfaceManager().getSurface(ctx).buildSurface(px, pz, top, ctx); + + int py = ctx.levels.scale(cell.value); + for (ColumnDecorator processor : generator.getBaseDecorators()) { + processor.decorate(ctx.buffer, ctx, px, py, pz); + } + }); + + FastChunk.updateWGHeightmaps(chunk, context.pos); + } + } + } + + private double getSurfaceNoise(int x, int z) { + double scale = 0.0625D; + double noiseX = x * scale; + double noiseZ = z * scale; + double unusedValue1 = scale; + double unusedValue2 = (x & 15) * scale; + return surfaceNoise.noiseAt(noiseX, noiseZ, unusedValue1, unusedValue2); + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/TerrainCarver.java b/src/main/java/com/terraforged/mod/chunk/generator/TerrainCarver.java new file mode 100644 index 0000000..1cecbfb --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/TerrainCarver.java @@ -0,0 +1,55 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.fix.ChunkCarverFix; +import com.terraforged.fm.template.StructureUtils; +import net.minecraft.util.SharedSeedRandom; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeManager; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.GenerationStage; +import net.minecraft.world.gen.carver.ConfiguredCarver; + +import java.util.BitSet; +import java.util.ListIterator; + +public class TerrainCarver implements Generator.Carvers { + + private final TerraChunkGenerator generator; + + public TerrainCarver(TerraChunkGenerator generator) { + this.generator = generator; + } + + @Override + public void carveTerrain(BiomeManager biomes, IChunk chunk, GenerationStage.Carving type) { + if (StructureUtils.hasOvergroundStructure(chunk)) { + return; + } + + chunk = new ChunkCarverFix(chunk, generator.getContext().materials); + + SharedSeedRandom random = new SharedSeedRandom(); + ChunkPos chunkpos = chunk.getPos(); + int chunkX = chunkpos.x; + int chunkZ = chunkpos.z; + BitSet mask = chunk.getCarvingMask(type); + Biome biome = generator.getBiome(biomes, chunkpos.asBlockPos()); + + for (int cx = chunkX - 8; cx <= chunkX + 8; ++cx) { + for (int cz = chunkZ - 8; cz <= chunkZ + 8; ++cz) { + ListIterator> iterator = biome.getCarvers(type).listIterator(); + while (iterator.hasNext()) { + int index = iterator.nextIndex(); + ConfiguredCarver carver = iterator.next(); + random.setLargeFeatureSeed(generator.getSeed() + index, cx, cz); + if (carver.shouldCarve(random, cx, cz)) { + carver.func_227207_a_(chunk, pos -> generator.getBiome(biomes, pos), random, generator.getSeaLevel(), cx, cz, chunkX, chunkZ, mask); + } + } + } + } + + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/generator/TerrainGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/TerrainGenerator.java new file mode 100644 index 0000000..fd80f56 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/generator/TerrainGenerator.java @@ -0,0 +1,49 @@ +package com.terraforged.mod.chunk.generator; + +import com.terraforged.api.chunk.column.DecoratorContext; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.column.BaseDecorator; +import com.terraforged.mod.chunk.util.FastChunk; +import com.terraforged.mod.chunk.util.TerraContainer; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.mod.feature.TerrainHelper; +import com.terraforged.world.climate.Climate; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.Terrains; +import net.minecraft.world.IWorld; +import net.minecraft.world.chunk.IChunk; + +public class TerrainGenerator implements Generator.Terrain { + + private final Levels levels; + private final Climate climate; + private final Terrains terrain; + private final TerraChunkGenerator generator; + private final TerrainHelper terrainHelper; + + public TerrainGenerator(TerraChunkGenerator generator) { + this.generator = generator; + this.levels = generator.getContext().levels; + this.terrain = generator.getContext().terrain; + this.climate = generator.getContext().factory.getClimate(); + this.terrainHelper = new TerrainHelper(0.75F); + } + + @Override + public final void generateTerrain(IWorld world, IChunk chunk) { + try (ChunkReader reader = generator.getChunkReader(chunk.getPos().x, chunk.getPos().z)) { + TerraContainer container = TerraContainer.getOrCreate(chunk, reader, generator.getBiomeProvider()); + try (DecoratorContext context = new DecoratorContext(FastChunk.wrap(chunk), levels, terrain, climate)) { + reader.iterate(context, (cell, dx, dz, ctx) -> { + int px = ctx.blockX + dx; + int pz = ctx.blockZ + dz; + int py = ctx.levels.scale(cell.value); + ctx.cell = cell; + ctx.biome = container.getNoiseBiome(dx, world.getSeaLevel(), dz); + BaseDecorator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz); + }); + terrainHelper.flatten(world, chunk); + } + } + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java b/src/main/java/com/terraforged/mod/chunk/settings/DimesionSettings.java similarity index 85% rename from TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java rename to src/main/java/com/terraforged/mod/chunk/settings/DimesionSettings.java index 7290350..ba88b7e 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/DimesionSettings.java +++ b/src/main/java/com/terraforged/mod/chunk/settings/DimesionSettings.java @@ -1,9 +1,9 @@ -package com.terraforged.mod.settings; +package com.terraforged.mod.chunk.settings; -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Range; -import com.terraforged.core.util.serialization.annotation.Serializable; import com.terraforged.mod.TerraWorld; +import com.terraforged.core.serialization.annotation.Comment; +import com.terraforged.core.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Serializable; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.StringNBT; import net.minecraft.world.WorldType; @@ -14,9 +14,9 @@ import org.jline.utils.Log; @Serializable public class DimesionSettings { - public BaseDecorator baseLayer = new BaseDecorator(); + public BaseDecorator bedrockLayer = new BaseDecorator(); - public DimensionGenerators dimensionGenerators = new DimensionGenerators(); + public DimensionGenerators dimensions = new DimensionGenerators(); @Serializable public static class BaseDecorator { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/FeatureSettings.java b/src/main/java/com/terraforged/mod/chunk/settings/Miscellaneous.java similarity index 74% rename from TerraForgedMod/src/main/java/com/terraforged/mod/settings/FeatureSettings.java rename to src/main/java/com/terraforged/mod/chunk/settings/Miscellaneous.java index 878f360..573dbc4 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/FeatureSettings.java +++ b/src/main/java/com/terraforged/mod/chunk/settings/Miscellaneous.java @@ -23,13 +23,15 @@ * SOFTWARE. */ -package com.terraforged.mod.settings; +package com.terraforged.mod.chunk.settings; -import com.terraforged.core.util.serialization.annotation.Comment; -import com.terraforged.core.util.serialization.annotation.Serializable; +import com.terraforged.mod.biome.modifier.MountainModifier; +import com.terraforged.core.serialization.annotation.Comment; +import com.terraforged.core.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Serializable; @Serializable -public class FeatureSettings { +public class Miscellaneous { @Comment("Modifies layer block levels (ie snow) to fit the terrain") public boolean smoothLayerDecorator = true; @@ -48,4 +50,11 @@ public class FeatureSettings { @Comment("Controls whether vanilla lakes & springs should generate") public boolean vanillaWaterFeatures = false; + + @Comment({ + "The probability that mountainous terrain will be set to a mountain biome type.", + "This may help improve compatibility with mods that rely exclusively on mountain biomes." + }) + @Range(min = 0F, max = 1F) + public float mountainBiomeUsage = MountainModifier.MOUNTAIN_CHANCE; } diff --git a/src/main/java/com/terraforged/mod/chunk/settings/SettingsHelper.java b/src/main/java/com/terraforged/mod/chunk/settings/SettingsHelper.java new file mode 100644 index 0000000..299e92b --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/settings/SettingsHelper.java @@ -0,0 +1,82 @@ +package com.terraforged.mod.chunk.settings; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.terraforged.mod.Log; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.world.storage.WorldInfo; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +public class SettingsHelper { + + public static final File SETTINGS_DIR = new File("config", "terraforged"); + public static final File DEFAULTS_FILE = new File(SETTINGS_DIR, "generator-defaults.json"); + + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + public static void clearDefaults() { + if (DEFAULTS_FILE.exists() && DEFAULTS_FILE.delete()) { + Log.info("Deleted generator defaults"); + } + } + + public static void exportDefaults(TerraSettings settings) { + CompoundNBT tag = NBTHelper.serializeCompact(settings); + JsonElement json = NBTHelper.toJson(tag); + try (Writer writer = new BufferedWriter(new FileWriter(DEFAULTS_FILE))) { + GSON.toJson(json, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static CompoundNBT applyDefaults(CompoundNBT options, TerraSettings dest) { + if (options.isEmpty()) { + try (Reader reader = new BufferedReader(new FileReader(DEFAULTS_FILE))) { + JsonElement json = new JsonParser().parse(reader); + options = NBTHelper.fromJson(json); + } catch (IOException ignored) { + + } + } + NBTHelper.deserialize(options, dest); + return options; + } + + public static TerraSettings getSettings(WorldInfo info) { + TerraSettings settings = new TerraSettings(); + if (info.getGeneratorOptions().isEmpty()) { + if (DEFAULTS_FILE.exists()) { + try (Reader reader = new BufferedReader(new FileReader(DEFAULTS_FILE))) { + Log.info("Loading generator settings from json"); + JsonElement json = new JsonParser().parse(reader); + CompoundNBT root = NBTHelper.fromJson(json); + NBTHelper.deserialize(root, settings); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } else { + Log.info("Loading generator settings from level.dat"); + NBTHelper.deserialize(info.getGeneratorOptions(), settings); + } + return settings; + } + + public static void init() { + if (!DEFAULTS_FILE.exists()) { + exportDefaults(new TerraSettings()); + } + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/settings/StructureSettings.java b/src/main/java/com/terraforged/mod/chunk/settings/StructureSettings.java new file mode 100644 index 0000000..df5bb21 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/settings/StructureSettings.java @@ -0,0 +1,114 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.chunk.settings; + +import com.terraforged.core.serialization.annotation.Comment; +import com.terraforged.core.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Serializable; +import net.minecraft.world.gen.OverworldGenSettings; + +@Serializable +public class StructureSettings { + + private static final StructureDefaults defaults = new StructureDefaults(); + + public Structure villages = new Structure(defaults.village_dist, defaults.village_sep); + + public Structure mansions = new Structure(defaults.mansionDist, defaults.mansionSep); + + public Structure strongholds = new Structure(defaults.strongholdDist, defaults.strongholdSep); + + public Structure shipwrecks = new Structure(defaults.shipWreckDist, defaults.shipWreckSep); + + public Structure oceanRuins = new Structure(defaults.oceanRuinDist, defaults.oceanRuinSep); + + public Structure oceanMonuments = new Structure(defaults.oceanMonumentDist, defaults.oceanMonumentSep); + + public Structure otherStructures = new Structure(defaults.otherStructureDist, defaults.otherStructureSep); + + @Serializable + public static class Structure { + + @Range(min = 1, max = 200) + @Comment("The distance (in chunks) between placements of this feature") + public int distance; + + @Range(min = 1, max = 50) + @Comment("The separation (in chunks) between placements of this feature") + public int separation; + + public Structure() { + + } + + public Structure(int distance, int separation) { + this.distance = distance; + this.separation = separation; + } + } + + private static class StructureDefaults { + + public final int village_dist; + public final int village_sep; + public final int mansionDist; + public final int mansionSep; + public final int strongholdDist; + public final int strongholdSep; + public final int shipWreckDist; + public final int shipWreckSep; + public final int oceanRuinDist; + public final int oceanRuinSep; + public final int oceanMonumentDist; + public final int oceanMonumentSep; + public final int otherStructureDist; + public final int otherStructureSep; + + public StructureDefaults() { + OverworldGenSettings defaults = new OverworldGenSettings(); + village_dist = (int) (defaults.getVillageDistance() * 1.5); + village_sep = (int) (defaults.getVillageSeparation() * 1.5); + + shipWreckDist = (int) (defaults.getShipwreckDistance() * 2.0); + shipWreckSep = (int) (defaults.getShipwreckSeparation() * 2.0); + + oceanRuinDist = (int) (defaults.getOceanRuinDistance() * 2.0); + oceanRuinSep = (int) (defaults.getOceanRuinSeparation() * 2.0); + + oceanMonumentDist = (int) (defaults.getOceanRuinDistance() * 1.5); + oceanMonumentSep = (int) (defaults.getOceanRuinSeparation() * 1.5); + + mansionDist = defaults.getMansionDistance(); + mansionSep = defaults.getMansionSeparation(); + + strongholdDist = defaults.getMansionSeparation(); + strongholdSep = defaults.getMansionSeparation(); + + otherStructureDist = defaults.getBiomeFeatureDistance(); + otherStructureSep = defaults.getBiomeFeatureSeparation(); + } + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java b/src/main/java/com/terraforged/mod/chunk/settings/TerraSettings.java similarity index 87% rename from TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java rename to src/main/java/com/terraforged/mod/chunk/settings/TerraSettings.java index e880506..0f04b62 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/TerraSettings.java +++ b/src/main/java/com/terraforged/mod/chunk/settings/TerraSettings.java @@ -23,17 +23,15 @@ * SOFTWARE. */ -package com.terraforged.mod.settings; +package com.terraforged.mod.chunk.settings; +import com.terraforged.core.serialization.annotation.Serializable; import com.terraforged.core.settings.Settings; -import com.terraforged.core.util.serialization.annotation.Serializable; @Serializable public class TerraSettings extends Settings { - public int version = 1; - - public FeatureSettings features = new FeatureSettings(); + public Miscellaneous miscellaneous = new Miscellaneous(); public StructureSettings structures = new StructureSettings(); diff --git a/src/main/java/com/terraforged/mod/chunk/settings/preset/Preset.java b/src/main/java/com/terraforged/mod/chunk/settings/preset/Preset.java new file mode 100644 index 0000000..db3f237 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/settings/preset/Preset.java @@ -0,0 +1,55 @@ +package com.terraforged.mod.chunk.settings.preset; + +import com.terraforged.mod.chunk.settings.TerraSettings; + +import java.io.File; + +public class Preset implements Comparable { + + private final boolean changed; + private final File file; + private final String id; + private final String name; + private final TerraSettings settings; + + Preset(String name, File file, TerraSettings settings) { + this.name = name; + this.file = file; + this.changed = false; + this.settings = settings; + this.id = name.toLowerCase(); + } + + public Preset(String name, TerraSettings settings) { + this.name = name; + this.changed = true; + this.settings = settings; + this.id = name.toLowerCase(); + this.file = new File(PresetManager.PRESETS_DIR, name + ".json"); + } + + public boolean changed() { + return changed; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public File getFile() { + return file; + } + + public TerraSettings getSettings() { + return settings; + } + + @Override + public int compareTo(Preset o) { + return id.compareTo(o.id); + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/settings/preset/PresetManager.java b/src/main/java/com/terraforged/mod/chunk/settings/preset/PresetManager.java new file mode 100644 index 0000000..482127f --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/settings/preset/PresetManager.java @@ -0,0 +1,143 @@ +package com.terraforged.mod.chunk.settings.preset; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.terraforged.mod.Log; +import com.terraforged.mod.chunk.settings.SettingsHelper; +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; + +public class PresetManager implements Iterable { + + public static final File PRESETS_DIR = new File(SettingsHelper.SETTINGS_DIR, "presets"); + + private final List presets; + private final List deleted = new ArrayList<>(); + + private PresetManager(List presets) { + this.presets = presets; + } + + public Optional get(String name) { + for (Preset preset : presets) { + if (preset.getName().equalsIgnoreCase(name)) { + return Optional.of(preset); + } + } + return Optional.empty(); + } + + public void add(Preset preset) { + // replace a preset by the same name + for (int i = 0; i < presets.size(); i++) { + if (presets.get(i).getId().equalsIgnoreCase(preset.getId())) { + presets.set(i, preset); + return; + } + } + + // otherwise add to end of list + presets.add(preset); + Collections.sort(presets); + } + + public void remove(String name) { + get(name).ifPresent(preset -> { + presets.remove(preset); + deleted.add(preset); + }); + } + + public void saveAll() { + if (!ensureDir()) { + Log.err("Unable to save presets to disk"); + return; + } + + for (Preset preset : deleted) { + if (preset.getFile().exists() && preset.getFile().delete()) { + Log.debug("Deleted preset: {}", preset.getName()); + } else { + Log.debug("Unable to delete file: {}", preset.getFile()); + } + } + + Log.info("Saving presets"); + Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + for (Preset preset : presets) { + if (!preset.changed()) { + continue; + } + + Log.debug("Saving preset: {}", preset.getName()); + CompoundNBT nbt = NBTHelper.serializeCompact(preset.getSettings()); + JsonElement json = NBTHelper.toJson(nbt); + try (Writer writer = new BufferedWriter(new FileWriter(preset.getFile()))) { + gson.toJson(json, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + public Iterator iterator() { + return presets.iterator(); + } + + private static boolean ensureDir() { + if (!PRESETS_DIR.exists() && !PRESETS_DIR.mkdirs()) { + Log.err("Unable to create presets directory: {}", PRESETS_DIR); + return false; + } + return true; + } + + public static PresetManager load() { + if (!ensureDir()) { + return new PresetManager(new ArrayList<>()); + } + + File[] files = PRESETS_DIR.listFiles(); + if (files == null || files.length == 0) { + return new PresetManager(new ArrayList<>()); + } + + List presets = new ArrayList<>(files.length); + for (File file : files) { + if (!file.getName().endsWith(".json")) { + continue; + } + + String name = file.getName().substring(0, file.getName().length() - 5); + try (Reader reader = new BufferedReader(new FileReader(file))) { + JsonElement data = new JsonParser().parse(reader); + CompoundNBT nbt = NBTHelper.fromJson(data); + TerraSettings settings = new TerraSettings(); + NBTHelper.deserialize(nbt, settings); + presets.add(new Preset(name, file, settings)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return new PresetManager(presets); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/Test.java b/src/main/java/com/terraforged/mod/chunk/test/Test.java similarity index 80% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/Test.java rename to src/main/java/com/terraforged/mod/chunk/test/Test.java index a6e716b..80b7061 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/Test.java +++ b/src/main/java/com/terraforged/mod/chunk/test/Test.java @@ -25,20 +25,24 @@ package com.terraforged.mod.chunk.test; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; +import com.terraforged.mod.biome.ModBiomes; +import com.terraforged.world.terrain.Terrain; +import com.terraforged.world.terrain.Terrains; import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.Biomes; public class Test { - public static boolean fixedBiome = true; + public static boolean fixedBiome = false; + + public static int getTerrainVariant() { + return 0; + } public static Terrain getTerrainType(Terrains terrains) { - return terrains.mountains; + return terrains.plains; } public static Biome getBiome() { - return Biomes.PLAINS; + return ModBiomes.ERODED_PINNACLE; } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/TestBiomeProvider.java b/src/main/java/com/terraforged/mod/chunk/test/TestBiomeProvider.java similarity index 86% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/TestBiomeProvider.java rename to src/main/java/com/terraforged/mod/chunk/test/TestBiomeProvider.java index 728d0e9..22decc3 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/test/TestBiomeProvider.java +++ b/src/main/java/com/terraforged/mod/chunk/test/TestBiomeProvider.java @@ -25,20 +25,19 @@ package com.terraforged.mod.chunk.test; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.mod.biome.provider.BiomeProvider; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.cell.Cell; import net.minecraft.world.biome.Biome; -public class TestBiomeProvider extends BiomeProvider { +public class TestBiomeProvider extends TerraBiomeProvider { public TestBiomeProvider(TerraContext chunkContext) { super(chunkContext); } @Override - public Biome getBiome(Cell cell, int x, int z) { + public Biome getBiome(Cell cell, int x, int z) { return Test.getBiome(); } } diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/MappedList.java b/src/main/java/com/terraforged/mod/chunk/test/TestChunkGenerator.java similarity index 62% rename from TerraForgedCore/src/main/java/com/terraforged/core/util/grid/MappedList.java rename to src/main/java/com/terraforged/mod/chunk/test/TestChunkGenerator.java index 1548782..7300800 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/util/grid/MappedList.java +++ b/src/main/java/com/terraforged/mod/chunk/test/TestChunkGenerator.java @@ -1,5 +1,5 @@ /* - * + * * MIT License * * Copyright (c) 2020 TerraForged @@ -23,28 +23,24 @@ * SOFTWARE. */ -package com.terraforged.core.util.grid; +package com.terraforged.mod.chunk.test; -import java.util.List; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.TerraContext; +import net.minecraft.world.gen.GenerationSettings; -public class MappedList extends FixedList { +public class TestChunkGenerator extends TerraChunkGenerator { - private final float min; - private final float range; + private final TerraBiomeProvider biomeProvider; - public MappedList(T[] elements, float min, float range) { - super(elements); - this.min = min; - this.range = range; + public TestChunkGenerator(TerraContext context, TerraBiomeProvider biomeProvider, GenerationSettings settings) { + super(new TestTerraContext(context), biomeProvider, settings); + this.biomeProvider = new TestBiomeProvider(context); } @Override - public int indexOf(float value) { - return super.indexOf((value - min) / range); - } - - @SuppressWarnings("unchecked") - public static MappedList of(List list, float min, float range) { - return new MappedList<>((T[]) list.toArray(), min, range); + public TerraBiomeProvider getBiomeProvider() { + return biomeProvider; } } diff --git a/src/main/java/com/terraforged/mod/chunk/test/TestHeightMap.java b/src/main/java/com/terraforged/mod/chunk/test/TestHeightMap.java new file mode 100644 index 0000000..868dad2 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/test/TestHeightMap.java @@ -0,0 +1,32 @@ +package com.terraforged.mod.chunk.test; + +import com.terraforged.core.cell.Cell; +import com.terraforged.core.cell.Populator; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.heightmap.Heightmap; +import com.terraforged.world.terrain.Terrains; + +public class TestHeightMap extends Heightmap { + + private final Terrains terrains; + + public TestHeightMap(GeneratorContext context) { + super(context); + terrains = context.terrain; + System.out.println("TESTETETEST"); + } + + @Override + public void applyBase(Cell cell, float x, float y) { + continentGenerator.apply(cell, x, y); + regionModule.apply(cell, x, y); + + Populator populator = getPopulator(Test.getTerrainType(terrains), Test.getTerrainVariant()); + if (populator == this) { + return; + } + + populator.apply(cell, x, y); + applyClimate(cell, x, y); + } +} diff --git a/src/main/java/com/terraforged/mod/chunk/test/TestTerraContext.java b/src/main/java/com/terraforged/mod/chunk/test/TestTerraContext.java new file mode 100644 index 0000000..4c20867 --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/test/TestTerraContext.java @@ -0,0 +1,17 @@ +package com.terraforged.mod.chunk.test; + +import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.WorldGeneratorFactory; + +public class TestTerraContext extends TerraContext { + + public TestTerraContext(TerraContext context) { + super(context); + } + + @Override + protected WorldGeneratorFactory createFactory(GeneratorContext context) { + return new WorldGeneratorFactory(context, new TestHeightMap(context)); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java b/src/main/java/com/terraforged/mod/chunk/util/FastChunk.java similarity index 82% rename from TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java rename to src/main/java/com/terraforged/mod/chunk/util/FastChunk.java index c166475..2d87139 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java +++ b/src/main/java/com/terraforged/mod/chunk/util/FastChunk.java @@ -1,9 +1,10 @@ -package com.terraforged.mod.chunk; +package com.terraforged.mod.chunk.util; import com.terraforged.api.chunk.ChunkDelegate; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.palette.PalettedContainer; import net.minecraft.world.biome.BiomeContainer; import net.minecraft.world.chunk.ChunkPrimer; import net.minecraft.world.chunk.ChunkSection; @@ -63,6 +64,31 @@ public class FastChunk implements ChunkDelegate { return Blocks.VOID_AIR.getDefaultState(); } + public void fill(BlockState state) { + int surfaceMinY = 255; + for (int dz = 0; dz < 16; dz++) { + for (int dx = 0; dx < 16; dx++) { + int y = primer.getTopBlockY(Heightmap.Type.OCEAN_FLOOR_WG, dx, dz); + surfaceMinY = Math.min(surfaceMinY, y); + } + } + + int topSection = (surfaceMinY >> 4); + for (int sectionIndex = 0; sectionIndex < topSection; sectionIndex++) { + ChunkSection section = primer.getSection(sectionIndex); + section.lock(); + PalettedContainer container = section.getData(); + for (int dy = 0; dy < 16; dy++) { + for (int dz = 0; dz < 16; dz++) { + for (int dx = 0; dx < 16; dx++) { + container.swap(dx, dy, dz, state); + } + } + } + section.unlock(); + } + } + public void setBiomes(BiomeContainer biomes) { primer.func_225548_a_(biomes); } diff --git a/src/main/java/com/terraforged/mod/chunk/util/TerraContainer.java b/src/main/java/com/terraforged/mod/chunk/util/TerraContainer.java new file mode 100644 index 0000000..e7b8b2a --- /dev/null +++ b/src/main/java/com/terraforged/mod/chunk/util/TerraContainer.java @@ -0,0 +1,108 @@ +package com.terraforged.mod.chunk.util; + +import com.terraforged.api.biome.BiomeVariant; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.core.util.PosIterator; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeContainer; +import net.minecraft.world.chunk.ChunkPrimer; +import net.minecraft.world.chunk.IChunk; + +public class TerraContainer extends BiomeContainer { + + private static final int BITS_WIDTH = (int) Math.round(Math.log(16.0D) / Math.log(2.0D)) - 2; + private static final int ZOOM_VERT = (int) Math.round(Math.log(256.0D) / Math.log(2.0D)) - 2; + public static final int BIOMES_3D_SIZE = 1 << BITS_WIDTH + BITS_WIDTH + ZOOM_VERT; + public static final int BIOMES_2D_SIZE = 16 * 16; + public static final int MASK_HORIZ = (1 << BITS_WIDTH) - 1; + public static final int MASK_VERT = (1 << ZOOM_VERT) - 1; + + private final Biome[] biomes; + private final Biome[] surface; + + public TerraContainer(Biome[] biomes, Biome[] surface) { + super(biomes); + this.biomes = biomes; + this.surface = surface; + } + + public Biome getBiome(int x, int z) { + x &= 15; + z &= 15; + return surface[z * 16 + x]; + } + + public Biome getFeatureBiome(ChunkReader chunkReader) { + PosIterator iterator = PosIterator.area(0, 0, 16, 16); + while (iterator.next()) { + Cell cell = chunkReader.getCell(iterator.x(), iterator.z()); + if (cell.biomeType.isExtreme()) { + return getBiome(iterator.x(), iterator.z()); + } + } + return getBiome(8, 8); + } + + public BiomeContainer bakeBiomes(boolean convertToVanilla) { + if (convertToVanilla) { + Biome[] biomeArray = new Biome[biomes.length]; + for (int i = 0; i < biomes.length; i++) { + Biome biome = biomes[i]; + if (biome instanceof BiomeVariant) { + biome = ((BiomeVariant) biome).getBase(); + } + biomeArray[i] = biome; + } + return new BiomeContainer(biomeArray); + } + return new BiomeContainer(biomes); + } + + public static TerraContainer getOrCreate(IChunk chunk, ChunkReader reader, TerraBiomeProvider biomeProvider) { + BiomeContainer biomes = chunk.getBiomes(); + if (biomes instanceof TerraContainer) { + return (TerraContainer) biomes; + } + + TerraContainer container = TerraContainer.create(reader, biomeProvider); + + // replace/set the primer's biomes + ((ChunkPrimer) chunk).func_225548_a_(container); + + return container; + } + + public static TerraContainer create(ChunkReader chunkReader, TerraBiomeProvider biomeProvider) { + Biome[] biomes2D = new Biome[BIOMES_2D_SIZE]; + Biome[] biomes3D = new Biome[BIOMES_3D_SIZE]; + PosIterator iterator = PosIterator.area(0, 0, 16, 16); + while (iterator.next()) { + int dx = iterator.x(); + int dz = iterator.z(); + int x = chunkReader.getBlockX() + dx; + int z = chunkReader.getBlockZ() + dz; + Biome biome = biomeProvider.getBiome(chunkReader.getCell(dx, dz), x, z); + biomes2D[indexOf(dx, dz)] = biome; + if ((dx & 3) == 0 && (dz & 3) == 0) { + for (int dy = 0; dy < 64; dy++) { + biomes3D[indexOf(dx >> 2, dy, dz >> 2)] = biome; + } + } + } + return new TerraContainer(biomes3D, biomes2D); + } + + private static int indexOf(int x, int z) { + return (z << 4) + x; + } + + public static int indexOf(int x, int y, int z) { + x &= MASK_HORIZ; + y = MathHelper.clamp(y, 0, MASK_VERT); + z &= MASK_HORIZ; + return y << BITS_WIDTH + BITS_WIDTH | z << BITS_WIDTH | x; + } +} \ No newline at end of file diff --git a/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java b/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java new file mode 100644 index 0000000..6bda3fa --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/GuiKeys.java @@ -0,0 +1,34 @@ +package com.terraforged.mod.client.gui; + +import com.terraforged.mod.util.TranslationKey; + +public class GuiKeys { + + public static final TranslationKey DONE = TranslationKey.gui("general.done", "Done"); + public static final TranslationKey CANCEL = TranslationKey.gui("general.cancel", "Cancel"); + + public static final TranslationKey PREVIEW_SEED = TranslationKey.gui("preview.seed", "New Seed"); + public static final TranslationKey PREVIEW_AREA = TranslationKey.gui("preview.area", "Area: "); + public static final TranslationKey PREVIEW_TERRAIN = TranslationKey.gui("preview.terrain", "Terrain: "); + public static final TranslationKey PREVIEW_BIOME = TranslationKey.gui("preview.biome", "Biome: "); + + public static final TranslationKey PRESETS = TranslationKey.gui("presets.title", "Presets & Defaults"); + public static final TranslationKey WORLD_SETTINGS = TranslationKey.gui("world.title", "World Settings"); + public static final TranslationKey CLIMATE_SETTINGS = TranslationKey.gui("climate.title", "Climate Settings"); + public static final TranslationKey TERRAIN_SETTINGS = TranslationKey.gui("terrain.title", "Terrain Settings"); + public static final TranslationKey RIVER_SETTINGS = TranslationKey.gui("river.title", "River Settings"); + public static final TranslationKey FILTER_SETTINGS = TranslationKey.gui("filters.title", "Filter Settings"); + public static final TranslationKey STRUCTURE_SETTINGS = TranslationKey.gui("structures.title", "Structure Settings"); + public static final TranslationKey MISC_SETTINGS = TranslationKey.gui("miscellaneous.title", "Miscellaneous Settings"); + + public static final TranslationKey PRESET_CREATE = TranslationKey.gui("preset.create", "Create"); + public static final TranslationKey PRESET_LOAD = TranslationKey.gui("preset.load", "Load"); + public static final TranslationKey PRESET_SAVE = TranslationKey.gui("preset.save", "Save"); + public static final TranslationKey PRESET_RESET = TranslationKey.gui("preset.reset", "Reset"); + public static final TranslationKey PRESET_DEFAULT = TranslationKey.gui("preset.default", "Make Default"); + public static final TranslationKey PRESET_DELETE = TranslationKey.gui("preset.delete", "Delete"); + + public static void init() { + + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/Instance.java b/src/main/java/com/terraforged/mod/client/gui/Instance.java new file mode 100644 index 0000000..5744a51 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/Instance.java @@ -0,0 +1,20 @@ +package com.terraforged.mod.client.gui; + +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; + +public class Instance { + + public TerraSettings settings = new TerraSettings(); + public CompoundNBT settingsData = new CompoundNBT(); + + public Instance(TerraSettings settings) { + sync(settings); + } + + public void sync(TerraSettings settings) { + this.settings = settings; + this.settingsData = NBTHelper.serialize(settings); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/OverlayRenderer.java b/src/main/java/com/terraforged/mod/client/gui/OverlayRenderer.java similarity index 96% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/OverlayRenderer.java rename to src/main/java/com/terraforged/mod/client/gui/OverlayRenderer.java index 2cc9fde..2390166 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/OverlayRenderer.java +++ b/src/main/java/com/terraforged/mod/client/gui/OverlayRenderer.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.gui; +package com.terraforged.mod.client.gui; import net.minecraft.client.gui.screen.Screen; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/OverlayScreen.java b/src/main/java/com/terraforged/mod/client/gui/OverlayScreen.java similarity index 95% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/OverlayScreen.java rename to src/main/java/com/terraforged/mod/client/gui/OverlayScreen.java index 289e701..d3ab784 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/OverlayScreen.java +++ b/src/main/java/com/terraforged/mod/client/gui/OverlayScreen.java @@ -23,10 +23,10 @@ * SOFTWARE. */ -package com.terraforged.mod.gui; +package com.terraforged.mod.client.gui; -import com.terraforged.mod.gui.element.CheckBox; -import com.terraforged.mod.gui.element.Element; +import com.terraforged.mod.client.gui.element.CheckBox; +import com.terraforged.mod.client.gui.element.Element; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.Widget; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/ScrollPane.java b/src/main/java/com/terraforged/mod/client/gui/ScrollPane.java similarity index 83% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/ScrollPane.java rename to src/main/java/com/terraforged/mod/client/gui/ScrollPane.java index dbbc9d3..081ef0b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/ScrollPane.java +++ b/src/main/java/com/terraforged/mod/client/gui/ScrollPane.java @@ -23,18 +23,20 @@ * SOFTWARE. */ -package com.terraforged.mod.gui; +package com.terraforged.mod.client.gui; -import com.terraforged.mod.gui.element.Element; -import com.terraforged.mod.gui.preview.Preview; +import com.terraforged.mod.client.gui.element.Element; +import com.terraforged.mod.client.gui.preview.Preview; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.list.AbstractOptionList; +import javax.annotation.Nullable; import java.util.Collections; import java.util.List; +import java.util.Objects; public class ScrollPane extends AbstractOptionList implements OverlayRenderer { @@ -42,6 +44,7 @@ public class ScrollPane extends AbstractOptionList implements public ScrollPane(int slotHeightIn) { super(Minecraft.getInstance(), 0, 0, 0, 0, slotHeightIn); + setRenderSelection(false); } public void addButton(Widget button) { @@ -82,6 +85,11 @@ public class ScrollPane extends AbstractOptionList implements return hovered && super.mouseScrolled(x, y, direction); } + @Override + protected boolean isSelectedItem(int index) { + return renderSelection && Objects.equals(getSelected(), children().get(index)); + } + public class Entry extends AbstractOptionList.Entry { public final Widget option; @@ -90,6 +98,12 @@ public class ScrollPane extends AbstractOptionList implements this.option = option; } + @Nullable + @Override + public IGuiEventListener getFocused() { + return option; + } + @Override public List children() { return Collections.singletonList(option); @@ -97,26 +111,21 @@ public class ScrollPane extends AbstractOptionList implements @Override public boolean mouseClicked(double x, double y, int button) { +// super.mouseClicked(x, y, button); + if (isMouseOver(x, y)) { + setSelected(this); + } return option.mouseClicked(x, y, button); } @Override public boolean mouseReleased(double x, double y, int button) { +// super.mouseReleased(x, y, button); return option.mouseReleased(x, y, button); } @Override - public boolean keyPressed(int i, int j, int k) { - return option.keyPressed(i, j, k); - } - - @Override - public boolean charTyped(char c, int code) { - return option.charTyped(c, code); - } - - @Override - public void render(int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean wut, float partialTicks) { + public void render(int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean hovered, float partialTicks) { int optionWidth = Math.min(396, width); int padding = (width - optionWidth) / 2; option.x = left + padding; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java b/src/main/java/com/terraforged/mod/client/gui/SettingsScreen.java similarity index 67% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java rename to src/main/java/com/terraforged/mod/client/gui/SettingsScreen.java index cae2e4b..251ecd6 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java +++ b/src/main/java/com/terraforged/mod/client/gui/SettingsScreen.java @@ -23,23 +23,17 @@ * SOFTWARE. */ -package com.terraforged.mod.gui; +package com.terraforged.mod.client.gui; -import com.terraforged.mod.gui.element.TerraButton; -import com.terraforged.mod.gui.element.TerraLabel; -import com.terraforged.mod.gui.page.ClimatePage; -import com.terraforged.mod.gui.page.DimensionsPage; -import com.terraforged.mod.gui.page.FeaturePage; -import com.terraforged.mod.gui.page.FilterPage; -import com.terraforged.mod.gui.page.GeneratorPage; -import com.terraforged.mod.gui.page.Page; -import com.terraforged.mod.gui.page.RiverPage; -import com.terraforged.mod.gui.page.StructurePage; -import com.terraforged.mod.gui.page.TerrainPage; -import com.terraforged.mod.gui.preview.PreviewPage; -import com.terraforged.mod.settings.SettingsHelper; -import com.terraforged.mod.settings.TerraSettings; -import com.terraforged.mod.util.nbt.NBTHelper; +import com.terraforged.mod.chunk.settings.SettingsHelper; +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.client.gui.element.TerraLabel; +import com.terraforged.mod.client.gui.page.Page; +import com.terraforged.mod.client.gui.page.PresetsPage; +import com.terraforged.mod.client.gui.page.SimplePage; +import com.terraforged.mod.client.gui.page.SimplePreviewPage; +import com.terraforged.mod.client.gui.page.WorldPage; +import com.terraforged.mod.client.gui.preview.PreviewPage; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.gui.screen.CreateWorldScreen; @@ -55,29 +49,35 @@ public class SettingsScreen extends OverlayScreen { private final Page[] pages; private final PreviewPage preview; private final CreateWorldScreen parent; - private final TerraSettings settings = new TerraSettings(); + private final Instance instance; private int pageIndex = 0; - private boolean hasChanged = false; public SettingsScreen(CreateWorldScreen parent) { + TerraSettings settings = new TerraSettings(); SettingsHelper.applyDefaults(parent.chunkProviderSettingsJson, settings); + this.parent = parent; - this.preview = new PreviewPage(settings, getSeed(parent)); + this.instance = new Instance(settings); + this.preview = new PreviewPage(instance.settings, getSeed(parent)); this.pages = new Page[]{ - new GeneratorPage(settings, preview), - new ClimatePage(settings, preview), - new TerrainPage(settings, preview), - new RiverPage(settings, preview), - new FilterPage(settings, preview), - new FeaturePage(settings), - new StructurePage(settings), - new DimensionsPage(settings), + new PresetsPage(instance, preview, preview.getPreviewWidget()), + new WorldPage(instance, preview), + new SimplePreviewPage(GuiKeys.CLIMATE_SETTINGS, "climate", preview, instance, s -> s.climate), + new SimplePreviewPage(GuiKeys.TERRAIN_SETTINGS, "terrain", preview, instance, s -> s.terrain), + new SimplePreviewPage(GuiKeys.RIVER_SETTINGS, "rivers", preview, instance, s -> s.rivers), + new SimplePreviewPage(GuiKeys.FILTER_SETTINGS, "filters", preview, instance, s -> s.filters), + new SimplePage(GuiKeys.STRUCTURE_SETTINGS, "structures", instance, s -> s.structures), + new SimplePage(GuiKeys.MISC_SETTINGS, "miscellaneous", instance, s -> s.miscellaneous) }; } + private boolean isPresetsPage() { + return pages[pageIndex] instanceof PresetsPage; + } + @Override - protected void init() { + public void init() { super.buttons.clear(); super.children.clear(); @@ -89,7 +89,6 @@ public class SettingsScreen extends OverlayScreen { if (pageIndex < pages.length) { Page page = pages[pageIndex]; - page.callback(() -> this.hasChanged = true); TerraLabel title = new TerraLabel(page.getTitle()); title.visible = true; title.x = 16; @@ -105,20 +104,18 @@ public class SettingsScreen extends OverlayScreen { } // -52 - addButton(new Button(buttonsCenter - buttonWidth - buttonPad, buttonsRow, buttonWidth, buttonHeight, "Cancel" - , b -> onClose())); + addButton(new Button(buttonsCenter - buttonWidth - buttonPad, buttonsRow, buttonWidth, buttonHeight, GuiKeys.CANCEL.get(), b -> onClose())); // +2 - addButton(new Button(buttonsCenter + buttonPad, buttonsRow, buttonWidth, buttonHeight, "Done", b -> { + addButton(new Button(buttonsCenter + buttonPad, buttonsRow, buttonWidth, buttonHeight, GuiKeys.DONE.get(), b -> { for (Page page : pages) { page.save(); } - parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings); +// parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings); SettingsScreen.setSeed(parent, preview.getSeed()); onClose(); })); - // -106 addButton(new Button(buttonsCenter - (buttonWidth * 2 + (buttonPad * 3)), buttonsRow, buttonWidth, buttonHeight, "<<", NO_ACTION) { @Override @@ -155,44 +152,6 @@ public class SettingsScreen extends OverlayScreen { } }); - addButton(new TerraButton("Set Defaults", "Use the current settings as the defaults", "CTRL + click to clear them") { - - private boolean ctrl = false; - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - if (Screen.hasControlDown()) { - if (!ctrl) { - ctrl = true; - setMessage("Clear Defaults"); - } - super.active = true; - } else { - if (ctrl) { - ctrl = false; - setMessage("Set Defaults"); - } - super.active = hasChanged; - } - super.render(mouseX, mouseY, partialTicks); - } - - @Override - public void onClick(double mouseX, double mouseY) { - super.onClick(mouseX, mouseY); - if (Screen.hasControlDown()) { - SettingsHelper.clearDefaults(); - hasChanged = true; - } else { - for (Page page : pages) { - page.save(); - } - hasChanged = false; - SettingsHelper.exportDefaults(settings); - } - } - }.init(width - buttonWidth - 55, buttonsRow, 90, buttonHeight)); - super.init(); } @@ -200,7 +159,9 @@ public class SettingsScreen extends OverlayScreen { public void render(int mouseX, int mouseY, float partialTicks) { super.renderBackground(); pages[pageIndex].visit(pane -> pane.render(mouseX, mouseY, partialTicks)); - preview.visit(pane -> pane.render(mouseX, mouseY, partialTicks)); + if (pageIndex > 0) { + preview.visit(pane -> pane.render(mouseX, mouseY, partialTicks)); + } super.render(mouseX, mouseY, partialTicks); } @@ -208,13 +169,15 @@ public class SettingsScreen extends OverlayScreen { public void renderOverlays(Screen screen, int mouseX, int mouseY) { super.renderOverlays(screen, mouseX, mouseY); pages[pageIndex].visit(pane -> pane.renderOverlays(screen, mouseX, mouseY)); - preview.visit(pane -> pane.renderOverlays(screen, mouseX, mouseY)); + if (!isPresetsPage()) { + preview.visit(pane -> pane.renderOverlays(screen, mouseX, mouseY)); + } } @Override public boolean mouseClicked(double x, double y, int button) { boolean a = pages[pageIndex].action(pane -> pane.mouseClicked(x, y, button)); - boolean b = preview.action(pane -> pane.mouseClicked(x, y, button)); + boolean b = isPresetsPage() || preview.action(pane -> pane.mouseClicked(x, y, button));; boolean c = super.mouseClicked(x, y, button); return a || b || c; } @@ -222,7 +185,7 @@ public class SettingsScreen extends OverlayScreen { @Override public boolean mouseReleased(double x, double y, int button) { boolean a = pages[pageIndex].action(pane -> pane.mouseReleased(x, y, button)); - boolean b = preview.action(pane -> pane.mouseReleased(x, y, button)); + boolean b = isPresetsPage() || preview.action(pane -> pane.mouseReleased(x, y, button)); boolean c = super.mouseReleased(x, y, button); return a || b || c; } @@ -230,7 +193,7 @@ public class SettingsScreen extends OverlayScreen { @Override public boolean mouseDragged(double x, double y, int button, double dx, double dy) { boolean a = pages[pageIndex].action(pane -> pane.mouseDragged(x, y, button, dx, dy)); - boolean b = preview.action(pane -> pane.mouseDragged(x, y, button, dx, dy)); + boolean b = isPresetsPage() || preview.action(pane -> pane.mouseDragged(x, y, button, dx, dy)); boolean c = super.mouseDragged(x, y, button, dx, dy); return a || b || c; } @@ -238,7 +201,7 @@ public class SettingsScreen extends OverlayScreen { @Override public boolean mouseScrolled(double x, double y, double direction) { boolean a = pages[pageIndex].action(pane -> pane.mouseScrolled(x, y, direction)); - boolean b = preview.action(pane -> pane.mouseScrolled(x, y, direction)); + boolean b = isPresetsPage() || preview.action(pane -> pane.mouseScrolled(x, y, direction)); boolean c = super.mouseScrolled(x, y, direction); return a || b || c; } @@ -246,16 +209,17 @@ public class SettingsScreen extends OverlayScreen { @Override public boolean keyPressed(int i, int j, int k) { boolean a = pages[pageIndex].action(pane -> pane.keyPressed(i, j, k)); - boolean b = preview.action(pane -> pane.keyPressed(i, j, k)); + boolean b = isPresetsPage() || preview.action(pane -> pane.keyPressed(i, j, k)); boolean c = super.keyPressed(i, j, k); return a || b || c; } @Override - public boolean charTyped(char c, int code) { - boolean a = pages[pageIndex].action(pane -> pane.charTyped(c, code)); - boolean b = preview.action(pane -> pane.charTyped(c, code)); - return a || b || super.charTyped(c, code); + public boolean charTyped(char ch, int code) { + boolean a = pages[pageIndex].action(pane -> pane.charTyped(ch, code)); + boolean b = isPresetsPage() || preview.action(pane -> pane.charTyped(ch, code)); + boolean c = super.charTyped(ch, code); + return a || b || c; } @Override diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/CheckBox.java b/src/main/java/com/terraforged/mod/client/gui/element/CheckBox.java similarity index 97% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/CheckBox.java rename to src/main/java/com/terraforged/mod/client/gui/element/CheckBox.java index bf68624..190dafc 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/CheckBox.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/CheckBox.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; public class CheckBox extends TerraButton implements Element { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/Element.java b/src/main/java/com/terraforged/mod/client/gui/element/Element.java similarity index 66% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/Element.java rename to src/main/java/com/terraforged/mod/client/gui/element/Element.java index 2596595..3147bea 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/Element.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/Element.java @@ -23,17 +23,14 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; +import net.minecraft.client.resources.I18n; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.nbt.ListNBT; -import net.minecraftforge.common.util.Constants; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; public interface Element { @@ -47,13 +44,23 @@ public interface Element { return ID_COUNTER.getAndAdd(1); } - static List readTooltip(CompoundNBT value) { - if (value.contains("#comment")) { - ListNBT comment = value.getList("#comment", Constants.NBT.TAG_STRING); - return comment.stream() - .map(INBT::getString) - .collect(Collectors.toList()); - } - return Collections.emptyList(); + static String getDisplayName(String name, CompoundNBT value) { + return I18n.format(getDisplayKey(name, value)); + } + + static List getToolTip(String name, CompoundNBT value) { + return Collections.singletonList(I18n.format(getCommentKey(name, value))); + } + + static String getDisplayKey(String name, CompoundNBT value) { + return "display.terraforged." + getKey(name, value); + } + + static String getCommentKey(String name, CompoundNBT value) { + return "tooltip.terraforged." + getKey(name, value); + } + + static String getKey(String name, CompoundNBT value) { + return value.getCompound("#" + name).getString("key"); } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraButton.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraButton.java similarity index 98% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraButton.java rename to src/main/java/com/terraforged/mod/client/gui/element/TerraButton.java index 8628c84..498ee09 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraButton.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraButton.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; import net.minecraft.client.gui.widget.button.Button; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraLabel.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraLabel.java similarity index 85% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraLabel.java rename to src/main/java/com/terraforged/mod/client/gui/element/TerraLabel.java index 8acddf5..9fce37f 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraLabel.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraLabel.java @@ -23,24 +23,16 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; public class TerraLabel extends TerraButton { -// private final GuiLabel label; - public TerraLabel(String text) { super(text); visible = true; -// label = new GuiLabel( -// Collections.singletonList(text), -// 0xFFFFFF, -// Minecraft.getInstance().fontRenderer -// ); -// label.visible = true; } @Override diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java similarity index 70% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java rename to src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java index d0f3707..f09b6fa 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraSlider.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraSlider.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; import net.minecraft.nbt.CompoundNBT; import net.minecraftforge.fml.client.gui.widget.Slider; @@ -32,16 +32,18 @@ import java.util.List; public abstract class TerraSlider extends Slider implements Slider.ISlider, Element { + protected final String name; private final CompoundNBT value; private final List tooltip; private Runnable callback = () -> {}; - public TerraSlider(String prefix, CompoundNBT value, boolean decimal) { - super(0, 0, 100, 20, prefix, "", value.getFloat("#min"), value.getFloat("#max"), 0F, decimal, true, b -> {}); + public TerraSlider(String name, CompoundNBT value, boolean decimal) { + super(0, 0, 100, 20, Element.getDisplayName(name, value) + ": ", "", min(name, value), max(name, value), 0F, decimal, true, b -> {}); + this.name = name; this.value = value; this.parent = this; - this.tooltip = Element.readTooltip(value); + this.tooltip = Element.getToolTip(name, value); } public TerraSlider callback(Runnable callback) { @@ -71,24 +73,24 @@ public abstract class TerraSlider extends Slider implements Slider.ISlider, Elem public static class Int extends TerraSlider { - public Int(String prefix, CompoundNBT value) { - super(prefix, value, false); - setValue(value.getInt("value")); + public Int(String name, CompoundNBT value) { + super(name, value, false); + setValue(value.getInt(name)); updateSlider(); } @Override protected void onChange(Slider slider, CompoundNBT value) { - value.putInt("value", slider.getValueInt()); + value.putInt(name, slider.getValueInt()); } } public static class Float extends TerraSlider { - public Float(String prefix, CompoundNBT value) { - super(prefix, value, true); + public Float(String name, CompoundNBT value) { + super(name, value, true); precision = 3; - setValue(value.getFloat("value")); + setValue(value.getFloat(name)); updateSlider(); } @@ -96,7 +98,17 @@ public abstract class TerraSlider extends Slider implements Slider.ISlider, Elem protected void onChange(Slider slider, CompoundNBT value) { int i = (int) (slider.getValue() * 1000); float f = i / 1000F; - value.putFloat("value", f); + value.putFloat(name, f); } } + + private static float min(String name, CompoundNBT value) { + CompoundNBT meta = value.getCompound("#" + name); + return meta.getFloat("min"); + } + + private static float max(String name, CompoundNBT value) { + CompoundNBT meta = value.getCompound("#" + name); + return meta.getFloat("max"); + } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraTextInput.java similarity index 60% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java rename to src/main/java/com/terraforged/mod/client/gui/element/TerraTextInput.java index 42c5d3e..ac4c403 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraTextInput.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraTextInput.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.TextFieldWidget; @@ -11,21 +11,45 @@ import java.util.function.Predicate; 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 -> {}; public TerraTextInput(String name, CompoundNBT value) { - super(Minecraft.getInstance().fontRenderer, 0, 0, 100, 20, name); + super(Minecraft.getInstance().fontRenderer, 0, 0, 100, 20, Element.getDisplayName(name, value) + ": "); + this.name = name; this.value = value; - this.tooltip = Element.readTooltip(value); - setText(value.getString("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 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 @@ -45,12 +69,17 @@ public class TerraTextInput extends TextFieldWidget implements Element, Consumer @Override public void accept(String text) { - value.put("value", StringNBT.valueOf(text)); - callback.accept(this); + value.put(name, StringNBT.valueOf(text)); + + stringValue = text; if (validator.test(text)) { + valid = true; setTextColor(14737632); } else { + valid = false; setTextColor(0xffff3f30); } + + callback.accept(this); } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraToggle.java b/src/main/java/com/terraforged/mod/client/gui/element/TerraToggle.java similarity index 82% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraToggle.java rename to src/main/java/com/terraforged/mod/client/gui/element/TerraToggle.java index 27946e9..36e5c55 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/element/TerraToggle.java +++ b/src/main/java/com/terraforged/mod/client/gui/element/TerraToggle.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.element; +package com.terraforged.mod.client.gui.element; import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundNBT; @@ -35,6 +35,7 @@ import java.util.List; public class TerraToggle extends TerraButton { private final String prefix; + private final String name; private final CompoundNBT value; private final ListNBT options; private final List tooltip; @@ -42,20 +43,22 @@ public class TerraToggle extends TerraButton { private int index; private Runnable callback = () -> {}; - public TerraToggle(String prefix, CompoundNBT value) { - super(value.getString("value")); + public TerraToggle(String name, CompoundNBT value) { + super(value.getString(name)); + this.name = name; this.value = value; - this.prefix = prefix; - this.tooltip = Element.readTooltip(value); - this.options = value.getList("#options", Constants.NBT.TAG_STRING); + this.prefix = Element.getDisplayName(name, value) + ": "; + this.tooltip = Element.getToolTip(name, value); + CompoundNBT meta = value.getCompound("#" + name); + this.options = meta.getList("options", Constants.NBT.TAG_STRING); for (int i = 0; i < options.size(); i++) { String s = options.getString(i); - if (s.equals(value.getString("value"))) { + if (s.equals(value.getString(name))) { index = i; break; } } - setMessage(prefix + value.getString("value")); + setMessage(prefix + value.getString(name)); } public TerraToggle callback(Runnable runnable) { @@ -88,7 +91,7 @@ public class TerraToggle extends TerraButton { index = options.size() - 1; } String option = options.getString(index); - value.putString("value", option); + value.putString(name, option); setMessage(prefix + option); callback.run(); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/BasePage.java b/src/main/java/com/terraforged/mod/client/gui/page/BasePage.java similarity index 97% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/BasePage.java rename to src/main/java/com/terraforged/mod/client/gui/page/BasePage.java index f4b2b9b..5f61d5e 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/BasePage.java +++ b/src/main/java/com/terraforged/mod/client/gui/page/BasePage.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.page; +package com.terraforged.mod.client.gui.page; public abstract class BasePage extends Page { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java b/src/main/java/com/terraforged/mod/client/gui/page/Page.java similarity index 83% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java rename to src/main/java/com/terraforged/mod/client/gui/page/Page.java index 824a562..91397f5 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/Page.java +++ b/src/main/java/com/terraforged/mod/client/gui/page/Page.java @@ -23,15 +23,16 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.page; +package com.terraforged.mod.client.gui.page; -import com.terraforged.mod.gui.OverlayRenderer; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.ScrollPane; -import com.terraforged.mod.gui.element.TerraLabel; -import com.terraforged.mod.gui.element.TerraSlider; -import com.terraforged.mod.gui.element.TerraTextInput; -import com.terraforged.mod.gui.element.TerraToggle; +import com.terraforged.mod.client.gui.OverlayRenderer; +import com.terraforged.mod.client.gui.OverlayScreen; +import com.terraforged.mod.client.gui.ScrollPane; +import com.terraforged.mod.client.gui.element.Element; +import com.terraforged.mod.client.gui.element.TerraLabel; +import com.terraforged.mod.client.gui.element.TerraSlider; +import com.terraforged.mod.client.gui.element.TerraTextInput; +import com.terraforged.mod.client.gui.element.TerraToggle; import com.terraforged.mod.util.nbt.NBTHelper; import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.gui.screen.Screen; @@ -135,9 +136,8 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { public void addElements(int x, int y, Column column, CompoundNBT settings, boolean deep, Consumer consumer, Runnable callback) { AtomicInteger top = new AtomicInteger(y); - NBTHelper.stream(settings).forEach(value -> { - String name = value.getString("#display"); - Widget button = createButton(name, value, callback); + NBTHelper.streamkeys(settings).forEach(name -> { + Widget button = createButton(name, settings, callback); if (button != null) { button.setWidth(column.width); button.setHeight(SLIDER_HEIGHT); @@ -146,11 +146,11 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { consumer.accept(button); onAddWidget(button); } else if (deep) { - INBT child = value.get("value"); + INBT child = settings.get(name); if (child == null || child.getId() != Constants.NBT.TAG_COMPOUND) { return; } - TerraLabel label = new TerraLabel(name); + TerraLabel label = new TerraLabel(Element.getDisplayName(name, settings)); label.x = x; label.y = top.getAndAdd(SLIDER_HEIGHT + SLIDER_PAD); consumer.accept(label); @@ -160,18 +160,18 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { } public Widget createButton(String name, CompoundNBT value, Runnable callback) { - INBT tag = value.get("value"); + INBT tag = value.get(name); if (tag == null) { return null; } byte type = tag.getId(); if (type == Constants.NBT.TAG_INT) { - return new TerraSlider.Int(name + ": ", value).callback(callback); + return new TerraSlider.Int(name, value).callback(callback); } else if (type == Constants.NBT.TAG_FLOAT) { - return new TerraSlider.Float(name + ": ", value).callback(callback); - } else if (type == Constants.NBT.TAG_STRING && value.contains("#options")) { - return new TerraToggle(name + ": ", value).callback(callback); + return new TerraSlider.Float(name, value).callback(callback); + } else if (type == Constants.NBT.TAG_STRING && hasOptions(name, value)) { + return new TerraToggle(name, value).callback(callback); } else if (type == Constants.NBT.TAG_STRING) { return new TerraTextInput(name, value); } else { @@ -205,4 +205,8 @@ public abstract class Page implements IGuiEventListener, OverlayRenderer { this.scrollPane.setLeftPos(this.left); } } + + private static boolean hasOptions(String name, CompoundNBT value) { + return value.getCompound("#" + name).contains("options"); + } } diff --git a/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java b/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java new file mode 100644 index 0000000..f39a249 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/page/PresetsPage.java @@ -0,0 +1,251 @@ +package com.terraforged.mod.client.gui.page; + +import com.terraforged.mod.chunk.settings.SettingsHelper; +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.chunk.settings.preset.Preset; +import com.terraforged.mod.chunk.settings.preset.PresetManager; +import com.terraforged.mod.client.gui.GuiKeys; +import com.terraforged.mod.client.gui.Instance; +import com.terraforged.mod.client.gui.OverlayScreen; +import com.terraforged.mod.client.gui.ScrollPane; +import com.terraforged.mod.client.gui.element.TerraButton; +import com.terraforged.mod.client.gui.element.TerraLabel; +import com.terraforged.mod.client.gui.element.TerraTextInput; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.client.gui.widget.Widget; +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 Widget previewWidget; + private final TerraTextInput nameInput; + private final PresetManager manager = PresetManager.load(); + + 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); + } + + @Override + public String getTitle() { + return GuiKeys.PRESETS.get(); + } + + @Override + public void close() { + manager.saveAll(); + } + + @Override + public void save() { + + } + + protected void update() { + preview.apply(settings -> NBTHelper.deserialize(instance.settingsData, settings)); + } + + @Override + public void init(OverlayScreen parent) { + rebuildPresetList(); + + Column right = getColumn(1); + right.scrollPane.addButton(nameInput); + + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_CREATE.get()) { + + @Override + public void render(int x, int z, float ticks) { + // only render as active if the text field is not empty + super.active = nameInput.isValid(); + super.render(x, z, ticks); + } + + @Override + public void onClick(double x, double y) { + super.onClick(x, y); + // create new preset with default settings + Preset preset = new Preset(nameInput.getValue(), new TerraSettings()); + + // register with the manager & reset the text field + manager.add(preset); + nameInput.setText(""); + + // select newly created preset & load + setSelected(preset); + load(preset); + + // update the ui + rebuildPresetList(); + } + }); + + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_LOAD.get()) { + + @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 -> load(preset)); + } + }); + + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_SAVE.get()) { + + @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 a copy of the settings + TerraSettings settings = new TerraSettings(); + NBTHelper.deserialize(instance.settingsData, settings); + + // replace the current preset with the updated version + manager.add(new Preset(preset.getName(), settings)); + + // update the ui + rebuildPresetList(); + }); + } + }); + + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_RESET.get()) { + + @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(GuiKeys.PRESET_DEFAULT.get()) { + + @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 -> { + TerraSettings settings = preset.getSettings(); + + SettingsHelper.exportDefaults(settings); + }); + } + }); + + right.scrollPane.addButton(new TerraButton(GuiKeys.PRESET_DELETE.get()) { + + @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 -> { + // remove & update the ui + manager.remove(preset.getName()); + rebuildPresetList(); + }); + } + }); + + 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() { + return getColumn(0).scrollPane.getSelected() != null; + } + + private void load(Preset preset) { + instance.sync(preset.getSettings()); + + 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 getSelected() { + ScrollPane.Entry entry = getColumn(0).scrollPane.getSelected(); + if (entry == null) { + return Optional.empty(); + } + return manager.get(entry.option.getMessage()); + } + + private void rebuildPresetList() { + Column left = getColumn(0); + left.scrollPane.setRenderSelection(true); + left.scrollPane.children().clear(); + + for (Preset preset : manager) { + left.scrollPane.addButton(new TerraLabel(preset.getName())); + } + } + + private static TerraButton createSpacer() { + return new TerraButton("") { + @Override + public void render(int x, int y, float tick) { } + }; + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/page/SimplePage.java b/src/main/java/com/terraforged/mod/client/gui/page/SimplePage.java new file mode 100644 index 0000000..d5e41ad --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/page/SimplePage.java @@ -0,0 +1,52 @@ +package com.terraforged.mod.client.gui.page; + +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.client.gui.Instance; +import com.terraforged.mod.client.gui.OverlayScreen; +import com.terraforged.mod.util.TranslationKey; +import net.minecraft.nbt.CompoundNBT; + +import java.util.function.Function; + +public class SimplePage extends BasePage { + + private final String title; + private final String sectionName; + protected final Instance instance; + protected final Function section; + + protected CompoundNBT sectionSettings = null; + + public SimplePage(TranslationKey title, String sectionName, Instance instance, Function section) { + this.title = title.get(); + this.section = section; + this.sectionName = sectionName; + this.instance = instance; + } + + @Override + public String getTitle() { + return title; + } + + @Override + public void save() { + + } + + @Override + public void init(OverlayScreen parent) { + sectionSettings = getSectionSettings(); + Column left = getColumn(0); + addElements(left.left, left.top, left, sectionSettings, true, left.scrollPane::addButton, this::update); + } + + @Override + protected void update() { + super.update(); + } + + private CompoundNBT getSectionSettings() { + return instance.settingsData.getCompound(sectionName); + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/page/SimplePreviewPage.java b/src/main/java/com/terraforged/mod/client/gui/page/SimplePreviewPage.java new file mode 100644 index 0000000..b1065b5 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/page/SimplePreviewPage.java @@ -0,0 +1,24 @@ +package com.terraforged.mod.client.gui.page; + +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.client.gui.Instance; +import com.terraforged.mod.util.TranslationKey; +import com.terraforged.mod.util.nbt.NBTHelper; + +import java.util.function.Function; + +public class SimplePreviewPage extends SimplePage { + + private final UpdatablePage preview; + + public SimplePreviewPage(TranslationKey title, String sectionName, UpdatablePage preview, Instance instance, Function section) { + super(title, sectionName, instance, section); + this.preview = preview; + } + + @Override + protected void update() { + super.update(); + preview.apply(settings -> NBTHelper.deserialize(sectionSettings, section.apply(settings))); + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/page/UpdatablePage.java b/src/main/java/com/terraforged/mod/client/gui/page/UpdatablePage.java new file mode 100644 index 0000000..158b0e1 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/page/UpdatablePage.java @@ -0,0 +1,23 @@ +package com.terraforged.mod.client.gui.page; + +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.client.gui.OverlayScreen; + +import java.util.function.Consumer; + +public class UpdatablePage extends BasePage { + + @Override + public void save() { + + } + + @Override + public void init(OverlayScreen parent) { + + } + + public void apply(Consumer consumer) { + + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java b/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java new file mode 100644 index 0000000..f996101 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/page/WorldPage.java @@ -0,0 +1,120 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.client.gui.page; + +import com.terraforged.mod.TerraWorld; +import com.terraforged.mod.client.gui.GuiKeys; +import com.terraforged.mod.client.gui.Instance; +import com.terraforged.mod.client.gui.OverlayScreen; +import com.terraforged.mod.client.gui.element.TerraTextInput; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.StringNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.WorldType; +import net.minecraftforge.registries.ForgeRegistries; + +public class WorldPage extends BasePage { + + private final UpdatablePage preview; + private final Instance instance; + + private CompoundNBT worldSettings = null; + private CompoundNBT dimSettings = null; + + public WorldPage(Instance instance, UpdatablePage preview) { + this.instance = instance; + this.preview = preview; + } + + @Override + public String getTitle() { + return GuiKeys.WORLD_SETTINGS.get(); + } + + @Override + public void save() { + + } + + @Override + public void init(OverlayScreen parent) { + // re-sync settings from the settings object to the data structure + worldSettings = getWorldSettings(); + dimSettings = getDimSettings(); + + Column left = getColumn(0); + addElements(left.left, left.top, left, worldSettings, true, left.scrollPane::addButton, this::update); + addElements(left.left, left.top, left, dimSettings, true, left.scrollPane::addButton, this::update); + } + + @Override + public void onAddWidget(Widget widget) { + if (widget instanceof TerraTextInput) { + TerraTextInput input = (TerraTextInput) widget; + input.setColorValidator(string -> ForgeRegistries.BLOCKS.containsKey(new ResourceLocation(string))); + } + } + + protected void update() { + super.update(); + preview.apply(settings -> { + NBTHelper.deserialize(worldSettings, settings.world); + NBTHelper.deserialize(dimSettings, settings.dimensions); + }); + } + + private CompoundNBT getWorldSettings() { + return instance.settingsData.getCompound("world"); + } + + private CompoundNBT getDimSettings() { + CompoundNBT dimSettings = instance.settingsData.getCompound("dimensions"); + + CompoundNBT generators = dimSettings.getCompound("dimensions").getCompound("value"); + for (String name : generators.keySet()) { + CompoundNBT setting = generators.getCompound(name); + setting.put("#options", getWorldTypes()); + } + + return dimSettings; + } + + private static ListNBT getWorldTypes() { + ListNBT options = new ListNBT(); + for (WorldType type : WorldType.WORLD_TYPES) { + if (type == null || (type.getId() >= 1 && type.getId() <= 6) || type.getId() == 8) { + continue; + } + if (!TerraWorld.isTerraType(type)) { + options.add(StringNBT.valueOf(type.getName())); + } + } + return options; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java b/src/main/java/com/terraforged/mod/client/gui/preview/Preview.java similarity index 76% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java rename to src/main/java/com/terraforged/mod/client/gui/preview/Preview.java index 226d03d..2af7133 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java +++ b/src/main/java/com/terraforged/mod/client/gui/preview/Preview.java @@ -23,23 +23,24 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.preview; +package com.terraforged.mod.client.gui.preview; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.terraforged.core.cell.Cell; -import com.terraforged.core.region.Region; -import com.terraforged.core.region.gen.RegionGenerator; +import com.terraforged.core.concurrent.cache.CacheEntry; +import com.terraforged.core.concurrent.thread.ThreadPools; import com.terraforged.core.settings.Settings; -import com.terraforged.core.util.concurrent.ThreadPool; -import com.terraforged.core.util.concurrent.cache.CacheEntry; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.WorldGeneratorFactory; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; +import com.terraforged.core.tile.Size; +import com.terraforged.core.tile.Tile; +import com.terraforged.core.tile.gen.TileGenerator; +import com.terraforged.mod.client.gui.GuiKeys; +import com.terraforged.n2d.util.NoiseUtil; import com.terraforged.mod.util.nbt.NBTHelper; -import me.dags.noise.util.NoiseUtil; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.continent.MutableVeci; +import com.terraforged.world.heightmap.Levels; +import com.terraforged.world.terrain.Terrains; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.gui.FontRenderer; @@ -54,7 +55,7 @@ import java.util.Random; public class Preview extends Button { private static final int FACTOR = 4; - public static final int WIDTH = 256; + public static final int WIDTH = Size.chunkToBlock(1 << FACTOR); private static final int SLICE_HEIGHT = 64; public static final int HEIGHT = WIDTH + SLICE_HEIGHT; private static final float[] LEGEND_SCALES = {1, 0.9F, 0.75F, 0.6F}; @@ -65,14 +66,14 @@ public class Preview extends Button { private final PreviewSettings previewSettings = new PreviewSettings(); private final DynamicTexture texture = new DynamicTexture(new NativeImage(WIDTH, HEIGHT, true)); - private final String[] values = {"", "", ""}; - private final String[] labels = {"Area: ", "Terrain: ", "Biome: "}; - private int seed; private long lastUpdate = 0L; private Settings settings = new Settings(); - private CacheEntry task = null; - private Region region = null; + private CacheEntry task = null; + private Tile tile = null; + + private String[] labels = {GuiKeys.PREVIEW_AREA.get(), GuiKeys.PREVIEW_TERRAIN.get(), GuiKeys.PREVIEW_BIOME.get()}; + private String[] values = {"", "", ""}; public Preview(int seed) { super(0, 0, 0, 0, "", b -> {}); @@ -122,7 +123,7 @@ public class Preview extends Button { lastUpdate = time; NBTHelper.deserialize(prevSettings, previewSettings); - settings.generator.seed = seed; + settings.world.seed = seed; task = generate(settings, prevSettings); } @@ -130,8 +131,8 @@ public class Preview extends Button { private void preRender() { if (task != null && task.isDone()) { try { - region = task.get(); - render(region); + tile = task.get(); + render(tile); } catch (Throwable t) { t.printStackTrace(); } finally { @@ -140,17 +141,17 @@ public class Preview extends Button { } } - private void render(Region region) { + private void render(Tile tile) { NativeImage image = texture.getTextureData(); if (image == null) { return; } - RenderMode renderer = previewSettings.mode; - Levels levels = new Levels(settings.generator); + RenderMode renderer = previewSettings.display; + Levels levels = new Levels(settings.world); int stroke = 2; - int width = region.getBlockSize().size; + int width = tile.getBlockSize().size; int zoom = (101 - previewSettings.zoom); int half = width / 2; @@ -159,11 +160,11 @@ public class Preview extends Button { float zoomUnit = 1F - (zoom / 100F); float zoomStrength = 0.5F; float unit = (1 - zoomStrength) + (zoomStrength * zoomUnit); - float heightModifier = settings.generator.world.worldHeight / 256F; - float waterLevelModifier = settings.generator.world.seaLevel / (float) settings.generator.world.worldHeight; + float heightModifier = settings.world.properties.worldHeight / 256F; + float waterLevelModifier = settings.world.properties.seaLevel / (float) settings.world.properties.worldHeight; float imageWaterLevelY = image.getHeight() - 1 - (waterLevelModifier * SLICE_HEIGHT * unit); - region.iterate((cell, x, z) -> { + tile.iterate((cell, x, z) -> { if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) { image.setPixelRGBA(x, z, Color.BLACK.getRGB()); } else { @@ -192,37 +193,43 @@ public class Preview extends Button { texture.updateDynamicTexture(); } - private CacheEntry generate(Settings settings, CompoundNBT prevSettings) { + private CacheEntry generate(Settings settings, CompoundNBT prevSettings) { NBTHelper.deserialize(prevSettings, previewSettings); - settings.generator.seed = seed; + settings.world.seed = seed; this.settings = settings; - GeneratorContext context = new GeneratorContext(Terrains.create(settings), settings); + GeneratorContext context = GeneratorContext.createNoCache(Terrains.create(settings), settings); - RegionGenerator renderer = RegionGenerator.builder() - .factory(new WorldGeneratorFactory(context)) - .pool(ThreadPool.getPool()) + MutableVeci center = new MutableVeci(); + context.factory.getHeightmap().getContinent().getNearestCenter(offsetX, offsetZ, center); + + TileGenerator renderer = TileGenerator.builder() + .pool(ThreadPools.getPool()) .size(FACTOR, 0) + .factory(context.factory) + .batch(6) .build(); - return renderer.queue(offsetX, offsetZ, 101 - previewSettings.zoom, false); + float zoom = 101 - previewSettings.zoom; + + return renderer.getAsync(center.x, center.z, zoom, false); } private void updateLegend(int mx ,int my) { - if (region != null) { + if (tile != null) { int left = this.x; int top = this.y; float size = this.width; int zoom = (101 - previewSettings.zoom); - int width = Math.max(1, region.getBlockSize().size * zoom); - int height = Math.max(1, region.getBlockSize().size * zoom); + int width = Math.max(1, tile.getBlockSize().size * zoom); + int height = Math.max(1, tile.getBlockSize().size * zoom); values[0] = width + "x" + height; if (mx >= left && mx <= left + size && my >= top && my <= top + size) { float fx = (mx - left) / size; float fz = (my - top) / size; - int ix = NoiseUtil.round(fx * region.getBlockSize().size); - int iz = NoiseUtil.round(fz * region.getBlockSize().size); - Cell cell = region.getCell(ix, iz); + int ix = NoiseUtil.round(fx * tile.getBlockSize().size); + int iz = NoiseUtil.round(fz * tile.getBlockSize().size); + Cell cell = tile.getCell(ix, iz); values[1] = getTerrainName(cell); values[2] = getBiomeName(cell); } @@ -269,16 +276,15 @@ public class Preview extends Button { RenderSystem.popMatrix(); } - private static String getTerrainName(Cell cell) { - String terrain = cell.tag.getName().toLowerCase(); - if (terrain.contains("river")) { + private static String getTerrainName(Cell cell) { + if (cell.terrain.isRiver()) { return "river"; } - return terrain; + return cell.terrain.getName().toLowerCase(); } - private static String getBiomeName(Cell cell) { - String terrain = cell.tag.getName().toLowerCase(); + private static String getBiomeName(Cell cell) { + String terrain = cell.terrain.getName().toLowerCase(); if (terrain.contains("ocean")) { if (cell.temperature < 0.3) { return "cold_ocean"; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java b/src/main/java/com/terraforged/mod/client/gui/preview/PreviewPage.java similarity index 79% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java rename to src/main/java/com/terraforged/mod/client/gui/preview/PreviewPage.java index 97bd7be..5847ece 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java +++ b/src/main/java/com/terraforged/mod/client/gui/preview/PreviewPage.java @@ -23,33 +23,39 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.preview; +package com.terraforged.mod.client.gui.preview; -import com.terraforged.core.settings.Settings; -import com.terraforged.mod.gui.OverlayScreen; -import com.terraforged.mod.gui.element.TerraButton; -import com.terraforged.mod.gui.page.BasePage; +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.client.gui.GuiKeys; +import com.terraforged.mod.client.gui.OverlayScreen; +import com.terraforged.mod.client.gui.element.TerraButton; +import com.terraforged.mod.client.gui.page.UpdatablePage; import com.terraforged.mod.util.nbt.NBTHelper; import net.minecraft.nbt.CompoundNBT; import java.util.function.Consumer; -public class PreviewPage extends BasePage { +public class PreviewPage extends UpdatablePage { private final Preview preview; - private final Settings settings; - private final CompoundNBT previewerSettings = NBTHelper.serialize(new PreviewSettings()); + private final TerraSettings settings; + private final CompoundNBT previewerSettings = NBTHelper.serialize("preview", new PreviewSettings()); - public PreviewPage(Settings settings, int seed) { + public PreviewPage(TerraSettings settings, int seed) { this.preview = new Preview(seed); this.settings = settings; } + public Preview getPreviewWidget() { + return preview; + } + public int getSeed() { return preview.getSeed(); } - public void apply(Consumer consumer) { + @Override + public void apply(Consumer consumer) { consumer.accept(settings); preview.update(settings, previewerSettings); } @@ -59,11 +65,6 @@ public class PreviewPage extends BasePage { preview.close(); } - @Override - public void save() { - - } - @Override public void init(OverlayScreen parent) { Column right = getColumn(1); @@ -73,7 +74,7 @@ public class PreviewPage extends BasePage { preview.setHeight(Preview.HEIGHT); addElements(right.left, right.top, right, previewerSettings, right.scrollPane::addButton, this::update); - right.scrollPane.addButton(new TerraButton("New Seed") { + right.scrollPane.addButton(new TerraButton(GuiKeys.PREVIEW_SEED.get()) { @Override public void onPress() { preview.regenerate(); @@ -92,6 +93,7 @@ public class PreviewPage extends BasePage { update(); } + @Override public void update() { preview.update(settings, previewerSettings); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewSettings.java b/src/main/java/com/terraforged/mod/client/gui/preview/PreviewSettings.java similarity index 74% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewSettings.java rename to src/main/java/com/terraforged/mod/client/gui/preview/PreviewSettings.java index 661c80c..e50f85d 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewSettings.java +++ b/src/main/java/com/terraforged/mod/client/gui/preview/PreviewSettings.java @@ -23,14 +23,19 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.preview; +package com.terraforged.mod.client.gui.preview; -import com.terraforged.core.util.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Comment; +import com.terraforged.core.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Serializable; +@Serializable public class PreviewSettings { @Range(min = 1, max = 100) + @Comment("Controls the zoom level of the preview map") public int zoom = 100 - 32; - public RenderMode mode = RenderMode.BIOME_TYPE; + @Comment("Controls the rendering mode on the preview map") + public RenderMode display = RenderMode.BIOME_TYPE; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java b/src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java similarity index 78% rename from TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java rename to src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java index 0442131..5117758 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/RenderMode.java +++ b/src/main/java/com/terraforged/mod/client/gui/preview/RenderMode.java @@ -23,19 +23,18 @@ * SOFTWARE. */ -package com.terraforged.mod.gui.preview; +package com.terraforged.mod.client.gui.preview; import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import me.dags.noise.util.NoiseUtil; +import com.terraforged.n2d.util.NoiseUtil; +import com.terraforged.world.heightmap.Levels; import java.awt.*; public enum RenderMode { BIOME_TYPE { @Override - public int getColor(Cell cell, float scale, float bias) { + public int getColor(Cell cell, float scale, float bias) { Color color = cell.biomeType.getColor(); float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); return rgba(hsb[0], hsb[1], (hsb[2] * scale) + bias); @@ -43,7 +42,7 @@ public enum RenderMode { }, TEMPERATURE { @Override - public int getColor(Cell cell, float scale, float bias) { + public int getColor(Cell cell, float scale, float bias) { float saturation = 0.7F; float brightness = 0.8F; return rgba(step(1 - cell.temperature, 8) * 0.65F, saturation, brightness); @@ -51,7 +50,7 @@ public enum RenderMode { }, MOISTURE { @Override - public int getColor(Cell cell, float scale, float bias) { + public int getColor(Cell cell, float scale, float bias) { float saturation = 0.7F; float brightness = 0.8F; return rgba(step(cell.moisture, 8) * 0.65F, saturation, brightness); @@ -59,15 +58,23 @@ public enum RenderMode { }, BIOME_SHAPE { @Override - public int getColor(Cell cell, float scale, float bias) { + public int getColor(Cell cell, float scale, float bias) { float saturation = 0.7F; float brightness = 0.8F; return rgba(cell.biome, saturation, brightness); } }, - TERRAIN_TYPE { + MACRO_NOISE_SHAPE { @Override - public int getColor(Cell cell, float scale, float bias) { + public int getColor(Cell cell, float scale, float bias) { + float saturation = 0.7F; + float brightness = 0.8F; + return rgba(cell.macroNoise, saturation, brightness); + } + }, + REGION_SHAPE { + @Override + public int getColor(Cell cell, float scale, float bias) { float saturation = 0.7F; float brightness = 0.8F; return rgba(cell.region, saturation, brightness); @@ -75,7 +82,7 @@ public enum RenderMode { }, ; - public int getColor(Cell cell, Levels levels) { + public int getColor(Cell cell, Levels levels) { float baseHeight = levels.water; if (cell.value < baseHeight) { return rgba(40, 140, 200); @@ -89,7 +96,7 @@ public enum RenderMode { return getColor(cell, scale, bias); } - public abstract int getColor(Cell cell, float scale, float bias); + public abstract int getColor(Cell cell, float scale, float bias); private static float step(float value, int steps) { return ((float) NoiseUtil.round(value * steps)) / steps; diff --git a/src/main/java/com/terraforged/mod/client/gui/preview2/MCRenderAPI.java b/src/main/java/com/terraforged/mod/client/gui/preview2/MCRenderAPI.java new file mode 100644 index 0000000..1f5d38d --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/preview2/MCRenderAPI.java @@ -0,0 +1,44 @@ +package com.terraforged.mod.client.gui.preview2; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.terraforged.core.render.RenderAPI; +import com.terraforged.core.render.RenderBuffer; +import net.minecraft.client.renderer.BufferBuilder; + +public class MCRenderAPI implements RenderAPI { + + @Override + public void pushMatrix() { + RenderSystem.pushMatrix(); + } + + @Override + public void popMatrix() { + RenderSystem.popMatrix(); + } + + @Override + public void translate(float x, float y, float z) { + RenderSystem.translatef(x, y, z); + } + + @Override + public void rotateX(float angle) { + + } + + @Override + public void rotateY(float angle) { + + } + + @Override + public void rotateZ(float angle) { + + } + + @Override + public RenderBuffer createBuffer() { + return new MCRenderBuffer(new BufferBuilder(4096)); + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/preview2/MCRenderBuffer.java b/src/main/java/com/terraforged/mod/client/gui/preview2/MCRenderBuffer.java new file mode 100644 index 0000000..9002fc1 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/preview2/MCRenderBuffer.java @@ -0,0 +1,66 @@ +package com.terraforged.mod.client.gui.preview2; + +import com.terraforged.core.render.RenderBuffer; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldVertexBufferUploader; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class MCRenderBuffer implements RenderBuffer { + + private final Object lock = new Object(); + private final BufferBuilder buffer; + + private BufferBuilder.State state = null; + + private float r, g, b; + + public MCRenderBuffer(BufferBuilder buffer) { + this.buffer = buffer; + } + + @Override + public void beginQuads() { + buffer.reset(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + } + + @Override + public void endQuads() { + synchronized (lock) { + state = buffer.getVertexState(); + buffer.finishDrawing(); + } + } + + @Override + public void vertex(float x, float y, float z) { + buffer.pos(x, y, z).color(r, g, b, 1).endVertex(); + } + + @Override + public void color(float hue, float saturation, float brightness) { + Color color = Color.getHSBColor(hue / 100F, saturation / 100F, brightness / 100F); + r = color.getRed() / 255F; + g = color.getGreen() / 255F; + b = color.getBlue() / 255F; + } + + @Override + public void draw() { + synchronized (lock) { + if (state != null) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder builder = tessellator.getBuffer(); + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + builder.setVertexState(state); + builder.sortVertexData(0, 0, 5000); + builder.finishDrawing(); + WorldVertexBufferUploader.draw(builder); + } + } + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/preview2/Preview.java b/src/main/java/com/terraforged/mod/client/gui/preview2/Preview.java new file mode 100644 index 0000000..22d10d5 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/preview2/Preview.java @@ -0,0 +1,119 @@ +package com.terraforged.mod.client.gui.preview2; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.core.concurrent.thread.ThreadPool; +import com.terraforged.core.concurrent.thread.ThreadPools; +import com.terraforged.core.render.RenderAPI; +import com.terraforged.core.render.RenderSettings; +import com.terraforged.core.render.RenderWorld; +import com.terraforged.core.tile.gen.TileGenerator; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.continent.MutableVeci; +import com.terraforged.world.continent.SpawnType; +import com.terraforged.world.terrain.Terrains; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.client.renderer.RenderHelper; + +public class Preview extends Widget { + + private static final float ZOOM_SCALE = 200F; + + private final ThreadPool threadPool = ThreadPools.getPool(); + + private final TerraSettings settings; + + private int seed; + private float zoom = 50; + private float offsetX = 0; + private float offsetZ = 0; + private float angle = 45F; + private RenderWorld world; + private PreviewSettings previewSettings = new PreviewSettings(); + + public Preview(TerraSettings settings, int seed) { + super(0, 0, "preview"); + this.seed = seed; + this.settings = settings; + this.world = createWorld(settings); + this.world.update(offsetX, offsetZ, zoom, true); + } + + public int getSeed() { + return seed; + } + + public void nextSeed() { + seed++; + world = createWorld(settings); + world.update(offsetX, offsetZ, zoom, true); + } + + @Override + public void render(int mx, int my, float ticks) { + try { + float scale = 0.75F; + + angle += 0.35F; + if (angle >= 360) { + angle = 0; + } + + RenderSystem.pushMatrix(); + RenderSystem.enableLighting(); + RenderHelper.enableStandardItemLighting(); + RenderHelper.setupGui3DDiffuseLighting(); + + RenderSystem.translatef(x, y, 0); + RenderSystem.translatef(width / 2F, width / 2F, 0); + RenderSystem.rotatef(70, 1, 0, 0); + RenderSystem.rotatef(angle, 0, 0, 1); + RenderSystem.scalef(scale, scale, scale); + + world.refresh(); + world.render(); + + RenderHelper.disableStandardItemLighting(); + RenderSystem.popMatrix(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public void update(PreviewSettings settings, TerraSettings genSettings) { + this.previewSettings = settings; + this.world = createWorld(genSettings); + world.update(offsetX, offsetZ, previewSettings.getZoom(ZOOM_SCALE), true); + } + + private RenderWorld createWorld(TerraSettings settings) { + int size = 4; + int regions = 1; + settings.world.seed = seed; + GeneratorContext context = GeneratorContext.createNoCache(Terrains.create(settings), settings); + + MutableVeci center = new MutableVeci(); + if (settings.world.properties.spawnType == SpawnType.CONTINENT_CENTER) { + context.factory.getHeightmap().getContinent().getNearestCenter(0, 0, center); + } + + offsetX = center.x; + offsetZ = center.z; + + TileGenerator generator = TileGenerator.builder() + .pool(threadPool) + .size(size, 0) + .factory(context.factory) + .batch(6) + .build(); + + RenderAPI renderAPI = new MCRenderAPI(); + RenderSettings renderSettings = new RenderSettings(context); + renderSettings.width = width; + renderSettings.height = height; + renderSettings.zoom = previewSettings.getZoom(ZOOM_SCALE); + renderSettings.renderMode = previewSettings.display; + + return new RenderWorld(generator, renderAPI, renderSettings, regions, size); + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/preview2/PreviewPage.java b/src/main/java/com/terraforged/mod/client/gui/preview2/PreviewPage.java new file mode 100644 index 0000000..106e756 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/preview2/PreviewPage.java @@ -0,0 +1,75 @@ +package com.terraforged.mod.client.gui.preview2; + +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.mod.client.gui.OverlayScreen; +import com.terraforged.mod.client.gui.element.TerraButton; +import com.terraforged.mod.client.gui.page.UpdatablePage; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; + +import java.util.function.Consumer; + +public class PreviewPage extends UpdatablePage { + + private final Preview preview; + private final CompoundNBT settings; + private final TerraSettings genSettings = new TerraSettings(); + + public PreviewPage(TerraSettings settings, int seed) { + this.preview = new Preview(settings, seed); + this.settings = NBTHelper.serialize("preview", new PreviewSettings()); + } + + public int getSeed() { + return preview.getSeed(); + } + + @Override + public void apply(Consumer consumer) { + consumer.accept(genSettings); + update(); + } + + @Override + public void init(OverlayScreen parent) { + Column right = getColumn(1); + preview.x = 0; + preview.y = 0; + preview.setWidth(com.terraforged.mod.client.gui.preview.Preview.WIDTH); + preview.setHeight(com.terraforged.mod.client.gui.preview.Preview.HEIGHT); + + addElements(right.left, right.top, right, settings, right.scrollPane::addButton, this::update); + + right.scrollPane.addButton(new TerraButton("New Seed") { + @Override + public void onPress() { + preview.nextSeed(); + update(); + } + }); + + right.scrollPane.addButton(preview); + + // 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); + } + +// update(); + } + + @Override + public void update() { + PreviewSettings settings = new PreviewSettings(); + NBTHelper.deserialize(this.settings, settings); + preview.update(settings, genSettings); + } + + private static TerraButton createSpacer() { + return new TerraButton("") { + @Override + public void render(int x, int y, float tick) { } + }; + } +} diff --git a/src/main/java/com/terraforged/mod/client/gui/preview2/PreviewSettings.java b/src/main/java/com/terraforged/mod/client/gui/preview2/PreviewSettings.java new file mode 100644 index 0000000..26d06f1 --- /dev/null +++ b/src/main/java/com/terraforged/mod/client/gui/preview2/PreviewSettings.java @@ -0,0 +1,19 @@ +package com.terraforged.mod.client.gui.preview2; + +import com.terraforged.core.render.RenderMode; +import com.terraforged.core.serialization.annotation.Range; +import com.terraforged.core.serialization.annotation.Serializable; + +@Serializable +public class PreviewSettings { + + @Range(min = 1, max = 100) + public float zoom = 90F; + + public RenderMode display = RenderMode.BIOME_TYPE; + + public float getZoom(float scale) { + float perc = (101F - zoom) / 100F; + return perc * scale; + } +} diff --git a/src/main/java/com/terraforged/mod/config/ConfigManager.java b/src/main/java/com/terraforged/mod/config/ConfigManager.java new file mode 100644 index 0000000..a398a01 --- /dev/null +++ b/src/main/java/com/terraforged/mod/config/ConfigManager.java @@ -0,0 +1,95 @@ +package com.terraforged.mod.config; + +import com.electronwill.nightconfig.core.CommentedConfig; +import com.electronwill.nightconfig.core.Config; +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.electronwill.nightconfig.toml.TomlFormat; +import com.terraforged.mod.Log; +import joptsimple.internal.Strings; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.function.Consumer; + +public class ConfigManager { + + private static final Path COMMON_DIR = Paths.get("config", "terraforged"); + + public static final ConfigRef BIOME_WEIGHTS = new ConfigRef(() -> create("biome_weights", cfg -> { + set( + cfg, + "terraforged:example_biome", + 10, + "Configure biome weights by entering their id and an integer value for their weight (default weight is 10)", + "This config will override the weights configured or provided by other mods for TerraForged worlds only." + ); + })); + + public static final ConfigRef PERFORMANCE = new ConfigRef(() -> create("performance", cfg -> { + set ( + cfg, + "thread_count", + PerfDefaults.THREAD_COUNT, + "Controls the total number of threads that will be used to generate heightmap tiles.", + "Allowing the generator to use more threads can help speed up generation but increases overall", + "load on your CPU which may adversely affect performance in other areas of the game engine." + ); + + set( + cfg, + "tile_size", + PerfDefaults.TILE_SIZE, + "Controls the size of heightmap tiles.", + "Smaller tiles are faster to generate but less memory efficient." + ); + + set( + cfg, + "batching", + PerfDefaults.BATCHING, + "Batching breaks heightmap tiles up into smaller pieces that can be generated concurrently.", + "This can help improve generation speed by utilizing more threads.", + "It is more effective when a higher thread count (+6) is available." + ); + + set( + cfg, + "batch_count", + PerfDefaults.BATCH_COUNT, + "Controls the number of pieces a heightmap tile is divided up into.", + "Higher batch counts may be able to utilize more of the available threads, improving performance." + ); + })); + + public static void init() { + Config.setInsertionOrderPreserved(true); + BIOME_WEIGHTS.get(); + PERFORMANCE.get(); + PerfDefaults.getAndPrintPerfSettings(); + } + + private static CommentedFileConfig create(String name, Consumer defaulter) { + Path path = COMMON_DIR.resolve(name + ".conf"); + if (!Files.exists(path)) { + Log.info("Creating default config: {}", name); + try { + Files.createDirectories(path.getParent()); + } catch (IOException e) { + e.printStackTrace(); + } + CommentedFileConfig config = CommentedFileConfig.of(path, TomlFormat.instance()); + defaulter.accept(config); + config.save(); + return config; + } else { + return CommentedFileConfig.of(path, TomlFormat.instance()); + } + } + + private static void set(CommentedConfig config, String path, T value, String... lines) { + config.setComment(path, Strings.join(lines, "\n")); + config.set(path, value); + } +} diff --git a/src/main/java/com/terraforged/mod/config/ConfigRef.java b/src/main/java/com/terraforged/mod/config/ConfigRef.java new file mode 100644 index 0000000..0a73815 --- /dev/null +++ b/src/main/java/com/terraforged/mod/config/ConfigRef.java @@ -0,0 +1,30 @@ +package com.terraforged.mod.config; + +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.terraforged.mod.Log; + +import java.util.function.Supplier; + +public class ConfigRef implements Supplier { + + private final Object lock = new Object(); + private final Supplier factory; + + private CommentedFileConfig ref; + + public ConfigRef(Supplier factory) { + this.factory = factory; + } + + @Override + public CommentedFileConfig get() { + synchronized (lock) { + if (ref != null) { + Log.info("Loading config: {}", ref.getFile().getName()); + ref.load(); + return ref; + } + return ref = factory.get(); + } + } +} diff --git a/src/main/java/com/terraforged/mod/config/PerfDefaults.java b/src/main/java/com/terraforged/mod/config/PerfDefaults.java new file mode 100644 index 0000000..3d7897c --- /dev/null +++ b/src/main/java/com/terraforged/mod/config/PerfDefaults.java @@ -0,0 +1,37 @@ +package com.terraforged.mod.config; + +import com.electronwill.nightconfig.core.CommentedConfig; +import com.terraforged.mod.Log; +import com.terraforged.core.concurrent.thread.ThreadPools; + +public class PerfDefaults { + + public static final boolean BATCHING = false; + public static final int TILE_SIZE = 3; + public static final int BATCH_COUNT = 6; + public static final int THREAD_COUNT = ThreadPools.defaultPoolSize(); + + public static final int MAX_TILE_SIZE = 8; + public static final int MAX_BATCH_COUNT = 20; + public static final int MAX_THREAD_COUNT = Runtime.getRuntime().availableProcessors(); + + private static boolean isUsingDefaultPerfSettings(CommentedConfig config) { + boolean yes = true; + yes &= config.getOrElse("batching", BATCHING); + yes &= config.getInt("thread_count") == THREAD_COUNT; + yes &= config.getInt("batch_count") == BATCH_COUNT; + yes &= config.getInt("tile_size") == TILE_SIZE; + return yes; + } + + public static CommentedConfig getAndPrintPerfSettings() { + CommentedConfig config = ConfigManager.PERFORMANCE.get(); + boolean defaults = isUsingDefaultPerfSettings(config); + Log.info("Performance Settings [default={}]", defaults); + Log.info(" - Thread Count: {}", config.getInt("thread_count")); + Log.info(" - Tile Size: {}", config.getInt("tile_size")); + Log.info(" - Batching: {}", config.getOrElse("batching", BATCHING)); + Log.info(" - Batch Count: {}", config.getInt("batch_count")); + return config; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/data/DataGen.java b/src/main/java/com/terraforged/mod/data/DataGen.java similarity index 96% rename from TerraForgedMod/src/main/java/com/terraforged/mod/data/DataGen.java rename to src/main/java/com/terraforged/mod/data/DataGen.java index 881b3f3..13a3df4 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/data/DataGen.java +++ b/src/main/java/com/terraforged/mod/data/DataGen.java @@ -55,7 +55,7 @@ public class DataGen { } protected static void write(JsonElement json, Writer writer) { - new GsonBuilder().setPrettyPrinting().create().toJson(json, writer); + new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(json, writer); } protected static String getJsonPath(String type, ResourceLocation location) { diff --git a/src/main/java/com/terraforged/mod/data/LangGenerator.java b/src/main/java/com/terraforged/mod/data/LangGenerator.java new file mode 100644 index 0000000..da76609 --- /dev/null +++ b/src/main/java/com/terraforged/mod/data/LangGenerator.java @@ -0,0 +1,102 @@ +package com.terraforged.mod.data; + +import com.terraforged.mod.chunk.settings.TerraSettings; +import com.terraforged.core.util.NameUtil; +import com.terraforged.mod.client.gui.GuiKeys; +import com.terraforged.mod.client.gui.preview2.PreviewSettings; +import com.terraforged.mod.util.TranslationKey; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.data.LanguageProvider; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.function.UnaryOperator; + +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) +public class LangGenerator { + + @SubscribeEvent + public static void gather(GatherDataEvent event) { + GuiKeys.init(); + + LanguageProvider langProvider = new LanguageProvider(event.getGenerator(), "terraforged", "en_us") { + @Override + protected void addTranslations() { + worlds(this); + biomes(this); + translationKeys(this); + settings(this); + } + }; + + event.getGenerator().addProvider(langProvider); + } + + private static void worlds(LanguageProvider provider) { + provider.add("generator.terraforged", "TerraForged"); + provider.add("generator.terratest", "TerraTest"); + } + + private static void biomes(LanguageProvider provider) { + for (Biome biome : ForgeRegistries.BIOMES) { + ResourceLocation name = biome.getRegistryName(); + if (name != null && name.getNamespace().equals("terraforged")) { + provider.add(biome, NameUtil.toDisplayName(name.getPath())); + } + } + } + + private static void translationKeys(LanguageProvider provider) { + TranslationKey.each(key -> provider.add(key.getKey(), key.getDefaultValue())); + } + + private static void settings(LanguageProvider provider) { + visit(NBTHelper.serialize(new DataGenSettings()), provider); + } + + private static void visit(CompoundNBT tag, LanguageProvider lang) { + tag.keySet().forEach(name -> { + if (name.startsWith("#")) { + return; + } + + INBT value = tag.get(name); + if (value instanceof CompoundNBT) { + visit((CompoundNBT) value, lang); + } + + CompoundNBT meta = tag.getCompound("#" + name); + if (meta.isEmpty()) { + return; + } + + add(meta, "key", "display", NameUtil::toDisplayNameKey, lang); + add(meta, "key", "comment", NameUtil::toTooltipKey, lang); + }); + } + + private static void add(CompoundNBT tag, String keyName, String valName, UnaryOperator keyFunc, LanguageProvider lang) { + String key = keyFunc.apply(tag.getString(keyName)); + if (key.isEmpty()) { + return; + } + + String value = tag.getString(valName); + if (value.isEmpty()) { + return; + } + + lang.add(key, value); + } + + public static class DataGenSettings extends TerraSettings { + + public PreviewSettings preview = new PreviewSettings(); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenBiomes.java b/src/main/java/com/terraforged/mod/data/WorldGenBiomes.java similarity index 65% rename from TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenBiomes.java rename to src/main/java/com/terraforged/mod/data/WorldGenBiomes.java index 0f99d3a..ded748b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenBiomes.java +++ b/src/main/java/com/terraforged/mod/data/WorldGenBiomes.java @@ -26,56 +26,28 @@ package com.terraforged.mod.data; import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.terraforged.core.world.biome.BiomeType; import com.terraforged.mod.biome.map.BiomeMap; import com.terraforged.mod.biome.provider.BiomeHelper; +import com.terraforged.world.biome.BiomeType; import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.Biome; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; -import java.util.Set; public class WorldGenBiomes extends DataGen { public static void genBiomeMap(File dataDir) { - BiomeMap map = BiomeHelper.getDefaultBiomeMap(); - for (BiomeType type : BiomeType.values()) { - genBiomes(dataDir, type, map); - } - - try (Writer writer = new BufferedWriter(new FileWriter(new File("biome_map.json")))) { + BiomeMap map = BiomeHelper.createBiomeMap(); + try (Writer writer = new BufferedWriter(new FileWriter(new File(dataDir, "biome_map.json")))) { new GsonBuilder().setPrettyPrinting().create().toJson(map.toJson(), writer); } catch (IOException e) { e.printStackTrace(); } } - private static void genBiomes(File dir, BiomeType type, BiomeMap map) { - String path = getJsonPath("tags/biomes", getName(type)); - - write(new File(dir, path), writer -> { - Set biomes = map.getBiomes(type); - JsonObject root = new JsonObject(); - JsonArray values = new JsonArray(); - - root.addProperty("replaceable", false); - root.add("values", values); - - biomes.stream() - .map(b -> b.getRegistryName() + "") - .sorted() - .forEach(values::add); - - write(root, writer); - }); - } - private static ResourceLocation getName(BiomeType type) { return new ResourceLocation("terraforged", type.name().toLowerCase()); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenBlocks.java b/src/main/java/com/terraforged/mod/data/WorldGenBlocks.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/data/WorldGenBlocks.java rename to src/main/java/com/terraforged/mod/data/WorldGenBlocks.java diff --git a/src/main/java/com/terraforged/mod/data/WorldGenFeatures.java b/src/main/java/com/terraforged/mod/data/WorldGenFeatures.java new file mode 100644 index 0000000..cbe327b --- /dev/null +++ b/src/main/java/com/terraforged/mod/data/WorldGenFeatures.java @@ -0,0 +1,68 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.data; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.JsonOps; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.GenerationStage; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraftforge.registries.ForgeRegistries; + +import java.io.File; + +public class WorldGenFeatures extends DataGen { + + public static void genBiomeFeatures(File dataDir) { + if (dataDir.exists() || dataDir.mkdirs()) { + for (Biome biome : ForgeRegistries.BIOMES) { + genBiomeFeatures(dataDir, biome); + } + } + } + + private static void genBiomeFeatures(File dir, Biome biome) { + write(new File(dir, getJsonPath("features", biome.getRegistryName())), writer -> { + JsonObject root = new JsonObject(); + for (GenerationStage.Decoration type : GenerationStage.Decoration.values()) { + JsonArray features = new JsonArray(); + for (ConfiguredFeature feature : biome.getFeatures(type)) { + try { + Dynamic dynamic = feature.serialize(JsonOps.INSTANCE); + features.add(dynamic.getValue()); + } catch (NullPointerException e) { + new NullPointerException("Badly written feature: " + feature.feature.getRegistryName()).printStackTrace(); + } + } + root.add(type.getName(), features); + } + write(root, writer); + }); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/BlockDataConfig.java b/src/main/java/com/terraforged/mod/feature/BlockDataConfig.java new file mode 100644 index 0000000..fcf6f54 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/BlockDataConfig.java @@ -0,0 +1,16 @@ +package com.terraforged.mod.feature; + +import com.google.gson.JsonObject; +import net.minecraft.block.Block; + +import java.util.Optional; + +public interface BlockDataConfig { + + Block getTarget(); + + interface Parser { + + Optional parse(JsonObject data); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/BlockDataManager.java b/src/main/java/com/terraforged/mod/feature/BlockDataManager.java new file mode 100644 index 0000000..66971f4 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/BlockDataManager.java @@ -0,0 +1,35 @@ +package com.terraforged.mod.feature; + +import com.google.common.collect.ImmutableMap; +import com.terraforged.mod.feature.sapling.SaplingConfig; +import com.terraforged.fm.data.DataManager; +import com.terraforged.fm.util.Json; +import net.minecraft.block.Block; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +public class BlockDataManager { + + private static final Map parsers = ImmutableMap.builder() + .put("terraforged:sapling", SaplingConfig::deserialize) + .build(); + + private final Map blockdata = new HashMap<>(); + + public BlockDataManager(DataManager dataManager) { + dataManager.forEachJson("blocks/saplings", (name, data) -> { + String type = Json.getString("type", data.getAsJsonObject(), ""); + BlockDataConfig.Parser parser = parsers.get(type); + if (parser == null) { + return; + } + parser.parse(data.getAsJsonObject()).ifPresent(config -> blockdata.put(config.getTarget(), config)); + }); + } + + public Optional getConfig(Block block, Class type) { + return Optional.ofNullable(blockdata.get(block)).filter(type::isInstance).map(type::cast); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/Matchers.java b/src/main/java/com/terraforged/mod/feature/Matchers.java similarity index 86% rename from TerraForgedMod/src/main/java/com/terraforged/mod/feature/Matchers.java rename to src/main/java/com/terraforged/mod/feature/Matchers.java index 645e85f..daa0770 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/Matchers.java +++ b/src/main/java/com/terraforged/mod/feature/Matchers.java @@ -25,10 +25,11 @@ package com.terraforged.mod.feature; -import com.terraforged.feature.matcher.BiomeFeatureMatcher; -import com.terraforged.feature.matcher.biome.BiomeMatcher; -import com.terraforged.feature.matcher.feature.FeatureMatcher; import com.terraforged.mod.feature.feature.DiskFeature; +import com.terraforged.fm.matcher.BiomeFeatureMatcher; +import com.terraforged.fm.matcher.biome.BiomeMatcher; +import com.terraforged.fm.matcher.feature.FeatureMatcher; +import net.minecraft.block.Blocks; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.feature.Feature; @@ -44,6 +45,12 @@ public class Matchers { .build(); } + public static FeatureMatcher tree() { + return FeatureMatcher.builder() + .or(Blocks.OAK_LOG).and(Blocks.OAK_LEAVES) + .build(); + } + public static BiomeFeatureMatcher sedimentDisks() { return new BiomeFeatureMatcher( BiomeMatcher.of(Biome.Category.RIVER, Biome.Category.SWAMP), diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java b/src/main/java/com/terraforged/mod/feature/TerrainHelper.java similarity index 75% rename from TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java rename to src/main/java/com/terraforged/mod/feature/TerrainHelper.java index 4dcab74..650b141 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java +++ b/src/main/java/com/terraforged/mod/feature/TerrainHelper.java @@ -25,11 +25,12 @@ package com.terraforged.mod.feature; +import com.google.common.collect.ImmutableSet; +import com.terraforged.n2d.util.NoiseUtil; import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectList; import it.unimi.dsi.fastutil.objects.ObjectListIterator; -import me.dags.noise.util.NoiseUtil; import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; @@ -37,15 +38,26 @@ import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.world.IWorld; import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.Heightmap; -import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.jigsaw.JigsawPattern; import net.minecraft.world.gen.feature.structure.AbstractVillagePiece; +import net.minecraft.world.gen.feature.structure.IStructurePieceType; import net.minecraft.world.gen.feature.structure.Structure; import net.minecraft.world.gen.feature.structure.StructurePiece; import net.minecraft.world.gen.feature.structure.StructureStart; +import java.util.List; +import java.util.Set; + public class TerrainHelper { + private static final Set SURFACE_STRUCTURES = ImmutableSet.of( + IStructurePieceType.PCP, // outpost + IStructurePieceType.NVI, // village + IStructurePieceType.TEJP, // jungle temple + IStructurePieceType.IGLU, // igloo + IStructurePieceType.TEDP // desert pyramid + ); + private final float radius; public TerrainHelper(float radius) { @@ -53,15 +65,15 @@ public class TerrainHelper { } public void flatten(IWorld world, IChunk chunk) { - ObjectList pieces = new ObjectArrayList<>(10); + ObjectList pieces = new ObjectArrayList<>(10); collectPieces(world, chunk, pieces); buildBases(chunk, pieces); } // see NoiseChunkGenerator - private void collectPieces(IWorld world, IChunk chunk, ObjectList pieces) { + private void collectPieces(IWorld world, IChunk chunk, ObjectList pieces) { ChunkPos pos = chunk.getPos(); - for (Structure structure : Feature.ILLAGER_STRUCTURES) { + for (Structure structure : Structure.ILLAGER_STRUCTURES) { String name = structure.getStructureName(); LongIterator structureIds = chunk.getStructureReferences(name).iterator(); @@ -72,12 +84,9 @@ public class TerrainHelper { StructureStart structurestart = neighbourChunk.getStructureStart(name); if (structurestart != null && structurestart.isValid()) { for (StructurePiece structurepiece : structurestart.getComponents()) { - if (structurepiece.func_214810_a(pos, 12) && structurepiece instanceof AbstractVillagePiece) { - AbstractVillagePiece piece = (AbstractVillagePiece) structurepiece; - JigsawPattern.PlacementBehaviour placement = piece.getJigsawPiece().getPlacementBehaviour(); - if (placement == JigsawPattern.PlacementBehaviour.RIGID) { - pieces.add(piece); - } + // collect if piece is within radius of the chunk + if (structurepiece.func_214810_a(pos, 12)) { + collectPiece(structurepiece, pieces); } } } @@ -86,11 +95,11 @@ public class TerrainHelper { } // lowers or raises the terrain matcher the base height of each structure piece - private void buildBases(IChunk chunk, ObjectList pieces) { + private void buildBases(IChunk chunk, ObjectList pieces) { int chunkStartX = chunk.getPos().getXStart(); int chunkStartZ = chunk.getPos().getZStart(); BlockPos.Mutable pos = new BlockPos.Mutable(); - ObjectListIterator iterator = pieces.iterator(); + ObjectListIterator iterator = pieces.iterator(); MutableBoundingBox chunkBounds = new MutableBoundingBox(chunkStartX, chunkStartZ, chunkStartX + 15, chunkStartZ + 15); for (int dz = 0; dz < 16; dz++) { @@ -100,9 +109,10 @@ public class TerrainHelper { int surface = chunk.getTopBlockY(Heightmap.Type.OCEAN_FLOOR_WG, dx, dz); float y = surface; - AbstractVillagePiece highest = null; + int highestOffset = 0; + StructurePiece highest = null; while (iterator.hasNext()) { - AbstractVillagePiece piece = iterator.next(); + StructurePiece piece = iterator.next(); MutableBoundingBox pieceBounds = piece.getBoundingBox(); int length = Math.min(pieceBounds.maxX - pieceBounds.minX, pieceBounds.maxZ - pieceBounds.minZ); int borderRadius = Math.min(5, Math.max(10, NoiseUtil.round(length * radius))); @@ -111,7 +121,8 @@ public class TerrainHelper { continue; } - int level = pieceBounds.minY + piece.getGroundLevelDelta(); + int offset = getGroundLevelDelta(piece); + int level = pieceBounds.minY + offset; if (level > y) { y = raise(pieceBounds, pos.setPos(x, surface, z), level, y, borderRadius); } @@ -119,6 +130,7 @@ public class TerrainHelper { if (x > pieceBounds.minX && x < pieceBounds.maxX && z > pieceBounds.minZ && z < pieceBounds.maxZ) { if (highest == null || pieceBounds.minY > highest.getBoundingBox().minY) { highest = piece; + highestOffset = offset; } } } @@ -136,7 +148,7 @@ public class TerrainHelper { if (highest != null) { MutableBoundingBox bounds = highest.getBoundingBox(); - for (int dy = bounds.minY + highest.getGroundLevelDelta(); dy <= surface; dy++) { + for (int dy = bounds.minY + highestOffset; dy <= surface; dy++) { pos.setPos(dx, dy, dz); chunk.setBlockState(pos, Blocks.AIR.getDefaultState(), false); } @@ -152,6 +164,25 @@ public class TerrainHelper { return NoiseUtil.lerp(surface, level, alpha); } + private static void collectPiece(StructurePiece structurepiece, List list) { + if (structurepiece instanceof AbstractVillagePiece) { + AbstractVillagePiece piece = (AbstractVillagePiece) structurepiece; + JigsawPattern.PlacementBehaviour placement = piece.getJigsawPiece().getPlacementBehaviour(); + if (placement == JigsawPattern.PlacementBehaviour.RIGID) { + list.add(piece); + } + } else if (SURFACE_STRUCTURES.contains(structurepiece.getStructurePieceType())) { + list.add(structurepiece); + } + } + + private static int getGroundLevelDelta(StructurePiece piece) { + if (piece instanceof AbstractVillagePiece) { + return ((AbstractVillagePiece) piece).getGroundLevelDelta(); + } + return 0; + } + private static MutableBoundingBox expand(MutableBoundingBox box, int radius) { return new MutableBoundingBox( box.minX - radius, diff --git a/src/main/java/com/terraforged/mod/feature/context/ChanceContext.java b/src/main/java/com/terraforged/mod/feature/context/ChanceContext.java new file mode 100644 index 0000000..6939500 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/ChanceContext.java @@ -0,0 +1,87 @@ +package com.terraforged.mod.feature.context; + +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.fix.RegionDelegate; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.concurrent.Resource; +import com.terraforged.core.concurrent.cache.SafeCloseable; +import com.terraforged.core.concurrent.pool.ObjectPool; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.world.heightmap.Levels; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.WorldGenRegion; + +import java.util.Random; + +public class ChanceContext implements SafeCloseable { + + private static final ObjectPool pool = new ObjectPool<>(10, ChanceContext::new); + + public IChunk chunk; + public Levels levels; + public ChunkReader reader; + public Cell cell = Cell.empty(); + + private int length; + private float total = 0F; + private float[] buffer; + + @Override + public void close() { + if (reader != null) { + reader.close(); + reader = null; + } + } + + void setPos(BlockPos pos) { + cell = reader.getCell(pos.getX(), pos.getZ()); + } + + void init(int size) { + total = 0F; + length = 0; + if (buffer == null || buffer.length < size) { + buffer = new float[size]; + } + } + + void record(int index, float chance) { + buffer[index] = chance; + total += chance; + length++; + } + + int nextIndex(Random random) { + if (total == 0) { + return -1; + } + float value = 0F; + float chance = total * random.nextFloat(); + for (int i = 0; i < length; i++) { + value += buffer[i]; + if (value >= chance) { + return i; + } + } + return -1; + } + + public static Resource pooled(IWorld world, ChunkGenerator generator) { + if (generator instanceof TerraChunkGenerator && world instanceof RegionDelegate) { + TerraChunkGenerator terraGenerator = (TerraChunkGenerator) generator; + Levels levels = terraGenerator.getContext().levels; + WorldGenRegion region = ((RegionDelegate) world).getRegion(); + IChunk chunk = region.getChunk(region.getMainChunkX(), region.getMainChunkZ()); + Resource item = pool.get(); + item.get().chunk = chunk; + item.get().levels = levels; + item.get().reader = terraGenerator.getChunkReader(chunk.getPos().x, chunk.getPos().z); + return item; + } + return null; + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/ContextSelectorConfig.java b/src/main/java/com/terraforged/mod/feature/context/ContextSelectorConfig.java new file mode 100644 index 0000000..17496a2 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/ContextSelectorConfig.java @@ -0,0 +1,28 @@ +package com.terraforged.mod.feature.context; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; +import net.minecraft.world.gen.feature.IFeatureConfig; + +import java.util.List; + +public class ContextSelectorConfig implements IFeatureConfig { + + public final List features; + + public ContextSelectorConfig(List features) { + this.features = features; + } + + @Override + public Dynamic serialize(DynamicOps ops) { + return new Dynamic<>(ops, ops.createMap(ImmutableMap.of( + ops.createString("features"), ops.createList(features.stream().map(f -> f.serialize(ops).getValue()) + )))); + } + + public static ContextSelectorConfig deserialize(Dynamic dynamic) { + return new ContextSelectorConfig(dynamic.get("features").asList(ContextualFeature::deserialize)); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/ContextSelectorFeature.java b/src/main/java/com/terraforged/mod/feature/context/ContextSelectorFeature.java new file mode 100644 index 0000000..85468aa --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/ContextSelectorFeature.java @@ -0,0 +1,45 @@ +package com.terraforged.mod.feature.context; + +import com.terraforged.core.concurrent.Resource; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.GenerationSettings; +import net.minecraft.world.gen.feature.Feature; + +import java.util.Random; + +public class ContextSelectorFeature extends Feature { + + public static final ContextSelectorFeature INSTANCE = new ContextSelectorFeature(); + + public ContextSelectorFeature() { + super(ContextSelectorConfig::deserialize); + setRegistryName("terraforged", "context_selector"); + } + + @Override + public boolean place(IWorld world, ChunkGenerator generator, Random random, BlockPos pos, ContextSelectorConfig config) { + try (Resource item = ChanceContext.pooled(world, generator)) { + if (item == null) { + return false; + } + + ChanceContext context = item.get(); + context.setPos(pos); + context.init(config.features.size()); + for (int i = 0; i < config.features.size(); i++) { + ContextualFeature feature = config.features.get(i); + float chance = feature.getChance(pos, context); + context.record(i, chance); + } + + int index = context.nextIndex(random); + if (index > -1) { + return config.features.get(index).feature.place(world, generator, random, pos); + } + + return false; + } + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/ContextualFeature.java b/src/main/java/com/terraforged/mod/feature/context/ContextualFeature.java new file mode 100644 index 0000000..8d60b8c --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/ContextualFeature.java @@ -0,0 +1,81 @@ +package com.terraforged.mod.feature.context; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.OptionalDynamic; +import com.mojang.datafixers.types.DynamicOps; +import com.terraforged.mod.feature.context.modifier.ContextModifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.gen.feature.ConfiguredFeature; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class ContextualFeature { + + public final float chance; + public final List contexts; + public final ConfiguredFeature feature; + + public ContextualFeature(ConfiguredFeature feature, float chance, List contexts) { + this.chance = chance; + this.feature = feature; + this.contexts = contexts; + } + + public String getName() { + return "chance"; + } + + public float getChance(BlockPos pos, ChanceContext context) { + float chance = this.chance; + for (ContextModifier modifier : contexts) { + chance *= modifier.getChance(pos, context); + } + return chance; + } + + public Dynamic serialize(DynamicOps ops) { + return new Dynamic<>(ops, ops.createMap(ImmutableMap.of( + ops.createString("feature"), feature.serialize(ops).getValue(), + ops.createString("context"), serializeContext(ops).getValue() + ))); + } + + private Dynamic serializeContext(DynamicOps ops) { + Map map = new LinkedHashMap<>(); + map.put(ops.createString("chance"), ops.createFloat(chance)); + for (ContextModifier context : contexts) { + map.put(ops.createString(context.getName()), context.serialize(ops).getValue()); + } + return new Dynamic<>(ops, ops.createMap(map)); + } + + public static ContextualFeature deserialize(Dynamic dynamic) { + ConfiguredFeature feature = deserializeFeature(dynamic.get("feature")); + OptionalDynamic context = dynamic.get("context"); + float chance = context.get("chance").asFloat(0); + List contexts = deserializeContexts(context); + return new ContextualFeature(feature, chance, contexts); + } + + private static ConfiguredFeature deserializeFeature(OptionalDynamic dynamic) { + return dynamic.map(ConfiguredFeature::deserialize).orElseThrow(NullPointerException::new); + } + + private static List deserializeContexts(OptionalDynamic dynamic) { + return dynamic.map(d -> d.getMapValues().map(map -> { + List contexts = new ArrayList<>(map.size()); + map.forEach((key, value) -> { + String name = key.asString(""); + if (!name.equals("chance")) { + contexts.add(ContextModifier.parse(name, value)); + } + }); + return contexts; + }).orElse(Collections.emptyList())).orElseThrow(NullPointerException::new); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/modifier/Biome.java b/src/main/java/com/terraforged/mod/feature/context/modifier/Biome.java new file mode 100644 index 0000000..c3e1da3 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/modifier/Biome.java @@ -0,0 +1,26 @@ +package com.terraforged.mod.feature.context.modifier; + +import com.mojang.datafixers.Dynamic; +import com.terraforged.mod.feature.context.ChanceContext; +import net.minecraft.util.math.BlockPos; + +public class Biome extends RangeContextModifier { + + public Biome(float from, float to, boolean exclusive) { + super(from, to, exclusive); + } + + @Override + public String getName() { + return "biome"; + } + + @Override + protected float getValue(BlockPos pos, ChanceContext context) { + return context.cell.biomeEdge; + } + + public static ContextModifier deserialize(Dynamic dynamic) { + return RangeContextModifier.deserialize(dynamic, Biome::new); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/modifier/ContextModifier.java b/src/main/java/com/terraforged/mod/feature/context/modifier/ContextModifier.java new file mode 100644 index 0000000..f540823 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/modifier/ContextModifier.java @@ -0,0 +1,34 @@ +package com.terraforged.mod.feature.context.modifier; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; +import com.terraforged.mod.feature.context.ChanceContext; +import net.minecraft.util.math.BlockPos; + +import java.util.Map; +import java.util.function.Function; + +public interface ContextModifier { + + Map, ContextModifier>> REGISTRY = ImmutableMap.of( + "elevation", Elevation::deserialize, + "biome", Biome::deserialize + ); + + ContextModifier NONE = new None(); + + String getName(); + + float getChance(BlockPos pos, ChanceContext context); + + Dynamic serialize(DynamicOps ops); + + static ContextModifier parse(String type, Dynamic dynamic) { + Function, ContextModifier> func = REGISTRY.get(type); + if (func == null) { + return NONE; + } + return func.apply(dynamic); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/modifier/Elevation.java b/src/main/java/com/terraforged/mod/feature/context/modifier/Elevation.java new file mode 100644 index 0000000..0230bf9 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/modifier/Elevation.java @@ -0,0 +1,26 @@ +package com.terraforged.mod.feature.context.modifier; + +import com.mojang.datafixers.Dynamic; +import com.terraforged.mod.feature.context.ChanceContext; +import net.minecraft.util.math.BlockPos; + +public class Elevation extends RangeContextModifier { + + public Elevation(float from, float to, boolean exclusive) { + super(from, to, exclusive); + } + + @Override + public String getName() { + return "elevation"; + } + + @Override + protected float getValue(BlockPos pos, ChanceContext context) { + return context.levels.elevation(context.cell.value); + } + + public static ContextModifier deserialize(Dynamic dynamic) { + return RangeContextModifier.deserialize(dynamic, Elevation::new); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/modifier/None.java b/src/main/java/com/terraforged/mod/feature/context/modifier/None.java new file mode 100644 index 0000000..6a4d572 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/modifier/None.java @@ -0,0 +1,24 @@ +package com.terraforged.mod.feature.context.modifier; + +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; +import com.terraforged.mod.feature.context.ChanceContext; +import net.minecraft.util.math.BlockPos; + +public class None implements ContextModifier { + + @Override + public String getName() { + return "none"; + } + + @Override + public float getChance(BlockPos pos, ChanceContext context) { + return 0; + } + + @Override + public Dynamic serialize(DynamicOps ops) { + return new Dynamic<>(ops); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/context/modifier/RangeContextModifier.java b/src/main/java/com/terraforged/mod/feature/context/modifier/RangeContextModifier.java new file mode 100644 index 0000000..dc26c4b --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/context/modifier/RangeContextModifier.java @@ -0,0 +1,43 @@ +package com.terraforged.mod.feature.context.modifier; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; +import com.terraforged.mod.feature.context.ChanceContext; +import com.terraforged.mod.util.RangeModifier; +import net.minecraft.util.math.BlockPos; + +public abstract class RangeContextModifier extends RangeModifier implements ContextModifier { + + public RangeContextModifier(float min, float max, boolean exclusive) { + super(min, max, exclusive); + } + + protected abstract float getValue(BlockPos pos, ChanceContext context); + + @Override + public float getChance(BlockPos pos, ChanceContext context) { + return apply(getValue(pos, context)); + } + + @Override + public Dynamic serialize(DynamicOps ops) { + return new Dynamic<>(ops, ops.createMap(ImmutableMap.of( + ops.createString("from"), ops.createFloat(from), + ops.createString("to"), ops.createFloat(to), + ops.createString("exclusive"), ops.createBoolean(max > 0) + ))); + } + + public static T deserialize(Dynamic dynamic, Factory factory) { + float from = dynamic.get("from").asFloat(0F); + float to = dynamic.get("to").asFloat(1F); + boolean exclusive = dynamic.get("exclusive").asBoolean(false); + return factory.create(from, to, exclusive); + } + + public interface Factory { + + T create(float from, float to, boolean exclusive); + } +} diff --git a/src/main/java/com/terraforged/mod/feature/decorator/poisson/BiomeVariance.java b/src/main/java/com/terraforged/mod/feature/decorator/poisson/BiomeVariance.java new file mode 100644 index 0000000..c9fb32a --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/decorator/poisson/BiomeVariance.java @@ -0,0 +1,39 @@ +package com.terraforged.mod.feature.decorator.poisson; + +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.tile.chunk.ChunkReader; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.n2d.util.NoiseUtil; +import net.minecraft.world.IWorld; +import net.minecraft.world.gen.ChunkGenerator; + +public class BiomeVariance implements Module { + + public static float MIN_FADE = 0.05F; + + private final ChunkReader chunk; + private final float fade; + private final float range; + + public BiomeVariance(ChunkReader chunk, float fade) { + this.chunk = chunk; + this.fade = fade; + this.range = fade - MIN_FADE; + } + + @Override + public float getValue(float x, float y) { + Cell cell = chunk.getCell((int) x, (int) y); + return NoiseUtil.map(1 - cell.biomeEdge, MIN_FADE, fade, range); + } + + public static Module of(IWorld world, ChunkGenerator generator, float fade) { + ChunkReader reader = TerraChunkGenerator.getChunk(world, generator); + if (reader != null) { + return new BiomeVariance(reader, fade); + } + return Source.ONE; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonAtSurface.java b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonAtSurface.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonAtSurface.java rename to src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonAtSurface.java diff --git a/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonConfig.java b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonConfig.java new file mode 100644 index 0000000..7bf2150 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonConfig.java @@ -0,0 +1,77 @@ +package com.terraforged.mod.feature.decorator.poisson; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; +import com.terraforged.core.util.poisson.PoissonContext; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import net.minecraft.world.IWorld; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.placement.IPlacementConfig; + +public class PoissonConfig implements IPlacementConfig { + + public final int radius; + public final float biomeFade; + public final int densityNoiseScale; + public final float densityNoiseMin; + public final float densityNoiseMax; + + public PoissonConfig(int radius, float biomeFade, int densityNoiseScale, float densityNoiseMin, float densityNoiseMax) { + this.radius = radius; + this.biomeFade = biomeFade; + this.densityNoiseScale = densityNoiseScale; + this.densityNoiseMin = densityNoiseMin; + this.densityNoiseMax = densityNoiseMax; + } + + public void apply(IWorld world, ChunkGenerator generator, PoissonContext context) { + Module fade = Source.ONE; + Module density = Source.ONE; + + if (biomeFade > 0.075F) { + fade = BiomeVariance.of(world, generator, biomeFade); + } + + if (densityNoiseScale > 0) { + density = Source.simplex(context.seed, densityNoiseScale, 1) + .scale(densityNoiseMax - densityNoiseMin) + .bias(densityNoiseMin); + } + + context.density = mult(fade, density); + } + + @Override + public Dynamic serialize(DynamicOps ops) { + return new Dynamic<>(ops, ops.createMap( + ImmutableMap.of( + ops.createString("radius"), ops.createInt(radius), + ops.createString("biome_fade"), ops.createFloat(biomeFade), + ops.createString("density_noise_scale"), ops.createInt(densityNoiseScale), + ops.createString("density_noise_min"), ops.createFloat(densityNoiseMin), + ops.createString("density_noise_max"), ops.createFloat(densityNoiseMax) + )) + ); + } + + public static PoissonConfig deserialize(Dynamic dynamic) { + int radius = dynamic.get("radius").asInt(4); + float biomeFade = dynamic.get("biome_fade").asFloat(0.2F); + int variance = dynamic.get("density_noise_scale").asInt(0); + float min = dynamic.get("density_noise_min").asFloat(0F); + float max = dynamic.get("density_noise_max").asFloat(1F); + return new PoissonConfig(radius, biomeFade, variance, min, max); + } + + private static Module mult(Module a, Module b) { + if (a == Source.ONE) { + return b; + } + if (b == Source.ONE) { + return a; + } + return a.mult(b); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonDecorator.java b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonDecorator.java similarity index 67% rename from TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonDecorator.java rename to src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonDecorator.java index 7a480e0..3a28c72 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonDecorator.java +++ b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonDecorator.java @@ -1,7 +1,6 @@ package com.terraforged.mod.feature.decorator.poisson; -import me.dags.noise.Module; -import me.dags.noise.Source; +import com.terraforged.core.util.poisson.Poisson; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; import net.minecraft.world.gen.ChunkGenerator; @@ -24,11 +23,11 @@ public abstract class PoissonDecorator extends Placement { } @Override - public final > boolean place(IWorld world, ChunkGenerator generator, Random random, BlockPos pos, PoissonConfig config, ConfiguredFeature feature) { + public > boolean place(IWorld world, ChunkGenerator generator, Random random, BlockPos pos, PoissonConfig config, ConfiguredFeature feature) { int radius = Math.max(1, Math.min(30, config.radius)); Poisson poisson = getInstance(radius); PoissonVisitor visitor = new PoissonVisitor(this, feature, world, generator, random, pos); - setVariance(world, visitor, config); + config.apply(world, generator, visitor); int chunkX = pos.getX() >> 4; int chunkZ = pos.getZ() >> 4; poisson.visit(chunkX, chunkZ, visitor, visitor); @@ -50,20 +49,4 @@ public abstract class PoissonDecorator extends Placement { return instance; } } - - private void setVariance(IWorld world, PoissonContext context, PoissonConfig config) { - Module module = Source.ONE; - - if (config.biomeFade > 0.075F) { - module = BiomeVariance.of(world, config.biomeFade); - } - - if (config.variance > 0) { - module = module.mult(Source.simplex(context.seed, config.variance, 1) - .scale(config.max - config.min) - .bias(config.min)); - } - - context.density = module; - } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonVisitor.java b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonVisitor.java similarity index 84% rename from TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonVisitor.java rename to src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonVisitor.java index b39b6ad..998ff1c 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonVisitor.java +++ b/src/main/java/com/terraforged/mod/feature/decorator/poisson/PoissonVisitor.java @@ -1,14 +1,15 @@ package com.terraforged.mod.feature.decorator.poisson; +import com.terraforged.core.util.poisson.Poisson; +import com.terraforged.core.util.poisson.PoissonContext; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.feature.ConfiguredFeature; import java.util.Random; -import java.util.function.BiConsumer; -public class PoissonVisitor extends PoissonContext implements BiConsumer { +public class PoissonVisitor extends PoissonContext implements Poisson.Visitor { private final BlockPos pos; private final IWorld world; @@ -33,7 +34,7 @@ public class PoissonVisitor extends PoissonContext implements BiConsumer { + + public static final BushFeature INSTANCE = new BushFeature(); + + private static final Vec3i[] logs = { + new Vec3i(+1, 0, +1), + new Vec3i(+1, 0, -1), + new Vec3i(-1, 0, -1), + new Vec3i(-1, 0, +1), + + new Vec3i(+2, 0, +1), + new Vec3i(+2, 0, -1), + new Vec3i(-2, 0, +1), + new Vec3i(-2, 0, -1), + + new Vec3i(+1, 0, +2), + new Vec3i(+1, 0, -2), + new Vec3i(-1, 0, +2), + new Vec3i(-1, 0, -2), + }; + + private static final Vec3i[] leaves = { + new Vec3i(0, 0, 1), + new Vec3i(0, 0, -1), + new Vec3i(1, 0, 0), + new Vec3i(-1, 0, 0), + new Vec3i(0, 1, 0), + }; + + public BushFeature() { + super(BushFeature::deserialize); + setRegistryName("terraforged", "bush"); + } + + @Override + public boolean place(IWorld world, ChunkGenerator generator, Random rand, BlockPos pos, Config config) { + try (BlockPos.PooledMutable log = BlockPos.PooledMutable.retain(); BlockPos.PooledMutable leaf = BlockPos.PooledMutable.retain()) { + place(world, log.setPos(pos), leaf, rand, config); + for (float chance = rand.nextFloat(); chance < config.size_chance; chance += rand.nextFloat()) { + add(log, logs[rand.nextInt(logs.length)]); + + if (!place(world, log, leaf, rand, config)) { + break; + } + } + } + return true; + } + + private boolean place(IWorld world, BlockPos.Mutable center, BlockPos.Mutable pos, Random random, Config config) { + center.setY(world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, center.getX(), center.getZ())); + + // don't replace solid blocks + if (BlockUtils.isSolid(world, center)) { + return false; + } + + // only place on solid blocks + center.move(Direction.DOWN, 1); + if (!BlockUtils.isSolid(world, center)) { + return false; + } + + center.move(Direction.UP, 1); + world.setBlockState(center, config.trunk, 2); + + for (Vec3i neighbour : leaves) { + // randomly skip NESW neighbours + if (neighbour.getY() == 0 && random.nextFloat() < config.airChance) { + continue; + } + + pos.setPos(center); + add(pos, neighbour); + + if (!BlockUtils.isSolid(world, pos)) { + world.setBlockState(pos, config.leaves, 2); + + // randomly place extra leaves below if non-solid + if (neighbour.getY() == 0 && random.nextFloat() < config.leafChance) { + pos.move(Direction.DOWN, 1); + if (!BlockUtils.isSolid(world, pos)) { + world.setBlockState(pos, config.leaves, 2); + } + pos.move(Direction.UP, 1); + } + + // randomly place extra leaves above + if (neighbour.getY() == 0 && random.nextFloat() < config.leafChance) { + pos.move(Direction.UP, 1); + if (!BlockUtils.isSolid(world, pos)) { + world.setBlockState(pos, config.leaves, 2); + } + } + } + } + + return true; + } + + private static void add(BlockPos.Mutable pos, Vec3i add) { + pos.setPos(pos.getX() + add.getX(), pos.getY() + add.getY(), pos.getZ() + add.getZ()); + } + + public static Config deserialize(Dynamic data) { + BlockState logs = BlockState.deserialize(data.get("trunk").get().get()); + BlockState leaves = BlockState.deserialize(data.get("leaves").get().get()); + float airChance = data.get("air_chance").asFloat(0.075F); + float leafChance = data.get("leaf_chance").asFloat(0.075F); + float sizeChance = data.get("size_chance").asFloat(0.75F); + return new Config(logs, leaves, airChance, leafChance, sizeChance); + } + + public static class Config implements IFeatureConfig { + + private final BlockState trunk; + private final BlockState leaves; + private final float airChance; + private final float leafChance; + private final float size_chance; + + public Config(BlockState trunk, BlockState leaves, float airChance, float leafChance, float size_chance) { + this.trunk = trunk; + this.leaves = leaves; + this.airChance = airChance; + this.leafChance = leafChance; + this.size_chance = size_chance; + } + + @Override + public Dynamic serialize(DynamicOps ops) { + return new Dynamic<>( + ops, + ops.createMap(ImmutableMap.of( + ops.createString("trunk"), BlockState.serialize(ops, trunk).getValue(), + ops.createString("leaves"), BlockState.serialize(ops, leaves).getValue(), + ops.createString("air_chance"), ops.createFloat(airChance), + ops.createString("leaf_chance"), ops.createFloat(airChance), + ops.createString("size_chance"), ops.createFloat(size_chance) + )) + ); + } + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/feature/DiskFeature.java b/src/main/java/com/terraforged/mod/feature/feature/DiskFeature.java similarity index 97% rename from TerraForgedMod/src/main/java/com/terraforged/mod/feature/feature/DiskFeature.java rename to src/main/java/com/terraforged/mod/feature/feature/DiskFeature.java index e069bda..6433b77 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/feature/DiskFeature.java +++ b/src/main/java/com/terraforged/mod/feature/feature/DiskFeature.java @@ -1,7 +1,7 @@ package com.terraforged.mod.feature.feature; -import me.dags.noise.Module; -import me.dags.noise.Source; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; import net.minecraft.block.BlockState; import net.minecraft.tags.FluidTags; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/com/terraforged/mod/feature/feature/FreezeLayer.java b/src/main/java/com/terraforged/mod/feature/feature/FreezeLayer.java new file mode 100644 index 0000000..868387f --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/feature/FreezeLayer.java @@ -0,0 +1,108 @@ +package com.terraforged.mod.feature.feature; + +import com.terraforged.fm.template.BlockUtils; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.SnowyDirtBlock; +import net.minecraft.tags.BlockTags; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.GenerationSettings; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.NoFeatureConfig; + +import java.util.Random; + +public class FreezeLayer extends Feature { + + public static final FreezeLayer INSTANCE = new FreezeLayer(); + + public FreezeLayer() { + super(NoFeatureConfig::deserialize); + setRegistryName("terraforged", "freeze_top_layer"); + } + + @Override + public boolean place(IWorld world, ChunkGenerator generator, Random rand, BlockPos pos, NoFeatureConfig config) { + BlockPos.Mutable pos1 = new BlockPos.Mutable(); + BlockPos.Mutable pos2 = new BlockPos.Mutable(); + + for(int dx = 0; dx < 16; ++dx) { + for(int dz = 0; dz < 16; ++dz) { + int x = pos.getX() + dx; + int z = pos.getZ() + dz; + int y1 = world.getHeight(Heightmap.Type.MOTION_BLOCKING, x, z); + int y2 = world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, x, z); + pos1.setPos(x, y1, z); + pos2.setPos(pos1).move(Direction.DOWN, 1); + + Biome biome = world.getBiome(pos1); + boolean freezesHere = freeze(world, biome, pos1, pos2, false, false); + + if (y1 != y2) { + pos1.setPos(x, y2, z); + pos2.setPos(pos1).move(Direction.DOWN, 1); + freeze(world, biome, pos1, pos2, freezesHere, true); + } + } + } + + return true; + } + + private boolean freeze(IWorld world, Biome biome, BlockPos.Mutable top, BlockPos below, boolean force, boolean ground) { + boolean hasFrozen = false; + if (biome.doesWaterFreeze(world, below, false)) { + world.setBlockState(below, Blocks.ICE.getDefaultState(), 2); + hasFrozen = true; + } + + if (force || biome.doesSnowGenerate(world, top)) { + hasFrozen = true; + BlockState stateUnder = world.getBlockState(below); + + if (stateUnder.getBlock() == Blocks.AIR) { + return false; + } + + if (ground) { + if (BlockTags.LOGS.contains(stateUnder.getBlock())) { + return false; + } + + top.move(Direction.UP, 1); + BlockState above = world.getBlockState(top); + if (BlockTags.LOGS.contains(above.getBlock()) || BlockTags.LEAVES.contains(above.getBlock())) { + return false; + } + + top.move(Direction.DOWN, 1); + if (setSnow(world, top, below, stateUnder)) { + if (above.getBlock() != Blocks.AIR) { + world.setBlockState(top, Blocks.AIR.getDefaultState(), 2); + } + } + } else { + setSnow(world, top, below, stateUnder); + } + } + return hasFrozen; + } + + private boolean setSnow(IWorld world, BlockPos pos1, BlockPos pos2, BlockState below) { + if (BlockUtils.isSolid(world, pos1)) { + return false; + } + + world.setBlockState(pos1, Blocks.SNOW.getDefaultState(), 2); + + if (below.has(SnowyDirtBlock.SNOWY)) { + world.setBlockState(pos2, below.with(SnowyDirtBlock.SNOWY, true), 2); + } + return true; + } +} diff --git a/src/main/java/com/terraforged/mod/feature/sapling/SaplingConfig.java b/src/main/java/com/terraforged/mod/feature/sapling/SaplingConfig.java new file mode 100644 index 0000000..f563269 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/sapling/SaplingConfig.java @@ -0,0 +1,103 @@ +package com.terraforged.mod.feature.sapling; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.terraforged.mod.feature.BlockDataConfig; +import com.terraforged.fm.template.TemplateManager; +import com.terraforged.fm.template.feature.TemplateFeatureConfig; +import com.terraforged.fm.util.Json; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Random; + +public class SaplingConfig implements BlockDataConfig { + + private final Block block; + private final List normal; + private final List giant; + + private SaplingConfig(Block block, List normal, List giant) { + this.block = block; + this.normal = normal; + this.giant = giant; + } + + @Override + public Block getTarget() { + return block; + } + + public boolean hasNormal() { + return !normal.isEmpty(); + } + + public boolean hasGiant() { + return !giant.isEmpty(); + } + + public TemplateFeatureConfig next(Random random, boolean giant) { + if (giant) { + TemplateFeatureConfig config = nextGiant(random); + if (config != null) { + return config; + } + } + return nextNormal(random); + } + + public TemplateFeatureConfig nextNormal(Random random) { + if (normal.isEmpty()) { + return null; + } + return normal.get(random.nextInt(normal.size())); + } + + public TemplateFeatureConfig nextGiant(Random random) { + if (giant.isEmpty()) { + return null; + } + return giant.get(random.nextInt(giant.size())); + } + + public static Optional deserialize(JsonObject data) { + String sapling = Json.getString("sapling", data, ""); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(sapling)); + if (block == Blocks.AIR) { + return Optional.empty(); + } + List normal = deserializeList(data.getAsJsonObject("normal")); + List giant = deserializeList(data.getAsJsonObject("giant")); + if (normal.isEmpty() && giant.isEmpty()) { + return Optional.empty(); + } + return Optional.of(new SaplingConfig(block, normal, giant)); + } + + private static List deserializeList(JsonObject object) { + List list = Collections.emptyList(); + if (object != null) { + for (Map.Entry e : object.entrySet()) { + ResourceLocation name = new ResourceLocation(e.getKey()); + TemplateFeatureConfig template = TemplateManager.getInstance().getTemplateConfig(name); + if (template != TemplateFeatureConfig.NONE) { + int weight = Json.getInt("weight", e.getValue().getAsJsonObject(), 1); + for (int i = 0; i < weight; i++) { + if (list.isEmpty()) { + list = new ArrayList<>(); + } + list.add(template); + } + } + } + } + return list; + } +} diff --git a/src/main/java/com/terraforged/mod/feature/sapling/SaplingListener.java b/src/main/java/com/terraforged/mod/feature/sapling/SaplingListener.java new file mode 100644 index 0000000..74a6f92 --- /dev/null +++ b/src/main/java/com/terraforged/mod/feature/sapling/SaplingListener.java @@ -0,0 +1,208 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.feature.sapling; + +import com.terraforged.mod.TerraWorld; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.mod.feature.BlockDataManager; +import com.terraforged.fm.template.Template; +import com.terraforged.fm.template.feature.TemplateFeature; +import com.terraforged.fm.template.feature.TemplateFeatureConfig; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.IWorld; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.event.world.SaplingGrowTreeEvent; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +import java.util.Optional; + +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) +public class SaplingListener { + + private static final BlockPos[] CENTER = {BlockPos.ZERO}; + + private static final Vec3i[][] DIRECTIONS = { + {new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(1, 0, 0)}, + {new Vec3i(1, 0, 0), new Vec3i(1, 0, -1), new Vec3i(0, 0, -1)}, + {new Vec3i(0, 0, -1), new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0)}, + {new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1)}, + }; + + @SubscribeEvent + public static void onTreeGrow(SaplingGrowTreeEvent event) { + Optional dataManager = getDataManger(event); + if (!dataManager.isPresent()) { + return; + } + + IWorld world = event.getWorld(); + Block block = world.getBlockState(event.getPos()).getBlock(); + Optional saplingConfig = dataManager.get().getConfig(block, SaplingConfig.class); + if (!saplingConfig.isPresent()) { + return; + } + + Mirror mirror = TemplateFeature.nextMirror(event.getRand()); + Rotation rotation = TemplateFeature.nextRotation(event.getRand()); + + // if part of a 2x2 grid get the min corner of it + BlockPos pos = getMinPos(world, block, event.getPos(), saplingConfig.get().hasGiant()); + Vec3i[] directions = getNeighbours(world, block, pos, saplingConfig.get().hasGiant()); + TemplateFeatureConfig feature = saplingConfig.get().next(event.getRand(), directions.length == 3); + if (feature == null) { + return; + } + + // translate the pos so that the mirrored/rotated 2x2 grid aligns correctly + BlockPos origin = pos.subtract(getTranslation(directions, mirror, rotation)); + + // require that directly above the sapling(s) is open air + if (!isClearOverhead(world, origin, directions)) { + event.setResult(Event.Result.DENY); + return; + } + + // attempt to paste the tree & then clear up any remaining saplings + if (TemplateFeature.pasteChecked(world, event.getRand(), origin, mirror, rotation, feature, feature.decorator)) { + event.setResult(Event.Result.DENY); + for (Vec3i dir : directions) { + BlockPos neighbour = origin.add(dir); + BlockState state = world.getBlockState(neighbour); + if (state.getBlock() == block) { + world.destroyBlock(neighbour, false); + } + } + } + } + + private static Optional getDataManger(SaplingGrowTreeEvent event) { + // ignore if client + if (event.getWorld().isRemote()) { + return Optional.empty(); + } + + // ignore other world types + if (!TerraWorld.isTerraWorld(event.getWorld())) { + return Optional.empty(); + } + + // get the data manager from the world's chunk generator + if (event.getWorld() instanceof ServerWorld) { + ServerWorld serverWorld = (ServerWorld) event.getWorld(); + ChunkGenerator generator = serverWorld.getChunkProvider().generator; + if (generator instanceof TerraChunkGenerator) { + TerraContext context = ((TerraChunkGenerator) generator).getContext(); + if (context.terraSettings.miscellaneous.customBiomeFeatures) { + return Optional.of(((TerraChunkGenerator) generator).getBlockDataManager()); + } + } + } + return Optional.empty(); + } + + private static boolean isClearOverhead(IWorld world, BlockPos pos, Vec3i[] directions) { + for (Vec3i dir : directions) { + int x = pos.getX() + dir.getX(); + int z = pos.getZ() + dir.getZ(); + int y = world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, x, z); + if (y > pos.getY()) { + return false; + } + } + return true; + } + + private static BlockPos getMinPos(IWorld world, Block block, BlockPos pos, boolean checkNeighbours) { + if (checkNeighbours) { + for (Vec3i[] dirs : DIRECTIONS) { + boolean match = true; + for (Vec3i dir : dirs) { + BlockState state = world.getBlockState(pos.add(dir)); + if (state.getBlock() != block) { + match = false; + break; + } + } + if (match) { + return pos.add(getMin(dirs, Mirror.NONE, Rotation.NONE)); + } + } + } + return pos; + } + + private static Vec3i getTranslation(Vec3i[] directions, Mirror mirror, Rotation rotation) { + if (directions.length == 1 || mirror == Mirror.NONE && rotation == Rotation.NONE) { + return Vec3i.NULL_VECTOR; + } + return getMin(directions, mirror, rotation); + } + + private static Vec3i getMin(Vec3i[] directions, Mirror mirror, Rotation rotation) { + Vec3i min = Vec3i.NULL_VECTOR; + BlockPos.Mutable pos = new BlockPos.Mutable(); + for (Vec3i vec : directions) { + BlockPos dir = Template.transform(pos.setPos(vec), mirror, rotation); + if (dir.getX() < min.getX() && dir.getZ() <= min.getZ()) { + min = dir; + continue; + } + if (dir.getZ() < min.getZ() && dir.getX() <= min.getX()) { + min = dir; + } + } + return min; + } + + private static Vec3i[] getNeighbours(IWorld world, Block block, BlockPos pos, boolean checkNeighbours) { + if (checkNeighbours) { + for (Vec3i[] dirs : DIRECTIONS) { + boolean match = true; + for (Vec3i dir : dirs) { + BlockState state = world.getBlockState(pos.add(dir)); + if (state.getBlock() != block) { + match = false; + break; + } + } + if (match) { + return dirs; + } + } + } + return CENTER; + } +} diff --git a/src/main/java/com/terraforged/mod/material/Materials.java b/src/main/java/com/terraforged/mod/material/Materials.java new file mode 100644 index 0000000..f493350 --- /dev/null +++ b/src/main/java/com/terraforged/mod/material/Materials.java @@ -0,0 +1,123 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.material; + +import com.terraforged.api.material.WGTags; +import com.terraforged.api.material.layer.LayerManager; +import com.terraforged.api.material.state.States; +import com.terraforged.core.concurrent.Resource; +import com.terraforged.mod.util.DummyBlockReader; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import it.unimi.dsi.fastutil.objects.ObjectSets; +import net.minecraft.block.AirBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.ConcretePowderBlock; +import net.minecraft.block.GrassBlock; +import net.minecraft.block.MyceliumBlock; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.Tag; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.registries.IForgeRegistryEntry; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +public class Materials { + + public final LayerManager layerManager = new LayerManager(); + public final Set stone = create(WGTags.STONE, States.STONE.getBlock()); + public final Set dirt = create(WGTags.DIRT, States.DIRT.getBlock()); + public final Set clay = create(WGTags.CLAY, States.CLAY.getBlock()); + public final Set sediment = create(WGTags.SEDIMENT, States.GRAVEL.getBlock()); + public final Set erodible = create(WGTags.ERODIBLE, null); + + public LayerManager getLayerManager() { + return layerManager; + } + + public boolean isStone(Block block) { + return stone.contains(block); + } + + public boolean isEarth(Block block) { + return dirt.contains(block); + } + + public boolean isClay(Block block) { + return clay.contains(block); + } + + public boolean isSediment(Block block) { + return sediment.contains(block); + } + + public boolean isErodible(Block block) { + return erodible.contains(block); + } + + public boolean isAir(Block block) { + return block instanceof AirBlock; + } + + public boolean isGrass(Block block) { + return block instanceof GrassBlock || block instanceof MyceliumBlock; + } + + public boolean isSand(Block block) { + return BlockTags.SAND.contains(block) && !(block instanceof ConcretePowderBlock); + } + + private static Set create(Tag tag, Block def) { + ObjectOpenHashSet set = new ObjectOpenHashSet<>(tag.getAllElements()); + if (set.isEmpty() && def != null) { + set.add(def); + } + return ObjectSets.unmodifiable(set); + } + + public static float getHardness(BlockState state) { + try (Resource reader = DummyBlockReader.pooled()) { + reader.get().set(state); + return state.getBlockHardness(reader.get(), BlockPos.ZERO); + } + } + + public static > List toList(Collection collection) { + List list = new ArrayList<>(collection); + list.sort(Materials::compare); + return Collections.unmodifiableList(list); + } + + public static int compare(IForgeRegistryEntry a, IForgeRegistryEntry b) { + String as = a.getRegistryName() + ""; + String bs = b.getRegistryName() + ""; + return as.compareTo(bs); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java b/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java similarity index 88% rename from TerraForgedMod/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java rename to src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java index a8760b9..5918dcf 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java +++ b/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java @@ -25,13 +25,11 @@ package com.terraforged.mod.material.geology; -import com.terraforged.api.material.WGTags; import com.terraforged.api.material.geology.StrataConfig; import com.terraforged.api.material.geology.StrataGenerator; -import com.terraforged.core.world.geology.Strata; -import com.terraforged.mod.material.MaterialHelper; import com.terraforged.mod.material.Materials; -import me.dags.noise.Source; +import com.terraforged.n2d.Source; +import com.terraforged.world.geology.Strata; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -50,10 +48,10 @@ public class GeoGenerator implements StrataGenerator { public GeoGenerator(Materials materials) { types.add(Source.PERLIN); - rock = new ArrayList<>(WGTags.STONE.getAllElements()); - soil = new ArrayList<>(WGTags.DIRT.getAllElements()); - clay = new ArrayList<>(WGTags.CLAY.getAllElements()); - sediment = new ArrayList<>(WGTags.SEDIMENT.getAllElements()); + rock = Materials.toList(materials.stone); + soil = Materials.toList(materials.dirt); + clay = Materials.toList(materials.clay); + sediment = Materials.toList(materials.sediment); } @Override @@ -100,7 +98,7 @@ public class GeoGenerator implements StrataGenerator { } private List sortHardness(List layers) { - layers.sort(Comparator.comparing(s -> MaterialHelper.getHardness(s.state))); + layers.sort(Comparator.comparing(s -> Materials.getHardness(s.state))); return layers; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/material/geology/GeoManager.java b/src/main/java/com/terraforged/mod/material/geology/GeoManager.java similarity index 93% rename from TerraForgedMod/src/main/java/com/terraforged/mod/material/geology/GeoManager.java rename to src/main/java/com/terraforged/mod/material/geology/GeoManager.java index 2b6634b..c1a7163 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/material/geology/GeoManager.java +++ b/src/main/java/com/terraforged/mod/material/geology/GeoManager.java @@ -27,13 +27,13 @@ package com.terraforged.mod.material.geology; import com.terraforged.api.material.geology.GeologyManager; import com.terraforged.api.material.geology.StrataConfig; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.geology.Geology; -import com.terraforged.core.world.geology.Strata; import com.terraforged.mod.chunk.TerraContext; +import com.terraforged.core.Seed; import com.terraforged.mod.material.Materials; -import me.dags.noise.Module; -import me.dags.noise.Source; +import com.terraforged.n2d.Module; +import com.terraforged.n2d.Source; +import com.terraforged.world.geology.Geology; +import com.terraforged.world.geology.Strata; import net.minecraft.block.BlockState; import net.minecraft.world.biome.Biome; @@ -49,7 +49,7 @@ public class GeoManager implements GeologyManager { private final Map> specific = new HashMap<>(); public GeoManager(TerraContext context) { - int scale = context.settings.generator.land.regionSize / 2; + int scale = context.settings.terrain.general.terrainRegionSize / 2; this.selector = Source.cell(context.seed.next(), scale) .warp(context.seed.next(), scale / 4, 2, scale / 2D) .warp(context.seed.next(), 15, 2, 30); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java b/src/main/java/com/terraforged/mod/server/command/TerraCommand.java similarity index 67% rename from TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java rename to src/main/java/com/terraforged/mod/server/command/TerraCommand.java index 00b8a27..80919a5 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java +++ b/src/main/java/com/terraforged/mod/server/command/TerraCommand.java @@ -23,31 +23,34 @@ * SOFTWARE. */ -package com.terraforged.mod.command; +package com.terraforged.mod.server.command; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import com.terraforged.core.cell.Cell; -import com.terraforged.core.world.WorldGenerator; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; import com.terraforged.mod.Log; -import com.terraforged.mod.biome.provider.BiomeProvider; +import com.terraforged.mod.biome.provider.TerraBiomeProvider; import com.terraforged.mod.chunk.TerraChunkGenerator; import com.terraforged.mod.chunk.TerraContext; -import com.terraforged.mod.command.arg.BiomeArgType; -import com.terraforged.mod.command.arg.TerrainArgType; -import com.terraforged.mod.command.search.BiomeSearchTask; -import com.terraforged.mod.command.search.BothSearchTask; -import com.terraforged.mod.command.search.Search; -import com.terraforged.mod.command.search.TerrainSearchTask; +import com.terraforged.mod.chunk.settings.SettingsHelper; +import com.terraforged.mod.server.command.arg.BiomeArgType; +import com.terraforged.mod.server.command.arg.TerrainArgType; +import com.terraforged.mod.server.command.search.BiomeSearchTask; +import com.terraforged.mod.server.command.search.BothSearchTask; +import com.terraforged.mod.server.command.search.Search; +import com.terraforged.mod.server.command.search.TerrainSearchTask; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.concurrent.Resource; import com.terraforged.mod.data.DataGen; -import com.terraforged.mod.settings.SettingsHelper; +import com.terraforged.world.WorldGenerator; +import com.terraforged.world.terrain.Terrain; +import com.terraforged.world.terrain.Terrains; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; +import net.minecraft.command.arguments.ArgumentSerializer; import net.minecraft.command.arguments.ArgumentTypes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -60,29 +63,26 @@ import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; -import net.minecraft.world.IWorldReader; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.ColumnFuzzedBiomeMagnifier; import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; -import net.minecraftforge.server.permission.DefaultPermissionLevel; -import net.minecraftforge.server.permission.PermissionAPI; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.function.Predicate; import java.util.function.Supplier; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) public class TerraCommand { public static void init() { - ArgumentTypes.register("terraforged:biome", BiomeArgType.class, new BiomeArgType.Serializer()); - ArgumentTypes.register("terraforged:terrain", TerrainArgType.class, new TerrainArgType.Serializer()); + ArgumentTypes.register("terraforged:biome", BiomeArgType.class, new ArgumentSerializer<>(BiomeArgType::new)); + ArgumentTypes.register("terraforged:terrain", TerrainArgType.class, new ArgumentSerializer<>(TerrainArgType::new)); } @SubscribeEvent @@ -92,59 +92,33 @@ public class TerraCommand { } public static void register(CommandDispatcher dispatcher) { - registerSimple(dispatcher); - registerLocate(dispatcher); - PermissionAPI.registerNode(Permissions.QUERY, DefaultPermissionLevel.OP, "Allows use of the query command"); - PermissionAPI.registerNode(Permissions.DATA, DefaultPermissionLevel.OP, "Allows use of the data command"); - PermissionAPI.registerNode(Permissions.DEFAULTS, DefaultPermissionLevel.OP, "Allows use of the defaults command"); - PermissionAPI.registerNode(Permissions.DEBUG, DefaultPermissionLevel.OP, "Allows use of the debug command"); - PermissionAPI.registerNode(Permissions.LOCATE, DefaultPermissionLevel.OP, "Allows use of the locate command"); + dispatcher.register(command()); } - private static void registerSimple(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("terra") + private static LiteralArgumentBuilder command() { + return Commands.literal("terra") + .requires(source -> source.hasPermissionLevel(2)) .then(Commands.literal("query") - .requires(perm(Permissions.QUERY)) .executes(TerraCommand::query)) .then(Commands.literal("data") - .requires(perm(Permissions.DATA)) .then(Commands.literal("dump") .executes(TerraCommand::dump))) .then(Commands.literal("defaults") - .requires(perm(Permissions.DEFAULTS)) .then(Commands.literal("set") .executes(TerraCommand::setDefaults))) .then(Commands.literal("debug") - .requires(perm(Permissions.DEBUG)) - .executes(TerraCommand::debugBiome))); - } - - private static void registerLocate(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("terra") + .executes(TerraCommand::debugBiome)) .then(Commands.literal("locate") - .requires(perm(Permissions.LOCATE)) - .then(Commands.argument("biome", BiomeArgType.biome()) - .executes(TerraCommand::findBiome)))); - - dispatcher.register(Commands.literal("terra") - .then(Commands.literal("locate") - .requires(perm(Permissions.LOCATE)) - .then(Commands.argument("terrain", TerrainArgType.terrain()) - .executes(TerraCommand::findTerrain)))); - - dispatcher.register(Commands.literal("terra") - .then(Commands.literal("locate") - .requires(perm(Permissions.LOCATE)) - .then(Commands.argument("biome", BiomeArgType.biome()) - .then(Commands.argument("terrain", TerrainArgType.terrain()) - .executes(TerraCommand::findTerrainAndBiome))))); - - dispatcher.register(Commands.literal("terra") - .then(Commands.literal("locate") - .requires(perm(Permissions.LOCATE)) - .then(Commands.argument("terrain", TerrainArgType.terrain()) + .then(Commands.literal("biome") .then(Commands.argument("biome", BiomeArgType.biome()) - .executes(TerraCommand::findTerrainAndBiome))))); + .executes(TerraCommand::findBiome))) + .then(Commands.literal("terrain") + .then(Commands.argument("terrain", TerrainArgType.terrain()) + .executes(TerraCommand::findTerrain))) + .then(Commands.literal("both") + .then(Commands.argument("biome", BiomeArgType.biome()) + .then(Commands.argument("terrain", TerrainArgType.terrain()) + .executes(TerraCommand::findTerrainAndBiome))))); } private static int query(CommandContext context) throws CommandSyntaxException { @@ -154,13 +128,14 @@ public class TerraCommand { )); BlockPos pos = context.getSource().asPlayer().getPosition(); - BiomeProvider biomeProvider = getBiomeProvider(context); - Cell cell = biomeProvider.lookupPos(pos.getX(), pos.getZ()); - Biome biome = biomeProvider.getBiome(cell, pos.getX(), pos.getZ()); - context.getSource().sendFeedback( - new StringTextComponent("Terrain=" + cell.tag.getName() + ", Biome=" + biome.getRegistryName()), - false - ); + TerraBiomeProvider biomeProvider = getBiomeProvider(context); + try (Resource cell = biomeProvider.lookupPos(pos.getX(), pos.getZ())) { + Biome biome = biomeProvider.getBiome(cell.get(), pos.getX(), pos.getZ()); + context.getSource().sendFeedback( + new StringTextComponent("Terrain=" + cell.get().terrain.getName() + ", Biome=" + biome.getRegistryName()), + false + ); + } return Command.SINGLE_SUCCESS; } @@ -192,7 +167,6 @@ public class TerraCommand { ServerPlayerEntity player = context.getSource().asPlayer(); BlockPos position = player.getPosition(); int x = position.getX(); - int y = position.getY(); int z = position.getZ(); long seed = player.getServerWorld().getSeed(); @@ -216,21 +190,21 @@ public class TerraCommand { )); Terrain terrain = TerrainArgType.getTerrain(context, "terrain"); - Terrain target = getTerrainInstance(terrain, terraContext.terrain); + Terrain type = getTerrainInstance(terrain, terraContext.terrain); BlockPos pos = context.getSource().asPlayer().getPosition(); UUID playerID = context.getSource().asPlayer().getUniqueID(); MinecraftServer server = context.getSource().getServer(); - WorldGenerator worldGenerator = terraContext.factory.get(); - Search search = new TerrainSearchTask(pos, worldGenerator, target); + WorldGenerator generator = terraContext.factory.get(); + Search search = new TerrainSearchTask(pos, type, getChunkGenerator(context), generator); doSearch(server, playerID, search); - context.getSource().sendFeedback(new StringTextComponent("Locating terrain..."), false); + context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); return Command.SINGLE_SUCCESS; } private static int findBiome(CommandContext context) throws CommandSyntaxException { // get the generator's context - TerraContext terraContext = getContext(context).orElseThrow(() -> createException( + getContext(context).orElseThrow(() -> createException( "Invalid world type", "This command can only be run in a TerraForged world!" )); @@ -239,10 +213,10 @@ public class TerraCommand { BlockPos pos = context.getSource().asPlayer().getPosition(); UUID playerID = context.getSource().asPlayer().getUniqueID(); MinecraftServer server = context.getSource().getServer(); - IWorldReader reader = context.getSource().asPlayer().getServerWorld(); - Search search = new BiomeSearchTask(pos, reader, biome); + ServerWorld world = context.getSource().asPlayer().getServerWorld(); + Search search = new BiomeSearchTask(pos, biome, world.getChunkProvider().getChunkGenerator(), getBiomeProvider(context)); doSearch(server, playerID, search); - context.getSource().sendFeedback(new StringTextComponent("Locating biome..."), false); + context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); return Command.SINGLE_SUCCESS; } @@ -258,15 +232,14 @@ public class TerraCommand { Terrain target = getTerrainInstance(terrain, terraContext.terrain); Biome biome = BiomeArgType.getBiome(context, "biome"); BlockPos pos = context.getSource().asPlayer().getPosition(); - IWorldReader world = context.getSource().asPlayer().getServerWorld(); UUID playerID = context.getSource().asPlayer().getUniqueID(); MinecraftServer server = context.getSource().getServer(); - WorldGenerator worldGenerator = terraContext.factory.get(); - Search biomeSearch = new BiomeSearchTask(pos, world, biome); - Search terrainSearch = new TerrainSearchTask(pos, worldGenerator, target); + WorldGenerator generator = terraContext.factory.get(); + Search biomeSearch = new BiomeSearchTask(pos, biome, getChunkGenerator(context), getBiomeProvider(context)); + Search terrainSearch = new TerrainSearchTask(pos, target, getChunkGenerator(context), generator); Search search = new BothSearchTask(pos, biomeSearch, terrainSearch); doSearch(server, playerID, search); - context.getSource().sendFeedback(new StringTextComponent("Locating biome & terrain..."), false); + context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); return Command.SINGLE_SUCCESS; } @@ -283,8 +256,11 @@ public class TerraCommand { return; } + double distance = Math.sqrt(player.getPosition().distanceSq(pos)); + ITextComponent result = new StringTextComponent("Nearest match: ") - .appendSibling(createTeleportMessage(pos)); + .appendSibling(createTeleportMessage(pos)) + .appendSibling(new StringTextComponent(String.format(" Distance: %.2f", distance))); player.sendMessage(result); })); @@ -304,33 +280,20 @@ public class TerraCommand { // the terrain parsed from the command will not be the same instance as used in the // world generator, so find the matching instance by name private static Terrain getTerrainInstance(Terrain find, Terrains terrains) { - // search for exact match first for (Terrain t : terrains.index) { if (t.getName().equals(find.getName())) { return t; } } - // find a mixed terrain as a fallback - for (Terrain t : terrains.index) { - if (t.getName().contains("-") && t.getName().contains(find.getName())) { - return t; - } - } return find; } - private static Predicate perm(String node) { - return source -> { - try { - return PermissionAPI.hasPermission(source.asPlayer(), node); - } catch (Throwable t) { - return source.hasPermissionLevel(2); - } - }; + private static ChunkGenerator getChunkGenerator(CommandContext context) { + return context.getSource().getWorld().getChunkProvider().getChunkGenerator(); } - private static BiomeProvider getBiomeProvider(CommandContext context) { - return (BiomeProvider) context.getSource().getWorld().getChunkProvider().getChunkGenerator().getBiomeProvider(); + private static TerraBiomeProvider getBiomeProvider(CommandContext context) { + return (TerraBiomeProvider) context.getSource().getWorld().getChunkProvider().getChunkGenerator().getBiomeProvider(); } private static CommandSyntaxException createException(String type, String message, Object... args) { @@ -344,7 +307,7 @@ public class TerraCommand { return TextComponentUtils.wrapInSquareBrackets(new TranslationTextComponent( "chat.coordinates", pos.getX(), "~", pos.getZ() )).applyTextStyle((style) -> style.setColor(TextFormatting.GREEN) - .setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + pos.getX() + " ~ " + pos.getZ())) + .setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + pos.getX() + " " + pos.getY() + " " + pos.getZ())) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.coordinates.tooltip"))) ); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java b/src/main/java/com/terraforged/mod/server/command/arg/BiomeArgType.java similarity index 65% rename from TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java rename to src/main/java/com/terraforged/mod/server/command/arg/BiomeArgType.java index 0053536..01f3fbd 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java +++ b/src/main/java/com/terraforged/mod/server/command/arg/BiomeArgType.java @@ -23,9 +23,8 @@ * SOFTWARE. */ -package com.terraforged.mod.command.arg; +package com.terraforged.mod.server.command.arg; -import com.google.gson.JsonObject; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; @@ -34,9 +33,8 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.command.ISuggestionProvider; -import net.minecraft.command.arguments.IArgumentSerializer; -import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.Registry; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.biome.Biome; import net.minecraftforge.registries.ForgeRegistries; @@ -47,28 +45,9 @@ public class BiomeArgType implements ArgumentType { @Override public Biome parse(StringReader reader) throws CommandSyntaxException { - int cursor = reader.getCursor(); - String raw = reader.getString().substring(cursor); - - if (raw.indexOf(':') == -1) { - reader.setCursor(cursor); - throw createException("Invalid biome", "%s is not a valid biome", raw); - } - - ResourceLocation resourcelocation = ResourceLocation.tryCreate(raw); - if (resourcelocation == null) { - reader.setCursor(cursor); - throw createException("Invalid biome", "%s is not a valid biome", raw); - } - - if (!ForgeRegistries.BIOMES.containsKey(resourcelocation)) { - reader.setCursor(cursor); - throw createException("Invalid biome", "%s is not a valid biome", resourcelocation); - } - - reader.setCursor(reader.getString().length()); - - return ForgeRegistries.BIOMES.getValue(resourcelocation); + ResourceLocation resourcelocation = ResourceLocation.read(reader); + return Registry.BIOME.getValue(resourcelocation) + .orElseThrow(() -> createException("Invalid biome", "%s is not a valid biome", resourcelocation)); } @Override @@ -90,22 +69,4 @@ public class BiomeArgType implements ArgumentType { public static Biome getBiome(CommandContext context, String name) { return context.getArgument(name, Biome.class); } - - public static class Serializer implements IArgumentSerializer { - - @Override - public void write(BiomeArgType type, PacketBuffer buffer) { - - } - - @Override - public BiomeArgType read(PacketBuffer buffer) { - return new BiomeArgType(); - } - - @Override - public void write(BiomeArgType type, JsonObject json) { - - } - } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java b/src/main/java/com/terraforged/mod/server/command/arg/TerrainArgType.java similarity index 77% rename from TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java rename to src/main/java/com/terraforged/mod/server/command/arg/TerrainArgType.java index dc843a0..edae287 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/TerrainArgType.java +++ b/src/main/java/com/terraforged/mod/server/command/arg/TerrainArgType.java @@ -23,9 +23,8 @@ * SOFTWARE. */ -package com.terraforged.mod.command.arg; +package com.terraforged.mod.server.command.arg; -import com.google.gson.JsonObject; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; @@ -33,12 +32,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import com.terraforged.core.settings.Settings; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.core.world.terrain.Terrains; +import com.terraforged.world.terrain.Terrain; import net.minecraft.command.ISuggestionProvider; -import net.minecraft.command.arguments.IArgumentSerializer; -import net.minecraft.network.PacketBuffer; import net.minecraft.util.text.StringTextComponent; import java.util.List; @@ -47,7 +42,7 @@ import java.util.stream.Collectors; public class TerrainArgType implements ArgumentType { - private final List terrains = createTerrainList(); + private final List terrains = Terrain.getRegistered(); @Override public Terrain parse(StringReader reader) throws CommandSyntaxException { @@ -81,26 +76,4 @@ public class TerrainArgType implements ArgumentType { new StringTextComponent(String.format(message, args)) ); } - - private static List createTerrainList() { - return Terrains.create(new Settings()).index; - } - - public static class Serializer implements IArgumentSerializer { - - @Override - public void write(TerrainArgType type, PacketBuffer buffer) { - - } - - @Override - public TerrainArgType read(PacketBuffer buffer) { - return new TerrainArgType(); - } - - @Override - public void write(TerrainArgType type, JsonObject json) { - - } - } } diff --git a/src/main/java/com/terraforged/mod/server/command/search/BiomeSearchTask.java b/src/main/java/com/terraforged/mod/server/command/search/BiomeSearchTask.java new file mode 100644 index 0000000..01cd6c6 --- /dev/null +++ b/src/main/java/com/terraforged/mod/server/command/search/BiomeSearchTask.java @@ -0,0 +1,32 @@ +package com.terraforged.mod.server.command.search; + +import com.terraforged.mod.biome.provider.TerraBiomeProvider; +import com.terraforged.core.cell.Cell; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.ChunkGenerator; + +public class BiomeSearchTask extends ChunkGeneratorSearch { + + private final Biome biome; + private final TerraBiomeProvider biomeProvider; + + private final Cell cell = new Cell(); + + public BiomeSearchTask(BlockPos center, Biome biome, ChunkGenerator generator, TerraBiomeProvider biomeProvider) { + super(center, generator); + this.biomeProvider = biomeProvider; + this.biome = biome; + } + + @Override + public int getSpacing() { + return 10; + } + + @Override + public boolean test(BlockPos pos) { + biomeProvider.getWorldLookup().applyCell(cell, pos.getX(), pos.getZ()); + return biomeProvider.getBiome(cell, pos.getX(), pos.getZ()) == biome; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/BothSearchTask.java b/src/main/java/com/terraforged/mod/server/command/search/BothSearchTask.java similarity index 79% rename from TerraForgedMod/src/main/java/com/terraforged/mod/command/search/BothSearchTask.java rename to src/main/java/com/terraforged/mod/server/command/search/BothSearchTask.java index 8dd576e..97b7a4b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/BothSearchTask.java +++ b/src/main/java/com/terraforged/mod/server/command/search/BothSearchTask.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.command.search; +package com.terraforged.mod.server.command.search; import net.minecraft.util.math.BlockPos; @@ -24,4 +24,9 @@ public class BothSearchTask extends Search { public boolean test(BlockPos pos) { return a.test(pos) && b.test(pos); } + + @Override + public BlockPos success(BlockPos.Mutable pos) { + return a.success(pos); + } } diff --git a/src/main/java/com/terraforged/mod/server/command/search/ChunkGeneratorSearch.java b/src/main/java/com/terraforged/mod/server/command/search/ChunkGeneratorSearch.java new file mode 100644 index 0000000..dff4e17 --- /dev/null +++ b/src/main/java/com/terraforged/mod/server/command/search/ChunkGeneratorSearch.java @@ -0,0 +1,30 @@ +package com.terraforged.mod.server.command.search; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.gen.ChunkGenerator; +import net.minecraft.world.gen.Heightmap; + +public abstract class ChunkGeneratorSearch extends Search { + + private final ChunkGenerator chunkGenerator; + + public ChunkGeneratorSearch(BlockPos center, ChunkGenerator chunkGenerator) { + super(center); + this.chunkGenerator = chunkGenerator; + } + + public ChunkGeneratorSearch(BlockPos center, int minRadius, ChunkGenerator chunkGenerator) { + this(center, minRadius, MAX_RADIUS, chunkGenerator); + } + + public ChunkGeneratorSearch(BlockPos center, int minRadius, int maxRadius, ChunkGenerator chunkGenerator) { + super(center, minRadius, maxRadius); + this.chunkGenerator = chunkGenerator; + } + + @Override + public BlockPos success(BlockPos.Mutable pos) { + pos.setY(chunkGenerator.func_222529_a(pos.getX(), pos.getZ(), Heightmap.Type.WORLD_SURFACE_WG)); + return pos; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/Search.java b/src/main/java/com/terraforged/mod/server/command/search/Search.java similarity index 94% rename from TerraForgedMod/src/main/java/com/terraforged/mod/command/search/Search.java rename to src/main/java/com/terraforged/mod/server/command/search/Search.java index 3bc5f1a..b27edae 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/search/Search.java +++ b/src/main/java/com/terraforged/mod/server/command/search/Search.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.command.search; +package com.terraforged.mod.server.command.search; import net.minecraft.util.math.BlockPos; @@ -38,14 +38,6 @@ public abstract class Search implements Supplier { return 16; } - protected BlockPos success(BlockPos.Mutable pos) { - return pos.toImmutable(); - } - - protected BlockPos fail(BlockPos pos) { - return pos; - } - @Override public BlockPos get() { int radius = maxRadius; @@ -87,4 +79,12 @@ public abstract class Search implements Supplier { } public abstract boolean test(BlockPos pos); + + public BlockPos success(BlockPos.Mutable pos) { + return pos.toImmutable(); + } + + public BlockPos fail(BlockPos pos) { + return pos; + } } diff --git a/src/main/java/com/terraforged/mod/server/command/search/TerrainSearchTask.java b/src/main/java/com/terraforged/mod/server/command/search/TerrainSearchTask.java new file mode 100644 index 0000000..ce24ea8 --- /dev/null +++ b/src/main/java/com/terraforged/mod/server/command/search/TerrainSearchTask.java @@ -0,0 +1,31 @@ +package com.terraforged.mod.server.command.search; + +import com.terraforged.core.cell.Cell; +import com.terraforged.world.WorldGenerator; +import com.terraforged.world.terrain.Terrain; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.gen.ChunkGenerator; + +public class TerrainSearchTask extends ChunkGeneratorSearch { + + private final Terrain type; + private final WorldGenerator worldGenerator; + private final Cell cell = new Cell(); + + public TerrainSearchTask(BlockPos center, Terrain type, ChunkGenerator chunkGenerator, WorldGenerator worldGenerator) { + super(center, 256, chunkGenerator); + this.type = type; + this.worldGenerator = worldGenerator; + } + + @Override + public int getSpacing() { + return 20; + } + + @Override + public boolean test(BlockPos pos) { + worldGenerator.getHeightmap().apply(cell, pos.getX(), pos.getZ()); + return cell.terrain == type; + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/DataPackFinder.java b/src/main/java/com/terraforged/mod/util/DataPackFinder.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/DataPackFinder.java rename to src/main/java/com/terraforged/mod/util/DataPackFinder.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/DummyBlockReader.java b/src/main/java/com/terraforged/mod/util/DummyBlockReader.java similarity index 93% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/DummyBlockReader.java rename to src/main/java/com/terraforged/mod/util/DummyBlockReader.java index 00254c4..dc45f37 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/DummyBlockReader.java +++ b/src/main/java/com/terraforged/mod/util/DummyBlockReader.java @@ -25,7 +25,8 @@ package com.terraforged.mod.util; -import com.terraforged.core.util.concurrent.ObjectPool; +import com.terraforged.core.concurrent.Resource; +import com.terraforged.core.concurrent.pool.ObjectPool; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.fluid.FluidState; @@ -74,7 +75,7 @@ public class DummyBlockReader implements IBlockReader { return fluid; } - public static ObjectPool.Item pooled() { + public static Resource pooled() { return pool.get(); } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/Environment.java b/src/main/java/com/terraforged/mod/util/Environment.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/Environment.java rename to src/main/java/com/terraforged/mod/util/Environment.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/ListUtils.java b/src/main/java/com/terraforged/mod/util/ListUtils.java similarity index 98% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/ListUtils.java rename to src/main/java/com/terraforged/mod/util/ListUtils.java index 608d5be..5268c02 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/ListUtils.java +++ b/src/main/java/com/terraforged/mod/util/ListUtils.java @@ -25,7 +25,7 @@ package com.terraforged.mod.util; -import me.dags.noise.util.NoiseUtil; +import com.terraforged.n2d.util.NoiseUtil; import java.util.ArrayList; import java.util.HashMap; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/NBTLeavesFixer.java b/src/main/java/com/terraforged/mod/util/NBTLeavesFixer.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/NBTLeavesFixer.java rename to src/main/java/com/terraforged/mod/util/NBTLeavesFixer.java diff --git a/src/main/java/com/terraforged/mod/util/RangeModifier.java b/src/main/java/com/terraforged/mod/util/RangeModifier.java new file mode 100644 index 0000000..e360f0a --- /dev/null +++ b/src/main/java/com/terraforged/mod/util/RangeModifier.java @@ -0,0 +1,37 @@ +package com.terraforged.mod.util; + +public abstract class RangeModifier { + + protected final float from; + protected final float to; + protected final float max; + private final float range; + + public RangeModifier(float from, float max, boolean exclusive) { + this.from = from; + this.to = max; + this.max = exclusive ? 0 : 1; + this.range = Math.abs(max - from); + } + + public float apply(float value) { + if (from < to) { + if (value <= from) { + return 0F; + } + if (value >= to) { + return max; + } + return (value - from) / range; + } else if (from > to) { + if (value <= to) { + return max; + } + if (value >= from) { + return 0F; + } + return 1 - ((value - to) / range); + } + return 0F; + } +} diff --git a/src/main/java/com/terraforged/mod/util/TranslationKey.java b/src/main/java/com/terraforged/mod/util/TranslationKey.java new file mode 100644 index 0000000..bdba02c --- /dev/null +++ b/src/main/java/com/terraforged/mod/util/TranslationKey.java @@ -0,0 +1,59 @@ +package com.terraforged.mod.util; + +import com.terraforged.core.util.NameUtil; +import net.minecraft.client.resources.I18n; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +public class TranslationKey { + + private static final Map keys = new HashMap<>(); + + private final String translationKey; + private final String defaultValue; + + public TranslationKey(String key, String display) { + this.translationKey = key; + this.defaultValue = display; + keys.put(translationKey, this); + } + + public String getKey() { + return translationKey; + } + + public String getDefaultValue() { + return defaultValue; + } + + public String get() { + if (I18n.hasKey(translationKey)) { + return I18n.format(translationKey); + } + return defaultValue; + } + + public String get(Object... args) { + if (I18n.hasKey(translationKey)) { + return I18n.format(translationKey, args); + } + return defaultValue; + } + + public static void each(Consumer consumer) { + keys.values().stream().sorted(Comparator.comparing(TranslationKey::getKey)).forEach(consumer); + } + + public static TranslationKey gui(String text) { + String key = NameUtil.toDisplayNameKey(text); + String display = NameUtil.toDisplayName(text.substring(text.lastIndexOf('.') + 1)); + return new TranslationKey(key, display); + } + + public static TranslationKey gui(String key, String display) { + return new TranslationKey(NameUtil.toDisplayNameKey(key), display); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/annotation/Name.java b/src/main/java/com/terraforged/mod/util/annotation/Name.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/annotation/Name.java rename to src/main/java/com/terraforged/mod/util/annotation/Name.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/annotation/Ref.java b/src/main/java/com/terraforged/mod/util/annotation/Ref.java similarity index 100% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/annotation/Ref.java rename to src/main/java/com/terraforged/mod/util/annotation/Ref.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTHelper.java b/src/main/java/com/terraforged/mod/util/nbt/NBTHelper.java similarity index 88% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTHelper.java rename to src/main/java/com/terraforged/mod/util/nbt/NBTHelper.java index a2c486f..536261a 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTHelper.java +++ b/src/main/java/com/terraforged/mod/util/nbt/NBTHelper.java @@ -28,7 +28,7 @@ package com.terraforged.mod.util.nbt; import com.google.gson.JsonElement; import com.mojang.datafixers.Dynamic; import com.mojang.datafixers.types.JsonOps; -import com.terraforged.core.util.serialization.serializer.Serializer; +import com.terraforged.core.serialization.serializer.Serializer; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; @@ -53,17 +53,14 @@ public class NBTHelper { return (CompoundNBT) output.getValue(); } - public static Stream stream(CompoundNBT tag) { - return tag.keySet().stream() - .map(tag::getCompound) - .sorted(Comparator.comparing(t -> t.getInt("#order"))); - + public static CompoundNBT serialize(Object object) { + return serialize("", object); } - public static CompoundNBT serialize(Object object) { + public static CompoundNBT serialize(String owner, Object object) { try { NBTWriter writer = new NBTWriter(); - writer.readFrom(object); + Serializer.serialize(object, writer, owner, true); return writer.compound(); } catch (IllegalAccessException e) { return new CompoundNBT(); @@ -91,6 +88,12 @@ public class NBTHelper { } } + public static Stream streamkeys(CompoundNBT compound) { + return compound.keySet().stream() + .filter(name -> !name.startsWith("#")) + .sorted(Comparator.comparing(name -> compound.getCompound("#" + name).getInt("order"))); + } + public static T stripMetadata(T tag) { if (tag instanceof CompoundNBT) { CompoundNBT compound = (CompoundNBT) tag; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTReader.java b/src/main/java/com/terraforged/mod/util/nbt/NBTReader.java similarity index 97% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTReader.java rename to src/main/java/com/terraforged/mod/util/nbt/NBTReader.java index 2ed5270..e634bf1 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/nbt/NBTReader.java +++ b/src/main/java/com/terraforged/mod/util/nbt/NBTReader.java @@ -25,7 +25,7 @@ package com.terraforged.mod.util.nbt; -import com.terraforged.core.util.serialization.serializer.Reader; +import com.terraforged.core.serialization.serializer.Reader; import net.minecraft.nbt.ByteNBT; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.FloatNBT; diff --git a/src/main/java/com/terraforged/mod/util/nbt/NBTWriter.java b/src/main/java/com/terraforged/mod/util/nbt/NBTWriter.java new file mode 100644 index 0000000..4e793f8 --- /dev/null +++ b/src/main/java/com/terraforged/mod/util/nbt/NBTWriter.java @@ -0,0 +1,66 @@ +package com.terraforged.mod.util.nbt; + +import com.terraforged.core.serialization.serializer.AbstractWriter; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.FloatNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.IntNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.StringNBT; + +public class NBTWriter extends AbstractWriter { + + public CompoundNBT compound() { + return (CompoundNBT) getRoot(); + } + + @Override + protected NBTWriter self() { + return this; + } + + @Override + protected boolean isObject(INBT value) { + return value instanceof CompoundNBT; + } + + @Override + protected boolean isArray(INBT value) { + return value instanceof ListNBT; + } + + @Override + protected void add(INBT parent, String key, INBT value) { + ((CompoundNBT) parent).put(key, value); + } + + @Override + protected void add(INBT parent, INBT value) { + ((ListNBT) parent).add(value); + } + + @Override + protected INBT createObject() { + return new CompoundNBT(); + } + + @Override + protected INBT createArray() { + return new ListNBT(); + } + + @Override + protected INBT create(String value) { + return StringNBT.valueOf(value); + } + + @Override + protected INBT create(int value) { + return IntNBT.valueOf(value); + } + + @Override + protected INBT create(float value) { + return FloatNBT.valueOf(value); + } +} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/setup/SetupDebug.java b/src/main/java/com/terraforged/mod/util/setup/SetupDebug.java similarity index 61% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/setup/SetupDebug.java rename to src/main/java/com/terraforged/mod/util/setup/SetupDebug.java index f0b73da..75f01b9 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/setup/SetupDebug.java +++ b/src/main/java/com/terraforged/mod/util/setup/SetupDebug.java @@ -25,8 +25,15 @@ package com.terraforged.mod.util.setup; -import com.terraforged.api.event.SetupEvent; import com.terraforged.mod.Log; +import com.terraforged.api.event.SetupEvent; +import com.terraforged.core.Seed; +import com.terraforged.n2d.Source; +import com.terraforged.n2d.source.Builder; +import com.terraforged.world.geology.Strata; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.world.biome.Biomes; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -50,7 +57,24 @@ public class SetupDebug { @SubscribeEvent public static void geology(SetupEvent.Geology event) { - log(event); + Seed seed = event.getContext().seed; + + // Noise parameters used to vary the depth of the strata bands + Builder noise = Source.build(seed.next(), 150, 1); + + // Set each layer material & its relative depth (top to bottom) + Strata strata = Strata.builder(seed.next(), noise) + .add(Blocks.STONE.getDefaultState(), 0.5) + .add(Blocks.GRANITE.getDefaultState(), 0.3) + .add(Blocks.DIORITE.getDefaultState(), 0.2) + // Note - you can specify the noise type to be used for a layer using the Source enum (default is Perlin) + .add(Source.RIDGE, Blocks.STONE.getDefaultState(), 0.1) + .build(); + + // Register to a specific biome. This creates a new geology system specific to that biome. The boolean + // flag 'inheritGlobal' determines whether global strata layers should be copied to this new geology system. + // If set false then only the strata specifically registered to it will be used. + event.getManager().register(Biomes.OCEAN, strata, true); } @SubscribeEvent diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/setup/SetupHooks.java b/src/main/java/com/terraforged/mod/util/setup/SetupHooks.java similarity index 86% rename from TerraForgedMod/src/main/java/com/terraforged/mod/util/setup/SetupHooks.java rename to src/main/java/com/terraforged/mod/util/setup/SetupHooks.java index f533316..2c1d37c 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/util/setup/SetupHooks.java +++ b/src/main/java/com/terraforged/mod/util/setup/SetupHooks.java @@ -28,13 +28,14 @@ package com.terraforged.mod.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; -import com.terraforged.core.world.GeneratorContext; -import com.terraforged.core.world.terrain.provider.TerrainProvider; -import com.terraforged.feature.modifier.FeatureModifiers; +import com.terraforged.fm.modifier.FeatureModifiers; +import com.terraforged.fm.structure.StructureManager; +import com.terraforged.world.GeneratorContext; +import com.terraforged.world.terrain.provider.TerrainProvider; import net.minecraftforge.common.MinecraftForge; import java.util.List; @@ -71,6 +72,11 @@ public class SetupHooks { return manager; } + public static T setup(T manager, GeneratorContext context) { + MinecraftForge.EVENT_BUS.post(new SetupEvent.Structures(manager, context)); + return manager; + } + public static void setup(List base, List feature, GeneratorContext context) { MinecraftForge.EVENT_BUS.post(new SetupEvent.Decorators(new DecoratorManager(base, feature), context)); } diff --git a/TerraForgedMod/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml similarity index 100% rename from TerraForgedMod/src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/mods.toml diff --git a/TerraForgedMod/src/main/resources/biomes.txt b/src/main/resources/biomes.txt similarity index 100% rename from TerraForgedMod/src/main/resources/biomes.txt rename to src/main/resources/biomes.txt diff --git a/TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_clay.json b/src/main/resources/data/forge/tags/blocks/wg_clay.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_clay.json rename to src/main/resources/data/forge/tags/blocks/wg_clay.json diff --git a/TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_dirt.json b/src/main/resources/data/forge/tags/blocks/wg_dirt.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_dirt.json rename to src/main/resources/data/forge/tags/blocks/wg_dirt.json diff --git a/TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_erodible.json b/src/main/resources/data/forge/tags/blocks/wg_erodible.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_erodible.json rename to src/main/resources/data/forge/tags/blocks/wg_erodible.json diff --git a/TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_sediment.json b/src/main/resources/data/forge/tags/blocks/wg_sediment.json similarity index 56% rename from TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_sediment.json rename to src/main/resources/data/forge/tags/blocks/wg_sediment.json index f605778..90c0616 100644 --- a/TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_sediment.json +++ b/src/main/resources/data/forge/tags/blocks/wg_sediment.json @@ -2,7 +2,6 @@ "replace": false, "values": [ "minecraft:sand", - "minecraft:gravel", - "minecraft:red_sand" + "minecraft:gravel" ] } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_stone.json b/src/main/resources/data/forge/tags/blocks/wg_stone.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/forge/tags/blocks/wg_stone.json rename to src/main/resources/data/forge/tags/blocks/wg_stone.json diff --git a/src/main/resources/data/terraforged/blocks/saplings/birch_sapling.json b/src/main/resources/data/terraforged/blocks/saplings/birch_sapling.json new file mode 100644 index 0000000..6d605e7 --- /dev/null +++ b/src/main/resources/data/terraforged/blocks/saplings/birch_sapling.json @@ -0,0 +1,12 @@ +{ + "type": "terraforged:sapling", + "sapling": "minecraft:birch_sapling", + "normal": { + "terraforged:birch_small": { + "weight": 1 + }, + "terraforged:birch_large": { + "weight": 2 + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/blocks/saplings/jungle_sapling.json b/src/main/resources/data/terraforged/blocks/saplings/jungle_sapling.json new file mode 100644 index 0000000..2bb6b3d --- /dev/null +++ b/src/main/resources/data/terraforged/blocks/saplings/jungle_sapling.json @@ -0,0 +1,17 @@ +{ + "type": "terraforged:sapling", + "sapling": "minecraft:jungle_sapling", + "normal": { + "terraforged:jungle_small": { + "weight": 2 + }, + "terraforged:jungle_large": { + "weight": 1 + } + }, + "giant": { + "terraforged:jungle_huge": { + "weight": 1 + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/blocks/saplings/oak_sapling.json b/src/main/resources/data/terraforged/blocks/saplings/oak_sapling.json new file mode 100644 index 0000000..b3c43eb --- /dev/null +++ b/src/main/resources/data/terraforged/blocks/saplings/oak_sapling.json @@ -0,0 +1,12 @@ +{ + "type": "terraforged:sapling", + "sapling": "minecraft:oak_sapling", + "normal": { + "terraforged:oak_small": { + "weight": 2 + }, + "terraforged:oak_large": { + "weight": 1 + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/coal.json b/src/main/resources/data/terraforged/features/ores/coal.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/coal.json rename to src/main/resources/data/terraforged/features/ores/coal.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/diamond.json b/src/main/resources/data/terraforged/features/ores/diamond.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/diamond.json rename to src/main/resources/data/terraforged/features/ores/diamond.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold.json b/src/main/resources/data/terraforged/features/ores/gold.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold.json rename to src/main/resources/data/terraforged/features/ores/gold.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold_extra.json b/src/main/resources/data/terraforged/features/ores/gold_extra.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/gold_extra.json rename to src/main/resources/data/terraforged/features/ores/gold_extra.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/iron.json b/src/main/resources/data/terraforged/features/ores/iron.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/iron.json rename to src/main/resources/data/terraforged/features/ores/iron.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/lapis.json b/src/main/resources/data/terraforged/features/ores/lapis.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/lapis.json rename to src/main/resources/data/terraforged/features/ores/lapis.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/ores/redstone.json b/src/main/resources/data/terraforged/features/ores/redstone.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/ores/redstone.json rename to src/main/resources/data/terraforged/features/ores/redstone.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/sediments/clay.json b/src/main/resources/data/terraforged/features/sediments/clay.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/sediments/clay.json rename to src/main/resources/data/terraforged/features/sediments/clay.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/sediments/dirt.json b/src/main/resources/data/terraforged/features/sediments/dirt.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/sediments/dirt.json rename to src/main/resources/data/terraforged/features/sediments/dirt.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/sediments/gravel.json b/src/main/resources/data/terraforged/features/sediments/gravel.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/sediments/gravel.json rename to src/main/resources/data/terraforged/features/sediments/gravel.json diff --git a/src/main/resources/data/terraforged/features/shrubs/birch_forest_bush.json b/src/main/resources/data/terraforged/features/shrubs/birch_forest_bush.json new file mode 100644 index 0000000..d3ab905 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/birch_forest_bush.json @@ -0,0 +1,115 @@ +{ + "biomes": [ + "minecraft:birch*", + "minecraft:tall_birch*" + ], + "match": [ + [ + "minecraft:birch_log", + "minecraft:birch_leaves" + ], + [ + "terraforged:poisson_surface" + ] + ], + "after": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "minecraft:jungle_ground_bush", + "config": { + "trunk_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + } + }, + "leaves_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:birch_leaves", + "Properties": { + "distance": "3", + "persistent": "false" + } + } + }, + "decorators": [], + "base_height": 3 + }, + "chance": 0.15 + }, + { + "name": "minecraft:jungle_ground_bush", + "config": { + "trunk_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + } + }, + "leaves_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_leaves", + "Properties": { + "distance": "3", + "persistent": "false" + } + } + }, + "decorators": [], + "base_height": 4 + }, + "chance": 0.25 + } + ], + "default": { + "name": "minecraft:jungle_ground_bush", + "config": { + "trunk_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + } + }, + "leaves_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_leaves", + "Properties": { + "distance": "3", + "persistent": "false" + } + } + }, + "decorators": [], + "base_height": 3 + } + } + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 0, + "extra_chance": 0.05, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/shrubs/birch_forest_grass.json b/src/main/resources/data/terraforged/features/shrubs/birch_forest_grass.json new file mode 100644 index 0000000..ff46a90 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/birch_forest_grass.json @@ -0,0 +1,188 @@ +{ + "biomes": [ + "minecraft:birch*", + "minecraft:tall_birch*" + ], + "match": [[ + "minecraft:double_plant_placer" + ]], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "chance": 0.8, + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:tall_grass", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:double_plant_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 56, + "xspread": 7, + "yspread": 3, + "zspread": 7, + "can_replace": false, + "project": false, + "need_water": false + } + }, + { + "chance": 0.5, + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:lilac", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:double_plant_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 64, + "xspread": 7, + "yspread": 3, + "zspread": 7, + "can_replace": false, + "project": false, + "need_water": false + } + }, + { + "chance": 0.3, + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:large_fern", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:double_plant_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 48, + "xspread": 5, + "yspread": 3, + "zspread": 5, + "can_replace": false, + "project": false, + "need_water": false + } + }, + { + "chance": 0.2, + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:fern", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:simple_block_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 24, + "xspread": 4, + "yspread": 3, + "zspread": 4, + "can_replace": false, + "project": false, + "need_water": false + } + }, + { + "chance": 0.1, + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:peony", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:double_plant_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 32, + "xspread": 6, + "yspread": 3, + "zspread": 6, + "can_replace": false, + "project": false, + "need_water": false + } + } + ], + "default": { + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:tall_grass", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:double_plant_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 48, + "xspread": 7, + "yspread": 3, + "zspread": 7, + "can_replace": false, + "project": false, + "need_water": false + } + } + } + }, + "decorator": { + "name": "minecraft:count_heightmap_32", + "config": { + "count": 5 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/shrubs/cold_steppe_bush.json b/src/main/resources/data/terraforged/features/shrubs/cold_steppe_bush.json new file mode 100644 index 0000000..1c3d119 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/cold_steppe_bush.json @@ -0,0 +1,40 @@ +{ + "biomes": [ + "terraforged:cold_steppe" + ], + "stage": "VEGETAL_DECORATION", + "prepend": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "terraforged:bush", + "config": { + "trunk": { + "Name": "minecraft:spruce_log", + "Properties": { + "axis": "y" + } + }, + "leaves": { + "Name": "minecraft:oak_leaves", + "Properties": { + "distance": "1", + "persistent": "false" + } + }, + "air_chance": 0.05, + "leaf_chance": 0.075, + "size_chance": 0.6 + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 0, + "extra_chance": 0.125, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/shrubs/dead_bush.json b/src/main/resources/data/terraforged/features/shrubs/dead_bush.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/features/shrubs/dead_bush.json rename to src/main/resources/data/terraforged/features/shrubs/dead_bush.json diff --git a/src/main/resources/data/terraforged/features/shrubs/forest_bush.json b/src/main/resources/data/terraforged/features/shrubs/forest_bush.json new file mode 100644 index 0000000..9537464 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/forest_bush.json @@ -0,0 +1,117 @@ +{ + "biomes": [ + "minecraft:forest", + "minecraft:forest_hills", + "minecraft:dark_forest", + "minecraft:dark_forest_hills" + ], + "match": [ + [ + "minecraft:oak_log", + "minecraft:oak_leaves" + ], + [ + "terraforged:poisson_surface" + ] + ], + "after": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "minecraft:jungle_ground_bush", + "config": { + "trunk_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + } + }, + "leaves_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:birch_leaves", + "Properties": { + "distance": "3", + "persistent": "false" + } + } + }, + "decorators": [], + "base_height": 3 + }, + "chance": 0.15 + }, + { + "name": "minecraft:jungle_ground_bush", + "config": { + "trunk_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + } + }, + "leaves_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_leaves", + "Properties": { + "distance": "3", + "persistent": "false" + } + } + }, + "decorators": [], + "base_height": 4 + }, + "chance": 0.25 + } + ], + "default": { + "name": "minecraft:jungle_ground_bush", + "config": { + "trunk_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + } + }, + "leaves_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:oak_leaves", + "Properties": { + "distance": "3", + "persistent": "false" + } + } + }, + "decorators": [], + "base_height": 3 + } + } + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 1, + "extra_chance": 0.05, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/shrubs/forest_fern.json b/src/main/resources/data/terraforged/features/shrubs/forest_fern.json new file mode 100644 index 0000000..8783843 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/forest_fern.json @@ -0,0 +1,110 @@ +{ + "biomes": [ + "minecraft:birch*", + "minecraft:tall_birch*", + "minecraft:forest", + "minecraft:forest_hills", + "minecraft:dark_forest", + "minecraft:dark_forest_hills" + ], + "match": [ + [ + "minecraft:decorated", + "minecraft:grass" + ] + ], + "after": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:fern" + } + }, + "block_placer": { + "type": "minecraft:simple_block_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 20, + "xspread": 7, + "yspread": 3, + "zspread": 7, + "can_replace": false, + "project": true, + "need_water": false + }, + "chance": 0.3 + }, + { + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:large_fern", + "Properties": { + "half": "lower" + } + } + }, + "block_placer": { + "type": "minecraft:double_plant_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 20, + "xspread": 7, + "yspread": 3, + "zspread": 7, + "can_replace": false, + "project": false, + "need_water": false + }, + "chance": 0.2 + } + ], + "default": { + "name": "minecraft:random_patch", + "config": { + "state_provider": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "minecraft:fern" + } + }, + "block_placer": { + "type": "minecraft:simple_block_placer" + }, + "whitelist": [], + "blacklist": [], + "tries": 10, + "xspread": 7, + "yspread": 3, + "zspread": 7, + "can_replace": false, + "project": true, + "need_water": false + } + } + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 1, + "extra_chance": 0.1, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/shrubs/forest_grass.json b/src/main/resources/data/terraforged/features/shrubs/forest_grass.json similarity index 94% rename from TerraForgedMod/src/main/resources/data/terraforged/features/shrubs/forest_grass.json rename to src/main/resources/data/terraforged/features/shrubs/forest_grass.json index e6a19e9..4959c94 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/shrubs/forest_grass.json +++ b/src/main/resources/data/terraforged/features/shrubs/forest_grass.json @@ -1,7 +1,7 @@ { "biomes": [ - "minecraft:birch_forest", - "minecraft:birch_forest_hills", + "minecraft:birch*", + "minecraft:tall_birch*", "minecraft:forest", "minecraft:forest_hills", "minecraft:dark_forest", diff --git a/src/main/resources/data/terraforged/features/shrubs/plains_bush.json b/src/main/resources/data/terraforged/features/shrubs/plains_bush.json new file mode 100644 index 0000000..2292cb7 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/plains_bush.json @@ -0,0 +1,42 @@ +{ + "biomes": [ + "minecraft:plains", + "minecraft:sunflower_plains", + "minecraft:mountains" + ], + "stage": "VEGETAL_DECORATION", + "prepend": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "terraforged:bush", + "config": { + "trunk": { + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } + }, + "leaves": { + "Name": "minecraft:oak_leaves", + "Properties": { + "distance": "1", + "persistent": "false" + } + }, + "air_chance": 0.05, + "leaf_chance": 0.09, + "size_chance": 0.65 + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 0, + "extra_chance": 0.05, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/shrubs/steppe_bush.json b/src/main/resources/data/terraforged/features/shrubs/steppe_bush.json new file mode 100644 index 0000000..029dfe8 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/steppe_bush.json @@ -0,0 +1,42 @@ +{ + "biomes": [ + "terraforged:steppe", + "terraforged:savanna_scrub", + "terraforged:shattered_savanna_scrub" + ], + "stage": "VEGETAL_DECORATION", + "prepend": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "terraforged:bush", + "config": { + "trunk": { + "Name": "minecraft:acacia_log", + "Properties": { + "axis": "y" + } + }, + "leaves": { + "Name": "minecraft:acacia_leaves", + "Properties": { + "distance": "1", + "persistent": "false" + } + }, + "air_chance": 0.06, + "leaf_chance": 0.08, + "size_chance": 0.7 + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 0, + "extra_chance": 0.125, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/shrubs/taiga_scrub_bush.json b/src/main/resources/data/terraforged/features/shrubs/taiga_scrub_bush.json new file mode 100644 index 0000000..714d969 --- /dev/null +++ b/src/main/resources/data/terraforged/features/shrubs/taiga_scrub_bush.json @@ -0,0 +1,49 @@ +{ + "biomes": [ + "minecraft:snowy_tundra", + "minecraft:taiga", + "minecraft:taiga_hills", + "minecraft:wooded_mountains", + "minecraft:taiga_mountains", + "minecraft:snowy_taiga_mountains", + "minecraft:gravelly_mountains", + "minecraft:modified_gravelly_mountains", + "terraforged:taiga_scrub", + "terraforged:snowy_taiga_scrub" + ], + "stage": "VEGETAL_DECORATION", + "prepend": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "terraforged:bush", + "config": { + "trunk": { + "Name": "minecraft:spruce_log", + "Properties": { + "axis": "y" + } + }, + "leaves": { + "Name": "minecraft:spruce_leaves", + "Properties": { + "distance": "1", + "persistent": "false" + } + }, + "air_chance": 0.05, + "leaf_chance": 0.075, + "size_chance": 0.6 + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 0, + "extra_chance": 0.1, + "extra_count": 1 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/acacia.json b/src/main/resources/data/terraforged/features/trees/acacia.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/acacia.json rename to src/main/resources/data/terraforged/features/trees/acacia.json index cf5e9ac..6b9f902 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/acacia.json +++ b/src/main/resources/data/terraforged/features/trees/acacia.json @@ -13,19 +13,25 @@ "config": { "features": [ { - "name": "terraforged:acacia_large", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:acacia_large" + }, "chance": 0.4 }, { - "name": "terraforged:acacia_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:acacia_small" + }, "chance": 0.15 } ], "default": { - "name": "terraforged:acacia_large", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:acacia_large" + } } } }, diff --git a/src/main/resources/data/terraforged/features/trees/birch.json b/src/main/resources/data/terraforged/features/trees/birch.json new file mode 100644 index 0000000..8cca74a --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/birch.json @@ -0,0 +1,54 @@ +{ + "biomes": [ + "minecraft:birch*", + "minecraft:tall_birch*" + ], + "match": [ + [ + "minecraft:birch_log", + "minecraft:birch_leaves" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_large" + }, + "chance": 0.2 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 8, + "biome_fade": 0.12, + "density_noise_scale": 300, + "density_noise_min": 0.5, + "density_noise_max": 1.5 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/trees/birch_oak.json b/src/main/resources/data/terraforged/features/trees/birch_oak.json new file mode 100644 index 0000000..a60498c --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/birch_oak.json @@ -0,0 +1,69 @@ +{ + "biomes": [ + "minecraft:wooded_hills" + ], + "match": [ + [ + "minecraft:birch_log", + "minecraft:birch_leaves", + "minecraft:oak_log", + "minecraft:oak_leaves" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_large" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_forest" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_large" + }, + "chance": 0.2 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 8, + "biome_fade": 0.35, + "density_noise_scale": 300, + "density_noise_min": 0, + "density_noise_max": 2 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/dark_oak.json b/src/main/resources/data/terraforged/features/trees/dark_oak.json similarity index 77% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/dark_oak.json rename to src/main/resources/data/terraforged/features/trees/dark_oak.json index 5c82c0e..0b71c3d 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/dark_oak.json +++ b/src/main/resources/data/terraforged/features/trees/dark_oak.json @@ -87,38 +87,50 @@ "chance": 0.05 }, { - "name": "terraforged:dark_oak_large", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:dark_oak_large" + }, "chance": 0.3 }, { - "name": "terraforged:dark_oak_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:dark_oak_small" + }, "chance": 0.2 }, { - "name": "terraforged:birch_forest", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + }, "chance": 0.05 }, { - "name": "terraforged:oak_forest", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_forest" + }, "chance": 0.025 } ], "default": { - "name": "terraforged:dark_oak_large", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:dark_oak_large" + } } } }, "decorator": { - "name": "minecraft:count_extra_heightmap", + "name": "terraforged:poisson_surface", "config": { - "count": 10, - "extra_chance": 0.1, - "extra_count": 1 + "radius": 8, + "biome_fade": 0.4, + "density_noise_scale": 200, + "density_noise_min": 0, + "density_noise_max": 1.85 } } } diff --git a/src/main/resources/data/terraforged/features/trees/fir_foreset.json b/src/main/resources/data/terraforged/features/trees/fir_foreset.json new file mode 100644 index 0000000..7ff93ee --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/fir_foreset.json @@ -0,0 +1,69 @@ +{ + "biomes": [ + "terraforged:fir_forest", + "terraforged:snowy_fir_forest" + ], + "match": [ + [ + "minecraft:normal_tree", + "minecraft:spruce_log", + "minecraft:spruce_leaves" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "terraforged:context_selector", + "config": { + "features": [ + { + "feature": { + "name": "terraforged:template", + "config": { + "template": "terraforged:spruce_small" + } + }, + "context": { + "chance": 0.1, + "elevation": { + "from": 0.55, + "to": 0.2 + } + } + }, + { + "feature": { + "name": "terraforged:template", + "config": { + "template": "terraforged:spruce_large" + } + }, + "context": { + "chance": 0.25, + "elevation": { + "from": 0.3, + "to": 0.0 + }, + "biome": { + "from": 0, + "to": 0.2 + } + } + } + ] + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 7, + "biome_fade": 0.3, + "density_noise_scale": 300, + "density_noise_min": 0, + "density_noise_max": 2.5 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/trees/flower_forest.json b/src/main/resources/data/terraforged/features/trees/flower_forest.json new file mode 100644 index 0000000..c0eeed8 --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/flower_forest.json @@ -0,0 +1,69 @@ +{ + "biomes": [ + "minecraft:flower_forest" + ], + "match": [ + [ + "minecraft:birch_log", + "minecraft:birch_leaves", + "minecraft:oak_log", + "minecraft:oak_leaves" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_large" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_forest" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_large" + }, + "chance": 0.2 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:birch_forest" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 15, + "biome_fade": 0.3, + "density_noise_scale": 500, + "density_noise_min": 0.75, + "density_noise_max": 2 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle.json b/src/main/resources/data/terraforged/features/trees/jungle.json similarity index 66% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle.json rename to src/main/resources/data/terraforged/features/trees/jungle.json index 791bfe7..997aad0 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle.json +++ b/src/main/resources/data/terraforged/features/trees/jungle.json @@ -17,18 +17,24 @@ "config": { "features": [ { - "name": "terraforged:jungle_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_small" + }, "chance": 0.2 }, { - "name": "terraforged:jungle_large", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_large" + }, "chance": 0.3 }, { - "name": "terraforged:jungle_huge", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_huge" + }, "chance": 0.4 }, { @@ -60,17 +66,21 @@ } ], "default": { - "name": "terraforged:jungle_small", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_small" + } } } }, "decorator": { - "name": "minecraft:count_extra_heightmap", + "name": "terraforged:poisson_surface", "config": { - "count": 15, - "extra_chance": 0.25, - "extra_count": 1 + "radius": 6, + "biome_fade": 0.2, + "density_noise_scale": 400, + "density_noise_min": 0.25, + "density_noise_max": 2 } } } diff --git a/src/main/resources/data/terraforged/features/trees/jungle_edge.json b/src/main/resources/data/terraforged/features/trees/jungle_edge.json new file mode 100644 index 0000000..2d14e5b --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/jungle_edge.json @@ -0,0 +1,54 @@ +{ + "biomes": [ + "minecraft:jungle_edge", + "minecraft:modified_jungle_edge", + "terraforged:stone_forest" + ], + "match": [ + [ + "minecraft:fancy_tree" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_small" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_large" + }, + "chance": 0.3 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_small" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 9, + "biome_fade": 0.3, + "density_noise_scale": 350, + "density_noise_min": 0.75, + "density_noise_max": 1.5 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle_hills.json b/src/main/resources/data/terraforged/features/trees/jungle_hills.json similarity index 64% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle_hills.json rename to src/main/resources/data/terraforged/features/trees/jungle_hills.json index 6e75e30..e8d69a4 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/jungle_hills.json +++ b/src/main/resources/data/terraforged/features/trees/jungle_hills.json @@ -16,19 +16,25 @@ "config": { "features": [ { - "name": "terraforged:jungle_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_small" + }, + "chance": 0.3 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_large" + }, "chance": 0.4 }, { - "name": "terraforged:jungle_large", - "config": {}, - "chance": 0.2 - }, - { - "name": "terraforged:jungle_huge", - "config": {}, - "chance": 0.05 + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_huge" + }, + "chance": 0.3 }, { "name": "minecraft:jungle_ground_bush", @@ -55,21 +61,25 @@ "decorators": [], "base_height": 4 }, - "chance": 0.3 + "chance": 0.2 } ], "default": { - "name": "terraforged:jungle_small", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:jungle_small" + } } } }, "decorator": { - "name": "minecraft:count_extra_heightmap", + "name": "terraforged:poisson_surface", "config": { - "count": 6, - "extra_chance": 0.25, - "extra_count": 1 + "radius": 8, + "biome_fade": 0.2, + "density_noise_scale": 200, + "density_noise_min": 0.35, + "density_noise_max": 1.85 } } } diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_badlands.json b/src/main/resources/data/terraforged/features/trees/oak_badlands.json similarity index 73% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_badlands.json rename to src/main/resources/data/terraforged/features/trees/oak_badlands.json index 6166a24..a2eb50d 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_badlands.json +++ b/src/main/resources/data/terraforged/features/trees/oak_badlands.json @@ -19,14 +19,18 @@ "config": { "features": [ { - "name": "terraforged:oak_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_small" + }, "chance": 0.2 } ], "default": { - "name": "terraforged:oak_small", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_small" + } } } }, diff --git a/src/main/resources/data/terraforged/features/trees/oak_forest.json b/src/main/resources/data/terraforged/features/trees/oak_forest.json new file mode 100644 index 0000000..bda0b2e --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/oak_forest.json @@ -0,0 +1,53 @@ +{ + "biomes": [ + "minecraft:forest" + ], + "match": [ + [ + "minecraft:oak_log", + "minecraft:oak_leaves" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_forest" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_large" + }, + "chance": 0.3 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_forest" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 8, + "biome_fade": 0.12, + "density_noise_scale": 150, + "density_noise_min": 0.5, + "density_noise_max": 1.75 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json b/src/main/resources/data/terraforged/features/trees/oak_plains.json similarity index 57% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json rename to src/main/resources/data/terraforged/features/trees/oak_plains.json index 777f214..7b8e068 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/oak_plains.json +++ b/src/main/resources/data/terraforged/features/trees/oak_plains.json @@ -1,19 +1,9 @@ { "biomes": [ + "minecraft:river", "minecraft:plains", "minecraft:sunflower_plains", - "minecraft:river", - "minecraft:frozen_river", - "minecraft:ocean", - "minecraft:deep_ocean", - "minecraft:warm_ocean", - "minecraft:deep_warm_ocean", - "minecraft:lukewarm_ocean", - "minecraft:deep_lukewarm_ocean", - "minecraft:cold_ocean", - "minecraft:deep_cold_ocean", - "minecraft:frozen_ocean", - "minecraft:deep_frozen_ocean" + "minecraft:mountains" ], "match": [ [ @@ -29,19 +19,25 @@ "config": { "features": [ { - "name": "terraforged:oak_huge", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_huge" + }, "chance": 0.1 }, { - "name": "terraforged:oak_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_small" + }, "chance": 0.2 } ], "default": { - "name": "terraforged:oak_small", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_small" + } } } }, @@ -55,4 +51,4 @@ } } } -} +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/pine.json b/src/main/resources/data/terraforged/features/trees/pine.json similarity index 55% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/pine.json rename to src/main/resources/data/terraforged/features/trees/pine.json index 119dacf..acb80ed 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/pine.json +++ b/src/main/resources/data/terraforged/features/trees/pine.json @@ -19,23 +19,29 @@ "config": { "features": [ { - "name": "terraforged:pine", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + }, "chance": 0.3 } ], "default": { - "name": "terraforged:pine", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + } } } }, "decorator": { - "name": "minecraft:count_extra_heightmap", + "name": "terraforged:poisson_surface", "config": { - "count": 8, - "extra_chance": 0.1, - "extra_count": 1 + "radius": 10, + "biome_fade": 0.25, + "density_noise_scale": 250, + "density_noise_min": 0.0, + "density_noise_max": 2.75 } } } diff --git a/src/main/resources/data/terraforged/features/trees/redwood.json b/src/main/resources/data/terraforged/features/trees/redwood.json new file mode 100644 index 0000000..83fd9fe --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/redwood.json @@ -0,0 +1,100 @@ +{ + "biomes": [ + "minecraft:*" + ], + "match": [ + [ + "minecraft:mega_spruce_tree" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "terraforged:context_selector", + "config": { + "features": [ + { + "feature": { + "name": "terraforged:template", + "config": { + "template": "terraforged:redwood_huge" + } + }, + "context": { + "chance": 0.4, + "elevation": { + "from": 0.15, + "to": 0.0 + }, + "biome": { + "from": 0.1, + "to": 0.4 + } + } + }, + { + "feature": { + "name": "terraforged:template", + "config": { + "template": "terraforged:redwood_large" + } + }, + "context": { + "chance": 0.2, + "elevation": { + "from": 0.25, + "to": 0.0 + } + }, + "biome": { + "from": 0.0, + "to": 0.25 + } + }, + { + "feature": { + "name": "terraforged:template", + "config": { + "template": "terraforged:spruce_large" + } + }, + "context": { + "chance": 0.4, + "elevation": { + "from": 0.35, + "to": 0.15 + } + } + }, + { + "feature": { + "name": "terraforged:template", + "config": { + "template": "terraforged:spruce_small" + } + }, + "context": { + "chance": 0.2, + "elevation": { + "from": 0.50, + "to": 0.2 + } + } + } + ] + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 8, + "biome_fade": 0.2, + "density_noise_scale": 250, + "density_noise_min": 0.15, + "density_noise_max": 2.25 + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/features/trees/scrub_trees.json b/src/main/resources/data/terraforged/features/trees/scrub_trees.json new file mode 100644 index 0000000..c3fd8f7 --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/scrub_trees.json @@ -0,0 +1,52 @@ +{ + "biomes": [ + "terraforged:steppe", + "terraforged:savanna_scrub", + "terraforged:shattered_savanna_scrub" + ], + "match": [ + [ + "minecraft:dead_bush" + ] + ], + "before": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_small" + }, + "chance": 0.2 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:acacia_bush" + }, + "chance": 0.1 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:oak_small" + } + } + } + }, + "decorator": { + "name": "minecraft:count_extra_heightmap", + "config": { + "count": 0, + "extra_chance": 0.02, + "extra_count": 3 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/spruce.json b/src/main/resources/data/terraforged/features/trees/spruce.json similarity index 53% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/spruce.json rename to src/main/resources/data/terraforged/features/trees/spruce.json index ff1b679..0804aef 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/spruce.json +++ b/src/main/resources/data/terraforged/features/trees/spruce.json @@ -2,7 +2,7 @@ "biomes": [ "minecraft:snowy_taiga", "minecraft:snowy_taiga_hills", - "minecraft:snowy_taiga_mountains" + "minecraft:taiga_mountains" ], "match": [ [ @@ -19,23 +19,29 @@ "config": { "features": [ { - "name": "terraforged:pine", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + }, "chance": 0.3 } ], "default": { - "name": "terraforged:pine", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + } } } }, "decorator": { - "name": "minecraft:count_extra_heightmap", + "name": "terraforged:poisson_surface", "config": { - "count": 8, - "extra_chance": 0.1, - "extra_count": 1 + "radius": 10, + "biome_fade": 0.3, + "density_noise_scale": 250, + "density_noise_min": 0.15, + "density_noise_max": 1.75 } } } diff --git a/src/main/resources/data/terraforged/features/trees/spruce_tundra.json b/src/main/resources/data/terraforged/features/trees/spruce_tundra.json new file mode 100644 index 0000000..aca1587 --- /dev/null +++ b/src/main/resources/data/terraforged/features/trees/spruce_tundra.json @@ -0,0 +1,66 @@ +{ + "biomes": [ + "minecraft:snowy_tundra", + "minecraft:snowy_taiga_mountains", + "minecraft:wooded_mountains", + "minecraft:gravelly_mountains", + "minecraft:modified_gravelly_mountains" + ], + "match": [ + [ + "minecraft:normal_tree", + "minecraft:spruce_log", + "minecraft:spruce_leaves" + ], + [ + "minecraft:fancy_tree", + "minecraft:spruce_log", + "minecraft:spruce_leaves" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + }, + "chance": 0.3 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 10, + "density_noise_scale": 120, + "density_noise_min": 0.5, + "density_noise_max": 1.5 + } + } + } + }, + "decorator": { + "name": "minecraft:chance_passthrough", + "config": { + "chance": 0.02 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/willow.json b/src/main/resources/data/terraforged/features/trees/willow.json similarity index 64% rename from TerraForgedMod/src/main/resources/data/terraforged/features/trees/willow.json rename to src/main/resources/data/terraforged/features/trees/willow.json index ba31490..da35439 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/features/trees/willow.json +++ b/src/main/resources/data/terraforged/features/trees/willow.json @@ -19,19 +19,25 @@ "config": { "features": [ { - "name": "terraforged:willow_small", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:willow_small" + }, "chance": 0.2 }, { - "name": "terraforged:willow_large", - "config": {}, + "name": "terraforged:template", + "config": { + "template": "terraforged:willow_large" + }, "chance": 0.35 } ], "default": { - "name": "terraforged:willow_large", - "config": {} + "name": "terraforged:template", + "config": { + "template": "terraforged:willow_large" + } } } }, diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_1.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_1.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_2.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_2.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_3.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_3.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_4.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_4.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_5.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_5.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_7.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_7.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_7.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_mushroom_7.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_musroom_6.nbt b/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_musroom_6.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/brown/brown_musroom_6.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/brown/brown_musroom_6.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_1.nbt b/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_1.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_2.nbt b/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_2.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_3.nbt b/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_3.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_4.nbt b/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_4.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_5.nbt b/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_5.nbt rename to src/main/resources/data/terraforged/structures/mushrooms/red/red_mushroom_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_1.nbt b/src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_1.nbt rename to src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_2.nbt b/src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_2.nbt rename to src/main/resources/data/terraforged/structures/trees/acacia/bush/acacia_bush_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_1.nbt b/src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_1.nbt rename to src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_2.nbt b/src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_2.nbt rename to src/main/resources/data/terraforged/structures/trees/acacia/large/acacia_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/acacia/small/acacia_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_1.nbt b/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_1.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_2.nbt b/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_2.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_3.nbt b/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_3.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_4.nbt b/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_4.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/forest/forest_birch_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/large/birch_1.nbt b/src/main/resources/data/terraforged/structures/trees/birch/large/birch_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/large/birch_1.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/large/birch_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/large/birch_2.nbt b/src/main/resources/data/terraforged/structures/trees/birch/large/birch_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/large/birch_2.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/large/birch_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/large/birch_3.nbt b/src/main/resources/data/terraforged/structures/trees/birch/large/birch_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/large/birch_3.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/large/birch_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_1.nbt b/src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_1.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_2.nbt b/src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_2.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/small/birch_bush_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/birch/small/birch_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_1.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_1.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_2.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_2.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_3.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_3.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_4.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_4.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_5.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_5.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/large/dark_oak_tall_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_1.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_1.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_2.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_2.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_3.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_3.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_1.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_1.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_2.nbt b/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_2.nbt rename to src/main/resources/data/terraforged/structures/trees/dark_oak/small/dark_oak_bush_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_1.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_1.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_2.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_2.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_3.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_3.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_4.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_4.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_5.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_5.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_6.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_6.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_6.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/huge/jungle_massive_6.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_1.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_1.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_2.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_2.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_3.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_3.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_4.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_4.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/large/jungle_tall_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_3.nbt b/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_3.nbt rename to src/main/resources/data/terraforged/structures/trees/jungle/small/jungle_small_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_1.nbt b/src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_1.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_2.nbt b/src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_2.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/forest/forest_oak_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_1.nbt b/src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_1.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_2.nbt b/src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_2.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/huge/oak_big_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_1.nbt b/src/main/resources/data/terraforged/structures/trees/oak/large/oak_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_1.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/large/oak_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_2.nbt b/src/main/resources/data/terraforged/structures/trees/oak/large/oak_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_2.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/large/oak_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_3.nbt b/src/main/resources/data/terraforged/structures/trees/oak/large/oak_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_3.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/large/oak_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_4.nbt b/src/main/resources/data/terraforged/structures/trees/oak/large/oak_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_4.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/large/oak_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_5.nbt b/src/main/resources/data/terraforged/structures/trees/oak/large/oak_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/large/oak_5.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/large/oak_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_1.nbt b/src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_1.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_2.nbt b/src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_2.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/small/oak_bush_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_3.nbt b/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_3.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_4.nbt b/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_4.nbt rename to src/main/resources/data/terraforged/structures/trees/oak/small/oak_small_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_1.nbt b/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_1.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_2.nbt b/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_2.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_3.nbt b/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_3.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/huangshan_pine_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_1.nbt b/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_1.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/scots_pine_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_2.nbt b/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_2.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/scots_pine_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/scots_pine_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/stone_pine_1.nbt b/src/main/resources/data/terraforged/structures/trees/pine/stone_pine_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/stone_pine_1.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/stone_pine_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/stone_pine_2.nbt b/src/main/resources/data/terraforged/structures/trees/pine/stone_pine_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/pine/stone_pine_2.nbt rename to src/main/resources/data/terraforged/structures/trees/pine/stone_pine_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_1.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_1.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_2.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_2.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_3.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_3.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_4.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_4.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_5.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_5.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_6.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_6.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_6.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/huge/redwood_massive_6.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_1.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_1.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_2.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_2.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_3.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_3.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_4.nbt b/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_4.nbt rename to src/main/resources/data/terraforged/structures/trees/redwood/large/redwood_tall_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_1.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_1.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_2.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_2.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/bush/spruce_bush_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_1.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_1.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_2.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_2.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_3.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_3.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_4.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_4.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_5.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_5.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_5.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/large/spruce_5.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_3.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_3.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_3.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_3.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_4.nbt b/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_4.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_4.nbt rename to src/main/resources/data/terraforged/structures/trees/spruce/small/spruce_small_4.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_1.nbt b/src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_1.nbt rename to src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_2.nbt b/src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_2.nbt rename to src/main/resources/data/terraforged/structures/trees/willow/large/weeping_willow_big_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_1.nbt b/src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_1.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_1.nbt rename to src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_1.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_2.nbt b/src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_2.nbt similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_2.nbt rename to src/main/resources/data/terraforged/structures/trees/willow/small/weeping_willow_small_2.nbt diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/alpine.json b/src/main/resources/data/terraforged/tags/biomes/alpine.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/alpine.json rename to src/main/resources/data/terraforged/tags/biomes/alpine.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/cold_steppe.json b/src/main/resources/data/terraforged/tags/biomes/cold_steppe.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/cold_steppe.json rename to src/main/resources/data/terraforged/tags/biomes/cold_steppe.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/desert.json b/src/main/resources/data/terraforged/tags/biomes/desert.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/desert.json rename to src/main/resources/data/terraforged/tags/biomes/desert.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/grassland.json b/src/main/resources/data/terraforged/tags/biomes/grassland.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/grassland.json rename to src/main/resources/data/terraforged/tags/biomes/grassland.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/savanna.json b/src/main/resources/data/terraforged/tags/biomes/savanna.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/savanna.json rename to src/main/resources/data/terraforged/tags/biomes/savanna.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/steppe.json b/src/main/resources/data/terraforged/tags/biomes/steppe.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/steppe.json rename to src/main/resources/data/terraforged/tags/biomes/steppe.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/taiga.json b/src/main/resources/data/terraforged/tags/biomes/taiga.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/taiga.json rename to src/main/resources/data/terraforged/tags/biomes/taiga.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/temperate_forest.json b/src/main/resources/data/terraforged/tags/biomes/temperate_forest.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/temperate_forest.json rename to src/main/resources/data/terraforged/tags/biomes/temperate_forest.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/temperate_rainforest.json b/src/main/resources/data/terraforged/tags/biomes/temperate_rainforest.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/temperate_rainforest.json rename to src/main/resources/data/terraforged/tags/biomes/temperate_rainforest.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/tropical_rainforest.json b/src/main/resources/data/terraforged/tags/biomes/tropical_rainforest.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/tropical_rainforest.json rename to src/main/resources/data/terraforged/tags/biomes/tropical_rainforest.json diff --git a/TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/tundra.json b/src/main/resources/data/terraforged/tags/biomes/tundra.json similarity index 100% rename from TerraForgedMod/src/main/resources/data/terraforged/tags/biomes/tundra.json rename to src/main/resources/data/terraforged/tags/biomes/tundra.json diff --git a/src/main/resources/data/terraforged/templates/trees/acacia_bush.json b/src/main/resources/data/terraforged/templates/trees/acacia_bush.json new file mode 100644 index 0000000..df55399 --- /dev/null +++ b/src/main/resources/data/terraforged/templates/trees/acacia_bush.json @@ -0,0 +1,11 @@ +{ + "type": "tree", + "name": "terraforged:acacia_bush", + "paths": [ + "terraforged:trees/acacia/bush" + ], + "config": { + "extend_base": 2, + "check_bounds": false + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/acacia_large.json b/src/main/resources/data/terraforged/templates/trees/acacia_large.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/acacia_large.json rename to src/main/resources/data/terraforged/templates/trees/acacia_large.json index 3d3c39b..4ef9117 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/acacia_large.json +++ b/src/main/resources/data/terraforged/templates/trees/acacia_large.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:acacia_large", "paths": [ "terraforged:trees/acacia/large" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/acacia_small.json b/src/main/resources/data/terraforged/templates/trees/acacia_small.json similarity index 67% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/acacia_small.json rename to src/main/resources/data/terraforged/templates/trees/acacia_small.json index 7fd1cab..9159f1d 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/acacia_small.json +++ b/src/main/resources/data/terraforged/templates/trees/acacia_small.json @@ -1,9 +1,12 @@ { "type": "tree", - "base": 3, "name": "terraforged:acacia_small", "paths": [ "terraforged:trees/acacia/small", "terraforged:trees/acacia/bush" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/src/main/resources/data/terraforged/templates/trees/birch_forest.json b/src/main/resources/data/terraforged/templates/trees/birch_forest.json new file mode 100644 index 0000000..ca616d7 --- /dev/null +++ b/src/main/resources/data/terraforged/templates/trees/birch_forest.json @@ -0,0 +1,23 @@ +{ + "type": "tree", + "name": "terraforged:birch_forest", + "paths": [ + "terraforged:trees/birch/forest" + ], + "config": { + "extend_base": 3, + "check_bounds": true + }, + "decorators": { + "default": { + "minecraft:beehive": { + "probability": 0.002 + } + }, + "minecraft:flower_forest": { + "minecraft:beehive": { + "probability": 0.02 + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/templates/trees/birch_large.json b/src/main/resources/data/terraforged/templates/trees/birch_large.json new file mode 100644 index 0000000..2dfd97e --- /dev/null +++ b/src/main/resources/data/terraforged/templates/trees/birch_large.json @@ -0,0 +1,23 @@ +{ + "type": "tree", + "name": "terraforged:birch_large", + "paths": [ + "terraforged:trees/birch/large" + ], + "config": { + "extend_base": 3, + "check_bounds": true + }, + "decorators": { + "default": { + "minecraft:beehive": { + "probability": 0.002 + } + }, + "minecraft:flower_forest": { + "minecraft:beehive": { + "probability": 0.02 + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_small.json b/src/main/resources/data/terraforged/templates/trees/birch_small.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_small.json rename to src/main/resources/data/terraforged/templates/trees/birch_small.json index 285f490..c5c80e0 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/birch_small.json +++ b/src/main/resources/data/terraforged/templates/trees/birch_small.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:birch_small", "paths": [ "terraforged:trees/birch/small" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/brown_mushroom.json b/src/main/resources/data/terraforged/templates/trees/brown_mushroom.json similarity index 69% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/brown_mushroom.json rename to src/main/resources/data/terraforged/templates/trees/brown_mushroom.json index 430485a..ea95b1d 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/brown_mushroom.json +++ b/src/main/resources/data/terraforged/templates/trees/brown_mushroom.json @@ -1,8 +1,10 @@ { "type": "tree", - "base": 0, "name": "terraforged:brown_mushroom", "paths": [ "terraforged:mushrooms/brown" - ] + ], + "config": { + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/dark_oak_large.json b/src/main/resources/data/terraforged/templates/trees/dark_oak_large.json similarity index 61% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/dark_oak_large.json rename to src/main/resources/data/terraforged/templates/trees/dark_oak_large.json index 0d08afb..a48e848 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/dark_oak_large.json +++ b/src/main/resources/data/terraforged/templates/trees/dark_oak_large.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:dark_oak_large", "paths": [ "terraforged:trees/dark_oak/large" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/dark_oak_small.json b/src/main/resources/data/terraforged/templates/trees/dark_oak_small.json similarity index 61% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/dark_oak_small.json rename to src/main/resources/data/terraforged/templates/trees/dark_oak_small.json index 1cab783..eb3b102 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/dark_oak_small.json +++ b/src/main/resources/data/terraforged/templates/trees/dark_oak_small.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:dark_oak_small", "paths": [ "terraforged:trees/dark_oak/small" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_huge.json b/src/main/resources/data/terraforged/templates/trees/jungle_huge.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_huge.json rename to src/main/resources/data/terraforged/templates/trees/jungle_huge.json index 9966e5b..c61262c 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_huge.json +++ b/src/main/resources/data/terraforged/templates/trees/jungle_huge.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:jungle_huge", "paths": [ "terraforged:trees/jungle/huge" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_large.json b/src/main/resources/data/terraforged/templates/trees/jungle_large.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_large.json rename to src/main/resources/data/terraforged/templates/trees/jungle_large.json index 2158117..47916e9 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_large.json +++ b/src/main/resources/data/terraforged/templates/trees/jungle_large.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:jungle_large", "paths": [ "terraforged:trees/jungle/large" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_small.json b/src/main/resources/data/terraforged/templates/trees/jungle_small.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_small.json rename to src/main/resources/data/terraforged/templates/trees/jungle_small.json index c242c73..31ce662 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/jungle_small.json +++ b/src/main/resources/data/terraforged/templates/trees/jungle_small.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:jungle_small", "paths": [ "terraforged:trees/jungle/small" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/src/main/resources/data/terraforged/templates/trees/oak_forest.json b/src/main/resources/data/terraforged/templates/trees/oak_forest.json new file mode 100644 index 0000000..5cca2a5 --- /dev/null +++ b/src/main/resources/data/terraforged/templates/trees/oak_forest.json @@ -0,0 +1,23 @@ +{ + "type": "tree", + "name": "terraforged:oak_forest", + "paths": [ + "terraforged:trees/oak/forest" + ], + "config": { + "extend_base": 3, + "check_bounds": true + }, + "decorators": { + "default": { + "minecraft:beehive": { + "probability": 0.002 + } + }, + "minecraft:flower_forest": { + "minecraft:beehive": { + "probability": 0.02 + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/templates/trees/oak_huge.json b/src/main/resources/data/terraforged/templates/trees/oak_huge.json new file mode 100644 index 0000000..05f1b54 --- /dev/null +++ b/src/main/resources/data/terraforged/templates/trees/oak_huge.json @@ -0,0 +1,23 @@ +{ + "type": "tree", + "name": "terraforged:oak_huge", + "paths": [ + "terraforged:trees/oak/huge" + ], + "config": { + "extend_base": 3, + "check_bounds": true + }, + "decorators": { + "default": { + "minecraft:beehive": { + "probability": 0.002 + } + }, + "minecraft:flower_forest": { + "minecraft:beehive": { + "probability": 0.02 + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/terraforged/templates/trees/oak_large.json b/src/main/resources/data/terraforged/templates/trees/oak_large.json new file mode 100644 index 0000000..ee09c8f --- /dev/null +++ b/src/main/resources/data/terraforged/templates/trees/oak_large.json @@ -0,0 +1,23 @@ +{ + "type": "tree", + "name": "terraforged:oak_large", + "paths": [ + "terraforged:trees/oak/large" + ], + "config": { + "extend_base": 3, + "check_bounds": true + }, + "decorators": { + "default": { + "minecraft:beehive": { + "probability": 0.002 + } + }, + "minecraft:flower_forest": { + "minecraft:beehive": { + "probability": 0.02 + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_small.json b/src/main/resources/data/terraforged/templates/trees/oak_small.json similarity index 59% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_small.json rename to src/main/resources/data/terraforged/templates/trees/oak_small.json index cbb9289..087b1ec 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/oak_small.json +++ b/src/main/resources/data/terraforged/templates/trees/oak_small.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:oak_small", "paths": [ "terraforged:trees/oak/small" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/pine.json b/src/main/resources/data/terraforged/templates/trees/pine.json similarity index 57% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/pine.json rename to src/main/resources/data/terraforged/templates/trees/pine.json index 8ec0f47..853e5ae 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/pine.json +++ b/src/main/resources/data/terraforged/templates/trees/pine.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:pine", "paths": [ "terraforged:trees/pine" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/red_mushroom.json b/src/main/resources/data/terraforged/templates/trees/red_mushroom.json similarity index 59% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/red_mushroom.json rename to src/main/resources/data/terraforged/templates/trees/red_mushroom.json index 6e7882b..d8ea62e 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/red_mushroom.json +++ b/src/main/resources/data/terraforged/templates/trees/red_mushroom.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 0, "name": "terraforged:red_mushroom", "paths": [ "terraforged:mushrooms/red" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/redwood_huge.json b/src/main/resources/data/terraforged/templates/trees/redwood_huge.json similarity index 85% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/redwood_huge.json rename to src/main/resources/data/terraforged/templates/trees/redwood_huge.json index f84b835..eb39293 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/redwood_huge.json +++ b/src/main/resources/data/terraforged/templates/trees/redwood_huge.json @@ -1,10 +1,13 @@ { "type": "tree", - "base": 3, "name": "terraforged:redwood_huge", "paths": [ "terraforged:trees/redwood/huge" ], + "config": { + "extend_base": 3, + "check_bounds": true + }, "decorators": { "minecraft:alter_ground": { "provider": { diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/redwood_large.json b/src/main/resources/data/terraforged/templates/trees/redwood_large.json similarity index 61% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/redwood_large.json rename to src/main/resources/data/terraforged/templates/trees/redwood_large.json index c9c829c..47b9690 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/redwood_large.json +++ b/src/main/resources/data/terraforged/templates/trees/redwood_large.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:redwood_large", "paths": [ "terraforged:trees/redwood/large" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/spruce_large.json b/src/main/resources/data/terraforged/templates/trees/spruce_large.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/spruce_large.json rename to src/main/resources/data/terraforged/templates/trees/spruce_large.json index 4738b7b..c11388b 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/spruce_large.json +++ b/src/main/resources/data/terraforged/templates/trees/spruce_large.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:spruce_large", "paths": [ "terraforged:trees/spruce/large" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/spruce_small.json b/src/main/resources/data/terraforged/templates/trees/spruce_small.json similarity index 67% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/spruce_small.json rename to src/main/resources/data/terraforged/templates/trees/spruce_small.json index 1e0c950..0ed96cf 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/spruce_small.json +++ b/src/main/resources/data/terraforged/templates/trees/spruce_small.json @@ -1,9 +1,12 @@ { "type": "tree", - "base": 3, "name": "terraforged:spruce_small", "paths": [ "terraforged:trees/spruce/small", "terraforged:trees/spruce/bush" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/willow_large.json b/src/main/resources/data/terraforged/templates/trees/willow_large.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/willow_large.json rename to src/main/resources/data/terraforged/templates/trees/willow_large.json index 467ae54..477b8b4 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/willow_large.json +++ b/src/main/resources/data/terraforged/templates/trees/willow_large.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:willow_large", "paths": [ "terraforged:trees/willow/large" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/willow_small.json b/src/main/resources/data/terraforged/templates/trees/willow_small.json similarity index 60% rename from TerraForgedMod/src/main/resources/data/terraforged/templates/trees/willow_small.json rename to src/main/resources/data/terraforged/templates/trees/willow_small.json index 1de4946..8014327 100644 --- a/TerraForgedMod/src/main/resources/data/terraforged/templates/trees/willow_small.json +++ b/src/main/resources/data/terraforged/templates/trees/willow_small.json @@ -1,8 +1,11 @@ { "type": "tree", - "base": 3, "name": "terraforged:willow_small", "paths": [ "terraforged:trees/willow/small" - ] + ], + "config": { + "extend_base": 3, + "check_bounds": true + } } \ No newline at end of file diff --git a/TerraForgedAPI/src/main/resources/license.txt b/src/main/resources/license.txt similarity index 100% rename from TerraForgedAPI/src/main/resources/license.txt rename to src/main/resources/license.txt diff --git a/TerraForgedMod/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta similarity index 100% rename from TerraForgedMod/src/main/resources/pack.mcmeta rename to src/main/resources/pack.mcmeta diff --git a/src/main/resources/redwood.json b/src/main/resources/redwood.json new file mode 100644 index 0000000..b8f3dc5 --- /dev/null +++ b/src/main/resources/redwood.json @@ -0,0 +1,59 @@ +{ + "biomes": [ + "minecraft:*" + ], + "match": [ + [ + "minecraft:mega_spruce_tree" + ] + ], + "replace": { + "name": "minecraft:decorated", + "config": { + "feature": { + "name": "minecraft:random_selector", + "config": { + "features": [ + { + "name": "terraforged:template", + "config": { + "template": "terraforged:redwood_huge" + }, + "chance": 0.025641026 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:pine" + }, + "chance": 0.15 + }, + { + "name": "terraforged:template", + "config": { + "template": "terraforged:redwood_large" + }, + "chance": 0.33333334 + } + ], + "default": { + "name": "terraforged:template", + "config": { + "template": "terraforged:redwood_large" + } + } + } + }, + "decorator": { + "name": "terraforged:poisson_surface", + "config": { + "radius": 9, + "biome_fade": 0.2, + "density_noise_scale": 250, + "density_noise_min": 0.15, + "density_noise_max": 2.25 + } + } + } + } +} \ No newline at end of file diff --git a/TerraForgedMod/psd/terraforged.png b/src/main/resources/terraforged.png similarity index 100% rename from TerraForgedMod/psd/terraforged.png rename to src/main/resources/terraforged.png