コード例 #1
0
ファイル: CmdFly.cs プロジェクト: hirsty/MCForge-Vanilla-1
        public void Use(Player p, string[] args)
        {
            p.isFlying = !p.isFlying;
            if (!p.isFlying)
            {
                return;
            }
            p.SendMessage("You are now flying. &cJump!");

            Thread fly = new Thread(new ThreadStart(delegate
                {
                Point3 pos;
                Point3 oldpos = new Point3();
                List<Point3> buffer = new List<Point3>();
                while (p.isFlying)
                {
                    Thread.Sleep(20);
                    if (p.Pos.x == oldpos.x && p.Pos.z == oldpos.z && p.Pos.y == oldpos.y) continue;
                    try
                    {
                        List<Point3> tempBuffer = new List<Point3>();
                        List<Point3> toRemove = new List<Point3>();
                        ushort x = (ushort)((p.Pos.x) / 32);
                        ushort z = (ushort)((p.Pos.z) / 32);
                        ushort y = (ushort)((p.Pos.y - 60) / 32);
                        try
                        {
                            for (ushort xx = (ushort)(x - 1); xx <= x + 1; xx++)
                            {
                                for (ushort yy = (ushort)(y - 1); yy <= y; yy++)
                                {
                                    for (ushort zz = (ushort)(z - 1); zz <= z + 1; zz++)
                                    {
                                        if (p.level.GetBlock(xx,zz, yy) == (byte)Blocks.Types.air)
                                        {
                                            pos.x = (short)xx; pos.y = (short)yy; pos.z = (short)zz;
                                            tempBuffer.Add(pos);
                                        }
                                    }
                                }
                            }
                            foreach (Point3 cP in tempBuffer)
                            {
                                if (!buffer.Contains(cP))
                                {
                                    buffer.Add(cP);
                                    p.SendBlockChange((ushort)cP.x, (ushort)cP.z, (ushort)cP.y, (byte)Blocks.Types.glass);
                                }
                            }
                            foreach (Point3 cP in buffer)
                            {
                                if (!tempBuffer.Contains(cP))
                                {
                                    p.SendBlockChange((ushort)cP.x, (ushort)cP.z, (ushort)cP.y, (byte)Blocks.Types.air);
                                    toRemove.Add(cP);
                                }
                            }
                            foreach (Point3 cP in toRemove)
                            {
                                buffer.Remove(cP);
                            }
                            tempBuffer.Clear();
                            toRemove.Clear();
                        }
                        catch { }
                    }
                    catch { }
                    //
                    //p.Pos.CopyTo(oldpos, 0);
                }

                foreach (Point3 cP in buffer)
                {
                    p.SendBlockChange((ushort)cP.x, (ushort)cP.z, (ushort)cP.y, (byte)Blocks.Types.air);
                }

                p.SendMessage("Stopped flying");
            }));
            fly.Start();
        }