public void OnPlayerBlockPlacement(ref PacketReader _pReader, PacketType pt, ref ClientManager _client)
        {
            PlayerBlockPlacementPacket p = new PlayerBlockPlacementPacket(PacketType.PlayerBlockPlacement);
            p.X = _pReader.ReadInt();
            p.Y = _pReader.ReadByte();
            p.Z = _pReader.ReadInt();
            p.Direction = _pReader.ReadByte();
            p.BlockID = _pReader.ReadSlot();
            //if (p.BlockID.s_short <= -1)
            //{
                p.Amount = _pReader.ReadByte();
                p.Damage = _pReader.ReadShort();
            //}
            GridServer.player_list[_client.id].WaitToRead = false;
            p.BuildPacket();

            PacketReader pr = new PacketReader(new System.IO.MemoryStream(p.GetBytes()));
            int i = 0;
            for (; i < base.ModuleAddons.Count; i++)
            {
                base.ModuleAddons.ElementAt(i).Value(pt, ModuleAddons.ElementAt(i).Key, ref pr, (PacketHandler)p, ref _client);
            }
        }
示例#2
0
        public BlockChangePacket SendBlockChange(BlockChangePacket block_change, ref ClientManager _client, ref PacketReader _pReader, PlayerBlockPlacementPacket _p, bool calculate_xyz)
        {
            int X = _p.X;
            byte Y = _p.Y;
            int Z = _p.Z;
            int index = 0;
            if (calculate_xyz == true)
            {
                int temp = (_p.Direction == 0 ? Y-- :
                    (_p.Direction == 1 ? Y++ :
                    (_p.Direction == 2 ? Z-- :
                    (_p.Direction == 3 ? Z++ :
                    (_p.Direction == 4 ? X-- : X++)))));
            }
            try
            {
                index = Chunk.GetIndex(X / 16, Z / 16);
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.Message + " Source:" + e.Source + " Method:" + e.TargetSite + " Data:" + e.Data);
            }

            block_change.X = X;
            block_change.Y = Y;
            block_change.Z = Z;
            block_change.BlockType = (byte)_p.BlockID.s_short;
            //block_change.Metadata = 0x00;
            block_change.BuildPacket();
            #region Send Block Changes
            try
            {
                int i = 0;
                for (; i < base.ModuleAddons.Count; i++)
                {
                    block_change = (BlockChangePacket)base.ModuleAddons.ElementAt(i).Value(PacketType.BlockChange, ModuleAddons.ElementAt(i).Key, ref _pReader, (PacketHandler)block_change, ref _client);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.Message + " Source:" + e.Source + " Method:" + e.TargetSite + " Data:" + e.Data);
            }

            World.chunks[index].SetBlocktype(X, Y, Z, block_change.BlockType);
            World.chunks[index].SetData(X, Y, Z, block_change.Metadata);
            ClientManager[] player = GridServer.player_list;
            for (int i = 0; i < player.Length; i++)
            {
                if (player[i] == null)
                {

                }
                else
                {
                    if (player[i]._client != null && player[i]._client.Connected == true)
                        player[i].SendPacket(block_change, player[i].id, ref player[i], false, false);
                    else if (player[i]._client == null || player[i]._client.Connected == false)
                    {

                    }
                }
            }
            #endregion Send Block Changes
            return block_change;
        }