Support map sizes from 1-15 blocks too.

This commit is contained in:
UnknownShadow200 2018-01-26 18:56:36 +11:00
parent 8adae20194
commit cf8c251d43
4 changed files with 26 additions and 31 deletions

View File

@ -27,8 +27,12 @@ namespace MCGalaxy {
public ConfigAttribute Attrib;
public FieldInfo Field;
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static |
BindingFlags.Public | BindingFlags.NonPublic;
public string Format(object instance) {
object value = Field.GetValue(instance);
return Attrib.Name + " = " + Attrib.Serialise(value);
}
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
public static ConfigElement[] GetAll(Type type) {
List<ConfigElement> elems = new List<ConfigElement>();
@ -59,10 +63,8 @@ namespace MCGalaxy {
}
/// <summary> Writes all config elements to the given stream, grouped by named sections. </summary>
public static void Serialise(ConfigElement[] elements, string suffix,
StreamWriter dst, object instance) {
Dictionary<string, List<ConfigElement>> sections
= new Dictionary<string, List<ConfigElement>>();
public static void Serialise(ConfigElement[] elements, string suffix, StreamWriter dst, object instance) {
Dictionary<string, List<ConfigElement>> sections = new Dictionary<string, List<ConfigElement>>();
foreach (ConfigElement elem in elements) {
List<ConfigElement> members;
@ -76,19 +78,10 @@ namespace MCGalaxy {
foreach (var kvp in sections) {
dst.WriteLine("# " + kvp.Key + suffix);
foreach (ConfigElement elem in kvp.Value) {
object value = elem.Field.GetValue(instance);
dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value));
dst.WriteLine(elem.Format(instance));
}
dst.WriteLine();
}
}
/// <summary> Writes all config elements to the given stream. </summary>
public static void SerialisePlain(ConfigElement[] elements, StreamWriter dst, object instance) {
foreach (ConfigElement elem in elements) {
object value = elem.Field.GetValue(instance);
dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value));
}
}
}
}

View File

@ -101,8 +101,11 @@ namespace MCGalaxy.Games {
}
public void Save(string mapName) {
ConfigElement[] elements = elems;
using (StreamWriter w = new StreamWriter("CTF/" + mapName + ".config")) {
ConfigElement.SerialisePlain(elems, w, this);
for (int i = 0; i < elements.Length; i++) {
w.WriteLine(elements[i].Format(this));
}
}
}

View File

@ -40,14 +40,15 @@ namespace MCGalaxy {
public sealed partial class Level : IDisposable {
public Level(string n, ushort x, ushort y, ushort z) {
Width = x; Height = y; Length = z;
if (Width < 16) Width = 16;
if (Height < 16) Height = 16;
if (Length < 16) Length = 16;
for (int i = 0; i < CustomBlockDefs.Length; i++)
public Level(string name, ushort width, ushort height, ushort length) {
if (width < 1) width = 1;
if (height < 1) height = 1;
if (length < 1) length = 1;
Width = width; Height = height; Length = length;
for (int i = 0; i < CustomBlockDefs.Length; i++) {
CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
}
LoadCoreProps();
for (int i = 0; i < blockAABBs.Length; i++) {
@ -56,10 +57,10 @@ namespace MCGalaxy {
}
UpdateBlockHandlers();
name = n; MapName = n.ToLower();
this.name = name; MapName = name.ToLower();
BlockDB = new BlockDB(this);
Config.EdgeLevel = (short)(y / 2);
Config.CloudsHeight = (short)(y + 2);
Config.EdgeLevel = (short)(height / 2);
Config.CloudsHeight = (short)(height + 2);
blocks = new byte[Width * Height * Length];
ChunksX = Utils.CeilDiv16(Width);

View File

@ -31,8 +31,7 @@ namespace MCGalaxy.Util {
}
public bool Get(int x, int y, int z) {
int index = (x >> 4) + chunksX *
((z >> 4) + (y >> 4) * chunksZ);
int index = (x >> 4) + chunksX * ((z >> 4) + (y >> 4) * chunksZ);
byte[] chunk = bits[index];
if (chunk == null) return false;
@ -41,8 +40,7 @@ namespace MCGalaxy.Util {
}
public void Set(int x, int y, int z, bool bit) {
int index = (x >> 4) + chunksX *
((z >> 4) + (y >> 4) * chunksZ);
int index = (x >> 4) + chunksX * ((z >> 4) + (y >> 4) * chunksZ);
byte[] chunk = bits[index];
if (chunk == null) {
chunk = new byte[(16 * 16 * 16) / 8];