Search in sources :

Example 41 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project Pearcel-Mod by MiningMark48.

the class ItemPearcelBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityLiving;
        int i = getInventorySlotContainItem(ModItems.pearcel_arrow, player);
        ItemStack itemstack = new ItemStack(ModItems.pearcel_arrow);
        int j = this.getMaxItemUseDuration(stack);
        ArrowLooseEvent event = new ArrowLooseEvent(player, stack, world, j, true);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled()) {
            return;
        }
        j = event.getCharge();
        boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        if (flag || (i != -1)) {
            float f = (float) j / 20.0F;
            f = (f * f + f * 2.0F) / 3.0F;
            if ((double) f < 0.1D) {
                return;
            }
            if (f > 1.0F) {
                f = 1.0F;
            }
            if (!world.isRemote) {
                ItemPearcelArrow itemarrow = (ItemPearcelArrow) ((ItemPearcelArrow) (itemstack.getItem() instanceof ItemPearcelArrow ? itemstack.getItem() : ModItems.pearcel_arrow));
                EntityArrow entityarrow = itemarrow.createArrow(world, itemstack, player);
                entityarrow.setAim(player, player.rotationPitch, player.rotationYaw, 0.0F, f * 3.0F, 1.0F);
                if (f == 1.0F) {
                    entityarrow.setIsCritical(true);
                }
                int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                if (k > 0) {
                    entityarrow.setDamage(entityarrow.getDamage() + (double) k * 0.5D + 0.5D);
                }
                int l = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
                if (l > 0) {
                    entityarrow.setKnockbackStrength(l);
                }
                if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
                    entityarrow.setFire(100);
                }
                stack.damageItem(1, player);
                world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (flag) {
                    entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                } else {
                    if (player.inventory.hasItemStack(new ItemStack(ModItems.pearcel_arrow))) {
                        if (player.inventory.getStackInSlot(i).hasTagCompound()) {
                            if (!player.inventory.getStackInSlot(i).getTagCompound().getBoolean("inf")) {
                                player.inventory.getStackInSlot(i).damageItem(1, player);
                                if (player.inventory.getStackInSlot(i).getItemDamage() == 0) {
                                    player.inventory.removeStackFromSlot(i);
                                }
                            }
                            if (player.inventory.getStackInSlot(i).getTagCompound().getBoolean("pow")) {
                                entityarrow.setDamage(entityarrow.getDamage() + 2.0D);
                            }
                            if (player.inventory.getStackInSlot(i).getTagCompound().getBoolean("knock")) {
                                entityarrow.setKnockbackStrength(2);
                            }
                        } else {
                            player.inventory.getStackInSlot(i).damageItem(1, player);
                            if (player.inventory.getStackInSlot(i).getItemDamage() == 0) {
                                player.inventory.removeStackFromSlot(i);
                            }
                        }
                        entityarrow.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
                    }
                }
                world.spawnEntity(entityarrow);
                zoomOut();
                entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
            }
        }
    }
    return;
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ArrowLooseEvent(net.minecraftforge.event.entity.player.ArrowLooseEvent)

Example 42 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project PneumaticCraft by MineMaarten.

the class TileEntityAirCannon method getPayloadEntity.

// warning: no null-check for inventory slot 0
private Entity getPayloadEntity() {
    if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE, getUpgradeSlots()) > 0) {
        Item item = inventory[0].getItem();
        if (item == Item.getItemFromBlock(Blocks.tnt)) {
            EntityTNTPrimed tnt = new EntityTNTPrimed(worldObj);
            tnt.fuse = 80;
            return tnt;
        } else if (item == Items.experience_bottle)
            return new EntityExpBottle(worldObj);
        else if (item == Items.potionitem) {
            EntityPotion potion = new EntityPotion(worldObj);
            potion.setPotionDamage(inventory[0].getItemDamage());
            return potion;
        } else if (item == Items.arrow)
            return new EntityArrow(worldObj);
        else if (item == Items.egg)
            return new EntityEgg(worldObj);
        else // EntitySmallFireball(worldObj);
        if (item == Items.snowball)
            return new EntitySnowball(worldObj);
        else if (item == Items.spawn_egg)
            return ItemMonsterPlacer.spawnCreature(worldObj, inventory[0].getItemDamage(), 0, 0, 0);
        else if (item == Items.minecart)
            return new EntityMinecartEmpty(worldObj);
        else if (item == Items.chest_minecart)
            return new EntityMinecartChest(worldObj);
        else if (item == Items.furnace_minecart)
            return new EntityMinecartFurnace(worldObj);
        else if (item == Items.hopper_minecart)
            return new EntityMinecartHopper(worldObj);
        else if (item == Items.tnt_minecart)
            return new EntityMinecartTNT(worldObj);
        else if (item == Items.boat)
            return new EntityBoat(worldObj);
    }
    EntityItem item = new EntityItem(worldObj);
    item.setEntityItemStack(inventory[0].copy());
    // 1200 ticks left to live, = 60s.
    item.age = 4800;
    // add
    item.lifespan += Math.min(getUpgrades(ItemMachineUpgrade.UPGRADE_ITEM_LIFE, getUpgradeSlots()) * 600, 4800);
    // min.
    return item;
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityMinecartChest(net.minecraft.entity.item.EntityMinecartChest) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EntityMinecartTNT(net.minecraft.entity.item.EntityMinecartTNT) EntityBoat(net.minecraft.entity.item.EntityBoat) EntityMinecartFurnace(net.minecraft.entity.item.EntityMinecartFurnace) EntityMinecartHopper(net.minecraft.entity.item.EntityMinecartHopper) EntityExpBottle(net.minecraft.entity.item.EntityExpBottle) EntityEgg(net.minecraft.entity.projectile.EntityEgg) Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) EntitySnowball(net.minecraft.entity.projectile.EntitySnowball) EntityPotion(net.minecraft.entity.projectile.EntityPotion) EntityMinecartEmpty(net.minecraft.entity.item.EntityMinecartEmpty) EntityItem(net.minecraft.entity.item.EntityItem)

Example 43 with EntityArrow

use of net.minecraft.entity.projectile.EntityArrow in project TechReborn by TechReborn.

the class BlockNuke method onEntityCollidedWithBlock.

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

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