Search in sources :

Example 1 with ChunkGenerator

use of net.minecraft.world.level.chunk.ChunkGenerator in project Tropicraft by Tropicraft.

the class TropicraftTrees method create.

private static AbstractTreeGrower create(FeatureProvider featureProvider) {
    return new AbstractTreeGrower() {

        @Nullable
        @Override
        protected ConfiguredFeature<TreeConfiguration, ?> getConfiguredFeature(Random random, boolean beehive) {
            return null;
        }

        @Override
        public boolean growTree(ServerLevel world, ChunkGenerator generator, BlockPos pos, BlockState sapling, Random random) {
            ConfiguredFeature<?, ?> feature = featureProvider.getFeature(world.getServer(), random, this.hasFlowers(world, pos));
            if (feature == null) {
                return false;
            }
            world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_INVISIBLE);
            if (feature.place(world, generator, random, pos)) {
                return true;
            } else {
                world.setBlock(pos, sapling, Block.UPDATE_INVISIBLE);
                return false;
            }
        }

        private boolean hasFlowers(LevelAccessor world, BlockPos origin) {
            BlockPos min = origin.offset(-2, -1, -2);
            BlockPos max = origin.offset(2, 1, 2);
            for (BlockPos pos : BlockPos.MutableBlockPos.betweenClosed(min, max)) {
                if (world.getBlockState(pos).is(BlockTags.FLOWERS)) {
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) AbstractTreeGrower(net.minecraft.world.level.block.grower.AbstractTreeGrower) LevelAccessor(net.minecraft.world.level.LevelAccessor) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) TreeConfiguration(net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration)

Example 2 with ChunkGenerator

use of net.minecraft.world.level.chunk.ChunkGenerator in project Tropicraft by Tropicraft.

the class TropicraftDimension method createDimension.

public static LevelStem createDimension(Registry<DimensionType> dimensionTypeRegistry, Registry<Biome> biomeRegistry, Registry<NoiseGeneratorSettings> dimensionSettingsRegistry, long seed) {
    Supplier<DimensionType> dimensionType = () -> dimensionTypeRegistry.getOrThrow(TropicraftDimension.DIMENSION_TYPE);
    ChunkGenerator generator = TropicraftDimension.createGenerator(biomeRegistry, dimensionSettingsRegistry, seed);
    return new LevelStem(dimensionType, generator);
}
Also used : DimensionType(net.minecraft.world.level.dimension.DimensionType) LevelStem(net.minecraft.world.level.dimension.LevelStem) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) TropicraftChunkGenerator(net.tropicraft.core.common.dimension.chunk.TropicraftChunkGenerator)

Aggregations

ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)2 Random (java.util.Random)1 BlockPos (net.minecraft.core.BlockPos)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 LevelAccessor (net.minecraft.world.level.LevelAccessor)1 AbstractTreeGrower (net.minecraft.world.level.block.grower.AbstractTreeGrower)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 DimensionType (net.minecraft.world.level.dimension.DimensionType)1 LevelStem (net.minecraft.world.level.dimension.LevelStem)1 TreeConfiguration (net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration)1 TropicraftChunkGenerator (net.tropicraft.core.common.dimension.chunk.TropicraftChunkGenerator)1