Search in sources :

Example 1 with EntityFallingTree

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);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityFallingTree(com.ferreusveritas.dynamictrees.entities.EntityFallingTree) EnumFacing(net.minecraft.util.EnumFacing)

Example 2 with EntityFallingTree

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());
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ModConfigs(com.ferreusveritas.dynamictrees.ModConfigs) EntitySelectors(net.minecraft.util.EntitySelectors) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) HashSet(java.util.HashSet) EntityFallingTree(com.ferreusveritas.dynamictrees.entities.EntityFallingTree) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) Predicates(com.google.common.base.Predicates) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) GlStateManager(net.minecraft.client.renderer.GlStateManager) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TreeHelper(com.ferreusveritas.dynamictrees.api.TreeHelper) Collectors(java.util.stream.Collectors) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Predicate(com.google.common.base.Predicate) EntityLivingBase(net.minecraft.entity.EntityLivingBase) MathHelper(net.minecraft.util.math.MathHelper) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) Entity(net.minecraft.entity.Entity) EnumFacing(net.minecraft.util.EnumFacing) EntityLivingBase(net.minecraft.entity.EntityLivingBase) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with EntityFallingTree

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);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityFallingTree(com.ferreusveritas.dynamictrees.entities.EntityFallingTree) EnumFacing(net.minecraft.util.EnumFacing)

Example 4 with EntityFallingTree

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;
            }
        }
    }
}
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 5 with EntityFallingTree

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);
}
Also used : ModConfigs(com.ferreusveritas.dynamictrees.ModConfigs) Explosion(net.minecraft.world.Explosion) FutureBreak(com.ferreusveritas.dynamictrees.event.FutureBreak) Item(net.minecraft.item.Item) EnumHand(net.minecraft.util.EnumHand) DestroyType(com.ferreusveritas.dynamictrees.entities.EntityFallingTree.DestroyType) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) EnumPushReaction(net.minecraft.block.material.EnumPushReaction) ITreePart(com.ferreusveritas.dynamictrees.api.treedata.ITreePart) BlockFaceShape(net.minecraft.block.state.BlockFaceShape) ItemAxe(net.minecraft.item.ItemAxe) Enchantments(net.minecraft.init.Enchantments) Collectors(java.util.stream.Collectors) BlockBounds(com.ferreusveritas.dynamictrees.util.BlockBounds) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NodeDestroyer(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeDestroyer) NodeSpecies(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies) SimpleVoxmap(com.ferreusveritas.dynamictrees.util.SimpleVoxmap) java.util(java.util) Blocks(net.minecraft.init.Blocks) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) Species(com.ferreusveritas.dynamictrees.trees.Species) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityFallingTree(com.ferreusveritas.dynamictrees.entities.EntityFallingTree) NodeNetVolume(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume) ModBlocks(com.ferreusveritas.dynamictrees.ModBlocks) IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Cell(com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell) IBlockAccess(net.minecraft.world.IBlockAccess) Nullable(javax.annotation.Nullable) IFutureBreakable(com.ferreusveritas.dynamictrees.api.IFutureBreakable) Properties(net.minecraftforge.common.property.Properties) World(net.minecraft.world.World) PropertyInteger(net.minecraft.block.properties.PropertyInteger) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TreeHelper(com.ferreusveritas.dynamictrees.api.TreeHelper) IBlockState(net.minecraft.block.state.IBlockState) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) NodeExtState(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeExtState) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityFallingTree (com.ferreusveritas.dynamictrees.entities.EntityFallingTree)5 EnumFacing (net.minecraft.util.EnumFacing)4 IBlockState (net.minecraft.block.state.IBlockState)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 Vec3d (net.minecraft.util.math.Vec3d)3 ModConfigs (com.ferreusveritas.dynamictrees.ModConfigs)2 TreeHelper (com.ferreusveritas.dynamictrees.api.TreeHelper)2 NodeSpecies (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies)2 Species (com.ferreusveritas.dynamictrees.trees.Species)2 BranchDestructionData (com.ferreusveritas.dynamictrees.util.BranchDestructionData)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.block.Block)2 EntityCreeper (net.minecraft.entity.monster.EntityCreeper)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 ModBlocks (com.ferreusveritas.dynamictrees.ModBlocks)1 IFutureBreakable (com.ferreusveritas.dynamictrees.api.IFutureBreakable)1