mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
Merge branch 'ver/6.4.0' into dev/image-caching
This commit is contained in:
commit
5829112a74
@ -12,7 +12,6 @@ object Versions {
|
||||
object Internal {
|
||||
const val shadow = "8.1.1"
|
||||
const val apacheText = "1.10.0"
|
||||
const val jafama = "2.3.2"
|
||||
const val apacheIO = "2.14.0"
|
||||
const val guava = "32.1.3-jre"
|
||||
const val asm = "9.5"
|
||||
|
@ -3,10 +3,6 @@ version = version("1.0.0")
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:library-image"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.biome.image.lib.jafama")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ package com.dfsek.terra.addons.biome.image.v2;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.addons.image.converter.ColorConverter;
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.converter.ColorConverter;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
@ -13,8 +13,8 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.biome.image.v2.ImageBiomeProvider;
|
||||
import com.dfsek.terra.addons.image.converter.ColorConverter;
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.converter.ColorConverter;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
@ -2,10 +2,6 @@ version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.biome.image.lib.jafama")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome.image;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
@ -34,7 +32,7 @@ public class ImageBiomeProvider implements BiomeProvider {
|
||||
}
|
||||
|
||||
private static int distance(Color a, Color b) {
|
||||
return FastMath.abs(a.getRed() - b.getRed()) + FastMath.abs(a.getGreen() - b.getGreen()) + FastMath.abs(a.getBlue() - b.getBlue());
|
||||
return Math.abs(a.getRed() - b.getRed()) + Math.abs(a.getGreen() - b.getGreen()) + Math.abs(a.getBlue() - b.getBlue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,14 +68,14 @@ public class ImageBiomeProvider implements BiomeProvider {
|
||||
CENTER {
|
||||
@Override
|
||||
public Color getColor(BufferedImage image, int x, int z) {
|
||||
return new Color(image.getRGB(FastMath.floorMod(x - image.getWidth() / 2, image.getWidth()),
|
||||
FastMath.floorMod(z - image.getHeight() / 2, image.getHeight())));
|
||||
return new Color(image.getRGB(Math.floorMod(x - image.getWidth() / 2, image.getWidth()),
|
||||
Math.floorMod(z - image.getHeight() / 2, image.getHeight())));
|
||||
}
|
||||
},
|
||||
NONE {
|
||||
@Override
|
||||
public Color getColor(BufferedImage image, int x, int z) {
|
||||
return new Color(image.getRGB(FastMath.floorMod(x, image.getWidth()), FastMath.floorMod(z, image.getHeight())));
|
||||
return new Color(image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(z, image.getHeight())));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2,11 +2,4 @@ version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.biome.pipeline.lib.jafama")
|
||||
}
|
@ -11,6 +11,9 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Source;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.BiomePipelineTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.PipelineBiomeLoader;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.source.SamplerSourceTemplate;
|
||||
@ -20,9 +23,6 @@ import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator.BorderStage
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator.ReplaceListStageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator.ReplaceStageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator.SmoothStageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Source;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
@ -1,13 +1,7 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.BiomeChunk;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Pipeline;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.SeededVector;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
@ -15,6 +9,11 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.BiomeChunk;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Pipeline;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.SeededVector;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.registry.key.StringIdentifiable;
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
@ -81,8 +80,8 @@ public class PipelineBiomeProvider implements BiomeProvider {
|
||||
x /= resolution;
|
||||
z /= resolution;
|
||||
|
||||
int chunkX = FastMath.floorDiv(x, chunkSize);
|
||||
int chunkZ = FastMath.floorDiv(z, chunkSize);
|
||||
int chunkX = Math.floorDiv(x, chunkSize);
|
||||
int chunkZ = Math.floorDiv(z, chunkSize);
|
||||
|
||||
int chunkWorldX = chunkX * chunkSize;
|
||||
int chunkWorldZ = chunkZ * chunkSize;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.api;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.BiomeChunkImpl.ViewPoint;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.BiomeChunkImpl.ViewPoint;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.api;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.BiomeChunkImpl.ViewPoint;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.BiomeChunkImpl.ViewPoint;
|
||||
|
||||
|
||||
public interface Stage {
|
||||
|
@ -15,9 +15,9 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.PipelineBiomeProvider;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.PipelineImpl;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Source;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.PipelineImpl;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.config.stage.expander;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Expander;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.stage.expander.FractalExpander;
|
||||
|
||||
|
||||
|
@ -11,9 +11,9 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.stage.mutators.BorderListStage;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
@ -9,9 +9,9 @@ package com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.stage.mutators.BorderStage;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
@ -11,9 +11,9 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.stage.mutators.ReplaceListStage;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
@ -9,9 +9,9 @@ package com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.stage.mutators.ReplaceStage;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.config.stage.mutator;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.stage.mutators.SmoothStage;
|
||||
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.pipeline;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.BiomeChunk;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Expander;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.SeededVector;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class BiomeChunkImpl implements BiomeChunk {
|
||||
@ -111,7 +110,7 @@ public class BiomeChunkImpl implements BiomeChunk {
|
||||
// chunk samples points on the same overall grid.
|
||||
// Without this, shared chunk borders (required because of adjacent cell reads) will not be identical
|
||||
// because points would be sampled on grids at different offsets, resulting in artifacts at borders.
|
||||
return FastMath.ceilToInt((double) finalGridOrigin / initialGridInterval) * initialGridInterval;
|
||||
return (int) Math.ceil((double) finalGridOrigin / initialGridInterval) * initialGridInterval;
|
||||
}
|
||||
|
||||
private static int calculateFinalGridOrigin(int totalExpanderCount, List<Stage> stages) {
|
||||
|
@ -3,8 +3,8 @@ package com.dfsek.terra.addons.biome.pipeline.v2.source;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Source;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
|
||||
|
||||
public class SingleSource implements Source {
|
||||
|
@ -2,11 +2,4 @@ version = version("1.0.1")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.biome.pipeline.lib.jafama")
|
||||
}
|
@ -9,7 +9,6 @@ package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
@ -86,8 +85,8 @@ public class BiomePipelineProvider implements BiomeProvider {
|
||||
x /= resolution;
|
||||
z /= resolution;
|
||||
|
||||
int fdX = FastMath.floorDiv(x, pipeline.getSize());
|
||||
int fdZ = FastMath.floorDiv(z, pipeline.getSize());
|
||||
int fdX = Math.floorDiv(x, pipeline.getSize());
|
||||
int fdZ = Math.floorDiv(z, pipeline.getSize());
|
||||
return holderCache.get(new SeededVector(fdX, fdZ, seed)).getBiome(x - fdX * pipeline.getSize(),
|
||||
z - fdZ * pipeline.getSize()).getBiome();
|
||||
}
|
||||
|
@ -2,11 +2,4 @@ version = version("1.2.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.chunkgenerator.lib.jafama")
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.BiomePaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.slant.SlantHolder;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
@ -8,15 +8,14 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation;
|
||||
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.BiomePaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.PaletteUtil;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.LazilyEvaluatedInterpolator;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.SamplerProvider;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.BiomePaletteInfo;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@ -133,8 +132,8 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
|
||||
BiomePaletteInfo paletteInfo = biome.getContext().get(paletteInfoPropertyKey);
|
||||
|
||||
int fdX = FastMath.floorMod(x, 16);
|
||||
int fdZ = FastMath.floorMod(z, 16);
|
||||
int fdX = Math.floorMod(x, 16);
|
||||
int fdZ = Math.floorMod(z, 16);
|
||||
|
||||
Palette palette = PaletteUtil.getPalette(fdX, y, fdZ, sampler, paletteInfo, 0);
|
||||
double noise = sampler.sample(fdX, y, fdZ);
|
||||
@ -156,8 +155,8 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
}
|
||||
|
||||
public double getSlant(int x, int y, int z, WorldProperties world, BiomeProvider biomeProvider) {
|
||||
int fdX = FastMath.floorMod(x, 16);
|
||||
int fdZ = FastMath.floorMod(z, 16);
|
||||
int fdX = Math.floorMod(x, 16);
|
||||
int fdZ = Math.floorMod(z, 16);
|
||||
return biomeProvider.getBiome(x, y, z, world.getSeed())
|
||||
.getContext()
|
||||
.get(paletteInfoPropertyKey)
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.BiomePaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.BiomePaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.slant.SlantHolder;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
@ -134,7 +132,7 @@ public class ChunkInterpolator {
|
||||
}
|
||||
|
||||
private static int reRange(int value, int high) {
|
||||
return FastMath.max(FastMath.min(value, high), 0);
|
||||
return Math.max(Math.min(value, high), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,7 +144,7 @@ public class ChunkInterpolator {
|
||||
* @return double - The interpolated noise at the coordinates.
|
||||
*/
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][(FastMath.max(FastMath.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4,
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][(Math.max(Math.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4,
|
||||
3)].trilerp(
|
||||
(x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
@ -30,8 +28,8 @@ public class LazilyEvaluatedInterpolator {
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int min, int horizontalRes, int verticalRes,
|
||||
long seed) {
|
||||
this.noisePropertiesKey = noisePropertiesKey;
|
||||
int hSamples = FastMath.ceilToInt(16.0 / horizontalRes);
|
||||
int vSamples = FastMath.ceilToInt((double) (max - min) / verticalRes);
|
||||
int hSamples = (int) Math.ceil(16.0 / horizontalRes);
|
||||
int vSamples = (int) Math.ceil((double) (max - min) / verticalRes);
|
||||
this.zMul = (hSamples + 1);
|
||||
this.yMul = zMul * zMul;
|
||||
samples = new Double[yMul * (vSamples + 1)];
|
||||
@ -52,7 +50,7 @@ public class LazilyEvaluatedInterpolator {
|
||||
int xi = ox + chunkX;
|
||||
int zi = oz + chunkZ;
|
||||
|
||||
int y = FastMath.min(max, oy);
|
||||
int y = Math.min(max, oy);
|
||||
|
||||
sample = biomeProvider
|
||||
.getBiome(xi, y, zi, seed)
|
||||
@ -93,7 +91,7 @@ public class LazilyEvaluatedInterpolator {
|
||||
return lerp_bottom;
|
||||
}
|
||||
|
||||
double yFrac = (double) FastMath.floorMod(y, verticalRes) / verticalRes;
|
||||
double yFrac = (double) Math.floorMod(y, verticalRes) / verticalRes;
|
||||
|
||||
|
||||
double sample_0_1_0 = sample(xIndex, yIndex + 1, zIndex, x, y + verticalRes, z);
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.ChunkInterpolator;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.ElevationInterpolator;
|
||||
@ -28,10 +26,10 @@ public class Sampler3D {
|
||||
}
|
||||
|
||||
public double sample(double x, double y, double z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation((int) Math.round(x), (int) Math.round(z));
|
||||
}
|
||||
|
||||
public double sample(int x, int y, int z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(x, z);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
@ -45,8 +44,8 @@ public class SamplerProvider {
|
||||
}
|
||||
|
||||
public Sampler3D get(int x, int z, WorldProperties world, BiomeProvider provider) {
|
||||
int cx = FastMath.floorDiv(x, 16);
|
||||
int cz = FastMath.floorDiv(z, 16);
|
||||
int cx = Math.floorDiv(x, 16);
|
||||
int cz = Math.floorDiv(z, 16);
|
||||
return getChunk(cx, cz, world, provider);
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.palette;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@ -55,11 +53,11 @@ public class PaletteHolder {
|
||||
|
||||
public PaletteHolder build() {
|
||||
|
||||
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
int min = Math.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = Math.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
Palette[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
|
||||
for(int y = min; y <= Math.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette d = null;
|
||||
for(Entry<Integer, Palette> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y) {
|
||||
|
@ -2,11 +2,4 @@ version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.feature.distributor.lib.jafama")
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
@ -21,21 +19,12 @@ public class PaddedGridDistributor implements Distributor {
|
||||
this.cellWidth = width + padding;
|
||||
}
|
||||
|
||||
private static long murmur64(long h) {
|
||||
h ^= h >>> 33;
|
||||
h *= 0xff51afd7ed558ccdL;
|
||||
h ^= h >>> 33;
|
||||
h *= 0xc4ceb9fe1a85ec53L;
|
||||
h ^= h >>> 33;
|
||||
return h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int z, long seed) {
|
||||
int cellX = FastMath.floorDiv(x, cellWidth);
|
||||
int cellZ = FastMath.floorDiv(z, cellWidth);
|
||||
int cellX = Math.floorDiv(x, cellWidth);
|
||||
int cellZ = Math.floorDiv(z, cellWidth);
|
||||
|
||||
Random random = new Random((murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
|
||||
Random random = new Random((MathUtil.murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
|
||||
|
||||
int pointX = random.nextInt(width) + cellX * cellWidth;
|
||||
int pointZ = random.nextInt(width) + cellZ * cellWidth;
|
||||
|
@ -2,10 +2,4 @@ version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.flora.lib.jafama")
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.flora.flora.gen;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@ -60,7 +58,7 @@ public class TerraFlora implements Structure {
|
||||
}
|
||||
|
||||
private ProbabilityCollection<BlockState> getStateCollection(int layer) {
|
||||
return layers.get(FastMath.max(FastMath.min(layer, layers.size() - 1), 0));
|
||||
return layers.get(Math.max(Math.min(layer, layers.size() - 1), 0));
|
||||
}
|
||||
|
||||
private EnumSet<Direction> getFaces(Vector3Int b, WritableWorld world) {
|
||||
@ -82,8 +80,8 @@ public class TerraFlora implements Structure {
|
||||
Direction.class);
|
||||
if(doRotation && faces.size() == 0) return false; // Don't plant if no faces are valid.
|
||||
|
||||
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (FastMath.abs(i));
|
||||
for(int i = 0; Math.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (Math.abs(i));
|
||||
BlockState data = getStateCollection((ceiling ? lvl : size - lvl - 1)).get(distribution, location.getX(), location.getY(),
|
||||
location.getZ(), world.getSeed());
|
||||
if(doRotation) {
|
||||
|
@ -2,11 +2,4 @@ version = version("1.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.feature.locator.lib.jafama")
|
||||
}
|
||||
}
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.locators;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
|
||||
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||
import com.dfsek.terra.api.structure.feature.Locator;
|
||||
@ -27,8 +25,8 @@ public class PatternLocator implements Locator {
|
||||
|
||||
@Override
|
||||
public BinaryColumn getSuitableCoordinates(Column<?> column) {
|
||||
int min = FastMath.max(column.getMinY(), search.getMin());
|
||||
int max = FastMath.min(column.getMaxY(), search.getMax());
|
||||
int min = Math.max(column.getMinY(), search.getMin());
|
||||
int max = Math.min(column.getMaxY(), search.getMax());
|
||||
if(min >= max) return BinaryColumn.getNull();
|
||||
return new BinaryColumn(min, max, y -> pattern.matches(y, column));
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.locators;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||
import com.dfsek.terra.api.structure.feature.Locator;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
@ -26,8 +24,8 @@ public class SurfaceLocator implements Locator {
|
||||
@Override
|
||||
public BinaryColumn getSuitableCoordinates(Column<?> column) {
|
||||
BinaryColumnBuilder builder = column.newBinaryColumn();
|
||||
int max = FastMath.min(search.getMax(), column.getMaxY());
|
||||
int min = FastMath.max(search.getMin(), column.getMinY());
|
||||
int max = Math.min(search.getMax(), column.getMaxY());
|
||||
int min = Math.max(search.getMin(), column.getMinY());
|
||||
if(min >= max) return builder.build();
|
||||
for(int y = min; y < max; y++) {
|
||||
if(column.getBlock(y).isAir() && !column.getBlock(y - 1).isAir()) {
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.patterns;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@ -28,8 +26,8 @@ public class MatchPattern implements Pattern {
|
||||
|
||||
@Override
|
||||
public boolean matches(int y, Column<?> column) {
|
||||
int min = FastMath.max(column.getMinY(), range.getMin() + y);
|
||||
int max = FastMath.min(column.getMaxY(), range.getMax() + y);
|
||||
int min = Math.max(column.getMinY(), range.getMin() + y);
|
||||
int max = Math.min(column.getMaxY(), range.getMax() + y);
|
||||
if(max <= min) return false;
|
||||
for(int i = min; i < max; i++) {
|
||||
if(!matches.test(column.getBlock(i))) return false;
|
||||
@ -39,8 +37,8 @@ public class MatchPattern implements Pattern {
|
||||
|
||||
@Override
|
||||
public boolean matches(WritableWorld world, int x, int y, int z) {
|
||||
int min = FastMath.max(world.getMinHeight(), range.getMin() + y);
|
||||
int max = FastMath.min(world.getMaxHeight(), range.getMax() + y);
|
||||
int min = Math.max(world.getMinHeight(), range.getMin() + y);
|
||||
int max = Math.min(world.getMaxHeight(), range.getMax() + y);
|
||||
if(max <= min) return false;
|
||||
for(int i = min; i < max; i++) {
|
||||
if(!matches.test(world.getBlockState(x, i, z))) return false;
|
||||
|
@ -5,12 +5,4 @@ version = version("1.1.0")
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
api("com.dfsek", "paralithic", Versions.Libraries.paralithic)
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("com.dfsek.paralithic", "com.dfsek.terra.addons.noise.lib.paralithic")
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.noise.lib.jafama")
|
||||
}
|
@ -2,14 +2,14 @@ package com.dfsek.terra.addons.noise.config.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.noise.math.CubicSpline;
|
||||
import com.dfsek.terra.addons.noise.math.CubicSpline.Point;
|
||||
import com.dfsek.terra.addons.noise.normalizer.CubicSplineNoiseSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CubicSplineNormalizerTemplate extends NormalizerTemplate<CubicSplineNoiseSampler> {
|
||||
|
||||
|
@ -11,16 +11,16 @@ import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.normalizer.ExpressionNormalizer;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.dfsek.terra.addons.noise.paralithic.FunctionUtil.convertFunctionsAndSamplers;
|
||||
|
||||
|
||||
|
@ -5,6 +5,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.dfsek.terra.api.util.MathUtil.lerp;
|
||||
|
||||
|
||||
public class CubicSpline {
|
||||
|
||||
@ -74,11 +76,7 @@ public class CubicSpline {
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
private static double lerp(double t, double a, double b) {
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
|
||||
public record Point(double from, double to, double gradient) implements Comparable<Point> {
|
||||
|
||||
@Override
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.normalizer;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@ -24,6 +22,6 @@ public class ClampNormalizer extends Normalizer {
|
||||
|
||||
@Override
|
||||
public double normalize(double in) {
|
||||
return FastMath.max(FastMath.min(in, max), min);
|
||||
return Math.max(Math.min(in, max), min);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.paralithic.functions.Function;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public class ExpressionNormalizer extends Normalizer {
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.normalizer;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
@ -41,8 +39,8 @@ public class NormalNormalizer extends Normalizer {
|
||||
end = mid;
|
||||
}
|
||||
}
|
||||
double left = FastMath.abs(lookup[start] - in);
|
||||
double right = FastMath.abs(lookup[end] - in);
|
||||
double left = Math.abs(lookup[start] - in);
|
||||
double right = Math.abs(lookup[end] - in);
|
||||
|
||||
double fin;
|
||||
if(left <= right) {
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.normalizer;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@ -22,6 +20,6 @@ public class PosterizationNormalizer extends Normalizer {
|
||||
|
||||
@Override
|
||||
public double normalize(double in) {
|
||||
return FastMath.roundToInt((in + 1) / stepSize) * stepSize - 1;
|
||||
return (int) Math.round((in + 1) / stepSize) * stepSize - 1;
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,15 @@ package com.dfsek.terra.addons.noise.paralithic;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.paralithic.functions.Function;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.paralithic.defined.UserDefinedFunction;
|
||||
import com.dfsek.terra.addons.noise.paralithic.noise.NoiseFunction2;
|
||||
import com.dfsek.terra.addons.noise.paralithic.noise.NoiseFunction3;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class FunctionUtil {
|
||||
private FunctionUtil() {}
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
@ -28,8 +26,8 @@ public class ImageSampler implements NoiseSampler {
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return ((channel.getChannel(image.getRGB(FastMath.floorMod(FastMath.floorToInt(x * frequency), image.getWidth()),
|
||||
FastMath.floorMod(FastMath.floorToInt(y * frequency), image.getHeight()))) / 255D) - 0.5) *
|
||||
return ((channel.getChannel(image.getRGB(Math.floorMod((int) Math.floor(x * frequency), image.getWidth()),
|
||||
Math.floorMod((int) Math.floor(y * frequency), image.getHeight()))) / 255D) - 0.5) *
|
||||
2;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.arithmetic;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@ -12,6 +10,6 @@ public class MaxSampler extends BinaryArithmeticSampler {
|
||||
|
||||
@Override
|
||||
public double operate(double left, double right) {
|
||||
return FastMath.max(left, right);
|
||||
return Math.max(left, right);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.arithmetic;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@ -12,6 +10,6 @@ public class MinSampler extends BinaryArithmeticSampler {
|
||||
|
||||
@Override
|
||||
public double operate(double left, double right) {
|
||||
return FastMath.min(left, right);
|
||||
return Math.min(left, right);
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.simplex.OpenSimplex2Sampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
@ -223,8 +221,8 @@ public class CellularSampler extends NoiseFunction {
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
int xr = fastRound(x);
|
||||
int yr = fastRound(y);
|
||||
int xr = (int) Math.round(x);
|
||||
int yr = (int) Math.round(y);
|
||||
|
||||
double distance0 = Double.MAX_VALUE;
|
||||
double distance1 = Double.MAX_VALUE;
|
||||
@ -251,12 +249,12 @@ public class CellularSampler extends NoiseFunction {
|
||||
double vecY = (yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
|
||||
|
||||
double newDistance = switch(distanceFunction) {
|
||||
case Manhattan -> fastAbs(vecX) + fastAbs(vecY);
|
||||
case Hybrid -> (fastAbs(vecX) + fastAbs(vecY)) + (vecX * vecX + vecY * vecY);
|
||||
case Manhattan -> Math.abs(vecX) + Math.abs(vecY);
|
||||
case Hybrid -> (Math.abs(vecX) + Math.abs(vecY)) + (vecX * vecX + vecY * vecY);
|
||||
default -> vecX * vecX + vecY * vecY;
|
||||
};
|
||||
|
||||
distance1 = fastMax(fastMin(distance1, newDistance), distance0);
|
||||
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
|
||||
if(newDistance < distance0) {
|
||||
distance0 = newDistance;
|
||||
closestHash = hash;
|
||||
@ -274,9 +272,9 @@ public class CellularSampler extends NoiseFunction {
|
||||
}
|
||||
|
||||
if(distanceFunction == DistanceFunction.Euclidean && returnType != ReturnType.CellValue) {
|
||||
distance0 = fastSqrt(distance0);
|
||||
distance0 = Math.sqrt(distance0);
|
||||
if(returnType != ReturnType.CellValue) {
|
||||
distance1 = fastSqrt(distance1);
|
||||
distance1 = Math.sqrt(distance1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,16 +293,16 @@ public class CellularSampler extends NoiseFunction {
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
case Distance3Mul -> distance2 * distance0 - 1;
|
||||
case Distance3Div -> distance0 / distance2 - 1;
|
||||
case Angle -> FastMath.atan2(y / frequency - centerY, x / frequency - centerX);
|
||||
case Angle -> Math.atan2(y / frequency - centerY, x / frequency - centerX);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
int xr = fastRound(x);
|
||||
int yr = fastRound(y);
|
||||
int zr = fastRound(z);
|
||||
int xr = (int) Math.round(x);
|
||||
int yr = (int) Math.round(y);
|
||||
int zr = (int) Math.round(z);
|
||||
|
||||
double distance0 = Double.MAX_VALUE;
|
||||
double distance1 = Double.MAX_VALUE;
|
||||
@ -338,10 +336,10 @@ public class CellularSampler extends NoiseFunction {
|
||||
double newDistance = 0;
|
||||
switch(distanceFunction) {
|
||||
case Euclidean, EuclideanSq -> newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
|
||||
case Manhattan -> newDistance = fastAbs(vecX) + fastAbs(vecY) + fastAbs(vecZ);
|
||||
case Manhattan -> newDistance = Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ);
|
||||
case Hybrid -> {
|
||||
newDistance = (fastAbs(vecX) + fastAbs(vecY) + fastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
|
||||
distance1 = fastMax(fastMin(distance1, newDistance), distance0);
|
||||
newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
|
||||
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -365,9 +363,9 @@ public class CellularSampler extends NoiseFunction {
|
||||
}
|
||||
|
||||
if(distanceFunction == DistanceFunction.Euclidean && returnType != ReturnType.CellValue) {
|
||||
distance0 = fastSqrt(distance0);
|
||||
distance0 = Math.sqrt(distance0);
|
||||
if(returnType != ReturnType.CellValue) {
|
||||
distance1 = fastSqrt(distance1);
|
||||
distance1 = Math.sqrt(distance1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,7 +384,7 @@ public class CellularSampler extends NoiseFunction {
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
case Distance3Mul -> distance2 * distance0 - 1;
|
||||
case Distance3Div -> distance0 / distance2 - 1;
|
||||
case Angle -> FastMath.atan2(y / frequency - centerY, x / frequency - centerX);
|
||||
case Angle -> Math.atan2(y / frequency - centerY, x / frequency - centerX);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,9 @@ public class DistanceSampler extends NoiseFunction {
|
||||
public double getNoiseRaw(long seed, double x, double y) {
|
||||
double dx = x - ox;
|
||||
double dy = y - oz;
|
||||
if (normalize && (fastAbs(dx) > radius || fastAbs(dy) > radius)) return 1;
|
||||
if (normalize && (Math.abs(dx) > radius || Math.abs(dy) > radius)) return 1;
|
||||
double dist = distance2d(distanceFunction, dx, dy);
|
||||
if (normalize) return fastMin(((2*dist)/distanceAtRadius)-1, 1);
|
||||
if (normalize) return Math.min(((2*dist)/distanceAtRadius)-1, 1);
|
||||
return dist;
|
||||
}
|
||||
|
||||
@ -36,25 +36,25 @@ public class DistanceSampler extends NoiseFunction {
|
||||
double dx = x - ox;
|
||||
double dy = y - oy;
|
||||
double dz = z - oz;
|
||||
if(normalize && (fastAbs(dx) > radius || fastAbs(dy) > radius || fastAbs(dz) > radius)) return 1;
|
||||
if(normalize && (Math.abs(dx) > radius || Math.abs(dy) > radius || Math.abs(dz) > radius)) return 1;
|
||||
double dist = distance3d(distanceFunction, dx, dy, dz);
|
||||
if (normalize) return fastMin(((2*dist)/distanceAtRadius)-1, 1);
|
||||
if (normalize) return Math.min(((2*dist)/distanceAtRadius)-1, 1);
|
||||
return dist;
|
||||
}
|
||||
|
||||
private static double distance2d(DistanceFunction distanceFunction, double x, double z) {
|
||||
return switch(distanceFunction) {
|
||||
case Euclidean -> fastSqrt(x*x + z*z);
|
||||
case Euclidean -> Math.sqrt(x*x + z*z);
|
||||
case EuclideanSq -> x*x + z*z;
|
||||
case Manhattan -> fastAbs(x) + fastAbs(z);
|
||||
case Manhattan -> Math.abs(x) + Math.abs(z);
|
||||
};
|
||||
}
|
||||
|
||||
private static double distance3d(DistanceFunction distanceFunction, double x, double y, double z) {
|
||||
return switch(distanceFunction) {
|
||||
case Euclidean -> fastSqrt(x*x + y*y + z*z);
|
||||
case Euclidean -> Math.sqrt(x*x + y*y + z*z);
|
||||
case EuclideanSq -> x*x + y*y + z*z;
|
||||
case Manhattan -> fastAbs(x) + fastAbs(y) + fastAbs(z);
|
||||
case Manhattan -> Math.abs(x) + Math.abs(y) + Math.abs(z);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class GaborNoiseSampler extends NoiseFunction {
|
||||
@ -17,11 +16,11 @@ public class GaborNoiseSampler extends NoiseFunction {
|
||||
private double k = 1.0;
|
||||
private double a = 0.1;
|
||||
private double f0 = 0.625;
|
||||
private double kernelRadius = (FastMath.sqrt(-FastMath.log(0.05) / Math.PI) / a);
|
||||
private double kernelRadius = (Math.sqrt(-Math.log(0.05) / Math.PI) / a);
|
||||
private double impulsesPerKernel = 64d;
|
||||
private double impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius));
|
||||
private double impulsesPerCell = impulseDensity * kernelRadius * kernelRadius;
|
||||
private double g = FastMath.exp(-impulsesPerCell);
|
||||
private double g = Math.exp(-impulsesPerCell);
|
||||
|
||||
private double omega0 = Math.PI * 0.25;
|
||||
private boolean isotropic = true;
|
||||
@ -32,17 +31,17 @@ public class GaborNoiseSampler extends NoiseFunction {
|
||||
}
|
||||
|
||||
private void recalculateRadiusAndDensity() {
|
||||
kernelRadius = (FastMath.sqrt(-FastMath.log(0.05) / Math.PI) / this.a);
|
||||
kernelRadius = (Math.sqrt(-Math.log(0.05) / Math.PI) / this.a);
|
||||
impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius));
|
||||
impulsesPerCell = impulseDensity * kernelRadius * kernelRadius;
|
||||
g = FastMath.exp(-impulsesPerCell);
|
||||
g = Math.exp(-impulsesPerCell);
|
||||
}
|
||||
|
||||
private double gaborNoise(long seed, double x, double y) {
|
||||
x /= kernelRadius;
|
||||
y /= kernelRadius;
|
||||
int xi = fastFloor(x);
|
||||
int yi = fastFloor(y);
|
||||
int xi = (int) Math.floor(x);
|
||||
int yi = (int) Math.floor(y);
|
||||
double xf = x - xi;
|
||||
double yf = y - yi;
|
||||
double noise = 0;
|
||||
@ -55,7 +54,7 @@ public class GaborNoiseSampler extends NoiseFunction {
|
||||
}
|
||||
|
||||
private double calculateCell(long seed, int xi, int yi, double x, double y) {
|
||||
long mashedSeed = murmur64(31L * xi + yi) + seed;
|
||||
long mashedSeed = MathUtil.murmur64(31L * xi + yi) + seed;
|
||||
|
||||
double gaussianSource = (rand.getNoiseRaw(mashedSeed++) + 1) / 2;
|
||||
int impulses = 0;
|
||||
@ -73,7 +72,7 @@ public class GaborNoiseSampler extends NoiseFunction {
|
||||
}
|
||||
|
||||
private double gabor(double omega_0, double x, double y) {
|
||||
return k * (FastMath.exp(-Math.PI * (a * a) * (x * x + y * y)) * fastCos(2 * Math.PI * f0 * (x * fastCos(omega_0) + y * fastSin(
|
||||
return k * (Math.exp(-Math.PI * (a * a) * (x * x + y * y)) * MathUtil.cos(2 * Math.PI * f0 * (x * MathUtil.cos(omega_0) + y * MathUtil.sin(
|
||||
omega_0))));
|
||||
}
|
||||
|
||||
|
@ -7,25 +7,15 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@SuppressWarnings("ManualMinMaxCalculation")
|
||||
public abstract class NoiseFunction implements NoiseSampler {
|
||||
// Hashing
|
||||
protected static final int PRIME_X = 501125321;
|
||||
protected static final int PRIME_Y = 1136930381;
|
||||
protected static final int PRIME_Z = 1720413743;
|
||||
static final int precision = 100;
|
||||
static final int modulus = 360 * precision;
|
||||
static final double[] sin = new double[360 * 100]; // lookup table
|
||||
static {
|
||||
for(int i = 0; i < sin.length; i++) {
|
||||
sin[i] = (float) Math.sin((double) (i) / (precision));
|
||||
}
|
||||
}
|
||||
|
||||
protected double frequency = 0.02d;
|
||||
protected long salt;
|
||||
|
||||
@ -33,10 +23,6 @@ public abstract class NoiseFunction implements NoiseSampler {
|
||||
this.salt = 0;
|
||||
}
|
||||
|
||||
protected static int fastFloor(double f) {
|
||||
return f >= 0 ? (int) f : (int) f - 1;
|
||||
}
|
||||
|
||||
protected static int hash(int seed, int xPrimed, int yPrimed, int zPrimed) {
|
||||
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
|
||||
|
||||
@ -51,77 +37,6 @@ public abstract class NoiseFunction implements NoiseSampler {
|
||||
return hash;
|
||||
}
|
||||
|
||||
protected static int fastRound(double f) {
|
||||
return f >= 0 ? (int) (f + 0.5f) : (int) (f - 0.5);
|
||||
}
|
||||
|
||||
protected static double lerp(double a, double b, double t) {
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
protected static double interpHermite(double t) {
|
||||
return t * t * (3 - 2 * t);
|
||||
}
|
||||
|
||||
protected static double interpQuintic(double t) {
|
||||
return t * t * t * (t * (t * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
protected static double cubicLerp(double a, double b, double c, double d, double t) {
|
||||
double p = (d - c) - (a - b);
|
||||
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
|
||||
}
|
||||
|
||||
protected static double fastMin(double a, double b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
protected static double fastMax(double a, double b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
protected static double fastAbs(double f) {
|
||||
return f < 0 ? -f : f;
|
||||
}
|
||||
|
||||
protected static double fastSqrt(double f) {
|
||||
return FastMath.sqrt(f);
|
||||
}
|
||||
|
||||
protected static int fastCeil(double f) {
|
||||
int i = (int) f;
|
||||
if(i < f) i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Murmur64 hashing function
|
||||
*
|
||||
* @param h Input value
|
||||
*
|
||||
* @return Hashed value
|
||||
*/
|
||||
protected static long murmur64(long h) {
|
||||
h ^= h >>> 33;
|
||||
h *= 0xff51afd7ed558ccdL;
|
||||
h ^= h >>> 33;
|
||||
h *= 0xc4ceb9fe1a85ec53L;
|
||||
h ^= h >>> 33;
|
||||
return h;
|
||||
}
|
||||
|
||||
protected static double fastSin(double a) {
|
||||
return sinLookup((int) (a * precision + 0.5f));
|
||||
}
|
||||
|
||||
protected static double fastCos(double a) {
|
||||
return sinLookup((int) ((a + Math.PI / 2) * precision + 0.5f));
|
||||
}
|
||||
|
||||
private static double sinLookup(int a) {
|
||||
return a >= 0 ? sin[a % (modulus)] : -sin[-a % (modulus)];
|
||||
}
|
||||
|
||||
public void setSalt(long salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class BrownianMotionSampler extends FractalNoiseFunction {
|
||||
@ -23,7 +24,7 @@ public class BrownianMotionSampler extends FractalNoiseFunction {
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double noise = input.noise(seed++, x, y);
|
||||
sum += noise * amp;
|
||||
amp *= lerp(1.0, fastMin(noise + 1, 2) * 0.5, weightedStrength);
|
||||
amp *= MathUtil.lerp(1.0, Math.min(noise + 1, 2) * 0.5, weightedStrength);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
@ -41,7 +42,7 @@ public class BrownianMotionSampler extends FractalNoiseFunction {
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double noise = input.noise(seed++, x, y, z);
|
||||
sum += noise * amp;
|
||||
amp *= lerp(1.0, (noise + 1) * 0.5, weightedStrength);
|
||||
amp *= MathUtil.lerp(1.0, (noise + 1) * 0.5, weightedStrength);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
|
@ -25,7 +25,7 @@ public abstract class FractalNoiseFunction extends NoiseFunction {
|
||||
}
|
||||
|
||||
protected void calculateFractalBounding() {
|
||||
double gain = fastAbs(this.gain);
|
||||
double gain = Math.abs(this.gain);
|
||||
double amp = gain;
|
||||
double ampFractal = 1.0;
|
||||
for(int i = 1; i < octaves; i++) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class PingPongSampler extends FractalNoiseFunction {
|
||||
@ -35,7 +36,7 @@ public class PingPongSampler extends FractalNoiseFunction {
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double noise = pingPong((input.noise(seed++, x, y) + 1) * pingPongStrength);
|
||||
sum += (noise - 0.5) * 2 * amp;
|
||||
amp *= lerp(1.0, noise, weightedStrength);
|
||||
amp *= MathUtil.lerp(1.0, noise, weightedStrength);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
@ -53,7 +54,7 @@ public class PingPongSampler extends FractalNoiseFunction {
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double noise = pingPong((input.noise(seed++, x, y, z) + 1) * pingPongStrength);
|
||||
sum += (noise - 0.5) * 2 * amp;
|
||||
amp *= lerp(1.0, noise, weightedStrength);
|
||||
amp *= MathUtil.lerp(1.0, noise, weightedStrength);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
|
@ -8,6 +8,7 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class RidgedFractalSampler extends FractalNoiseFunction {
|
||||
@ -22,9 +23,9 @@ public class RidgedFractalSampler extends FractalNoiseFunction {
|
||||
double amp = fractalBounding;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double noise = fastAbs(input.noise(seed++, x, y));
|
||||
double noise = Math.abs(input.noise(seed++, x, y));
|
||||
sum += (noise * -2 + 1) * amp;
|
||||
amp *= lerp(1.0, 1 - noise, weightedStrength);
|
||||
amp *= MathUtil.lerp(1.0, 1 - noise, weightedStrength);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
@ -40,9 +41,9 @@ public class RidgedFractalSampler extends FractalNoiseFunction {
|
||||
double amp = fractalBounding;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double noise = fastAbs(input.noise(seed++, x, y, z));
|
||||
double noise = Math.abs(input.noise(seed++, x, y, z));
|
||||
sum += (noise * -2 + 1) * amp;
|
||||
amp *= lerp(1.0, 1 - noise, weightedStrength);
|
||||
amp *= MathUtil.lerp(1.0, 1 - noise, weightedStrength);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.random;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
/**
|
||||
* NoiseSampler implementation to produce random, uniformly distributed (white) noise.
|
||||
*/
|
||||
@ -15,7 +18,7 @@ public class PositiveWhiteNoiseSampler extends WhiteNoiseSampler {
|
||||
// Bits that when applied to the exponent/sign section of a double, produce a positive number with a power of 1.
|
||||
|
||||
public double getNoiseRaw(long seed) {
|
||||
return (Double.longBitsToDouble((murmur64(seed) & 0x000fffffffffffffL) | POSITIVE_POW1) - 1.5) * 2;
|
||||
return (Double.longBitsToDouble((MathUtil.murmur64(seed) & 0x000fffffffffffffL) | POSITIVE_POW1) - 1.5) * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,6 +8,7 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.random;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
/**
|
||||
@ -24,18 +25,18 @@ public class WhiteNoiseSampler extends NoiseFunction {
|
||||
long hashX = Double.doubleToRawLongBits(x) ^ seed;
|
||||
long hashZ = Double.doubleToRawLongBits(y) ^ seed;
|
||||
long hash = (((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed) + Double.doubleToRawLongBits(z);
|
||||
return murmur64(hash);
|
||||
return MathUtil.murmur64(hash);
|
||||
}
|
||||
|
||||
public long randomBits(long seed, double x, double y) {
|
||||
long hashX = Double.doubleToRawLongBits(x) ^ seed;
|
||||
long hashZ = Double.doubleToRawLongBits(y) ^ seed;
|
||||
long hash = ((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed;
|
||||
return murmur64(hash);
|
||||
return MathUtil.murmur64(hash);
|
||||
}
|
||||
|
||||
public double getNoiseRaw(long seed) {
|
||||
return (Double.longBitsToDouble((murmur64(seed) & 0x000fffffffffffffL) | POSITIVE_POW1) - 1.5) * 2;
|
||||
return (Double.longBitsToDouble((MathUtil.murmur64(seed) & 0x000fffffffffffffL) | POSITIVE_POW1) - 1.5) * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,8 +26,8 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler {
|
||||
y += s;
|
||||
|
||||
|
||||
int i = fastFloor(x);
|
||||
int j = fastFloor(y);
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
|
||||
@ -131,9 +131,9 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler {
|
||||
z = r - z;
|
||||
|
||||
|
||||
int i = fastFloor(x);
|
||||
int j = fastFloor(y);
|
||||
int k = fastFloor(z);
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
int k = (int) Math.floor(z);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
double zi = z - k;
|
||||
|
@ -25,8 +25,8 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
y += s;
|
||||
|
||||
|
||||
int i = fastFloor(x);
|
||||
int j = fastFloor(y);
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
|
||||
@ -85,9 +85,9 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
z = r - z;
|
||||
|
||||
|
||||
int i = fastRound(x);
|
||||
int j = fastRound(y);
|
||||
int k = fastRound(z);
|
||||
int i = (int) Math.round(x);
|
||||
int j = (int) Math.round(y);
|
||||
int k = (int) Math.round(z);
|
||||
double x0 = x - i;
|
||||
double y0 = y - j;
|
||||
double z0 = z - k;
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.simplex;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
/**
|
||||
* NoiseSampler implementation to provide Perlin Noise.
|
||||
*/
|
||||
@ -14,34 +17,34 @@ public class PerlinSampler extends SimplexStyleSampler {
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
int x0 = fastFloor(x);
|
||||
int y0 = fastFloor(y);
|
||||
int x0 = (int) Math.floor(x);
|
||||
int y0 = (int) Math.floor(y);
|
||||
|
||||
double xd0 = x - x0;
|
||||
double yd0 = y - y0;
|
||||
double xd1 = xd0 - 1;
|
||||
double yd1 = yd0 - 1;
|
||||
|
||||
double xs = interpQuintic(xd0);
|
||||
double ys = interpQuintic(yd0);
|
||||
double xs = MathUtil.interpQuintic(xd0);
|
||||
double ys = MathUtil.interpQuintic(yd0);
|
||||
|
||||
x0 *= PRIME_X;
|
||||
y0 *= PRIME_Y;
|
||||
int x1 = x0 + PRIME_X;
|
||||
int y1 = y0 + PRIME_Y;
|
||||
|
||||
double xf0 = lerp(gradCoord(seed, x0, y0, xd0, yd0), gradCoord(seed, x1, y0, xd1, yd0), xs);
|
||||
double xf1 = lerp(gradCoord(seed, x0, y1, xd0, yd1), gradCoord(seed, x1, y1, xd1, yd1), xs);
|
||||
double xf0 = MathUtil.lerp(gradCoord(seed, x0, y0, xd0, yd0), gradCoord(seed, x1, y0, xd1, yd0), xs);
|
||||
double xf1 = MathUtil.lerp(gradCoord(seed, x0, y1, xd0, yd1), gradCoord(seed, x1, y1, xd1, yd1), xs);
|
||||
|
||||
return lerp(xf0, xf1, ys) * 1.4247691104677813;
|
||||
return MathUtil.lerp(xf0, xf1, ys) * 1.4247691104677813;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
int x0 = fastFloor(x);
|
||||
int y0 = fastFloor(y);
|
||||
int z0 = fastFloor(z);
|
||||
int x0 = (int) Math.floor(x);
|
||||
int y0 = (int) Math.floor(y);
|
||||
int z0 = (int) Math.floor(z);
|
||||
|
||||
double xd0 = x - x0;
|
||||
double yd0 = y - y0;
|
||||
@ -50,9 +53,9 @@ public class PerlinSampler extends SimplexStyleSampler {
|
||||
double yd1 = yd0 - 1;
|
||||
double zd1 = zd0 - 1;
|
||||
|
||||
double xs = interpQuintic(xd0);
|
||||
double ys = interpQuintic(yd0);
|
||||
double zs = interpQuintic(zd0);
|
||||
double xs = MathUtil.interpQuintic(xd0);
|
||||
double ys = MathUtil.interpQuintic(yd0);
|
||||
double zs = MathUtil.interpQuintic(zd0);
|
||||
|
||||
x0 *= PRIME_X;
|
||||
y0 *= PRIME_Y;
|
||||
@ -61,14 +64,14 @@ public class PerlinSampler extends SimplexStyleSampler {
|
||||
int y1 = y0 + PRIME_Y;
|
||||
int z1 = z0 + PRIME_Z;
|
||||
|
||||
double xf00 = lerp(gradCoord(seed, x0, y0, z0, xd0, yd0, zd0), gradCoord(seed, x1, y0, z0, xd1, yd0, zd0), xs);
|
||||
double xf10 = lerp(gradCoord(seed, x0, y1, z0, xd0, yd1, zd0), gradCoord(seed, x1, y1, z0, xd1, yd1, zd0), xs);
|
||||
double xf01 = lerp(gradCoord(seed, x0, y0, z1, xd0, yd0, zd1), gradCoord(seed, x1, y0, z1, xd1, yd0, zd1), xs);
|
||||
double xf11 = lerp(gradCoord(seed, x0, y1, z1, xd0, yd1, zd1), gradCoord(seed, x1, y1, z1, xd1, yd1, zd1), xs);
|
||||
double xf00 = MathUtil.lerp(gradCoord(seed, x0, y0, z0, xd0, yd0, zd0), gradCoord(seed, x1, y0, z0, xd1, yd0, zd0), xs);
|
||||
double xf10 = MathUtil.lerp(gradCoord(seed, x0, y1, z0, xd0, yd1, zd0), gradCoord(seed, x1, y1, z0, xd1, yd1, zd0), xs);
|
||||
double xf01 = MathUtil.lerp(gradCoord(seed, x0, y0, z1, xd0, yd0, zd1), gradCoord(seed, x1, y0, z1, xd1, yd0, zd1), xs);
|
||||
double xf11 = MathUtil.lerp(gradCoord(seed, x0, y1, z1, xd0, yd1, zd1), gradCoord(seed, x1, y1, z1, xd1, yd1, zd1), xs);
|
||||
|
||||
double yf0 = lerp(xf00, xf10, ys);
|
||||
double yf1 = lerp(xf01, xf11, ys);
|
||||
double yf0 = MathUtil.lerp(xf00, xf10, ys);
|
||||
double yf1 = MathUtil.lerp(xf01, xf11, ys);
|
||||
|
||||
return lerp(yf0, yf1, zs) * 0.964921414852142333984375;
|
||||
return MathUtil.lerp(yf0, yf1, zs) * 0.964921414852142333984375;
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ public class SimplexSampler extends SimplexStyleSampler {
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
double t = (x + y) * F2;
|
||||
int i = fastFloor(x + t);
|
||||
int j = fastFloor(y + t);
|
||||
int i = (int) Math.floor(x + t);
|
||||
int j = (int) Math.floor(y + t);
|
||||
|
||||
t = (i + j) * G2;
|
||||
double X0 = i - t;
|
||||
@ -118,9 +118,9 @@ public class SimplexSampler extends SimplexStyleSampler {
|
||||
public double getNoiseRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
double t = (x + y + z) * F3;
|
||||
int i = fastFloor(x + t);
|
||||
int j = fastFloor(y + t);
|
||||
int k = fastFloor(z + t);
|
||||
int i = (int) Math.floor(x + t);
|
||||
int j = (int) Math.floor(y + t);
|
||||
int k = (int) Math.floor(z + t);
|
||||
|
||||
t = (i + j + k) * G3;
|
||||
double x0 = x - (i - t);
|
||||
|
@ -7,12 +7,15 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.value;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class ValueCubicSampler extends ValueStyleNoise {
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
int x1 = fastFloor(x);
|
||||
int y1 = fastFloor(y);
|
||||
int x1 = (int) Math.floor(x);
|
||||
int y1 = (int) Math.floor(y);
|
||||
|
||||
double xs = x - x1;
|
||||
double ys = y - y1;
|
||||
@ -26,14 +29,14 @@ public class ValueCubicSampler extends ValueStyleNoise {
|
||||
int x3 = x1 + (PRIME_X << 1);
|
||||
int y3 = y1 + (PRIME_Y << 1);
|
||||
|
||||
return cubicLerp(
|
||||
cubicLerp(valCoord(seed, x0, y0), valCoord(seed, x1, y0), valCoord(seed, x2, y0), valCoord(seed, x3, y0),
|
||||
return MathUtil.cubicLerp(
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y0), valCoord(seed, x1, y0), valCoord(seed, x2, y0), valCoord(seed, x3, y0),
|
||||
xs),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y1), valCoord(seed, x1, y1), valCoord(seed, x2, y1), valCoord(seed, x3, y1),
|
||||
xs),
|
||||
cubicLerp(valCoord(seed, x0, y1), valCoord(seed, x1, y1), valCoord(seed, x2, y1), valCoord(seed, x3, y1),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y2), valCoord(seed, x1, y2), valCoord(seed, x2, y2), valCoord(seed, x3, y2),
|
||||
xs),
|
||||
cubicLerp(valCoord(seed, x0, y2), valCoord(seed, x1, y2), valCoord(seed, x2, y2), valCoord(seed, x3, y2),
|
||||
xs),
|
||||
cubicLerp(valCoord(seed, x0, y3), valCoord(seed, x1, y3), valCoord(seed, x2, y3), valCoord(seed, x3, y3),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y3), valCoord(seed, x1, y3), valCoord(seed, x2, y3), valCoord(seed, x3, y3),
|
||||
xs),
|
||||
ys) * (1 / (1.5 * 1.5));
|
||||
}
|
||||
@ -41,9 +44,9 @@ public class ValueCubicSampler extends ValueStyleNoise {
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
int x1 = fastFloor(x);
|
||||
int y1 = fastFloor(y);
|
||||
int z1 = fastFloor(z);
|
||||
int x1 = (int) Math.floor(x);
|
||||
int y1 = (int) Math.floor(y);
|
||||
int z1 = (int) Math.floor(z);
|
||||
|
||||
double xs = x - x1;
|
||||
double ys = y - y1;
|
||||
@ -63,45 +66,45 @@ public class ValueCubicSampler extends ValueStyleNoise {
|
||||
int y3 = y1 + (PRIME_Y << 1);
|
||||
int z3 = z1 + (PRIME_Z << 1);
|
||||
|
||||
return cubicLerp(
|
||||
cubicLerp(
|
||||
cubicLerp(valCoord(seed, x0, y0, z0), valCoord(seed, x1, y0, z0), valCoord(seed, x2, y0, z0),
|
||||
return MathUtil.cubicLerp(
|
||||
MathUtil.cubicLerp(
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y0, z0), valCoord(seed, x1, y0, z0), valCoord(seed, x2, y0, z0),
|
||||
valCoord(seed, x3, y0, z0), xs),
|
||||
cubicLerp(valCoord(seed, x0, y1, z0), valCoord(seed, x1, y1, z0), valCoord(seed, x2, y1, z0),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y1, z0), valCoord(seed, x1, y1, z0), valCoord(seed, x2, y1, z0),
|
||||
valCoord(seed, x3, y1, z0), xs),
|
||||
cubicLerp(valCoord(seed, x0, y2, z0), valCoord(seed, x1, y2, z0), valCoord(seed, x2, y2, z0),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y2, z0), valCoord(seed, x1, y2, z0), valCoord(seed, x2, y2, z0),
|
||||
valCoord(seed, x3, y2, z0), xs),
|
||||
cubicLerp(valCoord(seed, x0, y3, z0), valCoord(seed, x1, y3, z0), valCoord(seed, x2, y3, z0),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y3, z0), valCoord(seed, x1, y3, z0), valCoord(seed, x2, y3, z0),
|
||||
valCoord(seed, x3, y3, z0), xs),
|
||||
ys),
|
||||
cubicLerp(
|
||||
cubicLerp(valCoord(seed, x0, y0, z1), valCoord(seed, x1, y0, z1), valCoord(seed, x2, y0, z1),
|
||||
MathUtil.cubicLerp(
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y0, z1), valCoord(seed, x1, y0, z1), valCoord(seed, x2, y0, z1),
|
||||
valCoord(seed, x3, y0, z1), xs),
|
||||
cubicLerp(valCoord(seed, x0, y1, z1), valCoord(seed, x1, y1, z1), valCoord(seed, x2, y1, z1),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y1, z1), valCoord(seed, x1, y1, z1), valCoord(seed, x2, y1, z1),
|
||||
valCoord(seed, x3, y1, z1), xs),
|
||||
cubicLerp(valCoord(seed, x0, y2, z1), valCoord(seed, x1, y2, z1), valCoord(seed, x2, y2, z1),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y2, z1), valCoord(seed, x1, y2, z1), valCoord(seed, x2, y2, z1),
|
||||
valCoord(seed, x3, y2, z1), xs),
|
||||
cubicLerp(valCoord(seed, x0, y3, z1), valCoord(seed, x1, y3, z1), valCoord(seed, x2, y3, z1),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y3, z1), valCoord(seed, x1, y3, z1), valCoord(seed, x2, y3, z1),
|
||||
valCoord(seed, x3, y3, z1), xs),
|
||||
ys),
|
||||
cubicLerp(
|
||||
cubicLerp(valCoord(seed, x0, y0, z2), valCoord(seed, x1, y0, z2), valCoord(seed, x2, y0, z2),
|
||||
MathUtil.cubicLerp(
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y0, z2), valCoord(seed, x1, y0, z2), valCoord(seed, x2, y0, z2),
|
||||
valCoord(seed, x3, y0, z2), xs),
|
||||
cubicLerp(valCoord(seed, x0, y1, z2), valCoord(seed, x1, y1, z2), valCoord(seed, x2, y1, z2),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y1, z2), valCoord(seed, x1, y1, z2), valCoord(seed, x2, y1, z2),
|
||||
valCoord(seed, x3, y1, z2), xs),
|
||||
cubicLerp(valCoord(seed, x0, y2, z2), valCoord(seed, x1, y2, z2), valCoord(seed, x2, y2, z2),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y2, z2), valCoord(seed, x1, y2, z2), valCoord(seed, x2, y2, z2),
|
||||
valCoord(seed, x3, y2, z2), xs),
|
||||
cubicLerp(valCoord(seed, x0, y3, z2), valCoord(seed, x1, y3, z2), valCoord(seed, x2, y3, z2),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y3, z2), valCoord(seed, x1, y3, z2), valCoord(seed, x2, y3, z2),
|
||||
valCoord(seed, x3, y3, z2), xs),
|
||||
ys),
|
||||
cubicLerp(
|
||||
cubicLerp(valCoord(seed, x0, y0, z3), valCoord(seed, x1, y0, z3), valCoord(seed, x2, y0, z3),
|
||||
MathUtil.cubicLerp(
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y0, z3), valCoord(seed, x1, y0, z3), valCoord(seed, x2, y0, z3),
|
||||
valCoord(seed, x3, y0, z3), xs),
|
||||
cubicLerp(valCoord(seed, x0, y1, z3), valCoord(seed, x1, y1, z3), valCoord(seed, x2, y1, z3),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y1, z3), valCoord(seed, x1, y1, z3), valCoord(seed, x2, y1, z3),
|
||||
valCoord(seed, x3, y1, z3), xs),
|
||||
cubicLerp(valCoord(seed, x0, y2, z3), valCoord(seed, x1, y2, z3), valCoord(seed, x2, y2, z3),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y2, z3), valCoord(seed, x1, y2, z3), valCoord(seed, x2, y2, z3),
|
||||
valCoord(seed, x3, y2, z3), xs),
|
||||
cubicLerp(valCoord(seed, x0, y3, z3), valCoord(seed, x1, y3, z3), valCoord(seed, x2, y3, z3),
|
||||
MathUtil.cubicLerp(valCoord(seed, x0, y3, z3), valCoord(seed, x1, y3, z3), valCoord(seed, x2, y3, z3),
|
||||
valCoord(seed, x3, y3, z3), xs),
|
||||
ys),
|
||||
zs) * (1 / (1.5 * 1.5 * 1.5));
|
||||
|
@ -7,37 +7,40 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.value;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class ValueSampler extends ValueStyleNoise {
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
int x0 = fastFloor(x);
|
||||
int y0 = fastFloor(y);
|
||||
int x0 = (int) Math.floor(x);
|
||||
int y0 = (int) Math.floor(y);
|
||||
|
||||
double xs = interpHermite(x - x0);
|
||||
double ys = interpHermite(y - y0);
|
||||
double xs = MathUtil.interpHermite(x - x0);
|
||||
double ys = MathUtil.interpHermite(y - y0);
|
||||
|
||||
x0 *= PRIME_X;
|
||||
y0 *= PRIME_Y;
|
||||
int x1 = x0 + PRIME_X;
|
||||
int y1 = y0 + PRIME_Y;
|
||||
|
||||
double xf0 = lerp(valCoord(seed, x0, y0), valCoord(seed, x1, y0), xs);
|
||||
double xf1 = lerp(valCoord(seed, x0, y1), valCoord(seed, x1, y1), xs);
|
||||
double xf0 = MathUtil.lerp(valCoord(seed, x0, y0), valCoord(seed, x1, y0), xs);
|
||||
double xf1 = MathUtil.lerp(valCoord(seed, x0, y1), valCoord(seed, x1, y1), xs);
|
||||
|
||||
return lerp(xf0, xf1, ys);
|
||||
return MathUtil.lerp(xf0, xf1, ys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
int x0 = fastFloor(x);
|
||||
int y0 = fastFloor(y);
|
||||
int z0 = fastFloor(z);
|
||||
int x0 = (int) Math.floor(x);
|
||||
int y0 = (int) Math.floor(y);
|
||||
int z0 = (int) Math.floor(z);
|
||||
|
||||
double xs = interpHermite(x - x0);
|
||||
double ys = interpHermite(y - y0);
|
||||
double zs = interpHermite(z - z0);
|
||||
double xs = MathUtil.interpHermite(x - x0);
|
||||
double ys = MathUtil.interpHermite(y - y0);
|
||||
double zs = MathUtil.interpHermite(z - z0);
|
||||
|
||||
x0 *= PRIME_X;
|
||||
y0 *= PRIME_Y;
|
||||
@ -46,14 +49,14 @@ public class ValueSampler extends ValueStyleNoise {
|
||||
int y1 = y0 + PRIME_Y;
|
||||
int z1 = z0 + PRIME_Z;
|
||||
|
||||
double xf00 = lerp(valCoord(seed, x0, y0, z0), valCoord(seed, x1, y0, z0), xs);
|
||||
double xf10 = lerp(valCoord(seed, x0, y1, z0), valCoord(seed, x1, y1, z0), xs);
|
||||
double xf01 = lerp(valCoord(seed, x0, y0, z1), valCoord(seed, x1, y0, z1), xs);
|
||||
double xf11 = lerp(valCoord(seed, x0, y1, z1), valCoord(seed, x1, y1, z1), xs);
|
||||
double xf00 = MathUtil.lerp(valCoord(seed, x0, y0, z0), valCoord(seed, x1, y0, z0), xs);
|
||||
double xf10 = MathUtil.lerp(valCoord(seed, x0, y1, z0), valCoord(seed, x1, y1, z0), xs);
|
||||
double xf01 = MathUtil.lerp(valCoord(seed, x0, y0, z1), valCoord(seed, x1, y0, z1), xs);
|
||||
double xf11 = MathUtil.lerp(valCoord(seed, x0, y1, z1), valCoord(seed, x1, y1, z1), xs);
|
||||
|
||||
double yf0 = lerp(xf00, xf10, ys);
|
||||
double yf1 = lerp(xf01, xf11, ys);
|
||||
double yf0 = MathUtil.lerp(xf00, xf10, ys);
|
||||
double yf1 = MathUtil.lerp(xf01, xf11, ys);
|
||||
|
||||
return lerp(yf0, yf1, zs);
|
||||
return MathUtil.lerp(yf0, yf1, zs);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2021 Polyhedral Development
|
||||
|
||||
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.
|
@ -1,3 +0,0 @@
|
||||
# config-ore-v2
|
||||
|
||||
Registers the default configuration for Terra Ores, `ORE`.
|
@ -1,11 +0,0 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.ore.lib.jafama")
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.ore.v2;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
|
||||
|
||||
public class OreAddon implements AddonInitializer {
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
@Inject
|
||||
private BaseAddon addon;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().registerConfigType(new OreConfigType(), addon.key("ORE"), 1))
|
||||
.failThrough();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.ore.v2;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
public class OreConfigType implements ConfigType<OreTemplate, Structure> {
|
||||
public static final TypeKey<Structure> ORE_TYPE_TOKEN = new TypeKey<>() {
|
||||
};
|
||||
private final OreFactory factory = new OreFactory();
|
||||
|
||||
@Override
|
||||
public OreTemplate getTemplate(ConfigPack pack, Platform platform) {
|
||||
return new OreTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<OreTemplate, Structure> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Structure> getTypeKey() {
|
||||
return ORE_TYPE_TOKEN;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.ore.v2;
|
||||
|
||||
import com.dfsek.terra.addons.ore.v2.ores.VanillaOre;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
|
||||
|
||||
public class OreFactory implements ConfigFactory<OreTemplate, Structure> {
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.ore.v2;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Description;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Final;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class OreTemplate implements AbstractableTemplate {
|
||||
@Value("id")
|
||||
@Final
|
||||
private String id;
|
||||
|
||||
@Value("material")
|
||||
private @Meta BlockState material;
|
||||
|
||||
@Value("material-overrides")
|
||||
@Default
|
||||
private @Meta Map<@Meta BlockType, @Meta BlockState> materials = new HashMap<>();
|
||||
|
||||
@Value("replace")
|
||||
private @Meta MaterialSet replaceable;
|
||||
|
||||
@Value("physics")
|
||||
@Default
|
||||
private @Meta boolean physics = false;
|
||||
|
||||
@Value("size")
|
||||
private @Meta double size;
|
||||
|
||||
@Value("exposed")
|
||||
@Default
|
||||
@Description("The chance that ore blocks bordering air will be discarded as candidates for ore. 0 = 0%, 1 = 100%")
|
||||
private @Meta double exposed = 0.0f;
|
||||
|
||||
public boolean doPhysics() {
|
||||
return physics;
|
||||
}
|
||||
|
||||
public double getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public BlockState getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<BlockType, BlockState> getMaterialOverrides() {
|
||||
return materials;
|
||||
}
|
||||
|
||||
public double isExposed() {
|
||||
return exposed;
|
||||
}
|
||||
}
|
@ -1,207 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.ore.v2.ores;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public class VanillaOre implements Structure {
|
||||
|
||||
private final BlockState material;
|
||||
|
||||
private final double size;
|
||||
private final MaterialSet replaceable;
|
||||
private final boolean applyGravity;
|
||||
private final double exposed;
|
||||
private final Map<BlockType, BlockState> materials;
|
||||
|
||||
public VanillaOre(BlockState material, double size, MaterialSet replaceable, boolean applyGravity,
|
||||
double exposed, Map<BlockType, BlockState> materials) {
|
||||
this.material = material;
|
||||
this.size = size;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
this.exposed = exposed;
|
||||
this.materials = materials;
|
||||
}
|
||||
|
||||
protected static boolean shouldNotDiscard(Random random, double chance) {
|
||||
if(chance <= 0.0F) {
|
||||
return true;
|
||||
} else if(chance >= 1.0F) {
|
||||
return false;
|
||||
} else {
|
||||
return random.nextFloat() >= chance;
|
||||
}
|
||||
}
|
||||
|
||||
public static double lerp(double t, double v0, double v1) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
float randomRadian = random.nextFloat() * (float) Math.PI;
|
||||
double eigthSize = size / 8.0F;
|
||||
|
||||
// Place points to form a line segment
|
||||
double startX = (double) location.getX() + FastMath.sin(randomRadian) * eigthSize;
|
||||
double endX = (double) location.getX() - FastMath.sin(randomRadian) * eigthSize;
|
||||
|
||||
double startZ = (double) location.getZ() + FastMath.cos(randomRadian) * eigthSize;
|
||||
double endZ = (double) location.getZ() - FastMath.cos(randomRadian) * eigthSize;
|
||||
|
||||
double startY = location.getY() + random.nextInt(3) - 2;
|
||||
double endY = location.getY() + random.nextInt(3) - 2;
|
||||
|
||||
int sizeInt = (int) size;
|
||||
double[] points = new double[sizeInt * 4];
|
||||
|
||||
// Compute initial point positions and radius
|
||||
for(int i = 0; i < sizeInt; ++i) {
|
||||
float t = (float) i / (float) sizeInt;
|
||||
double xt = lerp(t, startX, endX);
|
||||
double yt = lerp(t, startY, endY);
|
||||
double zt = lerp(t, startZ, endZ);
|
||||
double roll = random.nextDouble() * size / 16.0;
|
||||
// Taper radius closer to line ends
|
||||
double radius = ((FastMath.sin((float) Math.PI * t) + 1.0F) * roll + 1.0) / 2.0;
|
||||
points[i * 4] = xt;
|
||||
points[i * 4 + 1] = yt;
|
||||
points[i * 4 + 2] = zt;
|
||||
points[i * 4 + 3] = radius;
|
||||
}
|
||||
|
||||
// Compare every point to every other point
|
||||
for(int a = 0; a < sizeInt - 1; ++a) {
|
||||
double radiusA = points[a * 4 + 3];
|
||||
if(radiusA > 0.0) {
|
||||
for(int b = a + 1; b < sizeInt; ++b) {
|
||||
double radiusB = points[b * 4 + 3];
|
||||
if(radiusB > 0.0) {
|
||||
double dxt = points[a * 4] - points[b * 4];
|
||||
double dyt = points[a * 4 + 1] - points[b * 4 + 1];
|
||||
double dzt = points[a * 4 + 2] - points[b * 4 + 2];
|
||||
double dRadius = radiusA - radiusB;
|
||||
|
||||
// If the radius difference is greater than the distance between the two points
|
||||
if(dRadius * dRadius > dxt * dxt + dyt * dyt + dzt * dzt) {
|
||||
// Set smaller of two radii to -1
|
||||
if(dRadius > 0.0) {
|
||||
points[b * 4 + 3] = -1.0;
|
||||
} else {
|
||||
points[a * 4 + 3] = -1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int outset = (int) FastMath.ceil((size / 16.0F * 2.0F + 1.0F) / 2.0F);
|
||||
int x = (int) (location.getX() - FastMath.ceil(eigthSize) - outset);
|
||||
int y = location.getY() - 2 - outset;
|
||||
int z = (int) (location.getZ() - FastMath.ceil(eigthSize) - outset);
|
||||
|
||||
int horizontalSize = (int) (2 * (FastMath.ceil(eigthSize) + outset));
|
||||
int verticalSize = 2 * (2 + outset);
|
||||
|
||||
int sphereCount = 0;
|
||||
BitSet visited = new BitSet(horizontalSize * verticalSize * horizontalSize);
|
||||
|
||||
// Generate a sphere at each point
|
||||
for(int i = 0; i < sizeInt; ++i) {
|
||||
double radius = points[i * 4 + 3];
|
||||
if(radius > 0.0) {
|
||||
double xt = points[i * 4];
|
||||
double yt = points[i * 4 + 1];
|
||||
double zt = points[i * 4 + 2];
|
||||
|
||||
int xLowerBound = (int) FastMath.max(FastMath.floor(xt - radius), x);
|
||||
int xUpperBound = (int) FastMath.max(FastMath.floor(xt + radius), xLowerBound);
|
||||
|
||||
int yLowerBound = (int) FastMath.max(FastMath.floor(yt - radius), y);
|
||||
int yUpperBound = (int) FastMath.max(FastMath.floor(yt + radius), yLowerBound);
|
||||
|
||||
int zLowerBound = (int) FastMath.max(FastMath.floor(zt - radius), z);
|
||||
int zUpperBound = (int) FastMath.max(FastMath.floor(zt + radius), zLowerBound);
|
||||
|
||||
// Iterate over coordinates within bounds
|
||||
for(int xi = xLowerBound; xi <= xUpperBound; ++xi) {
|
||||
double dx = ((double) xi + 0.5 - xt) / radius;
|
||||
if(dx * dx < 1.0) {
|
||||
for(int yi = yLowerBound; yi <= yUpperBound; ++yi) {
|
||||
double dy = ((double) yi + 0.5 - yt) / radius;
|
||||
if(dx * dx + dy * dy < 1.0) {
|
||||
for(int zi = zLowerBound; zi <= zUpperBound; ++zi) {
|
||||
double dz = ((double) zi + 0.5 - zt) / radius;
|
||||
|
||||
// If position is inside the sphere
|
||||
if(dx * dx + dy * dy + dz * dz < 1.0 && !(yi < world.getMinHeight() || yi >= world.getMaxHeight())) {
|
||||
int index = xi - x + (yi - y) * horizontalSize + (zi - z) * horizontalSize * verticalSize;
|
||||
if(!visited.get(index)) { // Skip blocks that have already been visited
|
||||
|
||||
visited.set(index);
|
||||
BlockType block = world.getBlockState(xi, yi, zi).getBlockType();
|
||||
if(shouldPlace(block, random, world, xi, yi, zi)) {
|
||||
world.setBlockState(xi, yi, zi, getMaterial(block), isApplyGravity());
|
||||
++sphereCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sphereCount > 0;
|
||||
}
|
||||
|
||||
public boolean shouldPlace(BlockType type, Random random, WritableWorld world, int x, int y, int z) {
|
||||
if(!getReplaceable().contains(type)) {
|
||||
return false;
|
||||
} else if(shouldNotDiscard(random, exposed)) {
|
||||
return true;
|
||||
} else {
|
||||
return !(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() ||
|
||||
world.getBlockState(x - 1, y, z).isAir() ||
|
||||
world.getBlockState(x + 1, y, z).isAir());
|
||||
}
|
||||
}
|
||||
|
||||
public BlockState getMaterial(BlockType replace) {
|
||||
return materials.getOrDefault(replace, material);
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public boolean isApplyGravity() {
|
||||
return applyGravity;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
schema-version: 1
|
||||
contributors:
|
||||
- Terra contributors
|
||||
id: config-ore-v2
|
||||
version: @VERSION@
|
||||
entrypoints:
|
||||
- "com.dfsek.terra.addons.ore.v2.OreAddon"
|
||||
website:
|
||||
issues: https://github.com/PolyhedralDev/Terra/issues
|
||||
source: https://github.com/PolyhedralDev/Terra
|
||||
docs: https://terra.polydev.org
|
||||
license: MIT License
|
@ -2,10 +2,5 @@ version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.ore.lib.jafama")
|
||||
}
|
||||
|
@ -7,14 +7,14 @@
|
||||
|
||||
package com.dfsek.terra.addons.ore.ores;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
@ -41,57 +41,130 @@ public class VanillaOre implements Structure {
|
||||
this.materials = materials;
|
||||
}
|
||||
|
||||
protected static boolean shouldNotDiscard(Random random, double chance) {
|
||||
if(chance <= 0.0F) {
|
||||
return true;
|
||||
} else if(chance >= 1.0F) {
|
||||
return false;
|
||||
} else {
|
||||
return random.nextFloat() >= chance;
|
||||
}
|
||||
}
|
||||
|
||||
public static double lerp(double t, double v0, double v1) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
int centerX = location.getX();
|
||||
int centerZ = location.getZ();
|
||||
int centerY = location.getY();
|
||||
float randomRadian = random.nextFloat() * (float) Math.PI;
|
||||
double eigthSize = size / 8.0F;
|
||||
|
||||
// Place points to form a line segment
|
||||
double startX = (double) location.getX() + MathUtil.sin(randomRadian) * eigthSize;
|
||||
double endX = (double) location.getX() - MathUtil.sin(randomRadian) * eigthSize;
|
||||
|
||||
float f = random.nextFloat() * (float) Math.PI;
|
||||
double startZ = (double) location.getZ() + MathUtil.cos(randomRadian) * eigthSize;
|
||||
double endZ = (double) location.getZ() - MathUtil.cos(randomRadian) * eigthSize;
|
||||
|
||||
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 startY = location.getY() + random.nextInt(3) - 2;
|
||||
double endY = location.getY() + random.nextInt(3) - 2;
|
||||
|
||||
double d5 = centerY + random.nextInt(3) - 2D;
|
||||
double d6 = centerY + random.nextInt(3) - 2D;
|
||||
int sizeInt = (int) size;
|
||||
double[] points = new double[sizeInt * 4];
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
float iFactor = (float) i / (float) size;
|
||||
|
||||
double d10 = random.nextDouble() * 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;
|
||||
|
||||
int xStart = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor - d11 / 2.0D));
|
||||
int yStart = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor - d12 / 2.0D));
|
||||
int zStart = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor - d11 / 2.0D));
|
||||
|
||||
int xEnd = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor + d11 / 2.0D));
|
||||
int yEnd = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor + d12 / 2.0D));
|
||||
int zEnd = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor + d11 / 2.0D));
|
||||
|
||||
for(int x = xStart; x <= xEnd; x++) {
|
||||
double d13 = (x + 0.5D - (d1 + (d2 - d1) * iFactor)) / (d11 / 2.0D);
|
||||
// Compute initial point positions and radius
|
||||
for(int i = 0; i < sizeInt; ++i) {
|
||||
float t = (float) i / (float) sizeInt;
|
||||
double xt = lerp(t, startX, endX);
|
||||
double yt = lerp(t, startY, endY);
|
||||
double zt = lerp(t, startZ, endZ);
|
||||
double roll = random.nextDouble() * size / 16.0;
|
||||
// Taper radius closer to line ends
|
||||
double radius = ((MathUtil.sin((float) Math.PI * t) + 1.0F) * roll + 1.0) / 2.0;
|
||||
points[i * 4] = xt;
|
||||
points[i * 4 + 1] = yt;
|
||||
points[i * 4 + 2] = zt;
|
||||
points[i * 4 + 3] = radius;
|
||||
}
|
||||
|
||||
// Compare every point to every other point
|
||||
for(int a = 0; a < sizeInt - 1; ++a) {
|
||||
double radiusA = points[a * 4 + 3];
|
||||
if(radiusA > 0.0) {
|
||||
for(int b = a + 1; b < sizeInt; ++b) {
|
||||
double radiusB = points[b * 4 + 3];
|
||||
if(radiusB > 0.0) {
|
||||
double dxt = points[a * 4] - points[b * 4];
|
||||
double dyt = points[a * 4 + 1] - points[b * 4 + 1];
|
||||
double dzt = points[a * 4 + 2] - points[b * 4 + 2];
|
||||
double dRadius = radiusA - radiusB;
|
||||
|
||||
// If the radius difference is greater than the distance between the two points
|
||||
if(dRadius * dRadius > dxt * dxt + dyt * dyt + dzt * dzt) {
|
||||
// Set smaller of two radii to -1
|
||||
if(dRadius > 0.0) {
|
||||
points[b * 4 + 3] = -1.0;
|
||||
} else {
|
||||
points[a * 4 + 3] = -1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int outset = (int) Math.ceil((size / 16.0F * 2.0F + 1.0F) / 2.0F);
|
||||
int x = (int) (location.getX() - Math.ceil(eigthSize) - outset);
|
||||
int y = location.getY() - 2 - outset;
|
||||
int z = (int) (location.getZ() - Math.ceil(eigthSize) - outset);
|
||||
|
||||
int horizontalSize = (int) (2 * (Math.ceil(eigthSize) + outset));
|
||||
int verticalSize = 2 * (2 + outset);
|
||||
|
||||
int sphereCount = 0;
|
||||
BitSet visited = new BitSet(horizontalSize * verticalSize * horizontalSize);
|
||||
|
||||
// Generate a sphere at each point
|
||||
for(int i = 0; i < sizeInt; ++i) {
|
||||
double radius = points[i * 4 + 3];
|
||||
if(radius > 0.0) {
|
||||
double xt = points[i * 4];
|
||||
double yt = points[i * 4 + 1];
|
||||
double zt = points[i * 4 + 2];
|
||||
|
||||
if(d13 * d13 < 1.0D) {
|
||||
for(int y = yStart; y <= yEnd; y++) {
|
||||
double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d12 / 2.0D);
|
||||
if(d13 * d13 + d14 * d14 < 1.0D) {
|
||||
for(int z = zStart; z <= zEnd; z++) {
|
||||
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
|
||||
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() ||
|
||||
world.getBlockState(x, y, z + 1).isAir() ||
|
||||
world.getBlockState(x, y - 1, z).isAir() ||
|
||||
world.getBlockState(x, y + 1, z).isAir() ||
|
||||
world.getBlockState(x - 1, y, z).isAir() ||
|
||||
world.getBlockState(x + 1, y, z).isAir())) {
|
||||
world.setBlockState(x, y, z, getMaterial(block), isApplyGravity());
|
||||
int xLowerBound = (int) Math.max(Math.floor(xt - radius), x);
|
||||
int xUpperBound = (int) Math.max(Math.floor(xt + radius), xLowerBound);
|
||||
|
||||
int yLowerBound = (int) Math.max(Math.floor(yt - radius), y);
|
||||
int yUpperBound = (int) Math.max(Math.floor(yt + radius), yLowerBound);
|
||||
|
||||
int zLowerBound = (int) Math.max(Math.floor(zt - radius), z);
|
||||
int zUpperBound = (int) Math.max(Math.floor(zt + radius), zLowerBound);
|
||||
|
||||
// Iterate over coordinates within bounds
|
||||
for(int xi = xLowerBound; xi <= xUpperBound; ++xi) {
|
||||
double dx = ((double) xi + 0.5 - xt) / radius;
|
||||
if(dx * dx < 1.0) {
|
||||
for(int yi = yLowerBound; yi <= yUpperBound; ++yi) {
|
||||
double dy = ((double) yi + 0.5 - yt) / radius;
|
||||
if(dx * dx + dy * dy < 1.0) {
|
||||
for(int zi = zLowerBound; zi <= zUpperBound; ++zi) {
|
||||
double dz = ((double) zi + 0.5 - zt) / radius;
|
||||
|
||||
// If position is inside the sphere
|
||||
if(dx * dx + dy * dy + dz * dz < 1.0 && !(yi < world.getMinHeight() || yi >= world.getMaxHeight())) {
|
||||
int index = xi - x + (yi - y) * horizontalSize + (zi - z) * horizontalSize * verticalSize;
|
||||
if(!visited.get(index)) { // Skip blocks that have already been visited
|
||||
|
||||
visited.set(index);
|
||||
BlockType block = world.getBlockState(xi, yi, zi).getBlockType();
|
||||
if(shouldPlace(block, random, world, xi, yi, zi)) {
|
||||
world.setBlockState(xi, yi, zi, getMaterial(block), isApplyGravity());
|
||||
++sphereCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,7 +173,23 @@ public class VanillaOre implements Structure {
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
return sphereCount > 0;
|
||||
}
|
||||
|
||||
public boolean shouldPlace(BlockType type, Random random, WritableWorld world, int x, int y, int z) {
|
||||
if(!getReplaceable().contains(type)) {
|
||||
return false;
|
||||
} else if(shouldNotDiscard(random, exposed)) {
|
||||
return true;
|
||||
} else {
|
||||
return !(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() ||
|
||||
world.getBlockState(x - 1, y, z).isAir() ||
|
||||
world.getBlockState(x + 1, y, z).isAir());
|
||||
}
|
||||
}
|
||||
|
||||
public BlockState getMaterial(BlockType replace) {
|
||||
|
@ -3,11 +3,4 @@ version = version("1.0.0")
|
||||
dependencies {
|
||||
api("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.structure.lib.jafama")
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.structure.structures.loot;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@ -62,12 +61,12 @@ public class Entry {
|
||||
max = (long) ((JSONObject) loot).get("max");
|
||||
min = (long) ((JSONObject) loot).get("min");
|
||||
}
|
||||
functions.add(new AmountFunction(FastMath.toIntExact(min), FastMath.toIntExact(max)));
|
||||
functions.add(new AmountFunction(Math.toIntExact(min), Math.toIntExact(max)));
|
||||
}
|
||||
case "minecraft:set_damage", "set_damage" -> {
|
||||
long maxDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("max");
|
||||
long minDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("min");
|
||||
functions.add(new DamageFunction(FastMath.toIntExact(minDamage), FastMath.toIntExact(maxDamage)));
|
||||
functions.add(new DamageFunction(Math.toIntExact(minDamage), Math.toIntExact(maxDamage)));
|
||||
}
|
||||
case "minecraft:enchant_with_levels", "enchant_with_levels" -> {
|
||||
long maxEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("max");
|
||||
@ -76,7 +75,7 @@ public class Entry {
|
||||
if(((JSONObject) function).containsKey("disabled_enchants"))
|
||||
disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants");
|
||||
functions.add(
|
||||
new EnchantFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled, platform));
|
||||
new EnchantFunction(Math.toIntExact(minEnchant), Math.toIntExact(maxEnchant), disabled, platform));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.structure.structures.loot;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@ -37,16 +36,16 @@ public class Pool {
|
||||
entries = new ProbabilityCollection<>();
|
||||
Object amount = pool.get("rolls");
|
||||
if(amount instanceof Long) {
|
||||
max = FastMath.toIntExact((Long) amount);
|
||||
min = FastMath.toIntExact((Long) amount);
|
||||
max = Math.toIntExact((Long) amount);
|
||||
min = Math.toIntExact((Long) amount);
|
||||
} else {
|
||||
max = FastMath.toIntExact((Long) ((JSONObject) amount).get("max"));
|
||||
min = FastMath.toIntExact((Long) ((JSONObject) amount).get("min"));
|
||||
max = Math.toIntExact((Long) ((JSONObject) amount).get("max"));
|
||||
min = Math.toIntExact((Long) ((JSONObject) amount).get("min"));
|
||||
}
|
||||
|
||||
for(Object entryJSON : (JSONArray) pool.get("entries")) {
|
||||
Entry entry = new Entry((JSONObject) entryJSON, platform);
|
||||
entries.add(entry, FastMath.toIntExact(entry.getWeight()));
|
||||
entries.add(entry, Math.toIntExact(entry.getWeight()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.structure.structures.loot.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -57,7 +56,7 @@ public class EnchantFunction implements LootFunction {
|
||||
possible.add(ench);
|
||||
}
|
||||
}
|
||||
int numEnchant = (r.nextInt((int) FastMath.abs(enchant)) / 10 + 1);
|
||||
int numEnchant = (r.nextInt((int) Math.abs(enchant)) / 10 + 1);
|
||||
Collections.shuffle(possible);
|
||||
ItemMeta meta = original.getItemMeta();
|
||||
iter:
|
||||
@ -68,12 +67,12 @@ public class EnchantFunction implements LootFunction {
|
||||
}
|
||||
int lvl = r.nextInt(1 + (int) (((enchant / 40 > 1) ? 1 : enchant / 40) * (chosen.getMaxLevel())));
|
||||
try {
|
||||
meta.addEnchantment(chosen, FastMath.max(lvl, 1));
|
||||
meta.addEnchantment(chosen, Math.max(lvl, 1));
|
||||
} catch(IllegalArgumentException e) {
|
||||
LOGGER.warn(
|
||||
"Attempted to enchant {} with {} at level {}, but an unexpected exception occurred! Usually this is caused by a " +
|
||||
"misbehaving enchantment plugin.",
|
||||
original.getType(), chosen, FastMath.max(lvl, 1));
|
||||
original.getType(), chosen, Math.max(lvl, 1));
|
||||
}
|
||||
}
|
||||
original.setItemMeta(meta);
|
||||
|
@ -3,6 +3,6 @@ version = version("1.0.1")
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.config.ColorLoader;
|
||||
import com.dfsek.terra.addons.image.config.ColorLoader.ColorString;
|
||||
import com.dfsek.terra.addons.image.config.ImageLibraryPackConfigTemplate;
|
||||
@ -16,9 +17,12 @@ import com.dfsek.terra.addons.image.config.colorsampler.image.SingleImageColorSa
|
||||
import com.dfsek.terra.addons.image.config.colorsampler.image.TileImageColorSamplerTemplate;
|
||||
import com.dfsek.terra.addons.image.config.colorsampler.mutate.RotateColorSamplerTemplate;
|
||||
import com.dfsek.terra.addons.image.config.colorsampler.mutate.TranslateColorSamplerTemplate;
|
||||
import com.dfsek.terra.addons.image.config.image.ImageTemplate;
|
||||
import com.dfsek.terra.addons.image.config.image.StitchedImageTemplate;
|
||||
import com.dfsek.terra.addons.image.config.noisesampler.ChannelNoiseSamplerTemplate;
|
||||
import com.dfsek.terra.addons.image.config.noisesampler.DistanceTransformNoiseSamplerTemplate;
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.operator.DistanceTransform;
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.addons.image.colorsampler.image;
|
||||
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.colorsampler.image.transform.ImageTransformation;
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
|
||||
|
||||
public class SingleImageColorSampler implements ColorSampler {
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.dfsek.terra.addons.image.colorsampler.image;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.colorsampler.image.transform.ImageTransformation;
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
|
||||
|
||||
public class TileImageColorSampler implements ColorSampler {
|
||||
@ -22,6 +20,6 @@ public class TileImageColorSampler implements ColorSampler {
|
||||
public int apply(int x, int z) {
|
||||
x = transformation.transformX(image, x);
|
||||
z = transformation.transformZ(image, z);
|
||||
return image.getRGB(FastMath.floorMod(x, image.getWidth()), FastMath.floorMod(z, image.getHeight()));
|
||||
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(z, image.getHeight()));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.dfsek.terra.addons.image.colorsampler.mutate;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
public class RotateColorSampler implements ColorSampler {
|
||||
|
||||
@ -29,7 +28,7 @@ public class RotateColorSampler implements ColorSampler {
|
||||
else
|
||||
rotationMethod = RotationMethod.RAD_ANY;
|
||||
|
||||
this.radians = FastMath.toRadians(degrees);
|
||||
this.radians = Math.toRadians(degrees);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,14 +38,14 @@ public class RotateColorSampler implements ColorSampler {
|
||||
case DEG_90 -> -z;
|
||||
case DEG_180 -> -x;
|
||||
case DEG_270 -> z;
|
||||
case RAD_ANY -> (int) (x * FastMath.cos(radians) - z * FastMath.sin(radians));
|
||||
case RAD_ANY -> (int) (x * MathUtil.cos(radians) - z * MathUtil.sin(radians));
|
||||
};
|
||||
int rz = switch(rotationMethod) {
|
||||
case DEG_0 -> z;
|
||||
case DEG_90 -> x;
|
||||
case DEG_180 -> -z;
|
||||
case DEG_270 -> -x;
|
||||
case RAD_ANY -> (int) (z * FastMath.cos(radians) + x * FastMath.sin(radians));
|
||||
case RAD_ANY -> (int) (z * MathUtil.cos(radians) + x * MathUtil.sin(radians));
|
||||
};
|
||||
return sampler.apply(rx, rz);
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.colorsampler.image.transform.Alignment;
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
|
||||
|
||||
public abstract class ImageColorSamplerTemplate implements ObjectTemplate<ColorSampler> {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.addons.image.operator;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.util.ColorUtil;
|
||||
import com.dfsek.terra.addons.image.util.ColorUtil.Channel;
|
||||
@ -115,7 +113,7 @@ public class DistanceTransform {
|
||||
row[x] = d[x][y];
|
||||
row = calculateDistance1D(row);
|
||||
for(int x = 0; x < f[0].length; x++) {
|
||||
d[x][y] = FastMath.sqrt(row[x]);
|
||||
d[x][y] = Math.sqrt(row[x]);
|
||||
}
|
||||
}
|
||||
return d;
|
||||
@ -130,10 +128,10 @@ public class DistanceTransform {
|
||||
z[0] = Integer.MIN_VALUE;
|
||||
z[1] = Integer.MAX_VALUE;
|
||||
for(int q = 1; q <= f.length-1; q++) {
|
||||
double s = ((f[q]+FastMath.pow2(q))-(f[v[k]]+FastMath.pow2(v[k])))/(2*q-2*v[k]);
|
||||
double s = ((f[q]+Math.pow(q, 2))-(f[v[k]]+Math.pow(v[k], 2)))/(2*q-2*v[k]);
|
||||
while (s <= z[k]) {
|
||||
k--;
|
||||
s = ((f[q]+FastMath.pow2(q))-(f[v[k]]+FastMath.pow2(v[k])))/(2*q-2*v[k]);
|
||||
s = ((f[q]+Math.pow(q, 2))-(f[v[k]]+Math.pow(v[k], 2)))/(2*q-2*v[k]);
|
||||
}
|
||||
k++;
|
||||
v[k] = q;
|
||||
@ -145,7 +143,7 @@ public class DistanceTransform {
|
||||
for(int q = 0; q <= f.length-1; q++) {
|
||||
while(z[k+1] < q)
|
||||
k++;
|
||||
d[q] = FastMath.pow2(q-v[k]) + f[v[k]];
|
||||
d[q] = Math.pow(q-v[k], 2) + f[v[k]];
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@ -166,9 +164,9 @@ public class DistanceTransform {
|
||||
yield lerp(distances[x][y], minDistance, -1, maxDistance, 1);
|
||||
} else {
|
||||
if(d > 0) {
|
||||
yield FastMath.pow2(d/maxDistance);
|
||||
yield Math.pow(d/maxDistance, 2);
|
||||
} else if(d < 0) {
|
||||
yield -FastMath.pow2(d/minDistance);
|
||||
yield -Math.pow(d/minDistance, 2);
|
||||
} else {
|
||||
yield 0;
|
||||
}
|
||||
@ -231,7 +229,7 @@ public class DistanceTransform {
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
if(x<0 || y<0 || x>=transform.width || y>=transform.height) return transform.minDistance;
|
||||
return transform.distances[FastMath.floorToInt(x)][FastMath.floorToInt(y)];
|
||||
return transform.distances[(int) Math.floor(x)][(int) Math.floor(y)];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.dfsek.terra.addons.image.util;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for manipulating 8 bit ARGB colors
|
||||
*/
|
||||
@ -11,9 +8,9 @@ public class ColorUtil {
|
||||
private ColorUtil() {}
|
||||
|
||||
public static int distance(int a, int b) {
|
||||
return FastMath.abs(getRed(a) - getRed(b)) +
|
||||
FastMath.abs(getGreen(a) - getGreen(b)) +
|
||||
FastMath.abs(getBlue(a) - getBlue(b));
|
||||
return Math.abs(getRed(a) - getRed(b)) +
|
||||
Math.abs(getGreen(a) - getGreen(b)) +
|
||||
Math.abs(getBlue(a) - getBlue(b));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,11 +5,4 @@ version = version("1.1.0")
|
||||
dependencies {
|
||||
api("commons-io:commons-io:2.7")
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("org.apache.commons", "com.dfsek.terra.addons.terrascript.lib.commons")
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.terrascript.lib.jafama")
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -102,21 +100,21 @@ public class Scope {
|
||||
}
|
||||
|
||||
private void updateBoolSize(int size) {
|
||||
this.boolSize = FastMath.max(boolSize, size);
|
||||
this.boolSize = Math.max(boolSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateBoolSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNumSize(int size) {
|
||||
this.numSize = FastMath.max(numSize, size);
|
||||
this.numSize = Math.max(numSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateNumSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStrSize(int size) {
|
||||
this.strSize = FastMath.max(strSize, size);
|
||||
this.strSize = Math.max(strSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateStrSize(size);
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@ -40,7 +38,7 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
Object leftValue = left.apply(implementationArguments, scope);
|
||||
Object rightValue = right.apply(implementationArguments, scope);
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
return Math.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
}
|
||||
|
||||
return leftValue.equals(rightValue);
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@ -33,7 +31,7 @@ public class NotEqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
Object leftValue = left.apply(implementationArguments, scope);
|
||||
Object rightValue = right.apply(implementationArguments, scope);
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
|
||||
return Math.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
|
||||
}
|
||||
|
||||
return !leftValue.equals(rightValue);
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -44,6 +43,7 @@ import com.dfsek.terra.api.registry.key.Keyed;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
@ -100,25 +100,25 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
Returnable.ReturnType.NUMBER))
|
||||
.registerFunction("print",
|
||||
new UnaryStringFunctionBuilder(string -> LOGGER.info("[TerraScript:{}] {}", id, string)))
|
||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
|
||||
.registerFunction("pow2", new UnaryNumberFunctionBuilder(number -> FastMath.pow2(number.doubleValue())))
|
||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> Math.abs(number.doubleValue())))
|
||||
.registerFunction("pow2", new UnaryNumberFunctionBuilder(number -> Math.pow(number.doubleValue(), 2)))
|
||||
.registerFunction("pow", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("sqrt", new UnaryNumberFunctionBuilder(number -> FastMath.sqrt(number.doubleValue())))
|
||||
.registerFunction("floor", new UnaryNumberFunctionBuilder(number -> FastMath.floor(number.doubleValue())))
|
||||
.registerFunction("ceil", new UnaryNumberFunctionBuilder(number -> FastMath.ceil(number.doubleValue())))
|
||||
.registerFunction("log", new UnaryNumberFunctionBuilder(number -> FastMath.log(number.doubleValue())))
|
||||
.registerFunction("round", new UnaryNumberFunctionBuilder(number -> FastMath.round(number.doubleValue())))
|
||||
.registerFunction("sin", new UnaryNumberFunctionBuilder(number -> FastMath.sin(number.doubleValue())))
|
||||
.registerFunction("cos", new UnaryNumberFunctionBuilder(number -> FastMath.cos(number.doubleValue())))
|
||||
.registerFunction("tan", new UnaryNumberFunctionBuilder(number -> FastMath.tan(number.doubleValue())))
|
||||
.registerFunction("asin", new UnaryNumberFunctionBuilder(number -> FastMath.asin(number.doubleValue())))
|
||||
.registerFunction("acos", new UnaryNumberFunctionBuilder(number -> FastMath.acos(number.doubleValue())))
|
||||
.registerFunction("atan", new UnaryNumberFunctionBuilder(number -> FastMath.atan(number.doubleValue())))
|
||||
(number, number2) -> Math.pow(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("sqrt", new UnaryNumberFunctionBuilder(number -> Math.sqrt(number.doubleValue())))
|
||||
.registerFunction("floor", new UnaryNumberFunctionBuilder(number -> Math.floor(number.doubleValue())))
|
||||
.registerFunction("ceil", new UnaryNumberFunctionBuilder(number -> Math.ceil(number.doubleValue())))
|
||||
.registerFunction("log", new UnaryNumberFunctionBuilder(number -> Math.log(number.doubleValue())))
|
||||
.registerFunction("round", new UnaryNumberFunctionBuilder(number -> Math.round(number.doubleValue())))
|
||||
.registerFunction("sin", new UnaryNumberFunctionBuilder(number -> MathUtil.sin(number.doubleValue())))
|
||||
.registerFunction("cos", new UnaryNumberFunctionBuilder(number -> MathUtil.cos(number.doubleValue())))
|
||||
.registerFunction("tan", new UnaryNumberFunctionBuilder(number -> Math.tan(number.doubleValue())))
|
||||
.registerFunction("asin", new UnaryNumberFunctionBuilder(number -> Math.asin(number.doubleValue())))
|
||||
.registerFunction("acos", new UnaryNumberFunctionBuilder(number -> Math.acos(number.doubleValue())))
|
||||
.registerFunction("atan", new UnaryNumberFunctionBuilder(number -> Math.atan(number.doubleValue())))
|
||||
.registerFunction("max", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.max(number.doubleValue(), number2.doubleValue())))
|
||||
(number, number2) -> Math.max(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("min", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue())));
|
||||
(number, number2) -> Math.min(number.doubleValue(), number2.doubleValue())));
|
||||
|
||||
if(!platform.getTerraConfig().isDebugScript()) {
|
||||
parser.ignoreFunction("debugBlock");
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@ -48,9 +46,9 @@ public class BiomeFunction implements Function<String> {
|
||||
return grid.getBiome(arguments.getOrigin()
|
||||
.toVector3()
|
||||
.mutable()
|
||||
.add(Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
.add(Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ()))).immutable(), arguments.getWorld().getSeed()).getID();
|
||||
(int) Math.round(xz.getZ()))).immutable(), arguments.getWorld().getSeed()).getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -73,9 +72,9 @@ public class BlockFunction implements Function<Void> {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
try {
|
||||
Vector3.Mutable set = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
Vector3.Mutable set = Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope).doubleValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
BlockState current = arguments.getWorld().getBlockState(set);
|
||||
if(overwrite.apply(implementationArguments, scope) || current.isAir()) {
|
||||
arguments.getWorld().setBlockState(set, rot, physics.apply(implementationArguments, scope));
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@ -45,9 +43,9 @@ public class CheckBlockFunction implements Function<String> {
|
||||
.getBlockState(arguments.getOrigin()
|
||||
.toVector3()
|
||||
.mutable()
|
||||
.add(Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
.add(Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope)
|
||||
.doubleValue(), FastMath.roundToInt(xz.getZ()))))
|
||||
.doubleValue(), (int) Math.round(xz.getZ()))))
|
||||
.getAsString();
|
||||
if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties
|
||||
else return data;
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@ -37,9 +35,9 @@ public class GetMarkFunction implements Function<String> {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
|
||||
String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(
|
||||
String mark = arguments.getMark(Vector3.of((int) Math.floor(xz.getX()), (int) Math.floor(
|
||||
y.apply(implementationArguments, scope).doubleValue()),
|
||||
FastMath.floorToInt(xz.getZ()))
|
||||
(int) Math.floor(xz.getZ()))
|
||||
.mutable()
|
||||
.add(arguments.getOrigin())
|
||||
.immutable());
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -66,10 +65,10 @@ public class LootFunction implements Function<Void> {
|
||||
|
||||
registry.get(RegistryKey.parse(id))
|
||||
.ifPresentOrElse(table -> {
|
||||
Vector3 apply = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
Vector3 apply = Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope)
|
||||
.intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
|
||||
try {
|
||||
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user