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);
}
}
}
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()));
}
}
Aggregations