CuboidPlacement .java

net.minecraft.world.level.levelgen.feature.CuboidPlacement (record, 52 lines): members: xzSize, ySize, includeEdges, includeInterior, modify, codec, CODEC.

net.minecraft.world.level.levelgen.featurerecord52 linescommon2.2 KB

Implements

API Surface (2)

MapCodec<CuboidPlacement> codec()
void modify(final PlacementContext context, final RandomSource random, final BlockPos origin, final Consumer<BlockPos> output)

Fields & Constants (1)

CODEC

String literals (4)

"xz_size"
"y_size"
"include_edges"
"include_interior"

Code Graph: Dependencies (6)

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

Full Source

CuboidPlacement.java52 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.function.Consumer;
7
import net.minecraft.core.BlockPos;
8
import net.minecraft.util.RandomSource;
9
import net.minecraft.util.valueproviders.IntProvider;
10
import net.minecraft.util.valueproviders.IntProviders;
11
import net.minecraft.world.level.levelgen.placement.PlacementContext;
12
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
13
14
public record CuboidPlacement(IntProvider xzSize, IntProvider ySize, boolean includeEdges, boolean includeInterior) implements PlacementModifier {
15
	public static final MapCodec<CuboidPlacement> CODEC = RecordCodecBuilder.mapCodec(
16
		i -> i.group(
17
				IntProviders.codec(1, 16).fieldOf("xz_size").forGetter(CuboidPlacement::xzSize),
18
				IntProviders.codec(1, 16).fieldOf("y_size").forGetter(CuboidPlacement::ySize),
19
				Codec.BOOL.optionalFieldOf("include_edges", true).forGetter(CuboidPlacement::includeEdges),
20
				Codec.BOOL.optionalFieldOf("include_interior", true).forGetter(CuboidPlacement::includeInterior)
21
			)
22
			.apply(i, CuboidPlacement::new)
23
	);
24
25
	@Override
26
	public MapCodec<CuboidPlacement> codec() {
27
		return CODEC;
28
	}
29
30
	@Override
31
	public void modify(final PlacementContext context, final RandomSource random, final BlockPos origin, final Consumer<BlockPos> output) {
32
		int height = this.ySize.sample(random);
33
		int width = this.xzSize.sample(random);
34
		int length = this.xzSize.sample(random);
35
		BlockPos.MutableBlockPos mutPos = origin.mutable();
36
37
		for (int x = 0; x <= width; x++) {
38
			for (int y = 0; y <= height; y++) {
39
				for (int z = 0; z <= length; z++) {
40
					mutPos.set(x + origin.getX(), y + origin.getY(), z + origin.getZ());
41
					if ((this.includeEdges || x != 0 && x != width || y != 0 && y != height)
42
						&& (this.includeEdges || z != 0 && z != length || y != 0 && y != height)
43
						&& (this.includeEdges || x != 0 && x != width || z != 0 && z != length)
44
						&& (this.includeInterior || x == 0 || x == width || y == 0 || y == height || z == 0 || z == length)) {
45
						output.accept(mutPos.immutable());
46
					}
47
				}
48
			}
49
		}
50
	}
51
}
52

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