All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.parzivail.util.noise.InfiniteWorleyNoise Maven / Gradle / Ivy

package com.parzivail.util.noise;

import D;
import com.parzivail.util.math.MathUtil;
import net.minecraft.class_241;
import net.minecraft.class_243;

public class InfiniteWorleyNoise
{
	private final long _seed;

	public InfiniteWorleyNoise(long seed)
	{
		_seed = seed;
	}

	public InfiniteWorleyNoise()
	{
		this(0);
	}

	private float R(double n)
	{
		return MathUtil.fract(Math.cos(MathUtil.seed(n * 89.42, _seed)) * 343.42);
	}

	private class_241 R(class_241 n)
	{
		return new class_241(R(n.field_1343 * 23.62f - 300 + n.field_1342 * 34.35f), R(n.field_1343 * 45.13f + 256 + n.field_1342 * 38.89f));
	}

	private class_243 R(class_243 n)
	{
		return new class_243(R(n.field_1352 * 23.62f - 300 + n.field_1351 * 34.35f + 663 + n.field_1350 * 36.57f), R(n.field_1352 * 45.13f + 256 + n.field_1351 * 38.89f - 764 + n.field_1350 * 91.58f), R(n.field_1352 * 13.2f - 458 + n.field_1351 * 56.24f + 172 + n.field_1350 * 68.45f));
	}

	public double eval(double nx, double ny)
	{
		var n = new class_241((float)nx, (float)ny);
		var dis = 2d;
		for (float x = -1; x <= 1; x++)
		{
			for (float y = -1; y <= 1; y++)
			{
				var q = new class_241(x, y);
				var p = MathUtil.add(MathUtil.floor(n), q);
				var d = MathUtil.length(MathUtil.sub(MathUtil.add(R(p), q), MathUtil.fract(n)));

				if (dis <= d)
					continue;

				dis = d;
			}
		}
		return dis;
	}

	public double eval(double nx, double ny, double nz)
	{
		var n = new class_243((float)nx, (float)ny, (float)nz);
		var dis = 2d;
		for (float x = -1; x <= 1; x++)
		{
			for (float y = -1; y <= 1; y++)
			{
				for (float z = -1; z <= 1; z++)
				{
					var q = new class_243(x, y, z);
					var p = MathUtil.floor(n).method_1019(q);
					var d = R(p).method_1019(q).method_1020(MathUtil.fract(n)).method_1033();

					if (dis <= d)
						continue;

					dis = d;
				}
			}
		}
		return dis;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy