From 8815518af9d3d6634352d378065ed5dd92214979 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 4 Jan 2021 20:53:46 -0500 Subject: [PATCH] Zone to feature --- .../com/volmit/iris/object/IrisFeature.java | 85 +++++++++++++ .../volmit/iris/object/NoiseEffectZone.java | 116 ------------------ 2 files changed, 85 insertions(+), 116 deletions(-) create mode 100644 src/main/java/com/volmit/iris/object/IrisFeature.java delete mode 100644 src/main/java/com/volmit/iris/object/NoiseEffectZone.java diff --git a/src/main/java/com/volmit/iris/object/IrisFeature.java b/src/main/java/com/volmit/iris/object/IrisFeature.java new file mode 100644 index 000000000..672b6fa34 --- /dev/null +++ b/src/main/java/com/volmit/iris/object/IrisFeature.java @@ -0,0 +1,85 @@ +package com.volmit.iris.object; + +import com.google.gson.Gson; +import com.volmit.iris.util.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +@Data +@DontObfuscate +@NoArgsConstructor +@AllArgsConstructor +@Desc("Represents an Iris zone") +public class IrisFeature { + @Required + @DontObfuscate + @Desc("The block radius of this zone") + private double blockRadius = 32; + + @MinNumber(0) + @MaxNumber(1) + @Required + @DontObfuscate + @Desc("The chance an object that should be place actually will place. Set to below 1 to affect objects in this zone") + private double objectChance = 1; + + @Required + @DontObfuscate + @Desc("The interpolation radius of this zone") + private double interpolationRadius = 7; + + @Required + @DontObfuscate + @MaxNumber(1) + @MinNumber(0) + @Desc("The strength of this effect") + private double strength = 0.75; + + @Required + @DontObfuscate + @Desc("The interpolator to use for smoothing the strength") + private InterpolationMethod interpolator = InterpolationMethod.BILINEAR_STARCAST_9; + + @Required + @DontObfuscate + @Desc("If set, this will shift the terrain height in blocks (up or down)") + private double shiftHeight = 0; + + @Required + @DontObfuscate + @Desc("If set, this will force the terrain closer to the specified height.") + private double convergeToHeight = -1; + + @Required + @DontObfuscate + @Desc("Multiplies the input noise") + private double multiplyHeight = 1; + + @Required + @DontObfuscate + @Desc("Invert the zone so that anything outside this zone is affected.") + private boolean invertZone = false; + + @Required + @DontObfuscate + @Desc("Add additional noise to this spot") + private IrisGeneratorStyle addNoise = NoiseStyle.FLAT.style(); + + public static IrisFeature read(DataInputStream s) throws IOException + { + return new Gson().fromJson(s.readUTF(), IrisFeature.class); + } + + public void write(DataOutputStream s) throws IOException { + s.writeUTF(new Gson().toJson(this)); + } + + public int getRealSize() { + return (int) Math.ceil(IrisInterpolation.getRealRadius(interpolator, 0, 0, interpolationRadius) + blockRadius * 2); + } +} diff --git a/src/main/java/com/volmit/iris/object/NoiseEffectZone.java b/src/main/java/com/volmit/iris/object/NoiseEffectZone.java deleted file mode 100644 index ea7df08d5..000000000 --- a/src/main/java/com/volmit/iris/object/NoiseEffectZone.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.volmit.iris.object; - -import com.volmit.iris.scaffold.cache.AtomicCache; -import com.volmit.iris.util.*; -import lombok.Data; - -@Data -@DontObfuscate -@Desc("Represents a flat zone") -public class NoiseEffectZone { - - - @Required - @DontObfuscate - @Desc("The x coordinate of this zone") - private int x; - - @Required - @DontObfuscate - @Desc("The z coordinate of this zone") - private int z; - - @Required - @DontObfuscate - @Desc("The block radius of this zone") - private double blockRadius = 32; - - @Required - @DontObfuscate - @Desc("The interpolation radius of this zone") - private double interpolationRadius = 7; - - @Required - @DontObfuscate - @MaxNumber(1) - @MinNumber(0) - @Desc("The strength of this effect") - private double strength = 0.75; - - @Required - @DontObfuscate - @Desc("The interpolator to use for smoothing the strength") - private InterpolationMethod interpolator = InterpolationMethod.BILINEAR_STARCAST_9; - - @Required - @DontObfuscate - @Desc("If set, this will shift the terrain height in blocks (up or down)") - private double shiftHeight = 0; - - @Required - @DontObfuscate - @Desc("If set, this will force the terrain closer to the specified height.") - private double convergeToHeight = -1; - - @Required - @DontObfuscate - @Desc("Multiplies the input noise") - private double multiplyHeight = 1; - - @Required - @DontObfuscate - @Desc("Invert the zone so that anything outside this zone is affected.") - private boolean invertZone = false; - - @Required - @DontObfuscate - @Desc("Add additional noise to this spot") - private IrisGeneratorStyle addNoise = NoiseStyle.FLAT.style(); - - private transient AtomicCache provider = new AtomicCache<>(); - private static double BLOCK = 1D / 256D; - - public double filter(double x, double z, double noise) { - if (invertZone && distance2(x, z) < (blockRadius - (interpolationRadius * 5)) * (blockRadius - (interpolationRadius * 5))) - { - return noise; - } - - if(distance2(x, z) > (blockRadius + (interpolationRadius * 5)) * (blockRadius + (interpolationRadius * 5))) - { - return noise; - } - - NoiseProvider d = provider.aquire(this::getNoiseProvider); - double s = IrisInterpolation.getNoise(interpolator, (int)x, (int)z, interpolationRadius, d); - - if(s <= 0) - { - return noise; - } - - double fx = noise; - - if(convergeToHeight >= 0) - { - fx = convergeToHeight; - } - - fx *= multiplyHeight; - fx += shiftHeight; - - return M.lerp(noise, fx, strength * s); - } - - public double distance(double x, double z) { - return Math.sqrt(Math.pow(this.x - x, 2) + Math.pow(this.z - z, 2)); - } - - public double distance2(double x, double z) { - return Math.pow(this.x - x, 2) + Math.pow(this.z - z, 2); - } - - private NoiseProvider getNoiseProvider() { - return (x, z) -> distance(x, z) < blockRadius ? invertZone ? 0D : 1d : invertZone ? 1D : 0d; - } -}