Example #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 (par3World.IsRemote)
            {
                return(true);
            }

            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);
            }

            if (!par2EntityPlayer.Capabilities.IsCreativeMode)
            {
                par1ItemStack.StackSize--;
            }

            return(true);
        }
        /// <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);
                }
            }
        }
Example #3
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 (IsSplash(par1ItemStack.GetItemDamage()))
            {
                par1ItemStack.StackSize--;
                par2World.PlaySoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / ((float)ItemRand.NextDouble() * 0.4F + 0.8F));

                if (!par2World.IsRemote)
                {
                    par2World.SpawnEntityInWorld(new EntityPotion(par2World, par3EntityPlayer, par1ItemStack.GetItemDamage()));
                }

                return(par1ItemStack);
            }
            else
            {
                par3EntityPlayer.SetItemInUse(par1ItemStack, GetMaxItemUseDuration(par1ItemStack));
                return(par1ItemStack);
            }
        }
Example #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.Capabilities.IsCreativeMode)
            {
                par1ItemStack.StackSize--;
            }

            par2World.PlaySoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (ItemRand.NextFloat() * 0.4F + 0.8F));

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

            return(par1ItemStack);
        }
        /// <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)
        {
            MovingObjectPosition movingobjectposition = GetMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false);

            if (movingobjectposition != null && movingobjectposition.TypeOfHit == EnumMovingObjectType.TILE)
            {
                int i = par2World.GetBlockId(movingobjectposition.BlockX, movingobjectposition.BlockY, movingobjectposition.BlockZ);

                if (i == Block.EndPortalFrame.BlockID)
                {
                    return(par1ItemStack);
                }
            }

            if (!par2World.IsRemote)
            {
                ChunkPosition chunkposition = par2World.FindClosestStructure("Stronghold", (int)par3EntityPlayer.PosX, (int)par3EntityPlayer.PosY, (int)par3EntityPlayer.PosZ);

                if (chunkposition != null)
                {
                    EntityEnderEye entityendereye = new EntityEnderEye(par2World, par3EntityPlayer.PosX, (par3EntityPlayer.PosY + 1.6200000000000001F) - par3EntityPlayer.YOffset, par3EntityPlayer.PosZ);
                    entityendereye.Func_40090_a(chunkposition.x, chunkposition.y, chunkposition.z);
                    par2World.SpawnEntityInWorld(entityendereye);
                    par2World.PlaySoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (ItemRand.NextFloat() * 0.4F + 0.8F));
                    par2World.PlayAuxSFXAtEntity(null, 1002, (int)par3EntityPlayer.PosX, (int)par3EntityPlayer.PosY, (int)par3EntityPlayer.PosZ, 0);

                    if (!par3EntityPlayer.Capabilities.IsCreativeMode)
                    {
                        par1ItemStack.StackSize--;
                    }
                }
            }

            return(par1ItemStack);
        }
        /// <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)
        {
            int i = par3World.GetBlockId(par4, par5, par6);
            int j = par3World.GetBlockMetadata(par4, par5, par6);

            if (par2EntityPlayer.CanPlayerEdit(par4, par5, par6) && i == Block.EndPortalFrame.BlockID && !BlockEndPortalFrame.IsEnderEyeInserted(j))
            {
                if (par3World.IsRemote)
                {
                    return(true);
                }

                par3World.SetBlockMetadataWithNotify(par4, par5, par6, j + 4);
                par1ItemStack.StackSize--;

                for (int k = 0; k < 16; k++)
                {
                    float d  = par4 + (5F + ItemRand.NextFloat() * 6F) / 16F;
                    float d1 = par5 + 0.8125F;
                    float d2 = par6 + (5F + ItemRand.NextFloat() * 6F) / 16F;
                    float d3 = 0.0F;
                    float d4 = 0.0F;
                    float d5 = 0.0F;
                    par3World.SpawnParticle("smoke", d, d1, d2, d3, d4, d5);
                }

                int  l     = j & 3;
                int  i1    = 0;
                int  j1    = 0;
                bool flag  = false;
                bool flag1 = true;
                int  k1    = Direction.EnderEyeMetaToDirection[l];

                for (int l1 = -2; l1 <= 2; l1++)
                {
                    int l2 = par4 + Direction.OffsetX[k1] * l1;
                    int l3 = par6 + Direction.OffsetZ[k1] * l1;
                    int l4 = par3World.GetBlockId(l2, par5, l3);

                    if (l4 != Block.EndPortalFrame.BlockID)
                    {
                        continue;
                    }

                    int l5 = par3World.GetBlockMetadata(l2, par5, l3);

                    if (!BlockEndPortalFrame.IsEnderEyeInserted(l5))
                    {
                        flag1 = false;
                        break;
                    }

                    if (!flag)
                    {
                        i1   = l1;
                        j1   = l1;
                        flag = true;
                    }
                    else
                    {
                        j1 = l1;
                    }
                }

                if (flag1 && j1 == i1 + 2)
                {
                    int i2 = i1;

                    do
                    {
                        if (i2 > j1)
                        {
                            break;
                        }

                        int i3 = par4 + Direction.OffsetX[k1] * i2;
                        int i4 = par6 + Direction.OffsetZ[k1] * i2;
                        i3 += Direction.OffsetX[l] * 4;
                        i4 += Direction.OffsetZ[l] * 4;
                        int i5 = par3World.GetBlockId(i3, par5, i4);
                        int i6 = par3World.GetBlockMetadata(i3, par5, i4);

                        if (i5 != Block.EndPortalFrame.BlockID || !BlockEndPortalFrame.IsEnderEyeInserted(i6))
                        {
                            flag1 = false;
                            break;
                        }

                        i2++;
                    }while (true);

label0:
                    //Unreachable
                    //for (int j2 = i1 - 1; j2 <= j1 + 1; j2 += 4)
                    //{
                    //	int j3 = 1;
                    //
                    //	do
                    //	{
                    //		if (j3 > 3)
                    //		{
                    //			goto label0;
                    //		}
                    //
                    //		int j4 = par4 + Direction.OffsetX[k1] * j2;
                    //		int j5 = par6 + Direction.OffsetZ[k1] * j2;
                    //		j4 += Direction.OffsetX[l] * j3;
                    //		j5 += Direction.OffsetZ[l] * j3;
                    //		int j6 = par3World.GetBlockId(j4, par5, j5);
                    //		int k6 = par3World.GetBlockMetadata(j4, par5, j5);
                    //
                    //		if (j6 != Block.EndPortalFrame.BlockID || !BlockEndPortalFrame.IsEnderEyeInserted(k6))
                    //		{
                    //			flag1 = false;
                    //			goto label0;
                    //		}
                    //
                    //		j3++;
                    //	}
                    //	while (true);
                    //}

                    if (flag1)
                    {
                        for (int k2 = i1; k2 <= j1; k2++)
                        {
                            for (int k3 = 1; k3 <= 3; k3++)
                            {
                                int k4 = par4 + Direction.OffsetX[k1] * k2;
                                int k5 = par6 + Direction.OffsetZ[k1] * k2;
                                k4 += Direction.OffsetX[l] * k3;
                                k5 += Direction.OffsetZ[l] * k3;
                                par3World.SetBlockWithNotify(k4, par5, k5, Block.EndPortal.BlockID);
                            }
                        }
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #7
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>
        /// 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);
            }

            if (par1ItemStack.GetItemDamage() == 15)
            {
                int i = par3World.GetBlockId(par4, par5, par6);

                if (i == Block.Sapling.BlockID)
                {
                    if (!par3World.IsRemote)
                    {
                        ((BlockSapling)Block.Sapling).GrowTree(par3World, par4, par5, par6, par3World.Rand);
                        par1ItemStack.StackSize--;
                    }

                    return(true);
                }

                if (i == Block.MushroomBrown.BlockID || i == Block.MushroomRed.BlockID)
                {
                    if (!par3World.IsRemote && ((BlockMushroom)Block.BlocksList[i]).FertilizeMushroom(par3World, par4, par5, par6, par3World.Rand))
                    {
                        par1ItemStack.StackSize--;
                    }

                    return(true);
                }

                if (i == Block.MelonStem.BlockID || i == Block.PumpkinStem.BlockID)
                {
                    if (!par3World.IsRemote)
                    {
                        ((BlockStem)Block.BlocksList[i]).FertilizeStem(par3World, par4, par5, par6);
                        par1ItemStack.StackSize--;
                    }

                    return(true);
                }

                if (i == Block.Crops.BlockID)
                {
                    if (!par3World.IsRemote)
                    {
                        ((BlockCrops)Block.Crops).Fertilize(par3World, par4, par5, par6);
                        par1ItemStack.StackSize--;
                    }

                    return(true);
                }

                if (i == Block.Grass.BlockID)
                {
                    if (!par3World.IsRemote)
                    {
                        par1ItemStack.StackSize--;
label0:

                        for (int j = 0; j < 128; j++)
                        {
                            int k  = par4;
                            int l  = par5 + 1;
                            int i1 = par6;

                            for (int j1 = 0; j1 < j / 16; j1++)
                            {
                                k  += ItemRand.Next(3) - 1;
                                l  += ((ItemRand.Next(3) - 1) * ItemRand.Next(3)) / 2;
                                i1 += ItemRand.Next(3) - 1;

                                if (par3World.GetBlockId(k, l - 1, i1) != Block.Grass.BlockID || par3World.IsBlockNormalCube(k, l, i1))
                                {
                                    goto label0;
                                }
                            }

                            if (par3World.GetBlockId(k, l, i1) != 0)
                            {
                                continue;
                            }

                            if (ItemRand.Next(10) != 0)
                            {
                                par3World.SetBlockAndMetadataWithNotify(k, l, i1, Block.TallGrass.BlockID, 1);
                                continue;
                            }

                            if (ItemRand.Next(3) != 0)
                            {
                                par3World.SetBlockWithNotify(k, l, i1, Block.PlantYellow.BlockID);
                            }
                            else
                            {
                                par3World.SetBlockWithNotify(k, l, i1, Block.PlantRed.BlockID);
                            }
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }