2025-11-24 22:52:51 +03:00

50 lines
2.0 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.world.attribute;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
public class GaussianSampler {
private static final int GAUSSIAN_SAMPLE_RADIUS = 2;
private static final int GAUSSIAN_SAMPLE_BREADTH = 6;
private static final double[] GAUSSIAN_SAMPLE_KERNEL = new double[]{0.0, 1.0, 4.0, 6.0, 4.0, 1.0, 0.0};
public static <V> void sample(Vec3 position, Sampler<V> sampler, Accumulator<V> accumulator) {
position = position.subtract(0.5, 0.5, 0.5);
int integralX = Mth.floor(position.x());
int integralY = Mth.floor(position.y());
int integralZ = Mth.floor(position.z());
double relativeX = position.x() - (double)integralX;
double relativeY = position.y() - (double)integralY;
double relativeZ = position.z() - (double)integralZ;
for (int z = 0; z < 6; ++z) {
double weightZ = Mth.lerp(relativeZ, GAUSSIAN_SAMPLE_KERNEL[z + 1], GAUSSIAN_SAMPLE_KERNEL[z]);
int sampleZ = integralZ - 2 + z;
for (int x = 0; x < 6; ++x) {
double weightX = Mth.lerp(relativeX, GAUSSIAN_SAMPLE_KERNEL[x + 1], GAUSSIAN_SAMPLE_KERNEL[x]);
int sampleX = integralX - 2 + x;
for (int y = 0; y < 6; ++y) {
double weightY = Mth.lerp(relativeY, GAUSSIAN_SAMPLE_KERNEL[y + 1], GAUSSIAN_SAMPLE_KERNEL[y]);
int sampleY = integralY - 2 + y;
double sampleWeight = weightX * weightY * weightZ;
V value = sampler.get(sampleX, sampleY, sampleZ);
accumulator.accumulate(sampleWeight, value);
}
}
}
}
@FunctionalInterface
public static interface Sampler<V> {
public V get(int var1, int var2, int var3);
}
@FunctionalInterface
public static interface Accumulator<V> {
public void accumulate(double var1, V var3);
}
}