Search in sources :

Example 11 with ItemArrow

use of net.minecraft.item.ItemArrow 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 12 with ItemArrow

use of net.minecraft.item.ItemArrow in project takumicraft by TNTModders.

the class ItemMagicBow method onPlayerStoppedUsing.

@Override
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 = 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) {
                    for (int i1 = -2; i1 <= 2; i1++) {
                        ItemArrow itemarrow = (ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
                        EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                        entityarrow.setAim(entityplayer, entityplayer.rotationPitch, (float) (entityplayer.rotationYaw + 15 * i1 / Math.PI), 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);
                        entityarrow.pickupStatus = PickupStatus.CREATIVE_ONLY;
                        worldIn.spawnEntity(entityarrow);
                    }
                }
                worldIn.playSound(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

ItemArrow (net.minecraft.item.ItemArrow)12 ItemStack (net.minecraft.item.ItemStack)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 EntityArrow (net.minecraft.entity.projectile.EntityArrow)9 IItemHandler (net.minecraftforge.items.IItemHandler)3 EntityTippedArrow (net.minecraft.entity.projectile.EntityTippedArrow)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ItemLivingArmour (WayofTime.bloodmagic.item.armour.ItemLivingArmour)1 LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)1 LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)1 StatTrackerGrimReaperSprint (WayofTime.bloodmagic.livingArmour.tracker.StatTrackerGrimReaperSprint)1 EnergyUpgradeHolder (crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec2f (net.minecraft.util.math.Vec2f)1 IQuiver (net.silentchaos512.gems.item.quiver.IQuiver)1 EntityInvisArrow (pokefenn.totemic.entity.projectile.EntityInvisArrow)1