mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 06:40:12 +00:00
move ChunkInterpolator to noise chunk generator addon
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
|
||||
|
||||
public interface ChunkInterpolator {
|
||||
default double computeNoise(Map<GenerationSettings, MutableInteger> gens, double x, double y, double z) {
|
||||
double n = 0;
|
||||
double div = 0;
|
||||
for(Map.Entry<GenerationSettings, MutableInteger> entry : gens.entrySet()) {
|
||||
GenerationSettings gen = entry.getKey();
|
||||
int weight = entry.getValue().get();
|
||||
double noise = computeNoise(gen, x, y, z);
|
||||
|
||||
n += noise * weight;
|
||||
div += gen.getWeight() * weight;
|
||||
}
|
||||
return n / div;
|
||||
}
|
||||
|
||||
double computeNoise(GenerationSettings generationSettings, double x, double y, double z);
|
||||
|
||||
/**
|
||||
* Gets the noise at a pair of internal chunk coordinates.
|
||||
*
|
||||
* @param x The internal X coordinate (0-15).
|
||||
* @param z The internal Z coordinate (0-15).
|
||||
*
|
||||
* @return double - The interpolated noise at the coordinates.
|
||||
*/
|
||||
double getNoise(double x, double y, double z);
|
||||
|
||||
default double getNoise(int x, int y,
|
||||
int z) { // Floating-point modulus operations are expensive. This allows implementations to optionally handle
|
||||
// integers separately.
|
||||
return getNoise((double) x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.ChunkInterpolator;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -19,7 +17,6 @@ import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.ChunkInterpolator;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user