Search in sources :

Example 6 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.

the class Species method grow.

/**
 * The grow handler.
 *
 * @param world     The world
 * @param rootyDirt The {@link BlockRooty} that is supporting this tree
 * @param rootPos   The {@link BlockPos} of the {@link BlockRooty} type in the world
 * @param soilLife  The life of the soil. 0: Depleted -> 15: Full
 * @param treePos   The {@link BlockPos} of the {@link TreeFamily} trunk base.
 * @param random    A random number generator
 * @param natural   If true then this member is being used to grow the tree naturally(create drops or fruit). If
 *                  false then this member is being used to grow a tree with a growth accelerant like bonemeal or
 *                  the potion of burgeoning
 * @return true if network is viable.  false if network is not viable(will destroy the {@link BlockRooty} this tree
 * is on)
 */
public boolean grow(World world, BlockRooty rootyDirt, BlockPos rootPos, int soilLife, ITreePart treeBase, BlockPos treePos, Random random, boolean natural) {
    float growthRate = getGrowthRate(world, rootPos) * ModConfigs.treeGrowthMultiplier * ModConfigs.treeGrowthFolding;
    do {
        if (soilLife > 0) {
            if (growthRate > random.nextFloat()) {
                GrowSignal signal = new GrowSignal(this, rootPos, getEnergy(world, rootPos));
                boolean success = treeBase.growSignal(world, treePos, signal).success;
                int soilLongevity = getSoilLongevity(world, rootPos) * // Don't deplete the soil as much if the grow operation failed
                (success ? 1 : 16);
                if (soilLongevity <= 0 || random.nextInt(soilLongevity) == 0) {
                    // 1 in X(soilLongevity) chance to draw nutrients from soil
                    // decrement soil life
                    rootyDirt.setSoilLife(world, rootPos, soilLife - 1);
                }
                if (signal.choked) {
                    soilLife = 0;
                    rootyDirt.setSoilLife(world, rootPos, soilLife);
                    TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(new NodeShrinker(signal.getSpecies())));
                }
            }
        }
    } while (--growthRate > 0.0f);
    return postGrow(world, rootPos, treePos, soilLife, natural);
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal) NodeShrinker(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeShrinker)

Example 7 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal 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)

Example 8 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.

the class CommandTransform method execute.

@Override
public void execute(World world, ICommandSender sender, String[] args) throws CommandException {
    BlockPos pos = BlockPos.ORIGIN;
    Species toSpecies = null;
    if (args.length < 5) {
        throw new WrongUsageException("commands.dynamictrees.transform.usage");
    }
    for (int arg = 0; arg < args.length; arg++) {
        switch(arg) {
            case 3:
                pos = CommandBase.parseBlockPos(sender, args, 1, false);
                break;
            case 4:
                toSpecies = TreeRegistry.findSpeciesSloppy(args[4]);
                if (toSpecies == Species.NULLSPECIES) {
                    throw new CommandException("commands.dynamictrees.setree.specieserror", args[4]);
                }
                break;
        }
    }
    BlockPos rootPos = TreeHelper.findRootNode(world, pos);
    Species fromSpecies = TreeHelper.getExactSpecies(world, rootPos);
    if (rootPos == BlockPos.ORIGIN) {
        throw new CommandException("commands.dynamictrees.soillife.notreeerror", pos.getX() + " " + pos.getY() + " " + pos.getZ());
    }
    if (!toSpecies.isTransformable() || !fromSpecies.isTransformable()) {
        throw new CommandException("commands.dynamictrees.transform.nottransformableerror", !toSpecies.isTransformable() ? args[4] : fromSpecies.getRegistryName());
    }
    IBlockState rootyState = world.getBlockState(rootPos);
    BlockRooty rootyBlock = TreeHelper.getRooty(rootyState);
    rootyBlock.startAnalysis(world, rootPos, new MapSignal(new NodeTransform(fromSpecies, toSpecies)));
    if (rootyBlock.getSpecies(rootyState, world, rootPos) != toSpecies) {
        // Place new rooty dirt block in case we're transforming to species that requires tile entity.
        toSpecies.placeRootyDirtBlock(world, rootPos, rootyBlock.getSoilLife(rootyState, world, rootPos));
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) IBlockState(net.minecraft.block.state.IBlockState) NodeTransform(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform) BlockPos(net.minecraft.util.math.BlockPos) CommandException(net.minecraft.command.CommandException) Species(com.ferreusveritas.dynamictrees.trees.Species) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 9 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.

the class SubstanceTransform method apply.

@Override
public Result apply(World world, BlockPos rootPos, BlockPos hitPos) {
    IBlockState rootyState = world.getBlockState(rootPos);
    BlockRooty dirt = TreeHelper.getRooty(rootyState);
    if (this.toSpecies == null) {
        return Result.failure("substance.dynamictrees.transform.error.not_brewed");
    }
    if (dirt == null) {
        return Result.failure();
    }
    final Species fromSpecies = dirt.getSpecies(rootyState, world, rootPos);
    if (!fromSpecies.isTransformable()) {
        return Result.failure("substance.dynamictrees.transform.error.not_transformable", fromSpecies.getLocalizedName());
    }
    if (fromSpecies == toSpecies) {
        return Result.failure("substance.dynamictrees.transform.error.already_transformed", fromSpecies.getLocalizedName());
    }
    if (world.isRemote) {
        TreeHelper.treeParticles(world, rootPos, EnumParticleTypes.FIREWORKS_SPARK, 8);
        WailaOther.invalidateWailaPosition();
    } else {
        dirt.startAnalysis(world, rootPos, new MapSignal(new NodeTransform(fromSpecies, toSpecies)));
        if (dirt.getSpecies(rootyState, world, rootPos) != toSpecies) {
            toSpecies.placeRootyDirtBlock(world, rootPos, dirt.getSoilLife(rootyState, world, rootPos));
        }
    }
    return Result.successful();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NodeTransform(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) Species(com.ferreusveritas.dynamictrees.trees.Species) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 10 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.

the class Species method getEnds.

/**
 * A little internal convenience function for getting branch endpoints
 *
 * @param world    The world
 * @param treePos  The {@link BlockPos} of the base of the {@link TreeFamily} trunk
 * @param treeBase The tree part that is the base of the {@link TreeFamily} trunk.  Provided for easy analysis.
 * @return A list of all branch endpoints for the {@link TreeFamily}
 */
protected final List<BlockPos> getEnds(World world, BlockPos treePos, ITreePart treeBase) {
    NodeFindEnds endFinder = new NodeFindEnds();
    treeBase.analyse(world.getBlockState(treePos), world, treePos, null, new MapSignal(endFinder));
    return endFinder.getEnds();
}
Also used : NodeFindEnds(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFindEnds) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Aggregations

MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)15 IBlockState (net.minecraft.block.state.IBlockState)10 BlockPos (net.minecraft.util.math.BlockPos)9 BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)6 Species (com.ferreusveritas.dynamictrees.trees.Species)5 BlockRooty (com.ferreusveritas.dynamictrees.blocks.BlockRooty)4 NodeFindEnds (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFindEnds)4 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)4 Block (net.minecraft.block.Block)3 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)2 NodeCollector (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector)2 NodeNetVolume (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume)2 NodeTransform (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform)2 SimpleVoxmap (com.ferreusveritas.dynamictrees.util.SimpleVoxmap)2 Cell (com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell)2 EnumFacing (net.minecraft.util.EnumFacing)2 WeightedList (net.minecraft.util.WeightedList)2 INodeInspector (com.ferreusveritas.dynamictrees.api.network.INodeInspector)1 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)1 BlockDynamicLeaves (com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves)1