Exemple #1
0
        /// <summary>
        /// Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
        /// True if something happen and false if it don't. This is for ITEMS, not BLOCKS !
        /// </summary>
        public override bool OnItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
        {
            if (!par2EntityPlayer.CanPlayerEdit(par4, par5, par6))
            {
                return(false);
            }

            int i = par3World.GetBlockId(par4, par5, par6);
            int j = par3World.GetBlockId(par4, par5 + 1, par6);

            if (par7 != 0 && j == 0 && i == Block.Grass.BlockID || i == Block.Dirt.BlockID)
            {
                Block block = Block.TilledField;
                par3World.PlaySoundEffect((float)par4 + 0.5F, (float)par5 + 0.5F, (float)par6 + 0.5F, block.StepSound.GetStepSound(), (block.StepSound.GetVolume() + 1.0F) / 2.0F, block.StepSound.GetPitch() * 0.8F);

                if (par3World.IsRemote)
                {
                    return(true);
                }
                else
                {
                    par3World.SetBlockWithNotify(par4, par5, par6, block.BlockID);
                    par1ItemStack.DamageItem(1, par2EntityPlayer);
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
 public override bool OnBlockDestroyed(ItemStack par1ItemStack, int par2, int par3, int par4, int par5, EntityLiving par6EntityLiving)
 {
     if (par2 == Block.Leaves.BlockID || par2 == Block.Web.BlockID || par2 == Block.TallGrass.BlockID || par2 == Block.Vine.BlockID)
     {
         par1ItemStack.DamageItem(1, par6EntityLiving);
         return(true);
     }
     else
     {
         return(base.OnBlockDestroyed(par1ItemStack, par2, par3, par4, par5, par6EntityLiving));
     }
 }
        /// <summary>
        /// Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
        /// True if something happen and false if it don't. This is for ITEMS, not BLOCKS !
        /// </summary>
        public override bool OnItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
        {
            if (par7 == 0)
            {
                par5--;
            }

            if (par7 == 1)
            {
                par5++;
            }

            if (par7 == 2)
            {
                par6--;
            }

            if (par7 == 3)
            {
                par6++;
            }

            if (par7 == 4)
            {
                par4--;
            }

            if (par7 == 5)
            {
                par4++;
            }

            if (!par2EntityPlayer.CanPlayerEdit(par4, par5, par6))
            {
                return(false);
            }

            int i = par3World.GetBlockId(par4, par5, par6);

            if (i == 0)
            {
                par3World.PlaySoundEffect((double)par4 + 0.5D, (double)par5 + 0.5D, (double)par6 + 0.5D, "fire.ignite", 1.0F, ItemRand.NextFloat() * 0.4F + 0.8F);
                par3World.SetBlockWithNotify(par4, par5, par6, Block.Fire.BlockID);
            }

            par1ItemStack.DamageItem(1, par2EntityPlayer);
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
        /// </summary>
        public override ItemStack OnItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
        {
            if (par3EntityPlayer.FishEntity != null)
            {
                int i = par3EntityPlayer.FishEntity.CatchFish();
                par1ItemStack.DamageItem(i, par3EntityPlayer);
                par3EntityPlayer.SwingItem();
            }
            else
            {
                par2World.PlaySoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (ItemRand.NextFloat() * 0.4F + 0.8F));

                if (!par2World.IsRemote)
                {
                    par2World.SpawnEntityInWorld(new EntityFishHook(par2World, par3EntityPlayer));
                }

                par3EntityPlayer.SwingItem();
            }

            return(par1ItemStack);
        }
        /// <summary>
        /// called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
        /// </summary>
        public override void OnPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
        {
            bool flag = par3EntityPlayer.Capabilities.IsCreativeMode || EnchantmentHelper.GetEnchantmentLevel(Enchantment.Infinity.EffectId, par1ItemStack) > 0;

            if (flag || par3EntityPlayer.Inventory.HasItem(Item.Arrow.ShiftedIndex))
            {
                int   i = GetMaxItemUseDuration(par1ItemStack) - par4;
                float f = (float)i / 20F;
                f = (f * f + f * 2.0F) / 3F;

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

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

                EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);

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

                int j = EnchantmentHelper.GetEnchantmentLevel(Enchantment.Power.EffectId, par1ItemStack);

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

                int k = EnchantmentHelper.GetEnchantmentLevel(Enchantment.Punch.EffectId, par1ItemStack);

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

                if (EnchantmentHelper.GetEnchantmentLevel(Enchantment.Flame.EffectId, par1ItemStack) > 0)
                {
                    entityarrow.SetFire(100);
                }

                par1ItemStack.DamageItem(1, par3EntityPlayer);
                par2World.PlaySoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (ItemRand.NextFloat() * 0.4F + 1.2F) + f * 0.5F);

                if (!flag)
                {
                    par3EntityPlayer.Inventory.ConsumeInventoryItem(Item.Arrow.ShiftedIndex);
                }
                else
                {
                    entityarrow.DoesArrowBelongToPlayer = false;
                }

                if (!par2World.IsRemote)
                {
                    par2World.SpawnEntityInWorld(entityarrow);
                }
            }
        }
 public override bool OnBlockDestroyed(ItemStack par1ItemStack, int par2, int par3, int par4, int par5, EntityLiving par6EntityLiving)
 {
     par1ItemStack.DamageItem(2, par6EntityLiving);
     return(true);
 }
 /// <summary>
 /// Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
 /// the damage on the stack.
 /// </summary>
 public override bool HitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
 {
     par1ItemStack.DamageItem(1, par3EntityLiving);
     return(true);
 }