Search in sources :

Example 31 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project MorePlanets by SteveKunG.

the class ItemSpaceBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingBase living, int timeLeft) {
    if (living instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) living;
        int useDuration = this.getMaxItemUseDuration(itemStack) - timeLeft;
        int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, itemStack);
        int punch = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, itemStack);
        ItemStack arrowStack = this.findAmmo(player);
        ArrowLooseEvent event = new ArrowLooseEvent(player, itemStack, world, useDuration, arrowStack != null);
        boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemStack) > 0;
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled()) {
            return;
        }
        useDuration = event.getCharge();
        float duration = useDuration / 20.0F;
        duration = (duration * duration + duration * 2.0F) / 3.0F;
        if (duration < 0.1D) {
            return;
        }
        if (duration > 1.0F) {
            duration = 1.0F;
        }
        if (flag || !arrowStack.isEmpty()) {
            if (arrowStack.isEmpty()) {
                arrowStack = new ItemStack(Items.ARROW);
            }
            if (arrowStack.getItem() instanceof ItemArrow) {
                ItemArrow itemArrow = (ItemArrow) arrowStack.getItem();
                EntityArrow vanillaArrow = itemArrow.createArrow(world, arrowStack, player);
                ItemSpaceBow.spawnArrow(itemStack, arrowStack, world, player, vanillaArrow, itemArrow, power, punch, duration, flag);
            }
        }
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ArrowLooseEvent(net.minecraftforge.event.entity.player.ArrowLooseEvent)

Example 32 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project MorePlanets by SteveKunG.

the class TileEntityShieldGenerator method update.

