mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
terraScript random is no more
This commit is contained in:
@@ -4,6 +4,7 @@ dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
compileOnlyApi(project(":common:addons:config-noise-function"))
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.ore;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.addons.ore.ores.VanillaOre;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -19,6 +20,6 @@ public class OreFactory implements ConfigFactory<OreTemplate, Structure> {
|
||||
public VanillaOre build(OreTemplate config, Platform platform) {
|
||||
BlockState m = config.getMaterial();
|
||||
return new VanillaOre(m, config.getSize(), config.getReplaceable(), config.doPhysics(), config.isExposed(),
|
||||
config.getMaterialOverrides());
|
||||
config.getMaterialOverrides(), new WhiteNoiseSampler());
|
||||
}
|
||||
}
|
||||
|
||||
+13
-8
@@ -7,10 +7,13 @@
|
||||
|
||||
package com.dfsek.terra.addons.ore.ores;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -30,38 +33,40 @@ public class VanillaOre implements Structure {
|
||||
private final boolean applyGravity;
|
||||
private final double exposed;
|
||||
private final Map<BlockType, BlockState> materials;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
public VanillaOre(BlockState material, double size, MaterialSet replaceable, boolean applyGravity,
|
||||
double exposed, Map<BlockType, BlockState> materials) {
|
||||
double exposed, Map<BlockType, BlockState> materials, NoiseSampler sampler) {
|
||||
this.material = material;
|
||||
this.size = size;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
this.exposed = exposed;
|
||||
this.materials = materials;
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Rotation rotation, Long seed){
|
||||
int centerX = location.getX();
|
||||
int centerZ = location.getZ();
|
||||
int centerY = location.getY();
|
||||
|
||||
|
||||
float f = random.nextFloat() * (float) Math.PI;
|
||||
double f = sampler.noise(centerX, centerY, centerZ, seed) * (float) Math.PI;
|
||||
|
||||
double d1 = centerX + 8 + FastMath.sin(f) * size / 8.0F;
|
||||
double d2 = centerX + 8 - FastMath.sin(f) * size / 8.0F;
|
||||
double d3 = centerZ + 8 + FastMath.cos(f) * size / 8.0F;
|
||||
double d4 = centerZ + 8 - FastMath.cos(f) * size / 8.0F;
|
||||
|
||||
double d5 = centerY + random.nextInt(3) - 2D;
|
||||
double d6 = centerY + random.nextInt(3) - 2D;
|
||||
double d5 = centerY + (Math.round(sampler.noise(centerX, centerY, centerZ, seed + 1) + 1)) - 2D;
|
||||
double d6 = centerY + (Math.round(sampler.noise(centerX, centerY, centerZ, seed + 2) + 1)) - 2D;
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
float iFactor = (float) i / (float) size;
|
||||
|
||||
double d10 = random.nextDouble() * size / 16.0D;
|
||||
double d10 = MathUtil.inverseLerp(sampler.noise(centerX, centerY, centerZ, seed + 2 + (i * 2 - 1)), -1, 1) * size / 16.0D;
|
||||
double d11 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
double d12 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
|
||||
@@ -85,7 +90,7 @@ public class VanillaOre implements Structure {
|
||||
if(y >= world.getMaxHeight() || y < world.getMinHeight()) continue;
|
||||
BlockType block = world.getBlockState(x, y, z).getBlockType();
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block)) {
|
||||
if(exposed > random.nextDouble() || !(world.getBlockState(x, y, z - 1).isAir() ||
|
||||
if(exposed > MathUtil.inverseLerp(sampler.noise(centerX, centerY, centerZ, seed + 2 + (i * 2)), -1, 1) || !(world.getBlockState(x, y, z - 1).isAir() ||
|
||||
world.getBlockState(x, y, z + 1).isAir() ||
|
||||
world.getBlockState(x, y - 1, z).isAir() ||
|
||||
world.getBlockState(x, y + 1, z).isAir() ||
|
||||
|
||||
@@ -9,4 +9,6 @@ website:
|
||||
issues: https://github.com/PolyhedralDev/Terra/issues
|
||||
source: https://github.com/PolyhedralDev/Terra
|
||||
docs: https://terra.polydev.org
|
||||
license: MIT License
|
||||
license: MIT License
|
||||
depends:
|
||||
config-noise-function: "1.+"
|
||||
Reference in New Issue
Block a user