Annotations

This commit is contained in:
TheMode 2021-07-11 03:26:08 +02:00
parent 37b5575484
commit 7cf5821341
5 changed files with 29 additions and 32 deletions

View File

@ -167,8 +167,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @param chunkX the chunk X * @param chunkX the chunk X
* @param chunkZ the chunk Z * @param chunkZ the chunk Z
* @return a {@link CompletableFuture} completed once the chunk has been loaded
*/ */
public abstract CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ); public abstract @NotNull CompletableFuture<@NotNull Chunk> loadChunk(int chunkX, int chunkZ);
/** /**
* Loads the chunk if the chunk is already loaded or if * Loads the chunk if the chunk is already loaded or if
@ -176,9 +177,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @param chunkX the chunk X * @param chunkX the chunk X
* @param chunkZ the chunk Z * @param chunkZ the chunk Z
* @return a {@link CompletableFuture} completed once the chunk has been processed * @return a {@link CompletableFuture} completed once the chunk has been processed, can be null if not loaded
*/ */
public abstract @NotNull CompletableFuture<Chunk> loadOptionalChunk(int chunkX, int chunkZ); public abstract @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(int chunkX, int chunkZ);
/** /**
* Schedules the removal of a {@link Chunk}, this method does not promise when it will be done. * Schedules the removal of a {@link Chunk}, this method does not promise when it will be done.
@ -200,30 +201,29 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* @param chunkZ the chunk Z * @param chunkZ the chunk Z
* @return the chunk at the specified position, null if not loaded * @return the chunk at the specified position, null if not loaded
*/ */
@Nullable public abstract @Nullable Chunk getChunk(int chunkX, int chunkZ);
public abstract Chunk getChunk(int chunkX, int chunkZ);
/** /**
* Saves a {@link Chunk} to permanent storage. * Saves a {@link Chunk} to permanent storage.
* *
* @param chunk the {@link Chunk} to save * @param chunk the {@link Chunk} to save
* @return future called when the chunk is done saving
*/ */
public abstract CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk); public abstract @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk);
/** /**
* Saves multiple chunks to permanent storage. * Saves multiple chunks to permanent storage.
* *
* @param callback optional callback called when the chunks are done saving * @return future called when the chunks are done saving
*/ */
public abstract CompletableFuture<Void> saveChunksToStorage(); public abstract @NotNull CompletableFuture<Void> saveChunksToStorage();
/** /**
* Gets the instance {@link ChunkGenerator}. * Gets the instance {@link ChunkGenerator}.
* *
* @return the {@link ChunkGenerator} of the instance * @return the {@link ChunkGenerator} of the instance
*/ */
@Nullable public abstract @Nullable ChunkGenerator getChunkGenerator();
public abstract ChunkGenerator getChunkGenerator();
/** /**
* Changes the instance {@link ChunkGenerator}. * Changes the instance {@link ChunkGenerator}.
@ -237,8 +237,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* *
* @return an unmodifiable containing all the instance chunks * @return an unmodifiable containing all the instance chunks
*/ */
@NotNull public abstract @NotNull Collection<@NotNull Chunk> getChunks();
public abstract Collection<Chunk> getChunks();
/** /**
* Gets the instance {@link StorageLocation}. * Gets the instance {@link StorageLocation}.
@ -489,9 +488,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
/** /**
* Loads the chunk at the given {@link Point} with a callback. * Loads the chunk at the given {@link Point} with a callback.
* *
* @param point the chunk position * @param point the chunk position
*/ */
public CompletableFuture<Chunk> loadChunk(@NotNull Point point) { public @NotNull CompletableFuture<@NotNull Chunk> loadChunk(@NotNull Point point) {
final int chunkX = ChunkUtils.getChunkCoordinate(point.x()); final int chunkX = ChunkUtils.getChunkCoordinate(point.x());
final int chunkZ = ChunkUtils.getChunkCoordinate(point.z()); final int chunkZ = ChunkUtils.getChunkCoordinate(point.z());
return loadChunk(chunkX, chunkZ); return loadChunk(chunkX, chunkZ);
@ -502,9 +501,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
* at the given {@link Point} with a callback. * at the given {@link Point} with a callback.
* *
* @param point the chunk position * @param point the chunk position
* @return a {@link CompletableFuture} completed once the chunk has been processed * @return a {@link CompletableFuture} completed once the chunk has been processed, null if not loaded
*/ */
public @NotNull CompletableFuture<Chunk> loadOptionalChunk(@NotNull Point point) { public @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(@NotNull Point point) {
final int chunkX = ChunkUtils.getChunkCoordinate(point.x()); final int chunkX = ChunkUtils.getChunkCoordinate(point.x());
final int chunkZ = ChunkUtils.getChunkCoordinate(point.z()); final int chunkZ = ChunkUtils.getChunkCoordinate(point.z());
return loadOptionalChunk(chunkX, chunkZ); return loadOptionalChunk(chunkX, chunkZ);

View File

@ -238,7 +238,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) { public @NotNull CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) {
final Chunk chunk = getChunk(chunkX, chunkZ); final Chunk chunk = getChunk(chunkX, chunkZ);
if (chunk != null) { if (chunk != null) {
// Chunk already loaded // Chunk already loaded
@ -306,17 +306,17 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) { public @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) {
return chunkLoader.saveChunk(chunk); return chunkLoader.saveChunk(chunk);
} }
@Override @Override
public CompletableFuture<Void> saveChunksToStorage() { public @NotNull CompletableFuture<Void> saveChunksToStorage() {
Collection<Chunk> chunksCollection = chunks.values(); Collection<Chunk> chunksCollection = chunks.values();
return chunkLoader.saveChunks(chunksCollection); return chunkLoader.saveChunks(chunksCollection);
} }
protected CompletableFuture<Chunk> retrieveChunk(int chunkX, int chunkZ) { protected @NotNull CompletableFuture<@NotNull Chunk> retrieveChunk(int chunkX, int chunkZ) {
CompletableFuture<Chunk> completableFuture = new CompletableFuture<>(); CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
final Runnable loader = () -> chunkLoader.loadChunk(this, chunkX, chunkZ) final Runnable loader = () -> chunkLoader.loadChunk(this, chunkX, chunkZ)
.whenComplete((chunk, throwable) -> { .whenComplete((chunk, throwable) -> {
@ -331,8 +331,7 @@ public class InstanceContainer extends Instance {
}); });
} else { } else {
// Not present // Not present
createChunk(chunkX, chunkZ).whenComplete((c, t) -> createChunk(chunkX, chunkZ).thenAccept(completableFuture::complete);
completableFuture.complete(c));
} }
}); });
if (chunkLoader.supportsParallelLoading()) { if (chunkLoader.supportsParallelLoading()) {
@ -344,7 +343,7 @@ public class InstanceContainer extends Instance {
return completableFuture; return completableFuture;
} }
protected CompletableFuture<Chunk> createChunk(int chunkX, int chunkZ) { protected @NotNull CompletableFuture<@NotNull Chunk> createChunk(int chunkX, int chunkZ) {
Biome[] biomes = new Biome[Biome.getBiomeCount(getDimensionType())]; Biome[] biomes = new Biome[Biome.getBiomeCount(getDimensionType())];
if (chunkGenerator == null) { if (chunkGenerator == null) {
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0)); Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
@ -365,13 +364,12 @@ public class InstanceContainer extends Instance {
if (chunkGenerator != null && chunk.shouldGenerate()) { if (chunkGenerator != null && chunk.shouldGenerate()) {
// Execute the chunk generator to populate the chunk // Execute the chunk generator to populate the chunk
final ChunkGenerationBatch chunkBatch = new ChunkGenerationBatch(this, chunk); final ChunkGenerationBatch chunkBatch = new ChunkGenerationBatch(this, chunk);
return chunkBatch.generate(chunkGenerator) return chunkBatch.generate(chunkGenerator)
.whenComplete((c, t) -> chunkRegisterCallback.accept(c)); .whenComplete((c, t) -> chunkRegisterCallback.accept(c));
} else { } else {
// No chunk generator, execute the callback with the empty chunk // No chunk generator, execute the callback with the empty chunk
return CompletableFuture.completedFuture(chunk) chunkRegisterCallback.accept(chunk);
.whenComplete((c, t) -> chunkRegisterCallback.accept(c)); return CompletableFuture.completedFuture(chunk);
} }
} }

View File

@ -43,7 +43,7 @@ public class SharedInstance extends Instance {
} }
@Override @Override
public CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) { public @NotNull CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) {
return instanceContainer.loadChunk(chunkX, chunkZ); return instanceContainer.loadChunk(chunkX, chunkZ);
} }
@ -63,12 +63,12 @@ public class SharedInstance extends Instance {
} }
@Override @Override
public CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) { public @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) {
return instanceContainer.saveChunkToStorage(chunk); return instanceContainer.saveChunkToStorage(chunk);
} }
@Override @Override
public CompletableFuture<Void> saveChunksToStorage() { public @NotNull CompletableFuture<Void> saveChunksToStorage() {
return instanceContainer.saveChunksToStorage(); return instanceContainer.saveChunksToStorage();
} }

