Search in sources :

Example 1 with ArrowLooseEvent

use of net.minecraftforge.event.entity.player.ArrowLooseEvent 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)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityArrow (net.minecraft.entity.projectile.EntityArrow)1 ArrowLooseEvent (net.minecraftforge.event.entity.player.ArrowLooseEvent)1