DensitySampler .java

net.minecraft.world.level.levelgen.densityfunction.DensitySampler (interface): members: sampleVolumeNaive, Bound, sampleVolume, sampleValue, bind.

net.minecraft.world.level.levelgen.densityfunctioninterface45 linescommon1.5 KB

API Surface (3)

float sampleValue(final int blockX, final int blockY, final int blockZ)
void sampleVolume(final DensityBuffer outputBuffer, final DensityVolume volume)
ScopedDensityBuffer sampleVolume(final DensityVolume volume)

Code Graph: Dependencies (4)

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

Full Source

DensitySampler.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.densityfunction;
2
3
public interface DensitySampler {
4
	void sampleVolume(SamplerContext context, DensityBuffer outputBuffer, DensityVolume volume);
5
6
	static void sampleVolumeNaive(final SamplerContext context, final DensityBuffer outputBuffer, final DensityVolume volume, final DensitySampler sampler) {
7
		int index = 0;
8
9
		for (int z = 0; z < volume.sizeZ(); z++) {
10
			int blockZ = volume.blockZ(z);
11
12
			for (int x = 0; x < volume.sizeX(); x++) {
13
				int blockX = volume.blockX(x);
14
15
				for (int y = 0; y < volume.sizeY(); y++) {
16
					int blockY = volume.blockY(y);
17
					outputBuffer.set(index++, sampler.sampleValue(context, blockX, blockY, blockZ));
18
				}
19
			}
20
		}
21
	}
22
23
	float sampleValue(SamplerContext context, int blockX, int blockY, int blockZ);
24
25
	default DensitySampler.Bound bind(final SamplerContext context) {
26
		return new DensitySampler.Bound(this, context);
27
	}
28
29
	record Bound(DensitySampler sampler, SamplerContext context) {
30
		public float sampleValue(final int blockX, final int blockY, final int blockZ) {
31
			return this.sampler.sampleValue(this.context, blockX, blockY, blockZ);
32
		}
33
34
		public void sampleVolume(final DensityBuffer outputBuffer, final DensityVolume volume) {
35
			this.sampler.sampleVolume(this.context, outputBuffer, volume);
36
		}
37
38
		public ScopedDensityBuffer sampleVolume(final DensityVolume volume) {
39
			ScopedDensityBuffer buffer = this.context.acquireBuffer(volume);
40
			this.sampleVolume(buffer, volume);
41
			return buffer;
42
		}
43
	}
44
}
45

Decompiled Minecraft 26.3 source of DensitySampler (net/minecraft/world/level/levelgen/densityfunction/DensitySampler.java) with Mojang official mappings, stored verbatim on the site.