Maps shouldn't generate with active water. (Thanks __Tauraiis__)

This commit is contained in:
UnknownShadow200 2017-05-01 20:33:19 +10:00
parent 7a6cd69e85
commit 6e6ca01a5d
3 changed files with 36 additions and 14 deletions

View File

@ -105,8 +105,9 @@ namespace MCGalaxy {
{ purple, "\u00036" }, { gold, "\u00037" }, { yellow, "\u00038" },
{ lime, "\u00039" },
};
static readonly Regex IrcTwoColorCode = new Regex("(\x03\\d{1,2}),\\d{1,2}");
/// <summary> Converts IRC colour codes into normal colour codes. </summary>
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();
}
/// <summary> Escapces then converts colour codes into IRC colour codes. </summary>
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();
}
/// <summary> Returns whether c is a colour code in 0-9, a-f, or A-F. </summary>
public static bool IsStandardColor(char c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
/// <summary> Converts percentage colour codes to actual/real colour codes. </summary>
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);
}
/// <summary> Maps internal system colour codes to their actual colour code. </summary>
/// <remarks> Also converts uppercase standard colour codes to lowercase. </remarks>
/// <returns> Whether color was a valid colour code. </returns>
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) {

View File

@ -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;

View File

@ -21,31 +21,39 @@ namespace MCGalaxy {
/// <summary> Utility methods for reading/writing big endian integers, and fixed length strings. </summary>
public static class NetUtils {
/// <summary> Number of bytes a string occupies in a packet.</summary>
public const int StringSize = 64;
/// <summary> Reads a 16 bit signed integer, big endian form. </summary>
public static short ReadI16(byte[] array, int offset) {
return (short)(array[offset] << 8 | array[offset + 1]);
}
/// <summary> Reads a 16 bit unsigned integer, big endian form. </summary>
public static ushort ReadU16(byte[] array, int offset) {
return (ushort)(array[offset] << 8 | array[offset + 1]);
}
/// <summary> Reads a 32 bit signed integer, big endian form. </summary>
public static int ReadI32(byte[] array, int offset) {
return array[offset] << 24 | array[offset + 1] << 16
| array[offset + 2] << 8 | array[offset + 3];
}
/// <summary> Writes a 16 bit signed integer, big endian form. </summary>
public static void WriteI16(short value, byte[] array, int index) {
array[index++] = (byte)(value >> 8);
array[index++] = (byte)(value);
}
/// <summary> Writes a 16 bit unsigned integer, big endian form. </summary>
public static void WriteU16(ushort value, byte[] array, int index) {
array[index++] = (byte)(value >> 8);
array[index++] = (byte)(value);
}
/// <summary> Writes a 32 bit signed integer, big endian form. </summary>
public static void WriteI32(int value, byte[] array, int index) {
array[index++] = (byte)(value >> 24);
array[index++] = (byte)(value >> 16);
@ -53,7 +61,8 @@ namespace MCGalaxy {
array[index++] = (byte)(value);
}
/// <summary> Writes three (X, Y, Z) either 16 or 32 bit signed integers, big endian form. </summary>
/// <returns> Number of bytes written. </returns>
internal static int WritePos(Position pos, byte[] arr, int offset, bool extPos) {
if (!extPos) {
WriteI16((short)pos.X, arr, offset + 0);
@ -68,6 +77,8 @@ namespace MCGalaxy {
}
/// <summary> Reads a string of unicode characters. (input is 64 bytes). </summary>
/// <remarks> String length may be less than 64, as string is trimmed of trailing spaces and nuls. </remarks>
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);
}
/// <summary> Writes a string of unicode characters. (output is 64 bytes). </summary>
/// <remarks> Unicode characters that are unable to be mapped into code page 437 are converted to '?'. </remarks>
/// <remarks> If 'hasCP437' is false, characters that cannot be mapped to ASCII are converted to '?'. </remarks>
public static void Write(string str, byte[] array, int offset, bool hasCP437) {
if (hasCP437) WriteCP437(str, array, offset);
else WriteAscii(str, array, offset);