| 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 net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.Holder;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.level.WorldGenLevel;
|
| 10 | import net.minecraft.world.level.block.HugeMushroomBlock;
|
| 11 | import net.minecraft.world.level.block.state.BlockState;
|
| 12 | import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
|
| 13 | import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
| 14 |
|
| 15 | public record HugeRedMushroomFeature(
|
| 16 | Holder<BlockStateProvider> capProvider, Holder<BlockStateProvider> stemProvider, int foliageRadius, BlockPredicate canPlaceOn
|
| 17 | ) implements AbstractHugeMushroomFeature {
|
| 18 | public static final MapCodec<HugeRedMushroomFeature> CODEC = RecordCodecBuilder.mapCodec(
|
| 19 | i -> i.group(
|
| 20 | BlockStateProvider.CODEC.fieldOf("cap_provider").forGetter(HugeRedMushroomFeature::capProvider),
|
| 21 | BlockStateProvider.CODEC.fieldOf("stem_provider").forGetter(HugeRedMushroomFeature::stemProvider),
|
| 22 | Codec.INT.optionalFieldOf("foliage_radius", 2).forGetter(HugeRedMushroomFeature::foliageRadius),
|
| 23 | BlockPredicate.CODEC.fieldOf("can_place_on").forGetter(HugeRedMushroomFeature::canPlaceOn)
|
| 24 | )
|
| 25 | .apply(i, HugeRedMushroomFeature::new)
|
| 26 | );
|
| 27 |
|
| 28 | @Override
|
| 29 | public MapCodec<HugeRedMushroomFeature> codec() {
|
| 30 | return CODEC;
|
| 31 | }
|
| 32 |
|
| 33 | @Override
|
| 34 | public void makeCap(final WorldGenLevel level, final RandomSource random, final BlockPos origin, final int treeHeight, final BlockPos.MutableBlockPos blockPos) {
|
| 35 | for (int dy = treeHeight - 3; dy <= treeHeight; dy++) {
|
| 36 | int radius = dy < treeHeight ? this.foliageRadius : this.foliageRadius - 1;
|
| 37 | int center = this.foliageRadius - 2;
|
| 38 |
|
| 39 | for (int dx = -radius; dx <= radius; dx++) {
|
| 40 | for (int dz = -radius; dz <= radius; dz++) {
|
| 41 | boolean minX = dx == -radius;
|
| 42 | boolean maxX = dx == radius;
|
| 43 | boolean minZ = dz == -radius;
|
| 44 | boolean maxZ = dz == radius;
|
| 45 | boolean xEdge = minX || maxX;
|
| 46 | boolean zEdge = minZ || maxZ;
|
| 47 | if (dy >= treeHeight || xEdge != zEdge) {
|
| 48 | blockPos.setWithOffset(origin, dx, dy, dz);
|
| 49 | BlockState state = this.capProvider.value().getState(level, random, origin);
|
| 50 | if (state.hasProperty(HugeMushroomBlock.WEST)
|
| 51 | && state.hasProperty(HugeMushroomBlock.EAST)
|
| 52 | && state.hasProperty(HugeMushroomBlock.NORTH)
|
| 53 | && state.hasProperty(HugeMushroomBlock.SOUTH)
|
| 54 | && state.hasProperty(HugeMushroomBlock.UP)) {
|
| 55 | state = state.setValue(HugeMushroomBlock.UP, dy >= treeHeight - 1)
|
| 56 | .setValue(HugeMushroomBlock.WEST, dx < -center)
|
| 57 | .setValue(HugeMushroomBlock.EAST, dx > center)
|
| 58 | .setValue(HugeMushroomBlock.NORTH, dz < -center)
|
| 59 | .setValue(HugeMushroomBlock.SOUTH, dz > center);
|
| 60 | }
|
| 61 |
|
| 62 | this.placeMushroomBlock(level, blockPos, state);
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | public int getTreeRadiusForHeight(final int trunkHeight, final int treeHeight, final int leafRadius, final int yo) {
|
| 71 | int radius = 0;
|
| 72 | if (yo < treeHeight && yo >= treeHeight - 3) {
|
| 73 | radius = leafRadius;
|
| 74 | } else if (yo == treeHeight) {
|
| 75 | radius = leafRadius;
|
| 76 | }
|
| 77 |
|
| 78 | return radius;
|
| 79 | }
|
| 80 | }
|
| 81 |
|