| 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.biome.Biome;
|
| 9 | import net.minecraft.world.level.block.Blocks;
|
| 10 | import net.minecraft.world.level.block.SnowyBlock;
|
| 11 | import net.minecraft.world.level.block.state.BlockState;
|
| 12 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 13 | import net.minecraft.world.level.levelgen.Heightmap;
|
| 14 |
|
| 15 | public record SnowAndFreezeFeature() implements Feature {
|
| 16 | public static final MapCodec<SnowAndFreezeFeature> CODEC = MapCodec.unit(SnowAndFreezeFeature::new);
|
| 17 |
|
| 18 | @Override
|
| 19 | public MapCodec<SnowAndFreezeFeature> codec() {
|
| 20 | return CODEC;
|
| 21 | }
|
| 22 |
|
| 23 | @Override
|
| 24 | public boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin) {
|
| 25 | BlockPos.MutableBlockPos topPos = new BlockPos.MutableBlockPos();
|
| 26 | BlockPos.MutableBlockPos belowPos = new BlockPos.MutableBlockPos();
|
| 27 |
|
| 28 | for (int dx = 0; dx < 16; dx++) {
|
| 29 | for (int dz = 0; dz < 16; dz++) {
|
| 30 | int x = origin.getX() + dx;
|
| 31 | int z = origin.getZ() + dz;
|
| 32 | int y = level.getHeight(Heightmap.Types.MOTION_BLOCKING, x, z);
|
| 33 | topPos.set(x, y, z);
|
| 34 | belowPos.set(topPos).move(Direction.DOWN, 1);
|
| 35 | Biome biome = level.getBiome(topPos).value();
|
| 36 | if (biome.shouldFreeze(level, belowPos, false)) {
|
| 37 | level.setBlock(belowPos, Blocks.ICE.defaultBlockState(), 2);
|
| 38 | }
|
| 39 |
|
| 40 | if (biome.shouldSnow(level, topPos)) {
|
| 41 | level.setBlock(topPos, Blocks.SNOW.defaultBlockState(), 2);
|
| 42 | BlockState belowState = level.getBlockState(belowPos);
|
| 43 | if (belowState.hasProperty(SnowyBlock.SNOWY)) {
|
| 44 | level.setBlock(belowPos, belowState.setValue(SnowyBlock.SNOWY, true), 2);
|
| 45 | }
|
| 46 | }
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | return true;
|
| 51 | }
|
| 52 | }
|
| 53 |
|