GaussianSampler .java

net.minecraft.world.attribute.GaussianSampler (class, 49 lines): members: GAUSSIAN_SAMPLE_BREADTH, GAUSSIAN_SAMPLE_KERNEL, GAUSSIAN_SAMPLE_RADIUS, Sampler.

net.minecraft.world.attributeclass49 linescommon1.7 KB

API Surface (1)

<V> void sample(Vec3 position, final GaussianSampler.Sampler<V> sampler, final GaussianSampler.Accumulator<V> accumulator)

Fields & Constants (3)

GAUSSIAN_SAMPLE_RADIUS
GAUSSIAN_SAMPLE_BREADTH
GAUSSIAN_SAMPLE_KERNEL

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

GaussianSampler.java49 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.attribute;
2
3
import net.minecraft.util.Mth;
4
import net.minecraft.world.phys.Vec3;
5
6
public class GaussianSampler {
7
	private static final int GAUSSIAN_SAMPLE_RADIUS = 2;
8
	private static final int GAUSSIAN_SAMPLE_BREADTH = 6;
9
	private static final double[] GAUSSIAN_SAMPLE_KERNEL = new double[]{0.0, 1.0, 4.0, 6.0, 4.0, 1.0, 0.0};
10
11
	public static <V> void sample(Vec3 position, final GaussianSampler.Sampler<V> sampler, final GaussianSampler.Accumulator<V> accumulator) {
12
		position = position.subtract(0.5, 0.5, 0.5);
13
		int integralX = Mth.floor(position.x());
14
		int integralY = Mth.floor(position.y());
15
		int integralZ = Mth.floor(position.z());
16
		double relativeX = position.x() - integralX;
17
		double relativeY = position.y() - integralY;
18
		double relativeZ = position.z() - integralZ;
19
20
		for (int z = 0; z < 6; z++) {
21
			double weightZ = Mth.lerp(relativeZ, GAUSSIAN_SAMPLE_KERNEL[z + 1], GAUSSIAN_SAMPLE_KERNEL[z]);
22
			int sampleZ = integralZ - 2 + z;
23
24
			for (int x = 0; x < 6; x++) {
25
				double weightX = Mth.lerp(relativeX, GAUSSIAN_SAMPLE_KERNEL[x + 1], GAUSSIAN_SAMPLE_KERNEL[x]);
26
				int sampleX = integralX - 2 + x;
27
28
				for (int y = 0; y < 6; y++) {
29
					double weightY = Mth.lerp(relativeY, GAUSSIAN_SAMPLE_KERNEL[y + 1], GAUSSIAN_SAMPLE_KERNEL[y]);
30
					int sampleY = integralY - 2 + y;
31
					double sampleWeight = weightX * weightY * weightZ;
32
					V value = sampler.get(sampleX, sampleY, sampleZ);
33
					accumulator.accumulate(sampleWeight, value);
34
				}
35
			}
36
		}
37
	}
38
39
	@FunctionalInterface
40
	public interface Accumulator<V> {
41
		void accumulate(double weight, V value);
42
	}
43
44
	@FunctionalInterface
45
	public interface Sampler<V> {
46
		V get(int x, int y, int z);
47
	}
48
}
49

Decompiled Minecraft 26.3 source of GaussianSampler (net/minecraft/world/attribute/GaussianSampler.java) with Mojang official mappings, stored verbatim on the site.