A few comments

This commit is contained in:
themode 2020-08-30 21:42:21 +02:00
parent 38dbaecb8f
commit 588b1f9c6d
4 changed files with 36 additions and 11 deletions

View File

@ -80,6 +80,12 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
// Pathfinder
private final PFInstanceSpace instanceSpace = new PFInstanceSpace(this);
/**
* Create a new instance
*
* @param uniqueId the unique id of the instance
* @param dimensionType the dimension type of the instance
*/
public Instance(UUID uniqueId, DimensionType dimensionType) {
this.uniqueId = uniqueId;
this.dimensionType = dimensionType;

View File

@ -66,21 +66,28 @@ public class InstanceContainer extends Instance {
@Setter
private BiFunction<Integer, Integer, BlockProvider> chunkDecider;
/**
* Create an {@link InstanceContainer}
*
* @param uniqueId the unique id of the instance
* @param dimensionType the dimension type of the instance
* @param storageFolder the {@link StorageFolder} of the instance,
* can be null if you do not wish to save the instance latter on
*/
public InstanceContainer(UUID uniqueId, DimensionType dimensionType, StorageFolder storageFolder) {
super(uniqueId, dimensionType);
this.storageFolder = storageFolder;
chunkLoader = new MinestomBasicChunkLoader(storageFolder);
this.chunkLoader = new MinestomBasicChunkLoader(storageFolder);
if (storageFolder == null) {
return;
// Get instance data from the saved data if a StorageFolder is defined
if (storageFolder != null) {
// Retrieve instance data
this.uniqueId = storageFolder.getOrDefault(UUID_KEY, UUID.class, uniqueId);
final Data data = storageFolder.getOrDefault(DATA_KEY, SerializableData.class, null);
setData(data);
}
// Retrieve instance data
this.uniqueId = storageFolder.getOrDefault(UUID_KEY, UUID.class, uniqueId);
final Data data = storageFolder.getOrDefault(DATA_KEY, SerializableData.class, null);
setData(data);
}
@Override

View File

@ -17,6 +17,15 @@ public class ChunkReader {
private static final BiomeManager BIOME_MANAGER = MinecraftServer.getBiomeManager();
/**
* Read a chunk from a byte array, the array should contain the whole chunk and only it
*
* @param b the byte array containing the chunk
* @param instance the instance of the chunk
* @param chunkX the chunk X
* @param chunkZ the chunk Z
* @param callback the consumer called once the chunk has been read
*/
public static void readChunk(byte[] b, Instance instance, int chunkX, int chunkZ, Consumer<Chunk> callback) {
BinaryReader binaryReader = new BinaryReader(b);
@ -26,8 +35,10 @@ public class ChunkReader {
ChunkBatch chunkBatch = null;
try {
// Get if the chunk has data indexes (used for blocks data)
final boolean hasIndex = binaryReader.readBoolean();
if (hasIndex) {
// Get the data indexes which will be used to read all the individual data
typeToIndexMap = DataReader.readDataIndexes(binaryReader);
}

View File

@ -4,7 +4,8 @@ import net.minestom.server.storage.StorageOptions;
import net.minestom.server.storage.StorageSystem;
import org.rocksdb.*;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
* A storage system which is local using OS files system
@ -20,7 +21,7 @@ public class FileStorageSystem implements StorageSystem {
@Override
public boolean exists(String folderPath) {
return new File(folderPath).exists();
return Files.isDirectory(Paths.get(folderPath));
}
@Override