View File

@ -24,7 +24,7 @@ public class ChunkGenerationBatch extends ChunkBatch {
chunk.setBlock(x, y, z, block); chunk.setBlock(x, y, z, block);
} }
public CompletableFuture<Chunk> generate(@NotNull ChunkGenerator chunkGenerator) { public @NotNull CompletableFuture<@NotNull Chunk> generate(@NotNull ChunkGenerator chunkGenerator) {
final CompletableFuture<Chunk> completableFuture = new CompletableFuture<>(); final CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
BLOCK_BATCH_POOL.execute(() -> { BLOCK_BATCH_POOL.execute(() -> {
synchronized (chunk) { synchronized (chunk) {

View File

@ -31,8 +31,8 @@ public final class ChunkUtils {
* @param eachCallback the optional callback when a chunk get loaded * @param eachCallback the optional callback when a chunk get loaded
* @return a {@link CompletableFuture} completed once all chunks have been processed * @return a {@link CompletableFuture} completed once all chunks have been processed
*/ */
public static CompletableFuture<Chunk> optionalLoadAll(@NotNull Instance instance, long @NotNull [] chunks, public static @NotNull CompletableFuture<@Nullable Chunk> optionalLoadAll(@NotNull Instance instance, long @NotNull [] chunks,
@Nullable ChunkCallback eachCallback) { @Nullable ChunkCallback eachCallback) {
CompletableFuture<Chunk> completableFuture = new CompletableFuture<>(); CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
final int length = chunks.length; final int length = chunks.length;
AtomicInteger counter = new AtomicInteger(0); AtomicInteger counter = new AtomicInteger(0);