54 lines
2 KiB
Java
54 lines
2 KiB
Java
package net.minecraft.world.level.levelgen.feature.trunkplacers;
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.mojang.serialization.MapCodec;
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
import java.util.List;
|
|
import java.util.function.BiConsumer;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.level.LevelSimulatedReader;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
|
|
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer.FoliageAttachment;
|
|
|
|
public class MegaJungleTrunkPlacer extends GiantTrunkPlacer {
|
|
public static final MapCodec<MegaJungleTrunkPlacer> CODEC = RecordCodecBuilder.mapCodec(
|
|
instance -> trunkPlacerParts(instance).apply(instance, MegaJungleTrunkPlacer::new)
|
|
);
|
|
|
|
public MegaJungleTrunkPlacer(int i, int j, int k) {
|
|
super(i, j, k);
|
|
}
|
|
|
|
@Override
|
|
protected TrunkPlacerType<?> type() {
|
|
return TrunkPlacerType.MEGA_JUNGLE_TRUNK_PLACER;
|
|
}
|
|
|
|
@Override
|
|
public List<FoliageAttachment> placeTrunk(
|
|
LevelSimulatedReader level, BiConsumer<BlockPos, BlockState> blockSetter, RandomSource random, int freeTreeHeight, BlockPos pos, TreeConfiguration config
|
|
) {
|
|
List<FoliageAttachment> list = Lists.<FoliageAttachment>newArrayList();
|
|
list.addAll(super.placeTrunk(level, blockSetter, random, freeTreeHeight, pos, config));
|
|
|
|
for (int i = freeTreeHeight - 2 - random.nextInt(4); i > freeTreeHeight / 2; i -= 2 + random.nextInt(4)) {
|
|
float f = random.nextFloat() * (float) (Math.PI * 2);
|
|
int j = 0;
|
|
int k = 0;
|
|
|
|
for (int l = 0; l < 5; l++) {
|
|
j = (int)(1.5F + Mth.cos(f) * l);
|
|
k = (int)(1.5F + Mth.sin(f) * l);
|
|
BlockPos blockPos = pos.offset(j, i - 3 + l / 2, k);
|
|
this.placeLog(level, blockSetter, random, blockPos, config);
|
|
}
|
|
|
|
list.add(new FoliageAttachment(pos.offset(j, i, k), -2, false));
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|