/// <summary> /// Draws the on level. /// </summary> /// <param name="mLevel">The level to draw on.</param> /// <param name="startPos">The start pos.</param> /// <param name="blockOverlay">A block to set the component as. If it is not already set</param> /// <remarks>if the block in the component is set to 255 a block overlay will be used automaticly, no block change will occur if the block is at 254</remarks> public void DrawOnLevel(Level mLevel, Vector3S startPos, Direction dir, byte blockOverlay = 1) { for (int i = 0; i < components.Length; i++) { var comp = components[i]; if (comp.Block == 254) continue; switch (dir) { case Direction.East: mLevel.SetBlock(comp.Pos + startPos, comp.Block == 255 ? blockOverlay : comp.Block); break; case Direction.West: mLevel.SetBlock(comp.Pos - startPos, comp.Block == 255 ? blockOverlay : comp.Block); break; } } }
/// <summary> /// Draws the on level. /// </summary> /// <param name="mLevel">The level to draw on.</param> /// <param name="startPos">The start pos.</param> /// <param name="blockOverlay">A block to set the component as. If it is not already set</param> /// <remarks>if the block in the component is set to 255 a block overlay will be used automaticly, no block change will occur if the block is at 254</remarks> public void DrawOnLevel(Level mLevel, Vector3S startPos, Direction dir, byte blockOverlay = 1) { for (int i = 0; i < components.Length; i++) { var comp = components[i]; if (comp.Block == 254) { continue; } switch (dir) { case Direction.East: mLevel.SetBlock(comp.Pos + startPos, comp.Block == 255 ? blockOverlay : comp.Block); break; case Direction.West: mLevel.SetBlock(comp.Pos - startPos, comp.Block == 255 ? blockOverlay : comp.Block); break; } } }
public virtual void SetBlock(int pos, Level l) { l.SetBlock(pos, VisibleBlock); }
public virtual void SetBlock(ushort x, ushort z, ushort y, Level l) { l.SetBlock(x, z, y, VisibleBlock); }
public virtual void SetBlock(int x, int z, int y, Level l) { l.SetBlock((ushort)x, (ushort)z, (ushort)y, VisibleBlock); }
public virtual void SetBlock(Vector3 pos, Level l) { l.SetBlock(pos.x, pos.z, pos.y, VisibleBlock); }
public virtual void SetBlock(Vector3S pos, Level l) { l.SetBlock(pos.x, pos.z, pos.y, VisibleBlock); }
/// <summary> /// Draws the on level. /// </summary> /// <param name="mLevel">The level to draw on.</param> /// <param name="startPos">The start pos.</param> /// <param name="blockOverlay">A block to set the component as. If it is not already set</param> /// <remarks>if the block in the component is set to 255 a block overlay will be used automaticly, no block change will occur if the block is at 254</remarks> public void DrawOnLevel(Level mLevel, Vector3S startPos, byte blockOverlay = 1) { for (int i = 0; i < components.Length; i++) { var comp = components[i]; if (comp.Block == 254) continue; mLevel.SetBlock(comp.Pos + startPos, comp.Block == 255 ? blockOverlay : comp.Block); } }
/// <summary> /// Load a level. /// </summary> /// <returns>The loaded level</returns> public static Level LoadLevel(string levelName) { string Name = "levels\\" + levelName + ".lvl"; Level finalLevel = new Level(new Vector3(32, 32, 32)); finalLevel.Name = levelName; try { var Binary = new BinaryReader(File.Open(Name, FileMode.Open)); using (Binary) { long v = Binary.ReadInt64(); if (v != 28542713840690029) //The magic number { Server.Log("Not a new MCForge Level! Attemping to load old MCForge level format!", ConsoleColor.Red, ConsoleColor.Black); Binary.Dispose(); FileStream fs = File.OpenRead(Name); try { GZipStream gs = new GZipStream(fs, CompressionMode.Decompress); byte[] ver = new byte[2]; gs.Read(ver, 0, ver.Length); ushort version = BitConverter.ToUInt16(ver, 0); if (version == 1874) //Is a old MCForge level! { #region Old MCForge Level ushort[] vars = new ushort[6]; byte[] rot = new byte[2]; byte[] header = new byte[16]; gs.Read(header, 0, header.Length); vars[0] = BitConverter.ToUInt16(header, 0); //X vars[1] = BitConverter.ToUInt16(header, 2); //Z vars[2] = BitConverter.ToUInt16(header, 4); //Y vars[3] = BitConverter.ToUInt16(header, 6); //SpawnX vars[4] = BitConverter.ToUInt16(header, 8); //SpawnZ vars[5] = BitConverter.ToUInt16(header, 10); //SpawnY rot[0] = header[12]; //SpawnHeading rot[1] = header[13]; //SpawnYaw finalLevel.Size = new Vector3((short)vars[0], (short)vars[1], (short)vars[2]); finalLevel.SpawnPos = new Vector3((short)vars[3], (short)vars[5], (short)vars[4]); finalLevel.SpawnRot = new byte[2] { rot[0], rot[1] }; finalLevel._TotalBlocks = finalLevel.Size.x * finalLevel.Size.z * finalLevel.Size.y; byte[] blocks = new byte[finalLevel.Size.x * finalLevel.Size.z * finalLevel.Size.y]; gs.Read(blocks, 0, blocks.Length); finalLevel.Data = new byte[finalLevel._TotalBlocks]; for (int x = 0; x < finalLevel.Size.x; x++) for (int y = 0; y < finalLevel.Size.y; y++) for (int z = 0; z < finalLevel.Size.z; z++) try { finalLevel.SetBlock(x, y, z, (byte)OldMCForgeToNewMCForge.Convert(blocks[finalLevel.PosToInt((ushort)x, (ushort)y, (ushort)z)])); } //Converts all custom blocks to normal blocks. catch { continue; } gs.Close(); #endregion } } catch { return null; } } else //Is a new MCForge level! { #region New MCForge Level string s = Binary.ReadString(); int x = Convert.ToInt32(s.Split('@')[0]); int y = Convert.ToInt32(s.Split('@')[1]); int z = Convert.ToInt32(s.Split('@')[2]); finalLevel.Size = new Vector3((short)x, (short)z, (short)y); s = Binary.ReadString(); x = Convert.ToInt32(s.Split('!')[0]); y = Convert.ToInt32(s.Split('!')[1]); z = Convert.ToInt32(s.Split('!')[2]); finalLevel.SpawnPos = new Vector3((short)x, (short)z, (short)y); s = Binary.ReadString(); int heading = Convert.ToInt32(s.Split('~')[0]); int yaw = Convert.ToInt32(s.Split('~')[1]); finalLevel.SpawnRot = new byte[2] { (byte)heading, (byte)yaw }; int count = Binary.ReadInt32(); for (int i = 0; i < count; i++) //Metadata for blocks { string key = Binary.ReadString(); string value = Binary.ReadString(); finalLevel.ExtraData[key] = value; } finalLevel._TotalBlocks = Binary.ReadInt32(); int ByteLength = Binary.ReadInt32(); byte[] b = Decompress(Binary.ReadBytes(ByteLength)); finalLevel.Data = new byte[finalLevel._TotalBlocks]; finalLevel.Data = b; try { string EOF = Binary.ReadString(); if (EOF != "EOF") { Binary.Dispose(); return null; } } catch { Binary.Dispose(); return null; } #endregion } } Binary.Dispose(); return finalLevel; } catch (Exception e) { Server.Log(e.Message); Server.Log(e.StackTrace); } return null; }