Search in sources :

Example 16 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project BuildCraft by BuildCraft.

the class StripesHandlerArrow method handle.

@Override
public boolean handle(World world, BlockPos pos, EnumFacing direction, ItemStack stack, EntityPlayer player, IStripesActivator activator) {
    EntityArrow entityArrow = new EntityArrow(world, player, 0);
    entityArrow.setPosition(pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d);
    entityArrow.setDamage(3);
    entityArrow.setKnockbackStrength(1);
    entityArrow.motionX = direction.getFrontOffsetX() * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
    entityArrow.motionY = direction.getFrontOffsetY() * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
    entityArrow.motionZ = direction.getFrontOffsetZ() * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
    world.spawnEntityInWorld(entityArrow);
    stack.stackSize--;
    if (stack.stackSize > 0) {
        activator.sendItem(stack, direction.getOpposite());
    }
    return true;
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow)

Example 17 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project ImmersiveEngineering by BluSunrize.

the class TileEntityBalloon method onEntityCollision.

@Override
public void onEntityCollision(World world, Entity entity) {
    if (entity instanceof EntityArrow || entity instanceof EntityRevolvershot) {
        Vec3d pos = new Vec3d(getPos()).add(.5, .5, .5);
        world.playSound(null, pos.x, pos.y, pos.z, SoundEvents.ENTITY_FIREWORK_BLAST, SoundCategory.BLOCKS, 1.5f, 0.7f);
        world.setBlockToAir(getPos());
        world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, pos.x, pos.y, pos.z, 0, .05, 0);
        Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry.getStoredShaderAndCase(this.shader);
        if (shader != null)
            shader.getMiddle().getEffectFunction().execute(world, shader.getLeft(), null, shader.getRight().getShaderType(), pos, null, .375f);
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) ShaderRegistryEntry(blusunrize.immersiveengineering.api.shader.ShaderRegistry.ShaderRegistryEntry) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) EntityRevolvershot(blusunrize.immersiveengineering.common.entities.EntityRevolvershot)

Example 18 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project GregTech by GregTechCE.

the class FieldProjectorEventHandler method isHostileProjectile.

private static Pair<Boolean, Entity> isHostileProjectile(Entity entity, Entity owner) {
    if (entity instanceof EntityFireball) {
        EntityLivingBase shooter = ((EntityFireball) entity).shootingEntity;
        return Pair.of(!owner.isEntityEqual(shooter), shooter);
    } else if (entity instanceof EntityArrow) {
        Entity shooter = ((EntityArrow) entity).shootingEntity;
        return Pair.of(!owner.isEntityEqual(shooter), shooter);
    } else if (entity instanceof EntityPotion) {
        EntityLivingBase shooter = ((EntityPotion) entity).getThrower();
        ItemStack potionStack = ((EntityPotion) entity).getPotion();
        List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(potionStack);
        boolean hasBadEffects = effectList.stream().anyMatch(it -> it.getPotion().isBadEffect());
        // potions without bad effects are not hostile, so do not touch them
        return Pair.of(!owner.isEntityEqual(shooter) && hasBadEffects, shooter);
    } else if (entity instanceof EntityThrowable) {
        EntityLivingBase shooter = ((EntityThrowable) entity).getThrower();
        return Pair.of(!owner.isEntityEqual(shooter), shooter);
    } else if (entity instanceof IThrowableEntity) {
        Entity shooter = ((IThrowableEntity) entity).getThrower();
        return Pair.of(!owner.isEntityEqual(shooter), shooter);
    } else if (entity instanceof IProjectile) {
        // unknown projectiles are always hostile
        return Pair.of(true, null);
    }
    return Pair.of(false, null);
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) Entity(net.minecraft.entity.Entity) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) PotionEffect(net.minecraft.potion.PotionEffect) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPotion(net.minecraft.entity.projectile.EntityPotion) ItemStack(net.minecraft.item.ItemStack) EntityFireball(net.minecraft.entity.projectile.EntityFireball) IProjectile(net.minecraft.entity.IProjectile)

