use of com.ferreusveritas.dynamictrees.event.FutureBreak in project DynamicTrees by DynamicTreesTeam.
the class BlockBranch method futureBreak.
/*
1.10.2 Simplified Block Harvesting Logic Flow(for no silk touch)
tryHarvestBlock {
canHarvest = canHarvestBlock() <- (ForgeHooks.canHarvestBlock occurs in here)
removed = removeBlock(canHarvest) {
removedByPlayer() {
onBlockHarvested()
world.setBlockState() <- block is set to air here
}
}
if (removed) harvestBlock() {
fortune = getEnchantmentLevel(FORTUNE)
dropBlockAsItem(fortune) {
dropBlockAsItemWithChance(fortune) {
items = getDrops(fortune) {
getItemDropped(fortune) {
Item.getItemFromBlock(this) <- (Standard block behavior)
}
}
ForgeEventFactory.fireBlockHarvesting(items) <- (BlockEvent.HarvestDropsEvent)
(for all items) -> spawnAsEntity(item)
}
}
}
}
*/
@Override
public void futureBreak(IBlockState state, World world, BlockPos cutPos, EntityLivingBase entity) {
// Try to get the face being pounded on
final double reachDistance = entity instanceof EntityPlayerMP ? entity.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue() : 5.0D;
RayTraceResult rtResult = playerRayTrace(entity, reachDistance, 1.0F);
EnumFacing toolDir = rtResult != null ? (entity.isSneaking() ? rtResult.sideHit.getOpposite() : rtResult.sideHit) : EnumFacing.DOWN;
if (toolDir == null) {
// Some rayTracing results can theoretically produce a face hit with no side designation.
// Make everything better
toolDir = EnumFacing.DOWN;
}
// Do the actual destruction
BranchDestructionData destroyData = destroyBranchFromNode(world, cutPos, toolDir, false);
// Get all of the wood drops
ItemStack heldItem = entity.getHeldItemMainhand();
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, heldItem);
float fortuneFactor = 1.0f + 0.25f * fortune;
// The amount of wood calculated from the body of the tree network
float woodVolume = destroyData.woodVolume;
List<ItemStack> woodItems = getLogDrops(world, cutPos, destroyData.species, woodVolume * fortuneFactor);
if (entity.getActiveHand() == null) {
// What the hell man? I trusted you!
// Players do things with hands.
entity.setActiveHand(EnumHand.MAIN_HAND);
}
float chance = 1.0f;
// Fire the block harvesting event. For An-Sar's PrimalCore mod :)
if (entity instanceof EntityPlayer) {
chance = net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(woodItems, world, cutPos, state, fortune, chance, false, (EntityPlayer) entity);
}
final float finalChance = chance;
// Build the final wood drop list taking chance into consideration
List<ItemStack> woodDropList = woodItems.stream().filter(i -> world.rand.nextFloat() <= finalChance).collect(Collectors.toList());
// This will drop the EntityFallingTree into the world
EntityFallingTree.dropTree(world, destroyData, woodDropList, DestroyType.HARVEST);
// Damage the axe by a prescribed amount
damageAxe(entity, heldItem, getRadius(state), woodVolume);
}
Aggregations