classpublicPriority 3
SmoothClampCurveAsset
com.hypixel.hytale.builtin.hytalegenerator.assets.curves.SmoothClampCurveAsset
extends CurveAsset
2
Methods
2
Public Methods
3
Fields
1
Constructors
Constants
BuilderCodec<SmoothClampCurveAsset>CODEC= BuilderCodec.builder(
SmoothClampCurveAsset.class, SmoothClampCurveAsset::new, CurveAsse...
Constructors
public
SmoothClampCurveAsset()Methods
Public Methods (2)
public
Double2DoubleFunction build()@Nonnull@Override
public
void cleanUp()@Override
Fields
Private/Package Fields (3)
private
double rangeprivate
double wallAprivate
double wallBInheritance
Parent
Current
Interface
Child
Use mouse wheel to zoom, drag to pan. Click nodes to navigate.
Related Classes
Source Code
package com.hypixel.hytale.builtin.hytalegenerator.assets.curves;
import com.hypixel.hytale.builtin.hytalegenerator.framework.math.Calculator;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.codec.validation.Validators;
import it.unimi.dsi.fastutil.doubles.Double2DoubleFunction;
import javax.annotation.Nonnull;
public class SmoothClampCurveAsset extends CurveAsset {
public static final BuilderCodec<SmoothClampCurveAsset> CODEC = BuilderCodec.builder(
SmoothClampCurveAsset.class, SmoothClampCurveAsset::new, CurveAsset.ABSTRACT_CODEC
)
.append(new KeyedCodec<>("Curve", CurveAsset.CODEC, false), (t, k) -> t.curveAsset = k, k -> k.curveAsset)
.add()
.append(new KeyedCodec<>("WallA", Codec.DOUBLE, false), (t, k) -> t.wallA = k, k -> k.wallA)
.add()
.append(new KeyedCodec<>("WallB", Codec.DOUBLE, false), (t, k) -> t.wallB = k, k -> k.wallB)
.add()
.<Double>append(new KeyedCodec<>("Range", Codec.DOUBLE, false), (t, k) -> t.range = k, k -> k.range)
.addValidator(Validators.greaterThanOrEqual(0.0))
.add()
.build();
private CurveAsset curveAsset = new ConstantCurveAsset();
private double wallA = 1.0;
private double wallB = -1.0;
private double range = 0.0;
public SmoothClampCurveAsset() {
}
@Nonnull
@Override
public Double2DoubleFunction build() {
double defaultValue = (this.wallA + this.wallB) / 2.0;
if (this.curveAsset == null) {
return in -> defaultValue;
} else {
double min = Math.min(this.wallA, this.wallB);
double max = Math.max(this.wallA, this.wallB);
Double2DoubleFunction inputCurve = this.curveAsset.build();
return this.range == 0.0 ? in -> Calculator.clamp(this.wallA, inputCurve.applyAsDouble(in), this.wallB) : in -> {
double value = inputCurve.applyAsDouble(in);
double smoothedMax = Calculator.smoothMax(this.range, min, value);
double smoothedMin = Calculator.smoothMin(this.range, max, value);
return (smoothedMin + smoothedMax) / 2.0;
};
}
}
@Override
public void cleanUp() {
this.curveAsset.cleanUp();
}
}