Made Chunk#getSerializedData public

This commit is contained in:
themode 2020-09-03 00:04:10 +02:00
parent 181c2b2b1b
commit 4b8ab2e55e
4 changed files with 15 additions and 4 deletions

View File

@ -240,9 +240,9 @@ public abstract class Chunk implements Viewable {
/**
* Serialize the chunk
*
* @return the serialized chunk
* @return the serialized chunk, can potentially be null if this chunk cannot be serialized
*/
protected abstract byte[] getSerializedData();
public abstract byte[] getSerializedData();
/**
* Get a {@link ChunkDataPacket} which should contain the full chunk

View File

@ -10,11 +10,13 @@ import net.minestom.server.entity.pathfinding.PFBlockDescription;
import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.instance.block.UpdateConsumer;
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
import net.minestom.server.reader.ChunkReader;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.world.biomes.Biome;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Consumer;
public class DynamicChunk extends Chunk {
@ -150,8 +152,15 @@ public class DynamicChunk extends Chunk {
this.blocksStateId[blockIndex] = blockStateId;
}
/**
* Serialize this {@link Chunk} based on {@link ChunkReader#readChunk(byte[], Instance, int, int, Consumer)}
* <p>
* It is also used by the default {@link IChunkLoader} which is {@link MinestomBasicChunkLoader}
*
* @return the serialized chunk data
*/
@Override
protected byte[] getSerializedData() {
public byte[] getSerializedData() {
// Used for blocks data
Object2ShortMap<String> typeToIndexMap = new Object2ShortOpenHashMap<>();

View File

@ -58,7 +58,7 @@ public class StaticChunk extends Chunk {
}
@Override
protected byte[] getSerializedData() {
public byte[] getSerializedData() {
return null;
}

View File

@ -20,6 +20,8 @@ public class ChunkReader {
/**
* Read a chunk from a byte array, the array should contain the whole chunk and only it
* <p>
* By default you can retrieve this byte array using {@link DynamicChunk#getSerializedData()}
*
* @param b the byte array containing the chunk
* @param instance the instance of the chunk