Search in sources :

Example 1 with RainforestVinesConfig

use of net.tropicraft.core.common.dimension.feature.config.RainforestVinesConfig in project Tropicraft by Tropicraft.

the class RainforestVinesFeature method place.

@Override
public boolean place(FeaturePlaceContext<RainforestVinesConfig> context) {
    WorldGenLevel world = context.level();
    Random rand = context.random();
    BlockPos pos = context.origin();
    RainforestVinesConfig config = context.config();
    BlockPos.MutableBlockPos mutablePos = pos.mutable();
    int maxY = Math.min(pos.getY() + config.height, world.getHeight());
    for (int y = pos.getY(); y < maxY; ++y) {
        for (int i = 0; i < config.rollsPerY; i++) {
            mutablePos.set(pos);
            mutablePos.move(rand.nextInt(config.xzSpread * 2) - config.xzSpread, 0, rand.nextInt(config.xzSpread * 2) - config.xzSpread);
            mutablePos.setY(y);
            if (world.isEmptyBlock(mutablePos)) {
                for (Direction direction : DIRECTIONS) {
                    mutablePos.move(direction);
                    BlockState attaching = world.getBlockState(mutablePos);
                    if ((attaching.getBlock() == Blocks.GRASS_BLOCK && rand.nextInt(4) == 0) || attaching.is(BlockTags.LEAVES)) {
                        if (direction != Direction.DOWN && VineBlock.isAcceptableNeighbour(world, mutablePos, direction)) {
                            mutablePos.move(direction.getOpposite());
                            int len = rand.nextInt(3) + 2;
                            for (int j = 0; j < len && world.isEmptyBlock(mutablePos); j++) {
                                world.setBlock(mutablePos, Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(direction), true), Block.UPDATE_CLIENTS);
                                mutablePos.move(Direction.DOWN);
                            }
                            break;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) RainforestVinesConfig(net.tropicraft.core.common.dimension.feature.config.RainforestVinesConfig) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Aggregations

Random (java.util.Random)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 RainforestVinesConfig (net.tropicraft.core.common.dimension.feature.config.RainforestVinesConfig)1