Search in sources :

Example 1 with FeatureConfiguration

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

the class TropicalFertilizerItem method useOn.

@Override
public InteractionResult useOn(UseOnContext context) {
    BlockState state = context.getLevel().getBlockState(context.getClickedPos());
    if (state.getBlock() == Blocks.GRASS_BLOCK) {
        if (!context.getLevel().isClientSide) {
            // Logic from GrassBlock#grow, with probability for grass significantly reduced
            BlockPos blockpos = context.getClickedPos().above();
            BlockState blockstate = Blocks.GRASS.defaultBlockState();
            Level world = context.getLevel();
            Random rand = world.getRandom();
            for (int i = 0; i < 128; ++i) {
                BlockPos blockpos1 = blockpos;
                int j = 0;
                while (true) {
                    if (j >= i / 16) {
                        BlockState blockstate2 = world.getBlockState(blockpos1);
                        if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
                            if (world instanceof ServerLevel) {
                                ((BonemealableBlock) blockstate.getBlock()).performBonemeal((ServerLevel) world, rand, blockpos1, blockstate2);
                            }
                        }
                        if (!blockstate2.isAir()) {
                            break;
                        }
                        BlockState blockstate1;
                        if (rand.nextInt(8) > 0) {
                            // Modification here, == changed to > to invert chances
                            List<ConfiguredFeature<?, ?>> list = world.getBiome(blockpos1).getGenerationSettings().getFlowerFeatures();
                            if (list.isEmpty()) {
                                break;
                            }
                            // TODO this is so ugly and hacky, pls
                            ConfiguredFeature<?, ?> pFlowerFeature = list.get(0);
                            AbstractFlowerFeature<FeatureConfiguration> abstractflowerfeature = (AbstractFlowerFeature) pFlowerFeature.feature;
                            blockstate1 = abstractflowerfeature.getRandomFlower(rand, blockpos1, pFlowerFeature.config());
                        } else {
                            blockstate1 = blockstate;
                        }
                        if (blockstate1.canSurvive(world, blockpos1)) {
                            world.setBlockAndUpdate(blockpos1, blockstate1);
                        }
                        break;
                    }
                    blockpos1 = blockpos1.offset(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
                    if (world.getBlockState(blockpos1.below()).getBlock() != Blocks.GRASS_BLOCK || world.getBlockState(blockpos1).isCollisionShapeFullBlock(world, blockpos1)) {
                        break;
                    }
                    ++j;
                }
            }
        }
        return InteractionResult.SUCCESS;
    }
    return super.useOn(context);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ConfiguredFeature(net.minecraft.world.level.levelgen.feature.ConfiguredFeature) BonemealableBlock(net.minecraft.world.level.block.BonemealableBlock) FeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) AbstractFlowerFeature(net.minecraft.world.level.levelgen.feature.AbstractFlowerFeature)

Aggregations

Random (java.util.Random)1 BlockPos (net.minecraft.core.BlockPos)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 Level (net.minecraft.world.level.Level)1 BonemealableBlock (net.minecraft.world.level.block.BonemealableBlock)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 AbstractFlowerFeature (net.minecraft.world.level.levelgen.feature.AbstractFlowerFeature)1 ConfiguredFeature (net.minecraft.world.level.levelgen.feature.ConfiguredFeature)1 FeatureConfiguration (net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration)1