Search in sources :

Example 1 with WeightedList

use of net.minecraft.util.WeightedList in project DynamicTrees-BYG by DynamicTreesTeam.

the class BranchSproutsGenFeature method placeSprouts.

private void placeSprouts(int count, GenFeatureConfiguration configuration, IWorld world, BlockPos rootPos) {
    WeightedList<Pair<BlockPos, Direction>> validSpots = new WeightedList<>();
    final FindSidedBlockNode sproutPlacer = new FindSidedBlockNode(validSpots, configuration.get(MIN_RADIUS));
    TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(sproutPlacer));
    if (!validSpots.isEmpty()) {
        for (int i = 0; i < count; i++) {
            Pair<BlockPos, Direction> selection = validSpots.getOne(world.getRandom());
            BlockPos pos = selection.getFirst();
            Block block = configuration.get(SPROUT_BLOCK);
            if (world.getBlockState(pos.below()).getBlock() == block)
                return;
            world.setBlock(pos, block.defaultBlockState().setValue(HorizontalBlock.FACING, selection.getSecond()), 3);
        }
    }
}
Also used : WeightedList(net.minecraft.util.WeightedList) BranchBlock(com.ferreusveritas.dynamictrees.blocks.branches.BranchBlock) TrunkShellBlock(com.ferreusveritas.dynamictrees.blocks.branches.TrunkShellBlock) Block(net.minecraft.block.Block) HorizontalBlock(net.minecraft.block.HorizontalBlock) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) Pair(com.mojang.datafixers.util.Pair) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 2 with WeightedList

use of net.minecraft.util.WeightedList in project DynamicTrees-BYG by DynamicTreesTeam.

the class AlternativeBranchGenFeature method placeAltBranches.

private void placeAltBranches(boolean isWorldgen, GenFeatureConfiguration configuration, IWorld world, BlockPos rootPos, Family family) {
    WeightedList<BlockPos> validSpots = new WeightedList<>();
    final FindValidBranchesNode altBranchPlacer = new FindValidBranchesNode(validSpots, configuration.get(MIN_RADIUS), family);
    TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(altBranchPlacer));
    if (!validSpots.isEmpty()) {
        if (isWorldgen) {
            for (BlockPos listPos : validSpots.stream().collect(Collectors.toSet())) if (world.getRandom().nextFloat() < configuration.get(WORLDGEN_PLACE_CHANCE))
                placeBranch(configuration, world, listPos);
        } else
            placeBranch(configuration, world, validSpots.getOne(world.getRandom()));
    }
}
Also used : WeightedList(net.minecraft.util.WeightedList) BlockPos(net.minecraft.util.math.BlockPos) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Aggregations

MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)2 WeightedList (net.minecraft.util.WeightedList)2 BlockPos (net.minecraft.util.math.BlockPos)2 BranchBlock (com.ferreusveritas.dynamictrees.blocks.branches.BranchBlock)1 TrunkShellBlock (com.ferreusveritas.dynamictrees.blocks.branches.TrunkShellBlock)1 Pair (com.mojang.datafixers.util.Pair)1 Block (net.minecraft.block.Block)1 HorizontalBlock (net.minecraft.block.HorizontalBlock)1 Direction (net.minecraft.util.Direction)1