Search in sources :

Example 41 with Species

use of com.ferreusveritas.dynamictrees.trees.Species 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 42 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.

the class SubstanceMega method apply.

@Override
public Result apply(World world, BlockPos rootPos, BlockPos hitPos) {
    IBlockState blockState = world.getBlockState(rootPos);
    BlockRooty dirt = TreeHelper.getRooty(blockState);
    Species species = dirt.getSpecies(blockState, world, rootPos);
    Species megaSpecies = species.getMegaSpecies();
    if (megaSpecies.isValid()) {
        int life = dirt.getSoilLife(blockState, world, rootPos);
        megaSpecies.placeRootyDirtBlock(world, rootPos, life);
        blockState = world.getBlockState(rootPos);
        dirt = TreeHelper.getRooty(blockState);
        if (dirt.getSpecies(blockState, world, rootPos) == megaSpecies) {
            TreeHelper.treeParticles(world, rootPos, EnumParticleTypes.DRAGON_BREATH, 8);
            WailaOther.invalidateWailaPosition();
            return Result.successful();
        }
    }
    return Result.failure("substance.dynamictrees.mega.error.no_mega_species", species.getLocalizedName());
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) Species(com.ferreusveritas.dynamictrees.trees.Species)

Example 43 with Species

use of com.ferreusveritas.dynamictrees.trees.Species 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 44 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.

the class RedwoodLogic method populateDirectionProbabilityMap.

@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
    final Species species = context.species();
    final World world = context.world();
    final GrowSignal signal = context.signal();
    final int[] probMap = context.probMap();
    final int radius = context.radius();
    final BlockPos pos = context.pos();
    Direction originDir = signal.dir.getOpposite();
    int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
    // Alter probability map for direction change
    // Down is always disallowed for spruce
    probMap[0] = 0;
    probMap[1] = signal.isInTrunk() ? species.getUpProbability() : 0;
    boolean branchOut = (signal.numSteps + treeHash) % 5 == 0;
    // Only allow turns when we aren't in the trunk(or the branch is not a twig)
    int sideTurn = !signal.isInTrunk() || (signal.isInTrunk() && branchOut && radius > 1) ? 2 : 0;
    int canopyHeight = species.getLowestBranchHeight() + treeHash % 8 + configuration.get(HEIGHT_OF_CANOPY);
    if (signal.delta.getY() < canopyHeight) {
        probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
        probMap[2 + getHashedVariation(world, pos, 4)] = sideTurn;
    } else {
        probMap[2] = probMap[3] = probMap[4] = // Only allow turns when we aren't in the trunk(or the branch is not a twig and step is odd)
        probMap[5] = !signal.isInTrunk() || (signal.isInTrunk() && signal.numSteps % 4 == 1 && radius > 1) ? 2 : 0;
    }
    // Disable the direction we came from
    probMap[originDir.ordinal()] = 0;
    // Favor current travel direction
    probMap[signal.dir.ordinal()] += signal.isInTrunk() ? 0 : signal.numTurns == 1 ? 2 : 1;
    if (!signal.isInTrunk() && signal.numTurns == 1 && signal.delta.distSqr(0, signal.delta.getY(), 0, false) <= 1.5) {
        // disable left and right if we JUST turned out of the trunk, this is to prevent branches from interfering with the other sides
        probMap[signal.dir.getClockWise().ordinal()] = probMap[signal.dir.getCounterClockWise().ordinal()] = 0;
    }
    return probMap;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Example 45 with Species

use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.

the class SmallRedwoodLogic method populateDirectionProbabilityMap.

// *-*-*-*-*-*-*-*- %2 < 1
// **--**--**--**-- %4 < 2
// ****----****---- %8 < 4
// ********-------- %16< 8
@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
    final Species species = context.species();
    final GrowSignal signal = context.signal();
    final int[] probMap = context.probMap();
    Direction originDir = signal.dir.getOpposite();
    int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
    // Alter probability map for direction change
    // Down is always disallowed for spruce
    probMap[0] = 0;
    probMap[1] = signal.isInTrunk() ? species.getUpProbability() : 0;
    int canopyHeight = species.getLowestBranchHeight() + 4;
    if (signal.delta.getY() == species.getLowestBranchHeight()) {
        int sideHash = treeHash % 16;
        probMap[2] = sideHash % 2 < 1 ? 1 : 0;
        probMap[3] = sideHash % 4 < 2 ? 1 : 0;
        probMap[4] = sideHash % 8 < 4 ? 1 : 0;
        probMap[5] = sideHash < 8 ? 1 : 0;
    } else if (signal.delta.getY() < canopyHeight) {
        probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
    } else {
        probMap[2] = probMap[3] = probMap[4] = // Only allow turns when we aren't in the trunk(or the branch is not a twig and step is odd)
        probMap[5] = !signal.isInTrunk() || (signal.isInTrunk() && signal.numSteps % 2 == 1 && context.radius() > 1) ? 2 : 0;
    }
    // Disable the direction we came from
    probMap[originDir.ordinal()] = 0;
    // Favor current travel direction
    probMap[signal.dir.ordinal()] += signal.isInTrunk() ? 0 : signal.numTurns == 1 ? 2 : 1;
    return probMap;
}
Also used : GrowSignal(com.ferreusveritas.dynamictrees.systems.GrowSignal) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Aggregations

Species (com.ferreusveritas.dynamictrees.trees.Species)56 BlockPos (net.minecraft.util.math.BlockPos)24 IBlockState (net.minecraft.block.state.IBlockState)19 ItemStack (net.minecraft.item.ItemStack)12 GrowSignal (com.ferreusveritas.dynamictrees.systems.GrowSignal)9 Direction (net.minecraft.util.Direction)9 ResourceLocation (net.minecraft.util.ResourceLocation)8 World (net.minecraft.world.World)8 TileEntitySpecies (com.ferreusveritas.dynamictrees.tileentity.TileEntitySpecies)6 EnumFacing (net.minecraft.util.EnumFacing)6 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)5 BlockRooty (com.ferreusveritas.dynamictrees.blocks.BlockRooty)4 ArrayList (java.util.ArrayList)4 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)4 WrongUsageException (net.minecraft.command.WrongUsageException)4 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)3 BlockBonsaiPot (com.ferreusveritas.dynamictrees.blocks.BlockBonsaiPot)3 TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)3