Search in sources :

Example 11 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project SpringFestival by TeamCovertDragon.

the class BlockHangingFirecracker method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    if (!worldIn.isRemote && entityIn.isBurning()) {
        if (entityIn instanceof EntityArrow) {
            EntityArrow entityarrow = (EntityArrow) entityIn;
            this.ignite(worldIn, pos, state, false, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null);
        } else if (entityIn instanceof EntityLivingBase) {
            this.ignite(worldIn, pos, state, false, (EntityLivingBase) entityIn);
        }
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 12 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project BetterRain by OreCruncher.

the class DamageEffectHandler method onLivingHurt.

@SubscribeEvent(priority = EventPriority.LOW)
public void onLivingHurt(final LivingHurtEvent event) {
    if (event == null || event.entity == null || event.entity.worldObj == null || event.entity.worldObj.isRemote)
        return;
    // Living heal should handle heals - I think..
    if (event.ammount <= 0 || event.entityLiving == null)
        return;
    // A bit hokey - may work.
    boolean isCrit = false;
    if (event.source instanceof EntityDamageSourceIndirect) {
        final EntityDamageSourceIndirect dmgSource = (EntityDamageSourceIndirect) event.source;
        if (dmgSource.getSourceOfDamage() instanceof EntityArrow) {
            final EntityArrow arrow = (EntityArrow) dmgSource.getSourceOfDamage();
            isCrit = arrow.getIsCritical();
        }
    } else if (event.source instanceof EntityDamageSource) {
        final EntityDamageSource dmgSource = (EntityDamageSource) event.source;
        if (dmgSource.getSourceOfDamage() instanceof EntityPlayer) {
            final EntityPlayer player = (EntityPlayer) dmgSource.getSourceOfDamage();
            isCrit = isCritical(player, event.entityLiving);
        }
    }
    final HealthData data = new HealthData(event.entityLiving, isCrit, (int) event.ammount);
    Network.sendHealthUpdate(data, event.entity.worldObj.provider.getDimensionId());
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityDamageSource(net.minecraft.util.EntityDamageSource) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project BloodMagic by WayofTime.

the class PotionEventHandlers method onEntityUpdate.

@SubscribeEvent
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
    if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND)) {
        int d0 = 3;
        AxisAlignedBB axisAlignedBB = new AxisAlignedBB(event.getEntityLiving().posX - 0.5, event.getEntityLiving().posY - 0.5, event.getEntityLiving().posZ - 0.5, event.getEntityLiving().posX + 0.5, event.getEntityLiving().posY + 0.5, event.getEntityLiving().posZ + 0.5).expand(d0, d0, d0);
        List<Entity> entityList = event.getEntityLiving().getEntityWorld().getEntitiesWithinAABB(Entity.class, axisAlignedBB);
        for (Entity projectile : entityList) {
            if (projectile == null)
                continue;
            if (!(projectile instanceof IProjectile))
                continue;
            Entity throwingEntity = null;
            if (projectile instanceof EntityArrow)
                throwingEntity = ((EntityArrow) projectile).shootingEntity;
            else if (projectile instanceof EntityThrowable)
                throwingEntity = ((EntityThrowable) projectile).getThrower();
            if (throwingEntity != null && throwingEntity.equals(event.getEntityLiving()))
                continue;
            double delX = projectile.posX - event.getEntityLiving().posX;
            double delY = projectile.posY - event.getEntityLiving().posY;
            double delZ = projectile.posZ - event.getEntityLiving().posZ;
            double angle = (delX * projectile.motionX + delY * projectile.motionY + delZ * projectile.motionZ) / (Math.sqrt(delX * delX + delY * delY + delZ * delZ) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
            angle = Math.acos(angle);
            if (angle < 3 * (Math.PI / 4))
                // angle is < 135 degrees
                continue;
            if (throwingEntity != null) {
                delX = -projectile.posX + throwingEntity.posX;
                delY = -projectile.posY + (throwingEntity.posY + throwingEntity.getEyeHeight());
                delZ = -projectile.posZ + throwingEntity.posZ;
            }
            double curVel = Math.sqrt(delX * delX + delY * delY + delZ * delZ);
            delX /= curVel;
            delY /= curVel;
            delZ /= curVel;
            double newVel = Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ);
            projectile.motionX = newVel * delX;
            projectile.motionY = newVel * delY;
            projectile.motionZ = newVel * delZ;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) IProjectile(net.minecraft.entity.IProjectile) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 14 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project BloodMagic by WayofTime.

the class LivingArmourHandler method onEntityJoinedWorld.

// Applies: Storm Trooper
@SubscribeEvent
public static void onEntityJoinedWorld(EntityJoinWorldEvent event) {
    Entity owner = null;
    if (event.getEntity() instanceof EntityArrow) {
        owner = ((EntityArrow) event.getEntity()).shootingEntity;
    } else if (event.getEntity() instanceof EntityThrowable) {
        owner = ((EntityThrowable) event.getEntity()).getThrower();
    }
    if (owner instanceof EntityPlayer) {
        Entity projectile = event.getEntity();
        EntityPlayer player = (EntityPlayer) owner;
        if (LivingArmour.hasFullSet(player)) {
            ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
            if (armour != null) {
                LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgrade(BloodMagic.MODID + ".upgrade.stormTrooper", chestStack);
                if (upgrade instanceof LivingArmourUpgradeStormTrooper) {
                    float velocityModifier = (float) (((LivingArmourUpgradeStormTrooper) upgrade).getArrowJiggle(player) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
                    projectile.motionX += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    projectile.motionY += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    projectile.motionZ += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) LivingArmourUpgradeStormTrooper(WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeStormTrooper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 15 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project CompositeGear by TwilightWingsStudio.

the class ItemCGBow method onPlayerStoppedUsing.

/**
 * Called when the player stops using an Item (stops holding the right mouse button).
 */
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) entityLiving;
        boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemstack = this.findAmmo(entityplayer);
        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
        if (i < 0)
            return;
        if (!itemstack.isEmpty() || flag) {
            if (itemstack.isEmpty()) {
                itemstack = new ItemStack(Items.ARROW);
            }
            float f = getArrowVelocity(i);
            if ((double) f >= 0.1D) {
                boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
                if (!worldIn.isRemote) {
                    ItemArrow itemarrow = (ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
                    EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                    entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
                    if (f == 1.0F) {
                        entityarrow.setIsCritical(true);
                    }
                    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                    if (j > 0) {
                        entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
                    }
                    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
                    if (k > 0) {
                        entityarrow.setKnockbackStrength(k);
                    }
                    if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
                        entityarrow.setFire(100);
                    }
                    stack.damageItem(1, entityplayer);
                    if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
                        entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    }
                    worldIn.spawnEntity(entityarrow);
                }
                worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (!flag1 && !entityplayer.capabilities.isCreativeMode) {
                    itemstack.shrink(1);
                    if (itemstack.isEmpty()) {
                        entityplayer.inventory.deleteStack(itemstack);
                    }
                }
                entityplayer.addStat(StatList.getObjectUseStats(this));
            }
        }
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) 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