BlueIceFeature .java

net.minecraft.world.level.levelgen.feature.BlueIceFeature (record, 70 lines): record. members: place, codec, CODEC. imports: ChunkGenerator.

net.minecraft.world.level.levelgen.featurerecord70 linescommon2.1 KB

Implements

API Surface (2)

MapCodec<BlueIceFeature> codec()
boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin)

Fields & Constants (1)

CODEC

Full Source

BlueIceFeature.java70 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.feature;
2
3
import com.mojang.serialization.MapCodec;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.level.WorldGenLevel;
8
import net.minecraft.world.level.block.Blocks;
9
import net.minecraft.world.level.block.state.BlockState;
10
import net.minecraft.world.level.chunk.ChunkGenerator;
11
12
public record BlueIceFeature() implements Feature {
13
	public static final MapCodec<BlueIceFeature> CODEC = MapCodec.unit(BlueIceFeature::new);
14
15
	@Override
16
	public MapCodec<BlueIceFeature> codec() {
17
		return CODEC;
18
	}
19
20
	@Override
21
	public boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
22
		if (origin.getY() > level.getSeaLevel() - 1) {
23
			return false;
24
		}
25
26
		if (!level.getBlockState(origin).is(Blocks.WATER) && !level.getBlockState(origin.below()).is(Blocks.WATER)) {
27
			return false;
28
		}
29
30
		boolean foundPackedIce = false;
31
32
		for (Direction direction : Direction.values()) {
33
			if (direction != Direction.DOWN && level.getBlockState(origin.relative(direction)).is(Blocks.PACKED_ICE)) {
34
				foundPackedIce = true;
35
				break;
36
			}
37
		}
38
39
		if (!foundPackedIce) {
40
			return false;
41
		}
42
43
		level.setBlock(origin, Blocks.BLUE_ICE.defaultBlockState(), 2);
44
45
		for (int i = 0; i < 200; i++) {
46
			int yOff = random.nextInt(5) - random.nextInt(6);
47
			int xzDiff = 3;
48
			if (yOff < 2) {
49
				xzDiff += yOff / 2;
50
			}
51
52
			if (xzDiff >= 1) {
53
				BlockPos placePos = origin.offset(random.nextInt(xzDiff) - random.nextInt(xzDiff), yOff, random.nextInt(xzDiff) - random.nextInt(xzDiff));
54
				BlockState placeState = level.getBlockState(placePos);
55
				if (placeState.isAir() || placeState.is(Blocks.WATER) || placeState.is(Blocks.PACKED_ICE) || placeState.is(Blocks.ICE)) {
56
					for (Direction direction : Direction.values()) {
57
						BlockState relativeBlockState = level.getBlockState(placePos.relative(direction));
58
						if (relativeBlockState.is(Blocks.BLUE_ICE)) {
59
							level.setBlock(placePos, Blocks.BLUE_ICE.defaultBlockState(), 2);
60
							break;
61
						}
62
					}
63
				}
64
			}
65
		}
66
67
		return true;
68
	}
69
}
70

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