@Override
public void update() {
    super.update();
    this.renderTicks++;
    if (!this.initialize) {
        this.renderTicks = this.renderTicks + this.world.rand.nextInt(100);
        this.solarRotate = this.solarRotate + this.world.rand.nextInt(360);
        this.initialize = TileEntityDummy.initialiseMultiTiles(this.getPos(), this.getWorld(), this);
    }
    if (this.hasEnoughEnergyToRun && !this.disabled) {
        this.solarRotate++;
        this.solarRotate %= 360;
        MorePlanetsMod.PROXY.spawnParticle(EnumParticleTypesMP.ALIEN_MINER_SPARK, this.pos.getX() + 0.5D, this.pos.getY() + 1.5D, this.pos.getZ() + 0.5D, new Object[] { -0.5F });
        if (this.ticks % 33 == 0) {
            this.world.playSound(null, this.getPos(), MPSounds.MACHINE_GENERATOR_AMBIENT, SoundCategory.BLOCKS, 0.075F, 1.0F);
        }
    }
    if (!this.world.isRemote) {
        int count = 0;
        int capacityUpgradeCount = 0;
        // shield damage upgrade
        if (!this.getInventory().get(1).isEmpty()) {
            count = this.getInventory().get(1).getCount();
            this.maxShieldDamage = 8 * count;
        } else {
            this.maxShieldDamage = 8;
        }
        // shield size upgrade
        if (!this.getInventory().get(2).isEmpty()) {
            count = this.getInventory().get(2).getCount();
            this.maxShieldSizeUpgrade = 16 + count;
        } else {
            this.maxShieldSizeUpgrade = 16;
        }
        // shield capacity upgrade
        if (!this.getInventory().get(3).isEmpty()) {
            count = this.getInventory().get(3).getCount();
            capacityUpgradeCount = this.getInventory().get(3).getCount();
            this.maxShieldCapacity = 32000 * count;
        } else {
            this.maxShieldCapacity = 16000;
        }
        int sum = (int) (this.shieldDamage + this.shieldSize + capacityUpgradeCount) / 2;
        this.storage.setMaxExtract(250 * sum);
        if (!this.needCharged && this.shieldCapacity == 0) {
            this.needCharged = true;
            this.shieldChargeCooldown = 1200;
            if (this.shieldChargeCooldown == 0) {
                this.shieldCapacity = 100;
            }
        }
        if (!this.disabled && this.getEnergyStoredGC() > 0.0F && this.hasEnoughEnergyToRun) {
            if (this.shieldSize <= this.maxShieldSize) {
                this.shieldSize += 0.1F;
                if (this.shieldChargeCooldown > 0) {
                    this.shieldChargeCooldown--;
                }
                if (this.shieldChargeCooldown == 0 && this.ticks % 2 == 0) {
                    this.shieldCapacity += 100;
                    this.needCharged = false;
                }
            }
        } else {
            this.shieldSize -= 0.1F;
        }
        if (this.shieldSize <= this.maxShieldSize) {
            this.shieldSize = Math.min(Math.max(this.shieldSize, 0.0F), this.maxShieldSize);
        } else {
            this.shieldSize -= 0.1F;
        }
        this.shieldCapacity = Math.min(Math.max(this.shieldCapacity, 0), this.maxShieldCapacity);
    }
    float range = this.shieldSize;
    for (Entity entity : this.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(this.pos.getX() - range, this.pos.getY() - range, this.pos.getZ() - range, this.pos.getX() + range, this.pos.getY() + range, this.pos.getZ() + range))) {
        if (!this.disabled && this.enableShield && this.shieldCapacity > 0) {
            if (entity instanceof EntityArrow && !(((EntityArrow) entity).shootingEntity instanceof EntityPlayer) && !((EntityArrow) entity).inGround || entity instanceof EntityPotion && !(((EntityPotion) entity).getThrower() instanceof EntityPlayer) || entity instanceof EntityFireball || entity instanceof EntityShulkerBullet) {
                if (this.world instanceof WorldServer) {
                    ((WorldServer) this.world).spawnParticle(EnumParticleTypes.CRIT_MAGIC, entity.posX, entity.posY, entity.posZ, 20, 0.0D, 0.5D, 0.0D, 1.0D);
                }
                float motion = MathHelper.sqrt(entity.motionX * entity.motionX + entity.motionZ * entity.motionZ);
                this.shieldCapacity -= motion * 2;
                entity.setDead();
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityShulkerBullet(net.minecraft.entity.projectile.EntityShulkerBullet) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPotion(net.minecraft.entity.projectile.EntityPotion) WorldServer(net.minecraft.world.WorldServer) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Example 33 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project Hyperium by HyperiumClient.

the class MixinItemBow method onPlayerStoppedUsing.

/**
 * @author Amp
 * @reason Events
 */
@Overwrite
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer entity, int timeLeft) {
    boolean infiniteArrows = entity.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
    if (infiniteArrows || entity.inventory.hasItem(Items.arrow)) {
        int maxTime = getMaxItemUseDuration(stack) - timeLeft;
        float pullBackTime = (float) maxTime / 20.0F;
        pullBackTime = (pullBackTime * pullBackTime + pullBackTime * 2.0F) / 3.0F;
        if ((double) pullBackTime < 0.1D)
            return;
        if (pullBackTime > 1.0F)
            pullBackTime = 1.0F;
        EntityArrow arrow = new EntityArrow(world, entity, pullBackTime * 2.0F);
        if (pullBackTime == 1.0F)
            arrow.setIsCritical(true);
        int powerEnchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
        if (powerEnchantmentLevel > 0)
            arrow.setDamage(arrow.getDamage() + (double) powerEnchantmentLevel * 0.5D + 0.5D);
        int punchEnchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
        if (punchEnchantmentLevel > 0)
            arrow.setKnockbackStrength(punchEnchantmentLevel);
        if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) {
            arrow.setFire(100);
        }
        stack.damageItem(1, entity);
        world.playSoundAtEntity(entity, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + pullBackTime * 0.5F);
        if (infiniteArrows)
            arrow.canBePickedUp = 2;
        else
            entity.inventory.consumeInventoryItem(Items.arrow);
        entity.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem((ItemBow) (Object) this)]);
        if (!world.isRemote)
            world.spawnEntityInWorld(arrow);
        EventBus.INSTANCE.post(new ArrowShootEvent(arrow, maxTime, stack));
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) ArrowShootEvent(cc.hyperium.event.entity.ArrowShootEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 34 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project SilentGems by SilentChaos512.

the class ItemGemBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityLiving;
        boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack ammo = this.findAmmo(player);
        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, i, StackHelper.isValid(ammo) || flag);
        if (i < 0)
            return;
        if (StackHelper.isValid(ammo) || flag) {
            if (StackHelper.isEmpty(ammo)) {
                ammo = new ItemStack(Items.ARROW);
            }
            float velocity = getArrowVelocity(stack, i);
            if ((double) velocity >= 0.1D) {
                boolean flag1 = player.capabilities.isCreativeMode || (ammo.getItem() instanceof ItemArrow ? ((ItemArrow) ammo.getItem()).isInfinite(ammo, stack, player) : false);
                if (!worldIn.isRemote) {
                    ItemArrow itemarrow = (ItemArrow) ((ItemArrow) (ammo.getItem() instanceof ItemArrow ? ammo.getItem() : Items.ARROW));
                    EntityArrow entityarrow = itemarrow.createArrow(worldIn, ammo, player);
                    entityarrow.setAim(player, player.rotationPitch, player.rotationYaw, 0.0F, velocity * 3.0F, 1.0F);
                    if (velocity == 1.0F) {
                        entityarrow.setIsCritical(true);
                    }
                    int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                    float powerBoost = power > 0 ? power * 0.5f + 0.5f : 0.0f;
                    float damageBoost = getArrowDamage(stack);
                    entityarrow.setDamage(entityarrow.getDamage() + damageBoost + powerBoost);
                    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, player);
                    if (flag1) {
                        entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    }
                    worldIn.spawnEntity(entityarrow);
                }
                worldIn.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + velocity * 0.5F);
                if (!flag1) {
                    StackHelper.shrink(ammo, 1);
                    if (StackHelper.getCount(ammo) == 0) {
                        player.inventory.deleteStack(ammo);
                    }
                }
                player.addStat(StatList.getObjectUseStats(this));
                // Shots fired statistic
                ToolHelper.incrementStatShotsFired(stack, 1);
            }
        }
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Example 35 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project Tale-of-Kingdoms by Ivasik78.

the class EntityDefendBandit method attackEntity.

protected void attackEntity(Entity entity, float f) {
    if (f < 10.0F) {
        double d = entity.posX - this.posX;
        double d1 = entity.posZ - this.posZ;
        if (this.attackTime == 0) {
            EntityArrow entityarrow = new EntityArrow(this.worldObj, this, 1.0F);
            double d2 = entity.posY + (double) entity.getEyeHeight() - 0.699999988079071D - entityarrow.posY;
            float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
            this.worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (this.rand.nextFloat() * 0.4F + 0.8F));
            this.worldObj.spawnEntityInWorld(entityarrow);
            entityarrow.setThrowableHeading(d, d2 + (double) f1, d1, 1.6F, 12.0F);
            this.attackTime = 20;
        }
        this.rotationYaw = (float) (Math.atan2(d1, d) * 180.0D / 3.1415927410125732D) - 90.0F;
        this.hasAttacked = true;
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow)

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