Search in sources :

Example 6 with ItemArrow

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

Example 7 with ItemArrow

use of net.minecraft.item.ItemArrow in project Cavern2 by kegare.

the class ItemBowCavenic method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
    if (!(entityLiving instanceof EntityPlayer)) {
        return;
    }
    EntityPlayer player = (EntityPlayer) entityLiving;
    BowMode mode = BowMode.byItemStack(stack);
    boolean infinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
    ItemStack ammo = findAmmo(player);
    ItemStack torch = mode == BowMode.TORCH ? findTorch(player) : ItemStack.EMPTY;
    int i = getMaxItemUseDuration(stack) - timeLeft;
    i = ForgeEventFactory.onArrowLoose(stack, world, player, i, !ammo.isEmpty() || infinity);
    if (i < 0 || ammo.isEmpty() && !infinity || mode == BowMode.TORCH && torch.isEmpty() && !infinity) {
        return;
    }
    if (ammo.isEmpty()) {
        ammo = new ItemStack(Items.ARROW);
    }
    if (mode == BowMode.TORCH && torch.isEmpty()) {
        torch = new ItemStack(Blocks.TORCH);
    }
    float f = getArrowVelocity(i);
    if (f < 0.1D) {
        return;
    }
    boolean flag = player.capabilities.isCreativeMode || ammo.getItem() instanceof ItemArrow && ((ItemArrow) ammo.getItem()).isInfinite(ammo, stack, player);
    if (!world.isRemote) {
        EntityArrow entityArrow = createCustomArrow(mode, world, player, torch);
        if (entityArrow == null) {
            ItemArrow arrow = (ItemArrow) (ammo.getItem() instanceof ItemArrow ? ammo.getItem() : Items.ARROW);
            entityArrow = arrow.createArrow(world, ammo, player);
        }
        entityArrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, f * 3.0F, 1.0F);
        if (f >= 1.0D || mode == BowMode.SNIPE && f >= 0.65D) {
            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 (flag || player.capabilities.isCreativeMode && (ammo.getItem() == Items.SPECTRAL_ARROW || ammo.getItem() == Items.TIPPED_ARROW)) {
            entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
        }
        entityArrow.setDamage(entityArrow.getDamage() * mode.getAttackPower());
        world.spawnEntity(entityArrow);
    }
    world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
    if (!flag && !player.capabilities.isCreativeMode) {
        ammo.shrink(1);
        if (ammo.isEmpty()) {
            player.inventory.deleteStack(ammo);
        }
    }
    player.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)

Example 8 with ItemArrow

use of net.minecraft.item.ItemArrow in project EnderIO by SleepyTrousers.

the class ItemDarkSteelBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World worldIn, @Nonnull EntityLivingBase entityLiving, int timeLeft) {
    if (!(entityLiving instanceof EntityPlayer)) {
        return;
    }
    EntityPlayer entityplayer = (EntityPlayer) entityLiving;
    boolean hasInfinateArrows = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
    ItemStack itemstack = getArrowsToShoot(entityplayer);
    int draw = getMaxItemUseDuration(stack) - timeLeft;
    draw = ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, draw, Prep.isValid(itemstack) || hasInfinateArrows);
    if (draw < 0) {
        return;
    }
    if (itemstack.isEmpty() && hasInfinateArrows) {
        itemstack = new ItemStack(Items.ARROW);
    }
    if (itemstack.isEmpty()) {
        return;
    }
    float drawRatio = getCustumArrowVelocity(stack, draw);
    if (drawRatio >= 0.1) {
        boolean arrowIsInfinite = hasInfinateArrows && itemstack.getItem() instanceof ItemArrow;
        if (!worldIn.isRemote) {
            EnergyUpgradeHolder upgrade = EnergyUpgradeManager.loadFromItem(stack);
            ItemArrow itemarrow = ((ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
            EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
            // ATTENTION:
            entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, drawRatio * 3.0F * getForceMultiplier(upgrade), 0.25F);
            if (drawRatio == 1.0F) {
                entityarrow.setIsCritical(true);
            }
            int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
            if (powerLevel > 0) {
                entityarrow.setDamage(entityarrow.getDamage() + powerLevel * 0.5D + 0.5D);
            }
            int knockBack = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
            if (knockBack > 0) {
                entityarrow.setKnockbackStrength(knockBack);
            }
            if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
                entityarrow.setFire(100);
            }
            stack.damageItem(1, entityplayer);
            if (arrowIsInfinite) {
                entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
            }
            entityarrow.setDamage(entityarrow.getDamage() + damageBonus);
            worldIn.spawnEntity(entityarrow);
            int used = getRequiredPower(draw, upgrade);
            if (used > 0) {
                upgrade.setEnergy(upgrade.getEnergy() - used);
                upgrade.writeToItem(stack, this);
            }
        }
        worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + drawRatio * 0.5F);
        if (!arrowIsInfinite) {
            itemstack.shrink(1);
        }
        supressed(entityplayer);
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Example 9 with ItemArrow

use of net.minecraft.item.ItemArrow in project BloodMagic by WayofTime.

