From 6e6ca01a5d3108f21e6c0b6c281b0115128823e4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 1 May 2017 20:33:19 +1000 Subject: [PATCH] Maps shouldn't generate with active water. (Thanks __Tauraiis__) --- MCGalaxy/Chat/Colors.cs | 14 +++++++++--- MCGalaxy/Generator/AdvNoiseGen.cs | 2 +- MCGalaxy/Network/Utils/NetUtils.cs | 34 +++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/MCGalaxy/Chat/Colors.cs b/MCGalaxy/Chat/Colors.cs index a7430bcd0..05b7a14d6 100644 --- a/MCGalaxy/Chat/Colors.cs +++ b/MCGalaxy/Chat/Colors.cs @@ -104,9 +104,10 @@ namespace MCGalaxy { { green, "\u00033" }, { red, "\u00034" }, { maroon, "\u00035" }, { purple, "\u00036" }, { gold, "\u00037" }, { yellow, "\u00038" }, { lime, "\u00039" }, - }; - + }; static readonly Regex IrcTwoColorCode = new Regex("(\x03\\d{1,2}),\\d{1,2}"); + + /// Converts IRC colour codes into normal colour codes. public static string IrcToMinecraftColors(string input) { if (input == null) throw new ArgumentNullException("input"); // get rid of background colour component of some IRC colour codes. @@ -125,12 +126,13 @@ namespace MCGalaxy { return sb.ToString(); } + /// Escapces then converts colour codes into IRC colour codes. public static string MinecraftToIrcColors(string input) { if (input == null) throw new ArgumentNullException("input"); input = EscapeColors(input); StringBuilder sb = new StringBuilder(input); - for (int i = 0; i < 128; i++) { + for (int i = 0; i < ExtColors.Length; i++) { CustomColor col = ExtColors[i]; if (col.Undefined) continue; sb.Replace("&" + col.Code, "&" + col.Fallback); @@ -142,10 +144,12 @@ namespace MCGalaxy { return sb.ToString(); } + /// Returns whether c is a colour code in 0-9, a-f, or A-F. public static bool IsStandardColor(char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } + /// Converts percentage colour codes to actual/real colour codes. public static string EscapeColors(string value) { if (value.IndexOf('%') == -1) return value; char[] chars = new char[value.Length]; @@ -166,6 +170,9 @@ namespace MCGalaxy { return new string(chars); } + /// Maps internal system colour codes to their actual colour code. + /// Also converts uppercase standard colour codes to lowercase. + /// Whether color was a valid colour code. public static bool MapColor(ref char color) { if (IsStandardColor(color)) { if (color >= 'A' && color <= 'F') color += ' '; @@ -196,6 +203,7 @@ namespace MCGalaxy { return new string(output, 0, usedChars); } + public static CustomColor[] ExtColors = new CustomColor[256]; public static char GetFallback(char c) { diff --git a/MCGalaxy/Generator/AdvNoiseGen.cs b/MCGalaxy/Generator/AdvNoiseGen.cs index a9aacce08..adb4f57d8 100644 --- a/MCGalaxy/Generator/AdvNoiseGen.cs +++ b/MCGalaxy/Generator/AdvNoiseGen.cs @@ -110,7 +110,7 @@ namespace MCGalaxy.Generator { if (dirtHeight < waterHeight) { for (int y = waterHeight; y >= dirtHeight; y--) - lvl.SetTile((ushort)x, (ushort)y, (ushort)z, Block.water); + lvl.SetTile((ushort)x, (ushort)y, (ushort)z, Block.waterstill); } for (int y = dirtHeight - 1; y >= 0; y--) { byte block = (y > dirtHeight * 3 / 4) ? Block.dirt : Block.rock; diff --git a/MCGalaxy/Network/Utils/NetUtils.cs b/MCGalaxy/Network/Utils/NetUtils.cs index f8b2f0efe..1e9b596d0 100644 --- a/MCGalaxy/Network/Utils/NetUtils.cs +++ b/MCGalaxy/Network/Utils/NetUtils.cs @@ -20,40 +20,49 @@ using System; namespace MCGalaxy { /// Utility methods for reading/writing big endian integers, and fixed length strings. public static class NetUtils { + + /// Number of bytes a string occupies in a packet. + public const int StringSize = 64; - public const int StringSize = 64; - + /// Reads a 16 bit signed integer, big endian form. public static short ReadI16(byte[] array, int offset) { return (short)(array[offset] << 8 | array[offset + 1]); } + /// Reads a 16 bit unsigned integer, big endian form. public static ushort ReadU16(byte[] array, int offset) { return (ushort)(array[offset] << 8 | array[offset + 1]); } - + + /// Reads a 32 bit signed integer, big endian form. public static int ReadI32(byte[] array, int offset) { - return array[offset] << 24 | array[offset + 1] << 16 + return array[offset] << 24 | array[offset + 1] << 16 | array[offset + 2] << 8 | array[offset + 3]; } + + /// Writes a 16 bit signed integer, big endian form. public static void WriteI16(short value, byte[] array, int index) { array[index++] = (byte)(value >> 8); array[index++] = (byte)(value); } - + + /// Writes a 16 bit unsigned integer, big endian form. public static void WriteU16(ushort value, byte[] array, int index) { array[index++] = (byte)(value >> 8); array[index++] = (byte)(value); } - + + /// Writes a 32 bit signed integer, big endian form. public static void WriteI32(int value, byte[] array, int index) { array[index++] = (byte)(value >> 24); array[index++] = (byte)(value >> 16); array[index++] = (byte)(value >> 8); array[index++] = (byte)(value); } - - + + /// Writes three (X, Y, Z) either 16 or 32 bit signed integers, big endian form. + /// Number of bytes written. internal static int WritePos(Position pos, byte[] arr, int offset, bool extPos) { if (!extPos) { WriteI16((short)pos.X, arr, offset + 0); @@ -65,9 +74,11 @@ namespace MCGalaxy { WriteI32((int)pos.Z, arr, offset + 8); } return extPos ? 12 : 6; - } + } - + + /// Reads a string of unicode characters. (input is 64 bytes). + /// String length may be less than 64, as string is trimmed of trailing spaces and nuls. public unsafe static string ReadString(byte[] data, int offset) { int length = 0; char* characters = stackalloc char[StringSize]; @@ -80,6 +91,9 @@ namespace MCGalaxy { return new String(characters, 0, length); } + /// Writes a string of unicode characters. (output is 64 bytes). + /// Unicode characters that are unable to be mapped into code page 437 are converted to '?'. + /// If 'hasCP437' is false, characters that cannot be mapped to ASCII are converted to '?'. public static void Write(string str, byte[] array, int offset, bool hasCP437) { if (hasCP437) WriteCP437(str, array, offset); else WriteAscii(str, array, offset);