OffsetPlacement .java

net.minecraft.world.level.levelgen.placement.OffsetPlacement (record, 62 lines): members: ofTriangle, vertical, horizontal, above, modify, codec, CODEC.

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

Implements

API Surface (9)

OffsetPlacement of(final IntProvider xzSpread, final IntProvider ySpread)
OffsetPlacement ofTriangle(final int xzRange, final int yRange)
OffsetPlacement vertical(final IntProvider ySpread)
OffsetPlacement horizontal(final IntProvider xzSpread)
OffsetPlacement of(final int x, final int y, final int z)
OffsetPlacement of(final Direction direction)
OffsetPlacement above()
void modify(final PlacementContext context, final RandomSource random, final BlockPos origin, final Consumer<BlockPos> output)
MapCodec<OffsetPlacement> codec()

Fields & Constants (1)

CODEC

Full Source

OffsetPlacement.java62 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.placement;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.function.Consumer;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.core.Direction;
8
import net.minecraft.util.RandomSource;
9
import net.minecraft.util.valueproviders.ConstantInt;
10
import net.minecraft.util.valueproviders.IntProvider;
11
import net.minecraft.util.valueproviders.IntProviders;
12
import net.minecraft.util.valueproviders.TrapezoidInt;
13
14
public record OffsetPlacement(IntProvider x, IntProvider y, IntProvider z) implements PlacementModifier {
15
	public static final MapCodec<OffsetPlacement> CODEC = RecordCodecBuilder.mapCodec(
16
		i -> i.group(
17
				IntProviders.codec(-16, 16).fieldOf("x").forGetter(OffsetPlacement::x),
18
				IntProviders.codec(-16, 16).fieldOf("y").forGetter(OffsetPlacement::y),
19
				IntProviders.codec(-16, 16).fieldOf("z").forGetter(OffsetPlacement::z)
20
			)
21
			.apply(i, OffsetPlacement::new)
22
	);
23
24
	public static OffsetPlacement of(final IntProvider xzSpread, final IntProvider ySpread) {
25
		return new OffsetPlacement(xzSpread, ySpread, xzSpread);
26
	}
27
28
	public static OffsetPlacement ofTriangle(final int xzRange, final int yRange) {
29
		return of(TrapezoidInt.triangle(xzRange), TrapezoidInt.triangle(yRange));
30
	}
31
32
	public static OffsetPlacement vertical(final IntProvider ySpread) {
33
		return of(ConstantInt.of(0), ySpread);
34
	}
35
36
	public static OffsetPlacement horizontal(final IntProvider xzSpread) {
37
		return of(xzSpread, ConstantInt.of(0));
38
	}
39
40
	public static OffsetPlacement of(final int x, final int y, final int z) {
41
		return new OffsetPlacement(ConstantInt.of(x), ConstantInt.of(y), ConstantInt.of(z));
42
	}
43
44
	public static OffsetPlacement of(final Direction direction) {
45
		return of(direction.getStepX(), direction.getStepY(), direction.getStepZ());
46
	}
47
48
	public static OffsetPlacement above() {
49
		return of(0, 1, 0);
50
	}
51
52
	@Override
53
	public void modify(final PlacementContext context, final RandomSource random, final BlockPos origin, final Consumer<BlockPos> output) {
54
		output.accept(origin.offset(this.x.sample(random), this.y.sample(random), this.z.sample(random)));
55
	}
56
57
	@Override
58
	public MapCodec<OffsetPlacement> codec() {
59
		return CODEC;
60
	}
61
}
62

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