use of com.ferreusveritas.dynamictrees.entities.EntityFallingTree in project DynamicTrees by DynamicTreesTeam.
the class BlockSurfaceRoot method addCollisionBoxToList.
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) {
if (entityIn instanceof EntityFallingTree) {
return;
}
boolean connectionMade = false;
int thisRadius = getRadius(state);
for (EnumFacing dir : EnumFacing.HORIZONTALS) {
RootConnection conn = getSideConnectionRadius(world, pos, thisRadius, dir);
if (conn != null) {
connectionMade = true;
int r = MathHelper.clamp(conn.radius, 1, thisRadius);
double radius = r / 16.0;
double radialHeight = getRadialHeight(r) / 16.0;
double gap = 0.5 - radius;
AxisAlignedBB aabb = new AxisAlignedBB(-radius, 0, -radius, radius, radialHeight, radius);
aabb = aabb.expand(dir.getFrontOffsetX() * gap, 0, dir.getFrontOffsetZ() * gap).offset(0.5, 0.0, 0.5);
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
if (!connectionMade) {
double radius = thisRadius / 16.0;
double radialHeight = getRadialHeight(thisRadius) / 16.0;
AxisAlignedBB aabb = new AxisAlignedBB(0.5 - radius, 0, 0.5 - radius, 0.5 + radius, radialHeight, 0.5 + radius);
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
use of com.ferreusveritas.dynamictrees.entities.EntityFallingTree in project DynamicTrees by DynamicTreesTeam.
the class AnimationHandlerFallover method testEntityCollision.
public List<EntityLivingBase> testEntityCollision(EntityFallingTree entity) {
World world = entity.world;
EnumFacing toolDir = entity.getDestroyData().toolDir;
float actingAngle = toolDir.getAxis() == EnumFacing.Axis.X ? entity.rotationYaw : entity.rotationPitch;
int offsetX = toolDir.getFrontOffsetX();
int offsetZ = toolDir.getFrontOffsetZ();
float h = MathHelper.sin((float) Math.toRadians(actingAngle)) * (offsetX | offsetZ);
float v = MathHelper.cos((float) Math.toRadians(actingAngle));
float xbase = (float) (entity.posX + offsetX * (-(0.5f) + (v * 0.5f) + (h * 0.5f)));
float ybase = (float) (entity.posY - (h * 0.5f) + (v * 0.5f));
float zbase = (float) (entity.posZ + offsetZ * (-(0.5f) + (v * 0.5f) + (h * 0.5f)));
int trunkHeight = entity.getDestroyData().trunkHeight;
float segX = xbase + h * (trunkHeight - 1) * offsetX;
float segY = ybase + v * (trunkHeight - 1);
float segZ = zbase + h * (trunkHeight - 1) * offsetZ;
float maxRadius = entity.getDestroyData().getBranchRadius(0) / 16.0f;
Vec3d vec3d1 = new Vec3d(xbase, ybase, zbase);
Vec3d vec3d2 = new Vec3d(segX, segY, segZ);
return world.getEntitiesInAABBexcluding(entity, new AxisAlignedBB(vec3d1.x, vec3d1.y, vec3d1.z, vec3d2.x, vec3d2.y, vec3d2.z), Predicates.and(EntitySelectors.NOT_SPECTATING, new Predicate<Entity>() {
public boolean apply(@Nullable Entity apply) {
if (apply instanceof EntityLivingBase && apply.canBeCollidedWith()) {
AxisAlignedBB axisalignedbb = apply.getEntityBoundingBox().grow(maxRadius);
return axisalignedbb.contains(vec3d1) || axisalignedbb.calculateIntercept(vec3d1, vec3d2) != null;
}
return false;
}
})).stream().map(a -> (EntityLivingBase) a).collect(Collectors.toList());
}
use of com.ferreusveritas.dynamictrees.entities.EntityFallingTree in project DynamicTrees by DynamicTreesTeam.
the class BlockBranchBasic method addCollisionBoxToList.
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) {
if (entityIn instanceof EntityFallingTree) {
return;
}
boolean hasConnections = false;
int thisRadius = getRadius(state);
for (EnumFacing dir : EnumFacing.VALUES) {
int connRadius = getSideConnectionRadius(world, pos, thisRadius, dir);
if (connRadius > 0) {
hasConnections = true;
double radius = MathHelper.clamp(connRadius, 1, thisRadius) / 16.0;
double gap = 0.5 - radius;
AxisAlignedBB aabb = new AxisAlignedBB(0, 0, 0, 0, 0, 0).grow(radius);
// .intersect(maxBranchBB);
aabb = aabb.expand(dir.getFrontOffsetX() * gap, dir.getFrontOffsetY() * gap, dir.getFrontOffsetZ() * gap).offset(0.5, 0.5, 0.5);
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
if (!hasConnections) {
AxisAlignedBB aabb = new AxisAlignedBB(0.5, 0.5, 0.5, 0.5, 0.5, 0.5).grow(thisRadius);
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
use of com.ferreusveritas.dynamictrees.entities.EntityFallingTree 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.entities.EntityFallingTree 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