Serialization/Deserialization of world
This commit is contained in:
10
core/src/main/java/mc/core/serialization/IChunkReader.java
Normal file
10
core/src/main/java/mc/core/serialization/IChunkReader.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package mc.core.serialization;
|
||||
|
||||
import mc.core.world.Chunk;
|
||||
import mc.core.world.Region;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IChunkReader {
|
||||
Chunk read (Region region, int x, int y, int z) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package mc.core.serialization;
|
||||
|
||||
import mc.core.world.Region;
|
||||
import mc.core.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IRegionReaderWriter {
|
||||
|
||||
Region read (int x, int z, World world) throws IOException;
|
||||
void write (Region region) throws IOException;
|
||||
}
|
||||
@@ -43,4 +43,8 @@ public enum Biome {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static Biome getById(int id) {
|
||||
return Biome.values()[id];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,11 @@ import java.io.Serializable;
|
||||
* +-------------+----------------+------------+
|
||||
* | param | range | bits |
|
||||
* +-------------+----------------+------------+
|
||||
* | | | 3 |
|
||||
* +-------------+----------------+------------+
|
||||
* | block_count | 0:4096 | 13 |
|
||||
* +-------------+----------------+------------+
|
||||
* | blocks | array | 24*count |
|
||||
* +-------------+----------------+------------+
|
||||
*
|
||||
* Total: 16 bits header (2 bytes) + 24 * block_count bits (3 * block_count bytes)
|
||||
* Max size: 12290 bytes (~12 Kb per chunk)
|
||||
* Total: 24 * block_count bits (3 * block_count bytes)
|
||||
* Max size: 12288 bytes (~12 Kb per chunk)
|
||||
*
|
||||
*/
|
||||
/* 16x16x16 */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mc.core.world;
|
||||
|
||||
import mc.core.serialization.IRegionReaderWriter;
|
||||
import mc.core.serialization.Serializer;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -29,5 +30,5 @@ public interface Region extends Serializable{
|
||||
Biome getBiomeAt (int x, int z);
|
||||
void setBiome (int x, int z, Biome biome);
|
||||
|
||||
void save(Serializer<Chunk> chunkSerializer, Serializer<Region> regionSerializer) throws IOException;
|
||||
void save(Serializer<Chunk> chunkSerializer, IRegionReaderWriter regionReaderWritter) throws IOException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user