Search in sources :

Example 51 with Species

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

the class BlockBranch method onBlockExploded.

// /////////////////////////////////////////
// EXPLOSIONS AND FIRE
// /////////////////////////////////////////
// Explosive harvesting methods will likely result in mostly sticks but I'm okay with that since it kinda makes sense.
@Override
public void onBlockExploded(World world, BlockPos pos, Explosion explosion) {
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() == this) {
        Species species = TreeHelper.getExactSpecies(world, pos);
        BranchDestructionData destroyData = destroyBranchFromNode(world, pos, EnumFacing.DOWN, false);
        float woodVolume = destroyData.woodVolume;
        List<ItemStack> woodDropList = getLogDrops(world, pos, species, woodVolume);
        EntityFallingTree treeEntity = EntityFallingTree.dropTree(world, destroyData, woodDropList, DestroyType.BLAST);
        if (treeEntity != null) {
            Vec3d expPos = explosion.getPosition();
            EntityLivingBase placer = explosion.getExplosivePlacedBy();
            // Since the size of an explosion is private we have to make some assumptions.. TNT: 4, Creeper: 3, Creeper+: 6
            float size = (placer instanceof EntityCreeper) ? (((EntityCreeper) placer).getPowered() ? 6 : 3) : 4;
            double distance = treeEntity.getDistance(expPos.x, expPos.y, expPos.z);
            if (distance / size <= 1.0D && distance != 0.0D) {
                treeEntity.motionX += (treeEntity.posX - expPos.x) / distance;
                treeEntity.motionY += (treeEntity.posY - expPos.y) / distance;
                treeEntity.motionZ += (treeEntity.posZ - expPos.z) / distance;
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityFallingTree(com.ferreusveritas.dynamictrees.entities.EntityFallingTree) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) ItemStack(net.minecraft.item.ItemStack) NodeSpecies(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies) Species(com.ferreusveritas.dynamictrees.trees.Species) Vec3d(net.minecraft.util.math.Vec3d)

Example 52 with Species

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

the class BlockBranch method destroyBranchFromNode.

/**
 * Destroys all branches recursively not facing the branching direction with the root node
 *
 * @param world     The world
 * @param cutPos    The position of the branch being lobbed
 * @param toolDir   The face that was pounded on when breaking the block at cutPos
 * @param wholeTree Indicates if the whole tree should be destroyed or just the branch
 * @return The volume of the portion of the tree that was destroyed
 */
public BranchDestructionData destroyBranchFromNode(World world, BlockPos cutPos, EnumFacing toolDir, boolean wholeTree) {
    IBlockState blockState = world.getBlockState(cutPos);
    NodeSpecies nodeSpecies = new NodeSpecies();
    // Analyze entire tree network to find root node and species
    MapSignal signal = analyse(blockState, world, cutPos, null, new MapSignal(nodeSpecies));
    // Get the species from the root node
    Species species = nodeSpecies.getSpecies();
    // Analyze only part of the tree beyond the break point and map out the extended block states
    // We can't destroy the branches during this step since we need accurate extended block states that include connections
    NodeExtState extStateMapper = new NodeExtState(cutPos);
    analyse(blockState, world, cutPos, wholeTree ? null : signal.localRootDir, new MapSignal(extStateMapper));
    // Analyze only part of the tree beyond the break point and calculate it's volume, then destroy the branches
    NodeNetVolume volumeSum = new NodeNetVolume();
    NodeDestroyer destroyer = new NodeDestroyer(species);
    destroyMode = EnumDestroyMode.HARVEST;
    analyse(blockState, world, cutPos, wholeTree ? null : signal.localRootDir, new MapSignal(volumeSum, destroyer));
    destroyMode = EnumDestroyMode.SLOPPY;
    // Destroy all the leaves on the branch, store them in a map and convert endpoint coordinates from absolute to relative
    List<BlockPos> endPoints = destroyer.getEnds();
    Map<BlockPos, IBlockState> destroyedLeaves = new HashMap<>();
    List<BlockItemStack> leavesDropsList = new ArrayList<>();
    destroyLeaves(world, cutPos, species, endPoints, destroyedLeaves, leavesDropsList);
    endPoints = endPoints.stream().map(p -> p.subtract(cutPos)).collect(Collectors.toList());
    // Calculate main trunk height
    int trunkHeight = 1;
    for (BlockPos iter = new BlockPos(0, 1, 0); extStateMapper.getExtStateMap().containsKey(iter); iter = iter.up()) {
        trunkHeight++;
    }
    EnumFacing cutDir = signal.localRootDir;
    if (cutDir == null) {
        cutDir = EnumFacing.DOWN;
    }
    return new BranchDestructionData(species, extStateMapper.getExtStateMap(), destroyedLeaves, leavesDropsList, endPoints, volumeSum.getVolume(), cutPos, cutDir, toolDir, trunkHeight);
}
Also used : NodeSpecies(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies) NodeNetVolume(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume) NodeExtState(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeExtState) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) NodeDestroyer(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeDestroyer) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) NodeSpecies(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies) Species(com.ferreusveritas.dynamictrees.trees.Species) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 53 with Species

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

