| 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.util.Mth;
|
| 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 MegaJungleTrunkPlacer extends GiantTrunkPlacer {
|
| 17 | public static final MapCodec<MegaJungleTrunkPlacer> CODEC = RecordCodecBuilder.mapCodec(i -> trunkPlacerParts(i).apply(i, MegaJungleTrunkPlacer::new));
|
| 18 |
|
| 19 | public MegaJungleTrunkPlacer(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.MEGA_JUNGLE_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 | attachments.addAll(super.placeTrunk(level, trunkSetter, random, treeHeight, origin, tree));
|
| 39 |
|
| 40 | for (int branchHeight = treeHeight - 2 - random.nextInt(4); branchHeight > treeHeight / 2; branchHeight -= 2 + random.nextInt(4)) {
|
| 41 | float angle = random.nextFloat() * (float) (Math.PI * 2);
|
| 42 | int bx = 0;
|
| 43 | int bz = 0;
|
| 44 |
|
| 45 | for (int b = 0; b < 5; b++) {
|
| 46 | bx = (int)(1.5F + Mth.cos(angle) * b);
|
| 47 | bz = (int)(1.5F + Mth.sin(angle) * b);
|
| 48 | BlockPos pos = origin.offset(bx, branchHeight - 3 + b / 2, bz);
|
| 49 | this.placeLog(level, trunkSetter, random, pos, tree);
|
| 50 | }
|
| 51 |
|
| 52 | attachments.add(new FoliagePlacer.FoliageAttachment(origin.offset(bx, branchHeight, bz), -2, false));
|
| 53 | }
|
| 54 |
|
| 55 | return attachments;
|
| 56 | }
|
| 57 | }
|
| 58 |
|