Search in sources :

Example 1 with ItemArrow

use of net.minecraft.item.ItemArrow in project SilentGems by SilentChaos512.

the class ItemQuiver method createArrow.

@Override
public EntityArrow createArrow(World worldIn, ItemStack quiverStack, EntityLivingBase shooter) {
    IItemHandler itemHandler = getInventory(quiverStack);
    for (int i = 0; i < itemHandler.getSlots(); ++i) {
        ItemStack arrowStack = itemHandler.getStackInSlot(i);
        if (!StackHelper.isEmpty(arrowStack) && arrowStack.getItem() instanceof ItemArrow) {
            // Found arrow stack in quiver
            boolean playerIsCreativeMode = shooter instanceof EntityPlayer && ((EntityPlayer) shooter).capabilities.isCreativeMode;
            if (!playerIsCreativeMode) {
                // Remove arrow from quiver
                itemHandler.extractItem(i, 1, false);
                updateQuiver(quiverStack, itemHandler, (EntityPlayer) shooter);
            }
            // Create arrow entity
            ItemArrow itemArrow = (ItemArrow) arrowStack.getItem();
            EntityArrow entity = itemArrow.createArrow(worldIn, arrowStack, shooter);
            if (!playerIsCreativeMode) {
                QuiverHelper.instance.addFiredArrow(entity);
            }
            return entity;
        }
    }
    // Something went wrong?
    SilentGems.logHelper.warning("Quiver could not find arrow! Player: " + shooter.getName());
    return new EntityTippedArrow(worldIn, shooter);
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) IItemHandler(net.minecraftforge.items.IItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Example 2 with ItemArrow

use of net.minecraft.item.ItemArrow in project Skree by Skelril.

the class ICustomBow method onPlayerStoppedUsing.

/**
 * Called when the player stops using an Item (stops holding the right mouse button).
 *
 * @param timeLeft The amount of ticks left before the using would have been complete
 */
default 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) entityLiving, i, itemstack != null || flag);
        if (i < 0) {
            return;
        }
        if (itemstack != null || flag) {
            if (itemstack == null) {
                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.setAim(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) {
                        entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    }
                    worldIn.spawnEntity(entityarrow);
                }
                worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (__getItemRand().nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (!flag1) {
                    itemstack.setCount(itemstack.getCount() - 1);
                    if (itemstack.getCount() == 0) {
                        entityplayer.inventory.deleteStack(itemstack);
                    }
                }
                entityplayer.addStat(StatList.getObjectUseStats(__getBowItem()));
            }
        }
    }
}
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 3 with ItemArrow

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

the class AlchemyArrayEffectArrowTurret method fireOnTarget.

public void fireOnTarget(World world, BlockPos pos, ItemStack arrowStack, EntityLiving targetMob) {
    float vel = 3f;
    double damage = 2;
    if (!world.isRemote) {
        if (arrowStack.getItem() instanceof ItemArrow) {
            // ItemArrow arrow = (ItemArrow) arrowStack.getItem();
            // EntityArrow entityarrow = arrow.createArrow(world, arrowStack, targetMob);
            EntityTippedArrow entityarrow = new EntityTippedArrow(world);
            entityarrow.setPotionEffect(arrowStack);
            entityarrow.posX = pos.getX() + 0.5;
            entityarrow.posY = pos.getY() + 0.5;
            entityarrow.posZ = pos.getZ() + 0.5;
            double d0 = targetMob.posX - (pos.getX() + 0.5);
            double d1 = targetMob.posY + targetMob.height - (pos.getY() + 0.5);
            double d2 = targetMob.posZ - (pos.getZ() + 0.5);
            double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
            entityarrow.setDamage(damage);
            entityarrow.shoot(d0, d1 + d3 * 0.05, d2, vel, 0);
            world.spawnEntity(entityarrow);
        }
    }
}
Also used : EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) ItemArrow(net.minecraft.item.ItemArrow)

Example 4 with ItemArrow

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

Example 5 with ItemArrow

use of net.minecraft.item.ItemArrow in project SilentGems by SilentChaos512.

the class GuiQuiverArrowOverlay method onRenderGameOverlay.

@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent event) {
    if (!GemsConfig.SHOW_ARROW_COUNT || event.getType() != ElementType.HOTBAR) {
        return;
    }
    // Player holding a bow?
    EntityPlayer player = SilentGems.proxy.getClientPlayer();
    ItemStack bow = getActiveBow(player);
    if (StackHelper.isValid(bow)) {
        // Get the "arrow" the bow would fire.
        ItemStack arrow = StackHelper.empty();
        int arrowCount = 0;
        ItemStack stack = findAmmo(player);
        if (StackHelper.isValid(stack)) {
            // Is it a quiver?
            if (stack.getItem() instanceof IQuiver) {
                // Find first arrow.
                IItemHandler itemHandler = ((IQuiver) stack.getItem()).getInventory(stack);
                for (int i = 0; i < itemHandler.getSlots(); ++i) {
                    ItemStack itemstack = itemHandler.getStackInSlot(i);
                    if (StackHelper.isValid(itemstack) && itemstack.getItem() instanceof ItemArrow) {
                        if (StackHelper.isEmpty(arrow)) {
                            arrow = itemstack;
                            arrowCount = arrow.getCount();
                        } else if (arrow.isItemEqual(itemstack) && ((!arrow.hasTagCompound() && !itemstack.hasTagCompound()) || itemstack.getTagCompound().equals(arrow.getTagCompound()))) {
                            arrowCount += itemstack.getCount();
                        }
                    }
                }
            } else {
                // It's just an arrow.
                arrow = stack;
                arrowCount = arrow.getCount();
            }
        }
        if (StackHelper.isValid(arrow)) {
            renderArrow(arrow, arrowCount, player);
        }
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IQuiver(net.silentchaos512.gems.item.quiver.IQuiver) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow) 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