| 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 HugeBrownMushroomFeature(
|
| 16 | Holder<BlockStateProvider> capProvider, Holder<BlockStateProvider> stemProvider, int foliageRadius, BlockPredicate canPlaceOn
|
| 17 | ) implements AbstractHugeMushroomFeature {
|
| 18 | public static final MapCodec<HugeBrownMushroomFeature> CODEC = RecordCodecBuilder.mapCodec(
|
| 19 | i -> i.group(
|
| 20 | BlockStateProvider.CODEC.fieldOf("cap_provider").forGetter(HugeBrownMushroomFeature::capProvider),
|
| 21 | BlockStateProvider.CODEC.fieldOf("stem_provider").forGetter(HugeBrownMushroomFeature::stemProvider),
|
| 22 | Codec.INT.optionalFieldOf("foliage_radius", 2).forGetter(HugeBrownMushroomFeature::foliageRadius),
|
| 23 | BlockPredicate.CODEC.fieldOf("can_place_on").forGetter(HugeBrownMushroomFeature::canPlaceOn)
|
| 24 | )
|
| 25 | .apply(i, HugeBrownMushroomFeature::new)
|
| 26 | );
|
| 27 |
|
| 28 | @Override
|
| 29 | public MapCodec<HugeBrownMushroomFeature> 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 dx = -this.foliageRadius; dx <= this.foliageRadius; dx++) {
|
| 36 | for (int dz = -this.foliageRadius; dz <= this.foliageRadius; dz++) {
|
| 37 | boolean minX = dx == -this.foliageRadius;
|
| 38 | boolean maxX = dx == this.foliageRadius;
|
| 39 | boolean minZ = dz == -this.foliageRadius;
|
| 40 | boolean maxZ = dz == this.foliageRadius;
|
| 41 | boolean xEdge = minX || maxX;
|
| 42 | boolean zEdge = minZ || maxZ;
|
| 43 | if (!xEdge || !zEdge) {
|
| 44 | blockPos.setWithOffset(origin, dx, treeHeight, dz);
|
| 45 | boolean west = minX || zEdge && dx == 1 - this.foliageRadius;
|
| 46 | boolean east = maxX || zEdge && dx == this.foliageRadius - 1;
|
| 47 | boolean north = minZ || xEdge && dz == 1 - this.foliageRadius;
|
| 48 | boolean south = maxZ || xEdge && dz == this.foliageRadius - 1;
|
| 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 = state.setValue(HugeMushroomBlock.WEST, west)
|
| 55 | .setValue(HugeMushroomBlock.EAST, east)
|
| 56 | .setValue(HugeMushroomBlock.NORTH, north)
|
| 57 | .setValue(HugeMushroomBlock.SOUTH, south);
|
| 58 | }
|
| 59 |
|
| 60 | this.placeMushroomBlock(level, blockPos, state);
|
| 61 | }
|
| 62 | }
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | @Override
|
| 67 | public int getTreeRadiusForHeight(final int trunkHeight, final int treeHeight, final int leafRadius, final int yo) {
|
| 68 | return yo <= 3 ? 0 : leafRadius;
|
| 69 | }
|
| 70 | }
|
| 71 |
|