Search in sources :

Example 1 with TreeConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration in project Tropicraft by Tropicraft.

the class TropicraftTrees method createFruit.

private static AbstractTreeGrower createFruit(Supplier<? extends Block> fruitLeaves, Supplier<Supplier<? extends Block>> fruitSapling) {
    return create((server, random, beehive) -> {
        WeightedStateProvider leaves = new WeightedStateProvider(SimpleWeightedRandomList.<BlockState>builder().add(TropicraftBlocks.FRUIT_LEAVES.get().defaultBlockState(), 1).add(fruitLeaves.get().defaultBlockState(), 1));
        TreeConfiguration config = new TreeConfiguration.TreeConfigurationBuilder(new SimpleStateProvider(Blocks.OAK_LOG.defaultBlockState()), new CitrusTrunkPlacer(6, 3, 0), leaves, new SimpleStateProvider(fruitSapling.get().get().defaultBlockState()), new CitrusFoliagePlacer(ConstantInt.of(0), ConstantInt.of(0)), new TwoLayersFeatureSize(1, 0, 2)).build();
        return Feature.TREE.configured(config);
    });
}
Also used : SimpleStateProvider(net.minecraft.world.level.levelgen.feature.stateproviders.SimpleStateProvider) CitrusTrunkPlacer(net.tropicraft.core.common.dimension.feature.tree.CitrusTrunkPlacer) WeightedStateProvider(net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider) TwoLayersFeatureSize(net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize) CitrusFoliagePlacer(net.tropicraft.core.common.dimension.feature.tree.CitrusFoliagePlacer) TreeConfiguration(net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration)

Example 2 with TreeConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration 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 3 with TreeConfiguration

use of net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration in project Tropicraft by Tropicraft.

the class MangroveTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<TreeConfiguration> pContext) {
    WorldGenLevel world = pContext.level();
    BlockPos pos = pContext.origin();
    TreeConfiguration config = pContext.config();
    BlockPos placePos = this.findPlacePos(world, pos, config);
    if (placePos == null)
        return false;
    BlockPos soilPos = placePos.below();
    BlockState soilState = world.getBlockState(soilPos);
    // Force placement: put dirt under the current position so that the tree always places
    boolean replaceSoil = soilState.is(TropicraftTags.Blocks.MUD) || soilState.getFluidState().is(FluidTags.WATER) || soilState.is(Tags.Blocks.SAND) || (world.getBlockState(soilPos.below()).getFluidState().is(FluidTags.WATER));
    try {
        if (replaceSoil)
            world.setBlock(soilPos, Blocks.DIRT.defaultBlockState(), Block.UPDATE_ALL);
        return this.backing.place(new FeaturePlaceContext<>(world, pContext.chunkGenerator(), pContext.random(), pos, config));
    } finally {
        if (replaceSoil)
            world.setBlock(soilPos, soilState, Block.UPDATE_ALL);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) TreeConfiguration(net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Aggregations

TreeConfiguration (net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration)3 BlockPos (net.minecraft.core.BlockPos)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 Random (java.util.Random)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 LevelAccessor (net.minecraft.world.level.LevelAccessor)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 AbstractTreeGrower (net.minecraft.world.level.block.grower.AbstractTreeGrower)1 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)1 TwoLayersFeatureSize (net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize)1 SimpleStateProvider (net.minecraft.world.level.levelgen.feature.stateproviders.SimpleStateProvider)1 WeightedStateProvider (net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider)1 CitrusFoliagePlacer (net.tropicraft.core.common.dimension.feature.tree.CitrusFoliagePlacer)1 CitrusTrunkPlacer (net.tropicraft.core.common.dimension.feature.tree.CitrusTrunkPlacer)1