the class AlchemyArrayEffectArrowTurret method update.

@Override
public boolean update(TileEntity tile, int ticksActive) {
    BlockPos pos = tile.getPos();
    World world = tile.getWorld();
    BlockPos chestPos = pos.down();
    TileEntity chestTile = world.getTileEntity(chestPos);
    if (chestTile == null) {
        return false;
    }
    IItemHandler itemHandler = Utils.getInventory(chestTile, EnumFacing.UP);
    if (itemHandler == null) {
        return false;
    }
    ItemStack arrowStack = new ItemStack(Items.AIR);
    if (lastChestSlot >= 0 && lastChestSlot < itemHandler.getSlots()) {
        ItemStack testStack = itemHandler.extractItem(lastChestSlot, 1, true);
        if (testStack.isEmpty() || !(testStack.getItem() instanceof ItemArrow)) {
            lastChestSlot = -1;
        } else {
            arrowStack = testStack;
        }
    }
    if (lastChestSlot < 0) {
        for (int i = 0; i < itemHandler.getSlots(); i++) {
            ItemStack testStack = itemHandler.extractItem(i, 1, true);
            if (!testStack.isEmpty() && testStack.getItem() instanceof ItemArrow) {
                arrowStack = testStack;
                lastChestSlot = i;
                break;
            }
        }
    }
    if (lastChestSlot < 0) {
        // No arrows in the chest. Welp!
        return false;
    }
    if (canFireOnMob(world, pos, target)) {
        Vec2f pitchYaw = getPitchYaw(pos, target);
        lastPitch = pitch;
        lastYaw = yaw;
        pitch = pitchYaw.x;
        yaw = pitchYaw.y;
        arrowTimer++;
        if (arrowTimer >= ARROW_WINDUP) {
            // ItemStack arrowStack = new ItemStack(Items.ARROW);
            fireOnTarget(world, pos, arrowStack, target);
            if (!world.isRemote) {
                itemHandler.extractItem(lastChestSlot, 1, false);
            }
            arrowTimer = 0;
        }
        return false;
    } else {
        target = null;
        arrowTimer = -1;
    }
    List<EntityMob> mobsInRange = world.getEntitiesWithinAABB(EntityMob.class, getBounds(pos));
    for (EntityMob entity : mobsInRange) {
        if (// && isMobInFilter(ent))
        canFireOnMob(world, pos, entity)) {
            target = entity;
            arrowTimer = 0;
            return false;
        }
    }
    arrowTimer = -1;
    target = null;
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityMob(net.minecraft.entity.monster.EntityMob) Vec2f(net.minecraft.util.math.Vec2f) IItemHandler(net.minecraftforge.items.IItemHandler) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Example 10 with ItemArrow

use of net.minecraft.item.ItemArrow in project BloodMagic by WayofTime.

the class LivingArmourHandler method onArrowFire.

// Applies: Arrow Shot
// Tracks: Arrow Shot
@SubscribeEvent
public static void onArrowFire(ArrowLooseEvent event) {
    World world = event.getEntityPlayer().getEntityWorld();
    ItemStack stack = event.getBow();
    EntityPlayer player = event.getEntityPlayer();
    if (world.isRemote)
        return;
    if (LivingArmour.hasFullSet(player)) {
        ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
        LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
        if (armour != null) {
            StatTrackerArrowShot.incrementCounter(armour);
            LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgrade(BloodMagic.MODID + ".upgrade.arrowShot", chestStack);
            if (upgrade instanceof LivingArmourUpgradeArrowShot) {
                int charge = event.getCharge();
                float velocity = (float) charge / 20.0F;
                velocity = (velocity * velocity + velocity * 2.0F) / 3.0F;
                if ((double) velocity < 0.1D)
                    return;
                if (velocity > 1.0F)
                    velocity = 1.0F;
                int extraArrows = ((LivingArmourUpgradeArrowShot) upgrade).getExtraArrows();
                for (int n = 0; n < extraArrows; n++) {
                    ItemStack arrowStack = new ItemStack(Items.ARROW);
                    ItemArrow itemarrow = (ItemArrow) ((stack.getItem() instanceof ItemArrow ? arrowStack.getItem() : Items.ARROW));
                    EntityArrow entityarrow = itemarrow.createArrow(world, arrowStack, player);
                    entityarrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, velocity * 3.0F, 1.0F);
                    float velocityModifier = 0.6f * velocity;
                    entityarrow.motionX += (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    entityarrow.motionY += (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    entityarrow.motionZ += (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
                    if (velocity == 1.0F)
                        entityarrow.setIsCritical(true);
                    int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                    if (powerLevel > 0)
                        entityarrow.setDamage(entityarrow.getDamage() + (double) powerLevel * 0.5D + 0.5D);
                    int punchLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
                    if (punchLevel > 0)
                        entityarrow.setKnockbackStrength(punchLevel);
                    if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
                        entityarrow.setFire(100);
                    entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    world.spawnEntity(entityarrow);
                }
            }
        }
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow) StatTrackerGrimReaperSprint(WayofTime.bloodmagic.livingArmour.tracker.StatTrackerGrimReaperSprint) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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