-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCsCoords.ps1
51 lines (44 loc) · 1.65 KB
/
CsCoords.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$source = @"
using System;
public class McBedrockTool {
public static string GetKeyByCoords(int x, int z, int y = 0, int Dimension = 0, byte Tag = 0x2f) {
// C# doesn't seem to handle negative integer division well, so have to divide a double then floor it
int ChunkX = (int)Math.Floor(x / 16.0);
int ChunkZ = (int)Math.Floor(z / 16.0);
byte SubChunkY = (byte) (y / 16);
string MyKey = HexKey(ChunkX) +
HexKey(ChunkZ) +
(Dimension == 0 ? "" : HexKey(Dimension)) +
HexKey(Tag) +
(Tag == 0x2f ? HexKey(SubChunkY) : "");
return MyKey;
}
public static string HexKey(int i) {
byte[] ByteArray = BitConverter.GetBytes(i);
// Force byte order to little endian no matter the local platform
if (! BitConverter.IsLittleEndian)
Array.Reverse(ByteArray);
return String.Concat(Array.ConvertAll(ByteArray, x => x.ToString("X2")));
}
public static string HexKey(byte i) {
return i.ToString("X2");
}
}
"@
Add-Type -TypeDefinition $source
"Overworld subchunk coordinate"
[McBedrockTool]::GetKeyByCoords(413,54,90)
# 19000000030000002F05
"Negative example"
[McBedrockTool]::GetKeyByCoords(-413,54,90)
# E6FFFFFF030000002F05
"Nether dimension"
[McBedrockTool]::GetKeyByCoords(-413,54,90, -1)
# E6FFFFFF03000000FFFFFFFF2F05
"End dimension"
[McBedrockTool]::GetKeyByCoords(413,-54,90, 1)
# 19000000FCFFFFFF010000002F05
"Overworld block entity data key"
# Y is irrelevant here and Dimension redundant, but I can't use named parameters from PowerShell to C#
[McBedrockTool]::GetKeyByCoords(413,54,90, 0, 50)
# 190000000300000032