diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeRegistry.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeRegistry.java new file mode 100644 index 0000000..990a73c --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeRegistry.java @@ -0,0 +1,31 @@ +/* + * + * 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.api.biome; + +public interface BiomeRegistry { + + void register(TransientBiome biome); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/TransientBiome.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/TransientBiome.java new file mode 100644 index 0000000..45ba191 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/TransientBiome.java @@ -0,0 +1,52 @@ +/* + * + * 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.api.biome; + +import net.minecraft.world.biome.Biome; + +public abstract class TransientBiome extends Biome { + + protected TransientBiome(Builder biomeBuilder) { + super(biomeBuilder); + } + + @Override + public int getGrassColor(double x, double z) { + return getBase().getGrassColor(x, z); + } + + @Override + public int getFoliageColor() { + return getBase().getFoliageColor(); + } + + @Override + public int getSkyColor() { + return getBase().getSkyColor(); + } + + public abstract Biome getBase(); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java b/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java index e05a98c..50ee70b 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java @@ -25,6 +25,7 @@ package com.terraforged.api.event; +import com.terraforged.api.biome.BiomeRegistry; import com.terraforged.api.biome.modifier.ModifierManager; import com.terraforged.api.chunk.column.DecoratorManager; import com.terraforged.api.chunk.surface.SurfaceManager; @@ -89,6 +90,16 @@ public abstract class SetupEvent extends Event { } } + /** + * Register custom Transient Biomes + */ + public static class Biomes extends SetupEvent { + + public Biomes(BiomeRegistry manager, GeneratorContext context) { + super(manager, context); + } + } + /** * Register custom BiomeModifiers */ 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 index 49b81d4..ee646b2 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java @@ -36,22 +36,22 @@ import java.util.List; public class Strata { - private final float[] depthBuffer; private final Module heightMod; private final List> strata; private Strata(Module heightMod, List> strata) { this.strata = strata; this.heightMod = heightMod; - this.depthBuffer = new float[strata.size()]; } public boolean downwards(final int x, final int y, final int z, Stratum.Visitor visitor) { + DepthBuffer depthBuffer = new DepthBuffer(strata, x, z); + int py = y; T last = null; - float sum = getDepth(x, z); + float sum = depthBuffer.sum; for (int i = 0; i < strata.size(); i++) { - float depth = depthBuffer[i] / sum; + float depth = depthBuffer.buffer[i] / sum; int height = NoiseUtil.round(depth * y); T value = strata.get(i).getValue(); last = value; @@ -77,10 +77,11 @@ public class Strata { } public boolean upwards(int x, int y, int z, Stratum.Visitor visitor) { + DepthBuffer depthBuffer = new DepthBuffer(strata, x, z); int py = 0; - float sum = getDepth(x, z); + float sum = depthBuffer.sum; for (int i = strata.size() - 1; i > 0; i--) { - float depth = depthBuffer[i] / sum; + float depth = depthBuffer.buffer[i] / sum; int height = NoiseUtil.round(depth * y); T value = strata.get(i).getValue(); for (int dy = 0; dy < height; dy++) { @@ -100,14 +101,21 @@ public class Strata { return (int) (64 * heightMod.getValue(x, z)); } - private float getDepth(int x, int z) { - float sum = 0F; - for (int i = 0; i < strata.size(); i++) { - float depth = strata.get(i).getDepth(x, z); - sum += depth; - depthBuffer[i] = depth; + private static class DepthBuffer { + + private final float sum; + private final float[] buffer; + + private DepthBuffer(List> strata, int x, int z) { + buffer = new float[strata.size()]; + float sum = 0F; + for (int i = 0; i < strata.size(); i++) { + float depth = strata.get(i).getDepth(x, z); + sum += depth; + buffer[i] = depth; + } + this.sum = sum; } - return sum; } public static Builder builder(int seed, me.dags.noise.source.Builder noise) { diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java index 48e97f5..166c90c 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java @@ -108,6 +108,10 @@ public class StandardTerrainProvider implements TerrainProvider { return result; } + protected GeneratorContext getContext() { + return context; + } + private TerrainPopulator combine(TerrainPopulator tp1, TerrainPopulator tp2) { return combine(tp1, tp2, context.seed, config.scale / 2); } diff --git a/TerraForgedMod b/TerraForgedMod index 0cd6356..28b3c0b 160000 --- a/TerraForgedMod +++ b/TerraForgedMod @@ -1 +1 @@ -Subproject commit 0cd63563bdc0fad258d78c21dfed1b14c975bdfd +Subproject commit 28b3c0bf7a47d22504cb958e5b2a03e585c76cc6