Fixed y >= 128 serialization in chunks

This commit is contained in:
jglrxavpok 2020-05-02 16:16:14 +02:00
parent 2bd5b1786b
commit bfc3975750
2 changed files with 12 additions and 14 deletions

View File

@ -179,7 +179,7 @@ public class Chunk implements Viewable {
}
protected CustomBlock getCustomBlock(int index) {
byte[] pos = SerializerUtils.indexToChunkPosition(index);
int[] pos = SerializerUtils.indexToChunkPosition(index);
return getCustomBlock(pos[0], pos[1], pos[2]);
}
@ -237,10 +237,10 @@ public class Chunk implements Viewable {
this.updatableBlocksLastUpdate.put(index, time); // Refresh last update time
byte[] blockPos = SerializerUtils.indexToChunkPosition(index);
byte x = blockPos[0];
byte y = blockPos[1];
byte z = blockPos[2];
int[] blockPos = SerializerUtils.indexToChunkPosition(index);
int x = blockPos[0];
int y = blockPos[1];
int z = blockPos[2];
BlockPosition blockPosition = new BlockPosition(x + 16 * chunkX, y, z + 16 * chunkZ);
Data data = getData(index);

View File

@ -29,18 +29,16 @@ public class SerializerUtils {
return index & 0xffff;
}
public static byte[] indexToChunkPosition(int index) {
byte z = (byte) (index >> 12 & 0xF);
byte y = (byte) (index >> 4 & 0xFF);
byte x = (byte) (index >> 0 & 0xF);
return new byte[]{x, y, z};
public static int[] indexToChunkPosition(int index) {
int z = (byte) (index >> 12 & 0xF);
int y = (index >>> 4 & 0xFF);
int x = (byte) (index >> 0 & 0xF);
return new int[]{x, y, z};
}
public static BlockPosition indexToChunkBlockPosition(int index) {
byte z = (byte) (index >> 12 & 0xF);
byte y = (byte) (index >> 4 & 0xFF);
byte x = (byte) (index >> 0 & 0xF);
return new BlockPosition(x, y, z);
int[] pos = indexToChunkPosition(index);
return new BlockPosition(pos[0], pos[1], pos[2]);
}
public static long positionToLong(int x, int y, int z) {