Java Code Examples for net.minecraft.entity.projectile.EntityArrow.setIsCritical()

The following are Jave code examples for showing how to use setIsCritical() of the net.minecraft.entity.projectile.EntityArrow class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: minecraft-quiverbow   File: EnderBow.java   Source Code and License Vote up 5 votes
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int par4) 
{
    int chargeTime = this.getMaxItemUseDuration(stack) - par4;

    ArrowLooseEvent event = new ArrowLooseEvent(player, stack, chargeTime);
    MinecraftForge.EVENT_BUS.post(event);
    
    if (event.isCanceled()) { return; }	// Not having it
    
    chargeTime = event.charge;

    // Either creative mode or infinity enchantment is higher than 0. Not using arrows
    boolean freeShot = player.capabilities.isCreativeMode;

    if (freeShot || player.inventory.hasItemStack(new ItemStack(Items.arrow)) ) 
    {
        float f = (float) chargeTime / 20.0F;
        f = (f * f + f * 2.0F) / 3.0F;

        if ((double)f < 0.1D) { return; }
        if (f > 1.0F) { f = 1.0F; }

        EntityArrow entityarrow = new EntityArrow(world, player, f * 2.0F);

        if (f == 1.0F) { entityarrow.setIsCritical(true); }

        stack.damageItem(1, player);
        world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

        if (freeShot) { entityarrow.canBePickedUp = 2; }
        else { player.inventory.consumeInventoryItem(Items.arrow); }

        if (!world.isRemote) { world.spawnEntityInWorld(entityarrow); }	// pew.
    }
}
 
Example 2
Project: minecraft-quiverbow   File: QuiverBow.java   Source Code and License Vote up 5 votes
@Override
public void onPlayerStoppedUsing(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer, int par4)
{
	if (!par2World.isRemote)
	{
		int j = this.getMaxItemUseDuration(stack) - par4;		// Reduces the durability by the ItemInUseCount (probably 1 for anything that isn't a tool)

		ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, stack, j);
		MinecraftForge.EVENT_BUS.post(event);
		if (event.isCanceled()) { return; }
		j = event.charge;

		if (this.getDamage(stack) == this.getMaxDamage()) {	return; }		// No arrows in the quiver? Getting out of here early

		float f = j / 20.0F;
		f = (f * f + f * 2.0F) / 3.0F;

		if (f < 0.1D) { return; }
		if (f > 1.0F) { f = 1.0F; }

		EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
		if (f == 1.0F) { entityarrow.setIsCritical(true); }

		par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

		if (par3EntityPlayer.capabilities.isCreativeMode) { entityarrow.canBePickedUp = 0; }
		else
		{
			entityarrow.canBePickedUp = 1;
			stack.setItemDamage(this.getDamage(stack) + 1);		// Reversed. MORE Damage for a shorter durability bar
		}

		par2World.spawnEntityInWorld(entityarrow);

	}
}
 
Example 3
Project: BaseClient   File: ItemBow.java   Source Code and License Vote up 4 votes
/**
 * Called when the player stops using an Item (stops holding the right mouse button).
 */
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
{
    boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;

    if (flag || playerIn.inventory.hasItem(Items.arrow))
    {
        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        float f = (float)i / 20.0F;
        f = (f * f + f * 2.0F) / 3.0F;

        if ((double)f < 0.1D)
        {
            return;
        }

        if (f > 1.0F)
        {
            f = 1.0F;
        }

        EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f * 2.0F);

        if (f == 1.0F)
        {
            entityarrow.setIsCritical(true);
        }

        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);

        if (j > 0)
        {
            entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
        }

        int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);

        if (k > 0)
        {
            entityarrow.setKnockbackStrength(k);
        }

        if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
        {
            entityarrow.setFire(100);
        }

        stack.damageItem(1, playerIn);
        worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

        if (flag)
        {
            entityarrow.canBePickedUp = 2;
        }
        else
        {
            playerIn.inventory.consumeInventoryItem(Items.arrow);
        }

        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(entityarrow);
        }
    }
}
 
Example 4
Project: BaseClient   File: ItemBow.java   Source Code and License Vote up 4 votes
/**
 * Called when the player stops using an Item (stops holding the right mouse button).
 */
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
{
    boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;

    if (flag || playerIn.inventory.hasItem(Items.arrow))
    {
        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        float f = (float)i / 20.0F;
        f = (f * f + f * 2.0F) / 3.0F;

        if ((double)f < 0.1D)
        {
            return;
        }

        if (f > 1.0F)
        {
            f = 1.0F;
        }

        EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f * 2.0F);

        if (f == 1.0F)
        {
            entityarrow.setIsCritical(true);
        }

        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);

        if (j > 0)
        {
            entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
        }

        int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);

        if (k > 0)
        {
            entityarrow.setKnockbackStrength(k);
        }

        if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
        {
            entityarrow.setFire(100);
        }

        stack.damageItem(1, playerIn);
        worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

        if (flag)
        {
            entityarrow.canBePickedUp = 2;
        }
        else
        {
            playerIn.inventory.consumeInventoryItem(Items.arrow);
        }

        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(entityarrow);
        }
    }
}