mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Maps shouldn't generate with active water. (Thanks __Tauraiis__)
This commit is contained in:
parent
7a6cd69e85
commit
6e6ca01a5d
@ -104,9 +104,10 @@ namespace MCGalaxy {
|
|||||||
{ green, "\u00033" }, { red, "\u00034" }, { maroon, "\u00035" },
|
{ green, "\u00033" }, { red, "\u00034" }, { maroon, "\u00035" },
|
||||||
{ purple, "\u00036" }, { gold, "\u00037" }, { yellow, "\u00038" },
|
{ purple, "\u00036" }, { gold, "\u00037" }, { yellow, "\u00038" },
|
||||||
{ lime, "\u00039" },
|
{ lime, "\u00039" },
|
||||||
};
|
};
|
||||||
|
|
||||||
static readonly Regex IrcTwoColorCode = new Regex("(\x03\\d{1,2}),\\d{1,2}");
|
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) {
|
public static string IrcToMinecraftColors(string input) {
|
||||||
if (input == null) throw new ArgumentNullException("input");
|
if (input == null) throw new ArgumentNullException("input");
|
||||||
// get rid of background colour component of some IRC colour codes.
|
// get rid of background colour component of some IRC colour codes.
|
||||||
@ -125,12 +126,13 @@ namespace MCGalaxy {
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Escapces then converts colour codes into IRC colour codes. </summary>
|
||||||
public static string MinecraftToIrcColors(string input) {
|
public static string MinecraftToIrcColors(string input) {
|
||||||
if (input == null) throw new ArgumentNullException("input");
|
if (input == null) throw new ArgumentNullException("input");
|
||||||
input = EscapeColors(input);
|
input = EscapeColors(input);
|
||||||
StringBuilder sb = new StringBuilder(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];
|
CustomColor col = ExtColors[i];
|
||||||
if (col.Undefined) continue;
|
if (col.Undefined) continue;
|
||||||
sb.Replace("&" + col.Code, "&" + col.Fallback);
|
sb.Replace("&" + col.Code, "&" + col.Fallback);
|
||||||
@ -142,10 +144,12 @@ namespace MCGalaxy {
|
|||||||
return sb.ToString();
|
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) {
|
public static bool IsStandardColor(char c) {
|
||||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
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) {
|
public static string EscapeColors(string value) {
|
||||||
if (value.IndexOf('%') == -1) return value;
|
if (value.IndexOf('%') == -1) return value;
|
||||||
char[] chars = new char[value.Length];
|
char[] chars = new char[value.Length];
|
||||||
@ -166,6 +170,9 @@ namespace MCGalaxy {
|
|||||||
return new string(chars);
|
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) {
|
public static bool MapColor(ref char color) {
|
||||||
if (IsStandardColor(color)) {
|
if (IsStandardColor(color)) {
|
||||||
if (color >= 'A' && color <= 'F') color += ' ';
|
if (color >= 'A' && color <= 'F') color += ' ';
|
||||||
@ -196,6 +203,7 @@ namespace MCGalaxy {
|
|||||||
return new string(output, 0, usedChars);
|
return new string(output, 0, usedChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static CustomColor[] ExtColors = new CustomColor[256];
|
public static CustomColor[] ExtColors = new CustomColor[256];
|
||||||
|
|
||||||
public static char GetFallback(char c) {
|
public static char GetFallback(char c) {
|
||||||
|
@ -110,7 +110,7 @@ namespace MCGalaxy.Generator {
|
|||||||
|
|
||||||
if (dirtHeight < waterHeight) {
|
if (dirtHeight < waterHeight) {
|
||||||
for (int y = waterHeight; y >= dirtHeight; y--)
|
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--) {
|
for (int y = dirtHeight - 1; y >= 0; y--) {
|
||||||
byte block = (y > dirtHeight * 3 / 4) ? Block.dirt : Block.rock;
|
byte block = (y > dirtHeight * 3 / 4) ? Block.dirt : Block.rock;
|
||||||
|
@ -20,40 +20,49 @@ using System;
|
|||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
/// <summary> Utility methods for reading/writing big endian integers, and fixed length strings. </summary>
|
/// <summary> Utility methods for reading/writing big endian integers, and fixed length strings. </summary>
|
||||||
public static class NetUtils {
|
public static class NetUtils {
|
||||||
|
|
||||||
|
/// <summary> Number of bytes a string occupies in a packet.</summary>
|
||||||
|
public const int StringSize = 64;
|
||||||
|
|
||||||
public const int StringSize = 64;
|
/// <summary> Reads a 16 bit signed integer, big endian form. </summary>
|
||||||
|
|
||||||
public static short ReadI16(byte[] array, int offset) {
|
public static short ReadI16(byte[] array, int offset) {
|
||||||
return (short)(array[offset] << 8 | array[offset + 1]);
|
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) {
|
public static ushort ReadU16(byte[] array, int offset) {
|
||||||
return (ushort)(array[offset] << 8 | array[offset + 1]);
|
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) {
|
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];
|
| 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) {
|
public static void WriteI16(short value, byte[] array, int index) {
|
||||||
array[index++] = (byte)(value >> 8);
|
array[index++] = (byte)(value >> 8);
|
||||||
array[index++] = (byte)(value);
|
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) {
|
public static void WriteU16(ushort value, byte[] array, int index) {
|
||||||
array[index++] = (byte)(value >> 8);
|
array[index++] = (byte)(value >> 8);
|
||||||
array[index++] = (byte)(value);
|
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) {
|
public static void WriteI32(int value, byte[] array, int index) {
|
||||||
array[index++] = (byte)(value >> 24);
|
array[index++] = (byte)(value >> 24);
|
||||||
array[index++] = (byte)(value >> 16);
|
array[index++] = (byte)(value >> 16);
|
||||||
array[index++] = (byte)(value >> 8);
|
array[index++] = (byte)(value >> 8);
|
||||||
array[index++] = (byte)(value);
|
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) {
|
internal static int WritePos(Position pos, byte[] arr, int offset, bool extPos) {
|
||||||
if (!extPos) {
|
if (!extPos) {
|
||||||
WriteI16((short)pos.X, arr, offset + 0);
|
WriteI16((short)pos.X, arr, offset + 0);
|
||||||
@ -65,9 +74,11 @@ namespace MCGalaxy {
|
|||||||
WriteI32((int)pos.Z, arr, offset + 8);
|
WriteI32((int)pos.Z, arr, offset + 8);
|
||||||
}
|
}
|
||||||
return extPos ? 12 : 6;
|
return extPos ? 12 : 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <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) {
|
public unsafe static string ReadString(byte[] data, int offset) {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
char* characters = stackalloc char[StringSize];
|
char* characters = stackalloc char[StringSize];
|
||||||
@ -80,6 +91,9 @@ namespace MCGalaxy {
|
|||||||
return new String(characters, 0, length);
|
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) {
|
public static void Write(string str, byte[] array, int offset, bool hasCP437) {
|
||||||
if (hasCP437) WriteCP437(str, array, offset);
|
if (hasCP437) WriteCP437(str, array, offset);
|
||||||
else WriteAscii(str, array, offset);
|
else WriteAscii(str, array, offset);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user