The code for creating the grid string becomes quite inaccurate on big maps, where it's wrong by half a grid cell.
I recommend replacing the FormatGridReference function with this function from MagicGridPanel as it is much more accurate. According to this thread they got it from official FP code (https://umod.org/community/magic-grid-panel/26510-not-always-accurate?page=1).
I recommend replacing the FormatGridReference function with this function from MagicGridPanel as it is much more accurate. According to this thread they got it from official FP code (https://umod.org/community/magic-grid-panel/26510-not-always-accurate?page=1).
public static string PositionToGridCoord(Vector3 position) // Credit: MagicGridPanel
{
char chr;
Vector2 vector2 = new Vector2(TerrainMeta.NormalizeX(position.x), TerrainMeta.NormalizeZ(position.z));
float size = TerrainMeta.Size.x / 1024f;
int num = 7;
Vector2 vector21 = (vector2 * size) * (float)num;
float single = Mathf.Floor(vector21.x) + 1f;
float single1 = Mathf.Floor(size * (float)num - vector21.y);
string empty = string.Empty;
float single2 = single / 26f;
float single3 = single % 26f;
if (single3 == 0f)
{
single3 = 26f;
}
if (single2 > 1f)
{
chr = Convert.ToChar(64 + (int)single2);
empty = string.Concat(empty, chr.ToString());
}
chr = Convert.ToChar(64 + (int)single3);
empty = string.Concat(empty, chr.ToString());
return string.Format("{0}{1}", empty, single1);
}