use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class BlockBranchBasic method growSignal.
@Override
public GrowSignal growSignal(World world, BlockPos pos, GrowSignal signal) {
if (signal.step()) {
// This is always placed at the beginning of every growSignal function
IBlockState currBlockState = world.getBlockState(pos);
Species species = signal.getSpecies();
boolean inTrunk = signal.isInTrunk();
// Direction this signal originated from
EnumFacing originDir = signal.dir.getOpposite();
// This must be cached on the stack for proper recursion
EnumFacing targetDir = species.selectNewDirection(world, pos, this, signal);
signal.doTurn(targetDir);
{
BlockPos deltaPos = pos.offset(targetDir);
IBlockState deltaState = world.getBlockState(deltaPos);
// Pass grow signal to next block in path
ITreePart treepart = TreeHelper.getTreePart(deltaState);
if (treepart != TreeHelper.nullTreePart) {
// Recurse
signal = treepart.growSignal(world, deltaPos, signal);
} else if (world.isAirBlock(deltaPos) || deltaState.getBlock() == ModBlocks.blockTrunkShell) {
signal = growIntoAir(world, deltaPos, signal, getRadius(currBlockState));
}
}
// Calculate Branch Thickness based on neighboring branches
// Start by accumulating the branch we just came from
float areaAccum = signal.radius * signal.radius;
for (EnumFacing dir : EnumFacing.VALUES) {
if (!dir.equals(originDir) && !dir.equals(targetDir)) {
// Don't count where the signal originated from or the branch we just came back from
BlockPos deltaPos = pos.offset(dir);
// If it is decided to implement a special block(like a squirrel hole, tree
// swing, rotting, burned or infested branch, etc) then this new block could be
// derived from BlockBranch and this works perfectly. Should even work with
// tileEntity blocks derived from BlockBranch.
IBlockState blockState = world.getBlockState(deltaPos);
ITreePart treepart = TreeHelper.getTreePart(blockState);
if (isSameTree(treepart)) {
int branchRadius = treepart.getRadius(blockState);
areaAccum += branchRadius * branchRadius;
}
}
}
// Only continue to set radii if the tree growth isn't choked out
if (!signal.choked) {
// Ensure that side branches are not thicker than the size of a block. Also enforce species max thickness
int maxRadius = inTrunk ? species.maxBranchRadius() : Math.min(species.maxBranchRadius(), RADMAX_NORMAL);
// The new branch should be the square root of all of the sums of the areas of the branches coming into it.
// But it shouldn't be smaller than it's current size(prevents the instant slimming effect when chopping off branches)
// WOW!
signal.radius = MathHelper.clamp((float) Math.sqrt(areaAccum) + species.getTapering(), getRadius(currBlockState), maxRadius);
int targetRadius = (int) Math.floor(signal.radius);
int setRad = setRadius(world, pos, targetRadius, originDir);
if (setRad < targetRadius) {
// We tried to set a radius but it didn't comply because something is in the way.
// If something is in the way then it means that the tree growth is choked
signal.choked = true;
}
}
}
return signal;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class BlockBranchBasic method growIntoAir.
public GrowSignal growIntoAir(World world, BlockPos pos, GrowSignal signal, int fromRadius) {
Species species = signal.getSpecies();
BlockDynamicLeaves leaves = TreeHelper.getLeaves(species.getLeavesProperties().getDynamicLeavesState());
if (leaves != null) {
if (fromRadius == 1) {
// If we came from a twig then just make some leaves
signal.success = leaves.growLeavesIfLocationIsSuitable(world, species.getLeavesProperties(), pos, 0);
} else {
// Otherwise make a proper branch
return leaves.branchOut(world, pos, signal);
}
}
return signal;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class BlockDynamicSapling method addHitEffects.
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(IBlockState state, World world, RayTraceResult target, ParticleManager manager) {
BlockPos pos = target.getBlockPos();
if (state instanceof IExtendedBlockState) {
Species species = ((IExtendedBlockState) getExtendedState(state, world, pos)).getValue(SpeciesProperty.SPECIES);
IBakedModel model = BakedModelSapling.getModelForSapling(species);
Random rand = world.rand;
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
AxisAlignedBB axisalignedbb = state.getBoundingBox(world, pos);
double d0 = x + rand.nextDouble() * (axisalignedbb.maxX - axisalignedbb.minX - 0.2D) + 0.1D + axisalignedbb.minX;
double d1 = y + rand.nextDouble() * (axisalignedbb.maxY - axisalignedbb.minY - 0.2D) + 0.1D + axisalignedbb.minY;
double d2 = z + rand.nextDouble() * (axisalignedbb.maxZ - axisalignedbb.minZ - 0.2D) + 0.1D + axisalignedbb.minZ;
switch(target.sideHit) {
case DOWN:
d1 = y + axisalignedbb.minY - 0.1D;
break;
case UP:
d1 = y + axisalignedbb.maxY + 0.1D;
break;
case NORTH:
d2 = z + axisalignedbb.minZ - 0.1D;
break;
case SOUTH:
d2 = z + axisalignedbb.maxZ + 0.1D;
break;
case WEST:
d0 = x + axisalignedbb.minX - 0.1D;
break;
case EAST:
d0 = x + axisalignedbb.maxX + 0.1D;
break;
}
// Safe to spawn particles here since this is a client side only member function
ParticleDigging particle = (ParticleDigging) manager.spawnEffectParticle(EnumParticleTypes.BLOCK_CRACK.getParticleID(), d0, d1, d2, 0, 0, 0, Block.getStateId(state));
if (particle != null) {
particle.setParticleTexture(model.getParticleTexture());
particle.setBlockPos(pos).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F);
}
}
return true;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class BlockDynamicSapling method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = player.getHeldItem(hand);
// Make a special case for the potion of burgeoning. Since it only makes sense.
if (heldItem != null && !heldItem.isEmpty()) {
// Use substance provider interface if it's available
if (heldItem.getItem() instanceof ISubstanceEffectProvider) {
ISubstanceEffectProvider provider = (ISubstanceEffectProvider) heldItem.getItem();
ISubstanceEffect substanceEffect = provider.getSubstanceEffect(heldItem);
if (substanceEffect instanceof SubstanceGrowth) {
Species species = getSpecies(world, pos, state);
if (canSaplingStay(world, species, pos)) {
if (species.transitionToTree(world, pos)) {
return species.onTreeActivated(world, pos.down(), pos, state, player, hand, heldItem, facing, hitX, hitY, hitZ);
}
}
}
}
}
return false;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class BlockBonsaiPot method onBlockActivated.
// /////////////////////////////////////////
// INTERACTION
// /////////////////////////////////////////
// Unlike a regular flower pot this is only used to eject the contents
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = player.getHeldItem(hand);
if (hand == EnumHand.MAIN_HAND && heldItem.getItem() == ItemBlock.getItemFromBlock(Blocks.AIR)) {
// Empty hand
Species species = getSpecies(world, pos);
if (!world.isRemote) {
ItemStack seedStack = species.getSeedStack(1);
world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), seedStack));
}
// Return back to an empty pot
world.setBlockState(pos, getPotState(world, pos));
return true;
}
return false;
}
Aggregations