HyCodeYourTale
classpublicPriority 3

GradientDensity

com.hypixel.hytale.builtin.hytalegenerator.density.nodes.GradientDensity

extends Density

2

Methods

2

Public Methods

3

Fields

1

Constructors

Constants

doubleHALF_PI= 1.5707963267948966

Constructors

public
GradientDensity(Density input, double slopeRange, Vector3d axis)

Methods

Public Methods (2)

public
double process(Density.Context context)
@Override
public
void setInputs(Density[] inputs)
@Override

Fields

Private/Package Fields (3)

privateVector3d axis
privateDensity input
privatedouble slopeRange

Inheritance

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.density.nodes;

import com.hypixel.hytale.builtin.hytalegenerator.VectorUtil;
import com.hypixel.hytale.builtin.hytalegenerator.density.Density;
import com.hypixel.hytale.math.vector.Vector3d;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class GradientDensity extends Density {
   private static final double HALF_PI = 1.5707963267948966;
   @Nullable
   private Density input;
   private final double slopeRange;
   @Nonnull
   private final Vector3d axis;

   public GradientDensity(@Nonnull Density input, double slopeRange, @Nonnull Vector3d axis) {
      if (slopeRange <= 0.0) {
         throw new IllegalArgumentException();
      } else {
         this.axis = axis.clone();
         this.slopeRange = slopeRange;
         this.input = input;
      }
   }

   @Override
   public double process(@Nonnull Density.Context context) {
      if (this.input == null) {
         return 0.0;
      } else {
         double valueAtOrigin = this.input.process(context);
         double maxX = context.position.x + this.slopeRange;
         double maxY = context.position.y + this.slopeRange;
         double maxZ = context.position.z + this.slopeRange;
         Density.Context childContext = new Density.Context(context);
         childContext.position = new Vector3d(maxX, context.position.y, context.position.z);
         double deltaX = Math.abs(this.input.process(childContext) - valueAtOrigin);
         childContext.position = new Vector3d(context.position.x, maxY, context.position.z);
         double deltaY = Math.abs(this.input.process(childContext) - valueAtOrigin);
         childContext.position = new Vector3d(context.position.x, context.position.y, maxZ);
         double deltaZ = Math.abs(this.input.process(childContext) - valueAtOrigin);
         Vector3d slopeDirection = new Vector3d(deltaX, deltaY, deltaZ);
         double slopeAngle = VectorUtil.angle(this.axis, slopeDirection);
         if (slopeAngle > 1.5707963267948966) {
            slopeAngle = 3.141592653589793 - slopeAngle;
         }

         slopeAngle /= 1.5707963267948966;
         return slopeAngle * 90.0;
      }
   }

   @Override
   public void setInputs(@Nonnull Density[] inputs) {
      if (inputs.length == 0) {
         this.input = null;
      }

      this.input = inputs[0];
   }
}