Merge pull request #46 from Nesaak/master

Use block index in chunk serialization
This commit is contained in:
TheMode 2020-09-02 22:37:30 +02:00 committed by GitHub
commit 58fa4cff1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View File

@ -12,6 +12,7 @@ import net.minestom.server.instance.block.UpdateConsumer;
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.world.biomes.Biome;
import java.util.concurrent.CopyOnWriteArraySet;
@ -175,9 +176,7 @@ public class DynamicChunk extends Chunk {
continue;
// Chunk coordinates
binaryWriter.writeByte(x);
binaryWriter.writeShort(y);
binaryWriter.writeByte(z);
binaryWriter.writeShort((short) ChunkUtils.getBlockIndex(x, y, z));
// Block ids
binaryWriter.writeShort(blockStateId);

View File

@ -8,6 +8,7 @@ import net.minestom.server.instance.DynamicChunk;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.batch.ChunkBatch;
import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.world.biomes.Biome;
import net.minestom.server.world.biomes.BiomeManager;
@ -54,9 +55,10 @@ public class ChunkReader {
while (true) {
// Position
final byte x = binaryReader.readByte();
final short y = binaryReader.readShort();
final byte z = binaryReader.readByte();
final short index = binaryReader.readShort();
final byte x = ChunkUtils.blockIndexToChunkPositionX(index);
final short y = ChunkUtils.blockIndexToChunkPositionY(index);
final byte z = ChunkUtils.blockIndexToChunkPositionZ(index);
// Block type
final short blockStateId = binaryReader.readShort();

View File

@ -223,8 +223,8 @@ public final class ChunkUtils {
* @param index an index computed from {@link #getBlockIndex(int, int, int)}
* @return the chunk position X (O-15) of the specified index
*/
public static int blockIndexToChunkPositionX(int index) {
return blockIndexToPositionX(index, 0);
public static byte blockIndexToChunkPositionX(int index) {
return (byte) blockIndexToPositionX(index, 0);
}
/**
@ -233,8 +233,8 @@ public final class ChunkUtils {
* @param index an index computed from {@link #getBlockIndex(int, int, int)}
* @return the chunk position Y (O-255) of the specified index
*/
public static int blockIndexToChunkPositionY(int index) {
return blockIndexToPositionY(index);
public static short blockIndexToChunkPositionY(int index) {
return (short) blockIndexToPositionY(index);
}
/**
@ -243,8 +243,8 @@ public final class ChunkUtils {
* @param index an index computed from {@link #getBlockIndex(int, int, int)}
* @return the chunk position Z (O-15) of the specified index
*/
public static int blockIndexToChunkPositionZ(int index) {
return blockIndexToPositionZ(index, 0);
public static byte blockIndexToChunkPositionZ(int index) {
return (byte) blockIndexToPositionZ(index, 0);
}
}