| 1 | package net.minecraft.world.level.levelgen.feature.trunkplacers;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 6 | import java.util.List;
|
| 7 | import java.util.function.BiConsumer;
|
| 8 | import net.minecraft.core.BlockPos;
|
| 9 | import net.minecraft.core.Direction;
|
| 10 | import net.minecraft.util.RandomSource;
|
| 11 | import net.minecraft.world.level.WorldGenLevel;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 | import net.minecraft.world.level.levelgen.feature.TreeFeature;
|
| 14 | import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;
|
| 15 |
|
| 16 | public class DarkOakTrunkPlacer extends TrunkPlacer {
|
| 17 | public static final MapCodec<DarkOakTrunkPlacer> CODEC = RecordCodecBuilder.mapCodec(i -> trunkPlacerParts(i).apply(i, DarkOakTrunkPlacer::new));
|
| 18 |
|
| 19 | public DarkOakTrunkPlacer(final int baseHeight, final int heightRandA, final int heightRandB) {
|
| 20 | super(baseHeight, heightRandA, heightRandB);
|
| 21 | }
|
| 22 |
|
| 23 | @Override
|
| 24 | protected TrunkPlacerType<?> type() {
|
| 25 | return TrunkPlacerType.DARK_OAK_TRUNK_PLACER;
|
| 26 | }
|
| 27 |
|
| 28 | @Override
|
| 29 | public List<FoliagePlacer.FoliageAttachment> placeTrunk(
|
| 30 | final WorldGenLevel level,
|
| 31 | final BiConsumer<BlockPos, BlockState> trunkSetter,
|
| 32 | final RandomSource random,
|
| 33 | final int treeHeight,
|
| 34 | final BlockPos origin,
|
| 35 | final TreeFeature tree
|
| 36 | ) {
|
| 37 | List<FoliagePlacer.FoliageAttachment> attachments = Lists.newArrayList();
|
| 38 | BlockPos below = origin.below();
|
| 39 | placeBelowTrunkBlock(level, trunkSetter, random, below, tree);
|
| 40 | placeBelowTrunkBlock(level, trunkSetter, random, below.east(), tree);
|
| 41 | placeBelowTrunkBlock(level, trunkSetter, random, below.south(), tree);
|
| 42 | placeBelowTrunkBlock(level, trunkSetter, random, below.south().east(), tree);
|
| 43 | Direction leanDirection = Direction.Plane.HORIZONTAL.getRandomDirection(random);
|
| 44 | int leanHeight = treeHeight - random.nextInt(4);
|
| 45 | int leanSteps = 2 - random.nextInt(3);
|
| 46 | int x = origin.getX();
|
| 47 | int y = origin.getY();
|
| 48 | int z = origin.getZ();
|
| 49 | int tx = x;
|
| 50 | int tz = z;
|
| 51 | int ey = y + treeHeight - 1;
|
| 52 |
|
| 53 | for (int dy = 0; dy < treeHeight; dy++) {
|
| 54 | if (dy >= leanHeight && leanSteps > 0) {
|
| 55 | tx += leanDirection.getStepX();
|
| 56 | tz += leanDirection.getStepZ();
|
| 57 | leanSteps--;
|
| 58 | }
|
| 59 |
|
| 60 | int yy = y + dy;
|
| 61 | BlockPos blockPos = new BlockPos(tx, yy, tz);
|
| 62 | if (TreeFeature.isAirOrLeaves(level, blockPos)) {
|
| 63 | this.placeLog(level, trunkSetter, random, blockPos, tree);
|
| 64 | this.placeLog(level, trunkSetter, random, blockPos.east(), tree);
|
| 65 | this.placeLog(level, trunkSetter, random, blockPos.south(), tree);
|
| 66 | this.placeLog(level, trunkSetter, random, blockPos.east().south(), tree);
|
| 67 | }
|
| 68 | }
|
| 69 |
|
| 70 | attachments.add(new FoliagePlacer.FoliageAttachment(new BlockPos(tx, ey, tz), 0, true));
|
| 71 |
|
| 72 | for (int ox = -1; ox <= 2; ox++) {
|
| 73 | for (int oz = -1; oz <= 2; oz++) {
|
| 74 | if ((ox < 0 || ox > 1 || oz < 0 || oz > 1) && random.nextInt(3) <= 0) {
|
| 75 | int length = random.nextInt(3) + 2;
|
| 76 |
|
| 77 | for (int branchY = 0; branchY < length; branchY++) {
|
| 78 | this.placeLog(level, trunkSetter, random, new BlockPos(x + ox, ey - branchY - 1, z + oz), tree);
|
| 79 | }
|
| 80 |
|
| 81 | attachments.add(new FoliagePlacer.FoliageAttachment(new BlockPos(x + ox, ey, z + oz), 0, false));
|
| 82 | }
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | return attachments;
|
| 87 | }
|
| 88 | }
|
| 89 |
|