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