Esempio 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 (par7 != 1)
            {
                return(false);
            }

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

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

            if (i == SoilBlockID && par3World.IsAirBlock(par4, par5 + 1, par6))
            {
                par3World.SetBlockWithNotify(par4, par5 + 1, par6, BlockType);
                par1ItemStack.StackSize--;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <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 != 1)
            {
                return(false);
            }

            par5++;
            BlockBed blockbed = (BlockBed)Block.Bed;
            int      i        = MathHelper2.Floor_double((double)((par2EntityPlayer.RotationYaw * 4F) / 360F) + 0.5D) & 3;
            sbyte    byte0    = 0;
            sbyte    byte1    = 0;

            if (i == 0)
            {
                byte1 = 1;
            }

            if (i == 1)
            {
                byte0 = -1;
            }

            if (i == 2)
            {
                byte1 = -1;
            }

            if (i == 3)
            {
                byte0 = 1;
            }

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

            if (par3World.IsAirBlock(par4, par5, par6) && par3World.IsAirBlock(par4 + byte0, par5, par6 + byte1) && par3World.IsBlockNormalCube(par4, par5 - 1, par6) && par3World.IsBlockNormalCube(par4 + byte0, par5 - 1, par6 + byte1))
            {
                par3World.SetBlockAndMetadataWithNotify(par4, par5, par6, blockbed.BlockID, i);

                if (par3World.GetBlockId(par4, par5, par6) == blockbed.BlockID)
                {
                    par3World.SetBlockAndMetadataWithNotify(par4 + byte0, par5, par6 + byte1, blockbed.BlockID, i + 8);
                }

                par1ItemStack.StackSize--;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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.GetBlockId(par4, par5, par6) != Block.Snow.BlockID)
            {
                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 (!par3World.IsAirBlock(par4, par5, par6))
                {
                    return(false);
                }
            }

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

            if (Block.RedstoneWire.CanPlaceBlockAt(par3World, par4, par5, par6))
            {
                par1ItemStack.StackSize--;
                par3World.SetBlockWithNotify(par4, par5, par6, Block.RedstoneWire.BlockID);
            }

            return(true);
        }
Esempio n. 6
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 (par7 != 1)
            {
                return(false);
            }

            par5++;
            Block block;

            if (DoorMaterial == Material.Wood)
            {
                block = Block.DoorWood;
            }
            else
            {
                block = Block.DoorSteel;
            }

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

            if (!block.CanPlaceBlockAt(par3World, par4, par5, par6))
            {
                return(false);
            }
            else
            {
                int i = MathHelper2.Floor_double((double)(((par2EntityPlayer.RotationYaw + 180F) * 4F) / 360F) - 0.5D) & 3;
                PlaceDoorBlock(par3World, par4, par5, par6, i, block);
                par1ItemStack.StackSize--;
                return(true);
            }
        }
Esempio n. 7
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 (par7 == 0)
            {
                return(false);
            }

            if (par7 == 1)
            {
                return(false);
            }

            sbyte byte0 = 0;

            if (par7 == 4)
            {
                byte0 = 1;
            }

            if (par7 == 3)
            {
                byte0 = 2;
            }

            if (par7 == 5)
            {
                byte0 = 3;
            }

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

            EntityPainting entitypainting = new EntityPainting(par3World, par4, par5, par6, byte0);

            if (entitypainting.OnValidSurface())
            {
                if (!par3World.IsRemote)
                {
                    par3World.SpawnEntityInWorld(entitypainting);
                }

                par1ItemStack.StackSize--;
            }

            return(true);
        }
