MCSharp.World.Map.Map C# (CSharp) Method

Map() public method

public Map ( string n, ushort x, ushort y, ushort z, string type ) : System
n string
x ushort
y ushort
z ushort
type string
return System
        public Map(string n, ushort x, ushort y, ushort z, string type)
        {
            this.Physics = Physics.Off;

            width = x;
            depth = y;
            height = z;

            // Make sure the level isn't too small
            if (width < 16) { width = 16; }
            if (depth < 16) { depth = 16; }
            if (height < 16) { height = 16; }

            name = n;
            blocks = new byte[width * depth * height];

            switch (type)
            {
                case "flat":
                case "pixel":
                    ushort half = (ushort)(depth / 2);
                    for (x = 0; x < width; ++x)
                    {
                        for (z = 0; z < height; ++z)
                        {
                            for (y = 0; y < depth; ++y)
                            {
                                //Block b = new Block();
                                switch (type)
                                {
                                    case "flat":
                                        if (y != half)
                                        {
                                            SetTile(x, y, z, (byte)((y >= half) ? Block.air : Block.dirt));
                                        }
                                        else
                                        {
                                            SetTile(x, y, z, Block.grass);
                                        }
                                        break;

                                    case "pixel":
                                        if (y == 0)
                                        {
                                            SetTile(x, y, z, Block.blackrock);
                                        }
                                        else
                                            if (x == 0 || x == width - 1 || z == 0 || z == height - 1)
                                            {
                                                SetTile(x, y, z, Block.white);
                                            }

                                        break;
                                }
                                //blocks[x + width * z + width * height * y] = b;
                            }
                        }
                    }
                    break;

                case "island":
                case "mountains":
                case "ocean":
                case "forest":
                    Server.MapGen.GenerateMap(this, type);
                    break;

                case "empty":
                default:
                    break;
            }

            spawnx = (ushort)(width / 2);
            spawny = (ushort)(depth * 0.75f);
            spawnz = (ushort)(height / 2);
            rotx = 0; roty = 0;
            Logger.Log("Map initialized.");

            if (type != "empty")
            {
                changed = true;
                Save();
                if (!Directory.Exists("levels/backups/" + name + "/1"))
                {
                    Directory.CreateDirectory("levels/backups/" + name + "/1");
                }
                Backup();
            }
        }