Ejemplo n.º 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);
            }

            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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
        /// block.
        /// </summary>
        public override bool BlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
        {
            int i = par1World.GetBlockMetadata(par2, par3, par4);
            int j = (i & 0xc) >> 2;

            j = j + 1 << 2 & 0xc;
            par1World.SetBlockMetadataWithNotify(par2, par3, par4, j | i & 3);
            return(true);
        }
 /// <summary>
 /// Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
 /// block.
 /// </summary>
 public override bool BlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
 {
     if (par1World.IsRemote)
     {
         return(true);
     }
     else
     {
         par5EntityPlayer.DisplayGUIEnchantment(par2, par3, par4);
         return(true);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Called when the block is clicked by a player. Args: x, y, z, entityPlayer
 /// </summary>
 public override void OnBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
 {
     EatCakeSlice(par1World, par2, par3, par4, par5EntityPlayer);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (Field_35126_c > 0)
            {
                Field_35126_c--;
            }

            PrevPosX = PosX;
            PrevPosY = PosY;
            PrevPosZ = PosZ;
            MotionY -= 0.029999999329447746F;

            if (WorldObj.GetBlockMaterial(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ)) == Material.Lava)
            {
                MotionY = 0.20000000298023224F;
                MotionX = (Rand.NextFloat() - Rand.NextFloat()) * 0.2F;
                MotionZ = (Rand.NextFloat() - Rand.NextFloat()) * 0.2F;
                WorldObj.PlaySoundAtEntity(this, "random.fizz", 0.4F, 2.0F + Rand.NextFloat() * 0.4F);
            }

            PushOutOfBlocks(PosX, (BoundingBox.MinY + BoundingBox.MaxY) / 2F, PosZ);
            float        d            = 8F;
            EntityPlayer entityplayer = WorldObj.GetClosestPlayerToEntity(this, d);

            if (entityplayer != null)
            {
                float d1 = (entityplayer.PosX - PosX) / d;
                float d2 = ((entityplayer.PosY + entityplayer.GetEyeHeight()) - PosY) / d;
                float d3 = (entityplayer.PosZ - PosZ) / d;
                float d4 = (float)Math.Sqrt(d1 * d1 + d2 * d2 + d3 * d3);
                float d5 = 1.0F - d4;

                if (d5 > 0.0F)
                {
                    d5      *= d5;
                    MotionX += (d1 / d4) * d5 * 0.10000000000000001F;
                    MotionY += (d2 / d4) * d5 * 0.10000000000000001F;
                    MotionZ += (d3 / d4) * d5 * 0.10000000000000001F;
                }
            }

            MoveEntity(MotionX, MotionY, MotionZ);
            float f = 0.98F;

            if (OnGround)
            {
                f = 0.5880001F;
                int i = WorldObj.GetBlockId(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(BoundingBox.MinY) - 1, MathHelper2.Floor_double(PosZ));

                if (i > 0)
                {
                    f = Block.BlocksList[i].Slipperiness * 0.98F;
                }
            }

            MotionX *= f;
            MotionY *= 0.98000001907348633F;
            MotionZ *= f;

            if (OnGround)
            {
                MotionY *= -0.89999997615814209F;
            }

            XpColor++;
            XpOrbAge++;

            if (XpOrbAge >= 6000)
            {
                SetDead();
            }
        }
        /// <summary>
        /// Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
        /// block.
        /// </summary>
        public override bool BlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
        {
            if (par1World.IsRemote)
            {
                return(true);
            }

            TileEntityDispenser tileentitydispenser = (TileEntityDispenser)par1World.GetBlockTileEntity(par2, par3, par4);

            if (tileentitydispenser != null)
            {
                par5EntityPlayer.DisplayGUIDispenser(tileentitydispenser);
            }

            return(true);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
 /// block.
 /// </summary>
 public override bool BlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
 {
     EatCakeSlice(par1World, par2, par3, par4, par5EntityPlayer);
     return(true);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
        /// </summary>
        public override bool Interact(EntityPlayer par1EntityPlayer)
        {
            ItemStack itemstack = par1EntityPlayer.Inventory.GetCurrentItem();

            if (!IsTamed())
            {
                if (itemstack != null && itemstack.ItemID == Item.Bone.ShiftedIndex && !IsAngry())
                {
                    if (!par1EntityPlayer.Capabilities.IsCreativeMode)
                    {
                        itemstack.StackSize--;
                    }

                    if (itemstack.StackSize <= 0)
                    {
                        par1EntityPlayer.Inventory.SetInventorySlotContents(par1EntityPlayer.Inventory.CurrentItem, null);
                    }

                    if (!WorldObj.IsRemote)
                    {
                        if (Rand.Next(3) == 0)
                        {
                            SetTamed(true);
                            SetPathToEntity(null);
                            SetAttackTarget(null);
                            AiSit.Func_48407_a(true);
                            SetEntityHealth(20);
                            SetOwner(par1EntityPlayer.Username);
                            Func_48142_a(true);
                            WorldObj.SetEntityState(this, (sbyte)7);
                        }
                        else
                        {
                            Func_48142_a(false);
                            WorldObj.SetEntityState(this, (sbyte)6);
                        }
                    }

                    return(true);
                }
            }
            else
            {
                if (itemstack != null && (Item.ItemsList[itemstack.ItemID] is ItemFood))
                {
                    ItemFood itemfood = (ItemFood)Item.ItemsList[itemstack.ItemID];

                    if (itemfood.IsWolfsFavoriteMeat() && DataWatcher.GetWatchableObjectInt(18) < 20)
                    {
                        if (!par1EntityPlayer.Capabilities.IsCreativeMode)
                        {
                            itemstack.StackSize--;
                        }

                        Heal(itemfood.GetHealAmount());

                        if (itemstack.StackSize <= 0)
                        {
                            par1EntityPlayer.Inventory.SetInventorySlotContents(par1EntityPlayer.Inventory.CurrentItem, null);
                        }

                        return(true);
                    }
                }

                if (par1EntityPlayer.Username.ToUpper() == GetOwnerName().ToUpper() && !WorldObj.IsRemote && !IsWheat(itemstack))
                {
                    AiSit.Func_48407_a(!IsSitting());
                    IsJumping = false;
                    SetPathToEntity(null);
                }
            }

            return(base.Interact(par1EntityPlayer));
        }
Ejemplo n.º 9
0
        private bool Func_48574_b()
        {
            List <EntityPlayer> list = Field_48582_a.PlayerEntities;

            for (IEnumerator <EntityPlayer> iterator = list.GetEnumerator(); iterator.MoveNext();)
            {
                EntityPlayer entityplayer = iterator.Current;
                Field_48576_f = Field_48582_a.VillageCollectionObj.FindNearestVillage((int)entityplayer.PosX, (int)entityplayer.PosY, (int)entityplayer.PosZ, 1);

                if (Field_48576_f != null && Field_48576_f.GetNumVillageDoors() >= 10 && Field_48576_f.GetTicksSinceLastDoorAdding() >= 20 && Field_48576_f.GetNumVillagers() >= 20)
                {
                    ChunkCoordinates chunkcoordinates = Field_48576_f.GetCenter();
                    float            f    = Field_48576_f.GetVillageRadius();
                    bool             flag = false;
                    int i = 0;

                    do
                    {
                        if (i >= 10)
                        {
                            break;
                        }

                        Field_48577_g = chunkcoordinates.PosX + (int)((double)(MathHelper2.Cos(Field_48582_a.Rand.NextFloat() * (float)Math.PI * 2.0F) * f) * 0.90000000000000002D);
                        Field_48583_h = chunkcoordinates.PosY;
                        Field_48584_i = chunkcoordinates.PosZ + (int)((double)(MathHelper2.Sin(Field_48582_a.Rand.NextFloat() * (float)Math.PI * 2.0F) * f) * 0.90000000000000002D);
                        flag          = false;
                        IEnumerator <Village> iterator1 = Field_48582_a.VillageCollectionObj.Func_48554_b().GetEnumerator();

                        do
                        {
                            if (!iterator1.MoveNext())
                            {
                                break;
                            }

                            Village village = iterator1.Current;

                            if (village == Field_48576_f || !village.IsInRange(Field_48577_g, Field_48583_h, Field_48584_i))
                            {
                                continue;
                            }

                            flag = true;
                            break;
                        }while (true);

                        if (!flag)
                        {
                            break;
                        }

                        i++;
                    }while (true);

                    if (flag)
                    {
                        return(false);
                    }

                    Vec3D vec3d = Func_48572_a(Field_48577_g, Field_48583_h, Field_48584_i);

                    if (vec3d != null)
                    {
                        Field_48579_e = 0;
                        Field_48578_d = 20;
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// called when the player releases the use item button. Args: world, entityplayer, itemInUseCount
 /// </summary>
 public void OnPlayerStoppedUsing(World par1World, EntityPlayer par2EntityPlayer, int par3)
 {
     GetItem().OnPlayerStoppedUsing(this, par1World, par2EntityPlayer, par3);
 }
Ejemplo n.º 11
0
 public void OnCrafting(World par1World, EntityPlayer par2EntityPlayer, int par3)
 {
     par2EntityPlayer.AddStat(StatList.ObjectCraftStats[ItemID], par3);
     Item.ItemsList[ItemID].OnCreated(this, par1World, par2EntityPlayer);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Called when a given item stack is about to be destroyed due to its damage level expiring when used on a block or
 /// entity. Typically used by tools.
 /// </summary>
 public void OnItemDestroyedByUse(EntityPlayer entityplayer)
 {
 }
Ejemplo n.º 13
0
 public ItemStack OnFoodEaten(World par1World, EntityPlayer par2EntityPlayer)
 {
     return(GetItem().OnFoodEaten(this, par1World, par2EntityPlayer));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Called whenever this item stack is equipped and right clicked. Returns the new item stack to put in the position
 /// where this item is. Args: world, player
 /// </summary>
 public ItemStack UseItemRightClick(World par1World, EntityPlayer par2EntityPlayer)
 {
     return(GetItem().OnItemRightClick(this, par1World, par2EntityPlayer));
 }