SineWaveResponseCurve class

Пакет: com.hypixel.hytale.server.core.asset.type.responsecurve.config

Файл: com/hypixel/hytale/server/core/asset/type/responsecurve/config/SineWaveResponseCurve.java

extends: ResponseCurve

Поля (1)

МодификаторыТипИмя
final BuilderCodec<SineWaveResponseCurve> CODEC

Методы (5)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("X must be between 0.0 and 1.0")
public double getAmplitudedouble getAmplitude()
public double getFrequencydouble getFrequency()
public double getHorizontalShiftdouble getHorizontalShift()
public double getVerticalShiftdouble getVerticalShift()

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.asset.type.responsecurve.config;

class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.math.util.TrigMathUtil;
class="kw">import javax.annotation.Nonnull;

class="kw">public class SineWaveResponseCurve class="kw">extends ResponseCurve {
   class="kw">public class="kw">static class="kw">final BuilderCodec<SineWaveResponseCurve> CODEC = BuilderCodec.builder(SineWaveResponseCurve.class, SineWaveResponseCurve::new, BASE_CODEC)
      .documentation("A response curve with a sine wave shape.")
      .<Double>appendInherited(
         new KeyedCodec<>("Amplitude", Codec.DOUBLE),
         (var0, var1) -> var0.amplitude = var1,
         var0 -> var0.amplitude,
         (var0, var1) -> var0.amplitude = var1.amplitude
      )
      .documentation("The vertical distance between the horizontal axis and the max/min value of the function.")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("Frequency", Codec.DOUBLE),
         (var0, var1) -> var0.frequency = var1,
         var0 -> var0.frequency,
         (var0, var1) -> var0.frequency = var1.frequency
      )
      .documentation("The frequency of the sine wave's repetition (e.g. set to 1, the full pattern will appear once in the 0-1 range, twice with 2, etc).")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("HorizontalShift", Codec.DOUBLE),
         (var0, var1) -> var0.horizontalShift = var1,
         var0 -> var0.horizontalShift,
         (var0, var1) -> var0.horizontalShift = var1.horizontalShift
      )
      .documentation("The horizontal shift to apply to the curve,. This decides how far the curve is shifted left or right along the x axis.")
      .addValidator(Validators.range(-1.0, 1.0))
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("VerticalShift", Codec.DOUBLE),
         (var0, var1) -> var0.verticalShift = var1,
         var0 -> var0.verticalShift,
         (var0, var1) -> var0.verticalShift = var1.verticalShift
      )
      .documentation("The vertical shift to apply to the curve. This decides how far the curve is shifted up or down along the y axis.")
      .addValidator(Validators.range(-1.0, 1.0))
      .add()
      .build();
   class="kw">protected double amplitude = 1.0;
   class="kw">protected double frequency = 0.5;
   class="kw">protected double horizontalShift;
   class="kw">protected double verticalShift;

   class="kw">protected SineWaveResponseCurve() {
   }

   @Override
   class="kw">public double computeY(double var1) {
      if (!(var1 < 0.0) && !(var1 > 1.0)) {
         class="kw">return this.amplitude * TrigMathUtil.sin((float) (Math.PI * 2) * this.frequency * var1 + this.horizontalShift) + this.verticalShift;
      } else {
         throw new IllegalArgumentException("X must be between 0.0 and 1.0");
      }
   }

   class="kw">public double getAmplitude() {
      class="kw">return this.amplitude;
   }

   class="kw">public double getFrequency() {
      class="kw">return this.frequency;
   }

   class="kw">public double getHorizontalShift() {
      class="kw">return this.horizontalShift;
   }

   class="kw">public double getVerticalShift() {
      class="kw">return this.verticalShift;
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "SineWaveResponseCurve{amplitude="
         + this.amplitude
         + ", frequency="
         + this.frequency
         + ", horizontalShift="
         + this.horizontalShift
         + ", verticalShift="
         + this.verticalShift
         + "} "
         + super.toString();
   }
}