Example 19 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityDraggable method tickAddedVelocity.

//TODO: Finishme
public void tickAddedVelocity() {
    if (worldBelowFeet != null && !ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
        CoordTransformObject coordTransform = worldBelowFeet.wrapping.coordTransform;
        float rotYaw = draggableAsEntity.rotationYaw;
        float rotPitch = draggableAsEntity.rotationPitch;
        float prevYaw = draggableAsEntity.prevRotationYaw;
        float prevPitch = draggableAsEntity.prevRotationPitch;
        Vector oldPos = new Vector(draggableAsEntity);
        RotationMatrices.applyTransform(coordTransform.prevwToLTransform, coordTransform.prevWToLRotation, draggableAsEntity);
        RotationMatrices.applyTransform(coordTransform.lToWTransform, coordTransform.lToWRotation, draggableAsEntity);
        Vector newPos = new Vector(draggableAsEntity);
        //Move the entity back to its old position, the added velocity will be used afterwards
        draggableAsEntity.setPosition(oldPos.X, oldPos.Y, oldPos.Z);
        Vector addedVel = oldPos.getSubtraction(newPos);
        velocityAddedToPlayer = addedVel;
        draggableAsEntity.rotationYaw = rotYaw;
        draggableAsEntity.rotationPitch = rotPitch;
        draggableAsEntity.prevRotationYaw = prevYaw;
        draggableAsEntity.prevRotationPitch = prevPitch;
        Vector oldLookingPos = new Vector(draggableAsEntity.getLook(1.0F));
        RotationMatrices.applyTransform(coordTransform.prevWToLRotation, oldLookingPos);
        RotationMatrices.applyTransform(coordTransform.lToWRotation, oldLookingPos);
        double newPitch = Math.asin(oldLookingPos.Y) * -180D / Math.PI;
        double f4 = -Math.cos(-newPitch * 0.017453292D);
        double radianYaw = Math.atan2((oldLookingPos.X / f4), (oldLookingPos.Z / f4));
        radianYaw += Math.PI;
        radianYaw *= -180D / Math.PI;
        if (!(Double.isNaN(radianYaw) || Math.abs(newPitch) > 85)) {
            double wrappedYaw = MathHelper.wrapDegrees(radianYaw);
            double wrappedRotYaw = MathHelper.wrapDegrees(draggableAsEntity.rotationYaw);
            double yawDif = wrappedYaw - wrappedRotYaw;
            if (Math.abs(yawDif) > 180D) {
                if (yawDif < 0) {
                    yawDif += 360D;
                } else {
                    yawDif -= 360D;
                }
            }
            yawDif %= 360D;
            final double threshold = .1D;
            if (Math.abs(yawDif) < threshold) {
                yawDif = 0D;
            }
            yawDifVelocity = yawDif;
        }
    }
    boolean onGroundOrig = draggableAsEntity.onGround;
    if (!ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
        float originalWalked = draggableAsEntity.distanceWalkedModified;
        float originalWalkedOnStep = draggableAsEntity.distanceWalkedOnStepModified;
        boolean originallySneaking = draggableAsEntity.isSneaking();
        draggableAsEntity.setSneaking(false);
        if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
            EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
            MovementInput moveInput = playerSP.movementInput;
            originallySneaking = moveInput.sneak;
            moveInput.sneak = false;
        }
        draggableAsEntity.moveEntity(velocityAddedToPlayer.X, velocityAddedToPlayer.Y, velocityAddedToPlayer.Z);
        if (!(draggableAsEntity instanceof EntityPlayer)) {
            if (draggableAsEntity instanceof EntityArrow) {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw -= yawDifVelocity;
            } else {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw += yawDifVelocity;
            }
        } else {
            if (draggableAsEntity.worldObj.isRemote) {
                draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
                draggableAsEntity.rotationYaw += yawDifVelocity;
            }
        }
        //Do not add this movement as if the entity were walking it
        draggableAsEntity.distanceWalkedModified = originalWalked;
        draggableAsEntity.distanceWalkedOnStepModified = originalWalkedOnStep;
        draggableAsEntity.setSneaking(originallySneaking);
        if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
            EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
            MovementInput moveInput = playerSP.movementInput;
            moveInput.sneak = originallySneaking;
        }
    }
    if (onGroundOrig) {
        draggableAsEntity.onGround = onGroundOrig;
    }
    velocityAddedToPlayer.multiply(.99D);
    yawDifVelocity *= .95D;
}
Also used : CoordTransformObject(ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Vector(ValkyrienWarfareBase.API.Vector) MovementInput(net.minecraft.util.MovementInput)

Example 20 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project Totemic by TeamTotemic.

the class ItemBaykokBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int timeLeft) {
    if (!(entity instanceof EntityPlayer))
        return;
    EntityPlayer player = (EntityPlayer) entity;
    boolean infinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
    ItemStack arrow = findAmmo0(player);
    int chargeTicks = this.getMaxItemUseDuration(stack) - timeLeft;
    chargeTicks = ForgeEventFactory.onArrowLoose(stack, world, player, chargeTicks, !arrow.isEmpty() || infinity);
    if (chargeTicks < 0)
        return;
    if (!arrow.isEmpty() || infinity) {
        if (arrow.isEmpty())
            arrow = new ItemStack(Items.ARROW);
        float charge = getArrowVelocity(chargeTicks);
        if (charge >= 0.1) {
            // Forge: Fix consuming custom arrows.
            boolean flag1 = infinity && arrow.getItem() instanceof ItemArrow;
            if (!world.isRemote) {
                ItemArrow itemarrow = ((ItemArrow) (arrow.getItem() instanceof ItemArrow ? arrow.getItem() : Items.ARROW));
                EntityArrow entityarrow;
                if (// Mundane arrows will become invisible
                itemarrow == Items.ARROW) {
                    entityarrow = new EntityInvisArrow(world, player);
                } else {
                    entityarrow = itemarrow.createArrow(world, arrow, entity);
                }
                if (entityarrow.getDamage() < 2.5)
                    entityarrow.setDamage(2.5);
                entityarrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, charge * 4.0F, 1.0F);
                if (charge == 1.0F)
                    entityarrow.setIsCritical(true);
                int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                if (power > 0)
                    entityarrow.setDamage(entityarrow.getDamage() + power * 0.5D + 0.5D);
                int punch = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
                if (punch > 0)
                    entityarrow.setKnockbackStrength(punch);
                if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
                    entityarrow.setFire(100);
                stack.damageItem(1, player);
                if (flag1)
                    entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                world.spawnEntity(entityarrow);
            }
            world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + charge * 0.5F);
            if (!flag1) {
                arrow.shrink(1);
                if (arrow.isEmpty())
                    player.inventory.deleteStack(arrow);
            }
            player.addStat(StatList.getObjectUseStats(this));
        }
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityInvisArrow(pokefenn.totemic.entity.projectile.EntityInvisArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Aggregations

EntityArrow (net.minecraft.entity.projectile.EntityArrow)43 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)15 Entity (net.minecraft.entity.Entity)9 ItemArrow (net.minecraft.item.ItemArrow)9 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 EntityItem (net.minecraft.entity.item.EntityItem)4 EntityPotion (net.minecraft.entity.projectile.EntityPotion)3 EntityThrowable (net.minecraft.entity.projectile.EntityThrowable)3 EntityTippedArrow (net.minecraft.entity.projectile.EntityTippedArrow)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 ItemLivingArmour (WayofTime.bloodmagic.item.armour.ItemLivingArmour)2 LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)2 LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)2 EntityJuicer (micdoodle8.mods.galacticraft.planets.venus.entities.EntityJuicer)2 IProjectile (net.minecraft.entity.IProjectile)2 EntityFireball (net.minecraft.entity.projectile.EntityFireball)2 EntityShulkerBullet (net.minecraft.entity.projectile.EntityShulkerBullet)2 TileEntity (net.minecraft.tileentity.TileEntity)2