Esempio n. 8
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)
        {
            MovingObjectPosition movingobjectposition = GetMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

            if (movingobjectposition == null)
            {
                return(par1ItemStack);
            }

            if (movingobjectposition.TypeOfHit == EnumMovingObjectType.TILE)
            {
                int i = movingobjectposition.BlockX;
                int j = movingobjectposition.BlockY;
                int k = movingobjectposition.BlockZ;

                if (!par2World.CanMineBlock(par3EntityPlayer, i, j, k))
                {
                    return(par1ItemStack);
                }

                if (!par3EntityPlayer.CanPlayerEdit(i, j, k))
                {
                    return(par1ItemStack);
                }

                if (par2World.GetBlockMaterial(i, j, k) == Material.Water)
                {
                    par1ItemStack.StackSize--;

                    if (par1ItemStack.StackSize <= 0)
                    {
                        return(new ItemStack(Item.Potion));
                    }

                    if (!par3EntityPlayer.Inventory.AddItemStackToInventory(new ItemStack(Item.Potion)))
                    {
                        par3EntityPlayer.DropPlayerItem(new ItemStack(Item.Potion.ShiftedIndex, 1, 0));
                    }
                }
            }

            return(par1ItemStack);
        }
Esempio n. 9
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)
        {
            MovingObjectPosition movingobjectposition = GetMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

            if (movingobjectposition == null)
            {
                return(par1ItemStack);
            }

            if (movingobjectposition.TypeOfHit == EnumMovingObjectType.TILE)
            {
                int i = movingobjectposition.BlockX;
                int j = movingobjectposition.BlockY;
                int k = movingobjectposition.BlockZ;

                if (!par2World.CanMineBlock(par3EntityPlayer, i, j, k))
                {
                    return(par1ItemStack);
                }

                if (!par3EntityPlayer.CanPlayerEdit(i, j, k))
                {
                    return(par1ItemStack);
                }

                if (par2World.GetBlockMaterial(i, j, k) == Material.Water && par2World.GetBlockMetadata(i, j, k) == 0 && par2World.IsAirBlock(i, j + 1, k))
                {
                    par2World.SetBlockWithNotify(i, j + 1, k, Block.Waterlily.BlockID);

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

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

            if (i == Block.Snow.BlockID)
            {
                par7 = 1;
            }
            else if (i != Block.Vine.BlockID && i != Block.TallGrass.BlockID && i != Block.DeadBush.BlockID)
            {
                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);
            }

            if (par1ItemStack.StackSize == 0)
            {
                return(false);
            }

            if (par3World.CanBlockBePlacedAt(SpawnID, par4, par5, par6, false, par7))
            {
                Block block = Block.BlocksList[SpawnID];

                if (par3World.SetBlockWithNotify(par4, par5, par6, SpawnID))
                {
                    if (par3World.GetBlockId(par4, par5, par6) == SpawnID)
                    {
                        Block.BlocksList[SpawnID].OnBlockPlaced(par3World, par4, par5, par6, par7);
                        Block.BlocksList[SpawnID].OnBlockPlacedBy(par3World, par4, par5, par6, par2EntityPlayer);
                    }

                    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);
                    par1ItemStack.StackSize--;
                }
            }

            return(true);
        }
        /// <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);
            }
        }
Esempio n. 12
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 (par7 == 0)
            {
                return(false);
            }

            if (!par3World.GetBlockMaterial(par4, par5, par6).IsSolid())
            {
                return(false);
            }

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

            if (!Block.SignPost.CanPlaceBlockAt(par3World, par4, par5, par6))
            {
                return(false);
            }

            if (par7 == 1)
            {
                int i = MathHelper2.Floor_double((double)(((par2EntityPlayer.RotationYaw + 180F) * 16F) / 360F) + 0.5D) & 0xf;
                par3World.SetBlockAndMetadataWithNotify(par4, par5, par6, Block.SignPost.BlockID, i);
            }
            else
            {
                par3World.SetBlockAndMetadataWithNotify(par4, par5, par6, Block.SignWall.BlockID, par7);
            }

            par1ItemStack.StackSize--;
            TileEntitySign tileentitysign = (TileEntitySign)par3World.GetBlockTileEntity(par4, par5, par6);

            if (tileentitysign != null)
            {
                par2EntityPlayer.DisplayGUIEditSign(tileentitysign);
            }

            return(true);
        }