the class BlockRooty method setSoilLife.

public void setSoilLife(World world, BlockPos rootPos, int life) {
    Species species = getSpecies(world.getBlockState(rootPos), world, rootPos);
    world.setBlockState(rootPos, getDefaultState().withProperty(LIFE, MathHelper.clamp(life, 0, 15)), 3);
    // Notify all neighbors of NSEWUD neighbors(for comparator)
    world.notifyNeighborsOfStateChange(rootPos, this, false);
    setSpecies(world, rootPos, species);
}
Also used : Species(com.ferreusveritas.dynamictrees.trees.Species) TileEntitySpecies(com.ferreusveritas.dynamictrees.tileentity.TileEntitySpecies)

Example 54 with Species

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

the class BlockRooty method updateTree.

/**
 * @param world
 * @param rootPos
 * @param random
 * @param natural
 */
public void updateTree(IBlockState rootyState, World world, BlockPos rootPos, Random random, boolean natural) {
    if (CoordUtils.isSurroundedByLoadedChunks(world, rootPos)) {
        boolean viable = false;
        Species species = getSpecies(rootyState, world, rootPos);
        if (species.isValid()) {
            BlockPos treePos = rootPos.offset(getTrunkDirection(world, rootPos));
            ITreePart treeBase = TreeHelper.getTreePart(world.getBlockState(treePos));
            if (treeBase != TreeHelper.nullTreePart) {
                viable = species.update(world, this, rootPos, getSoilLife(rootyState, world, rootPos), treeBase, treePos, random, natural);
            }
        }
        if (!viable) {
            // TODO: Attempt to destroy what's left of the tree before setting rooty to dirt
            world.setBlockState(rootPos, getDecayBlockState(world, rootPos), 3);
        }
    }
}
Also used : ITreePart(com.ferreusveritas.dynamictrees.api.treedata.ITreePart) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) TileEntitySpecies(com.ferreusveritas.dynamictrees.tileentity.TileEntitySpecies)

Example 55 with Species

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

the class TreeRegistry method getPotionTransformableSpecies.

/**
 * @return All species which can be transformed and have their own seed (so should have a potion recipe created).
 */
public static List<Species> getPotionTransformableSpecies() {
    final List<Species> speciesList = getTransformableSpecies();
    speciesList.removeIf(species -> {
        TreeFamily family = species.getFamily();
        // Remove the species if its seed not set, or if it's not the common species and its seed is the same as the common species'.
        return (species.getSeedStack(1) == null || species.getSeed() == Seed.NULLSEED) || (species != family.getCommonSpecies() && species.getSeed() == family.getCommonSpecies().getSeed());
    });
    return speciesList;
}
Also used : TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) Species(com.ferreusveritas.dynamictrees.trees.Species)

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