diff --git a/src/main/java/org/spongepowered/api/event/world/chunk/ChunkEvent.java b/src/main/java/org/spongepowered/api/event/world/chunk/ChunkEvent.java index 0b50b0c264..f192db6f56 100644 --- a/src/main/java/org/spongepowered/api/event/world/chunk/ChunkEvent.java +++ b/src/main/java/org/spongepowered/api/event/world/chunk/ChunkEvent.java @@ -29,7 +29,9 @@ import org.spongepowered.api.event.Event; import org.spongepowered.api.util.annotation.eventgen.NoFactoryMethod; import org.spongepowered.api.world.World; +import org.spongepowered.api.world.chunk.BlockChunk; import org.spongepowered.api.world.chunk.Chunk; +import org.spongepowered.api.world.chunk.EntityChunk; import org.spongepowered.api.world.chunk.WorldChunk; import org.spongepowered.api.world.server.ServerWorld; import org.spongepowered.math.vector.Vector3i; @@ -64,41 +66,116 @@ interface WorldScoped extends ChunkEvent { } /** - * Called when a {@link WorldChunk chunk} was unloaded. + * Called when a {@link WorldChunk chunk} is performing a block related operation. */ - interface Unload extends WorldScoped { + interface Blocks extends WorldScoped { /** - * Called before the {@link WorldChunk chunk} is unloaded. + * Called when a block data of {@link WorldChunk chunk} is loaded. + * This can be called outside the {@link World#engine() main} {@link Thread}. + * It is NOT safe to perform modifications to the {@link World} or via + * {@link org.spongepowered.api.world.server.ServerLocation} as this could + * result in a deadlock. */ - interface Pre extends Unload { + interface Load extends Blocks { /** - * Gets the {@link WorldChunk chunk} being changed. + * Gets the {@link WorldChunk chunk} block volume. * - * @return The chunk + * @return The block volume */ - WorldChunk chunk(); + BlockChunk blockVolume(); } /** - * Called after the {@link WorldChunk chunk} is unloaded. + * Called when a {@link WorldChunk chunk} is performing a block related save. */ - interface Post extends Unload { + interface Save extends Blocks { + + /** + * Called before the {@link WorldChunk chunk} block data is saved. Cancelling this + * will prevent any of the chunk's block data being written to it's storage container. + */ + interface Pre extends Save, Cancellable { + /** + * Gets the {@link WorldChunk chunk} block volume. + * + * @return The block volume + */ + BlockChunk blockVolume(); + } + + /** + * Called after the {@link WorldChunk chunk} block data is saved. + * Guaranteed to exist in the chunk's block storage container. + *
+ * Depending on the implementation, this event may be called off-thread. + */ + interface Post extends Save {} } } /** - * Called when a {@link WorldChunk chunk} is performing a save. + * Called when a {@link WorldChunk chunk} is performing a entity related operation. */ - interface Save extends WorldScoped { + interface Entities extends WorldScoped { + + /** + * Called when an entity data of {@link WorldChunk chunk} is loaded. + * This can be called outside the {@link World#engine() main} {@link Thread}. + * It is NOT safe to perform modifications to the {@link World} or via + * {@link org.spongepowered.api.world.server.ServerLocation} as this could + * result in a deadlock. + */ + interface Load extends Entities { + + /** + * Gets the {@link WorldChunk chunk} entity volume. + * + * @return The entity volume + */ + EntityChunk entityVolume(); + } /** - * Called before the {@link WorldChunk chunk} is saved. Cancelling this will prevent any of - * the chunk's data being written to it's storage container. + * Called when a {@link WorldChunk chunk} is performing a entity related save. */ - interface Pre extends Save, Cancellable { + interface Save extends Entities { + + /** + * Called before the {@link WorldChunk chunk} entity data is saved. Cancelling this + * will prevent any of the chunk's entity data being written to it's storage container. + */ + interface Pre extends Save, Cancellable { + + /** + * Gets the {@link WorldChunk chunk} entity volume. + * + * @return The entity volume + */ + EntityChunk entityVolume(); + } + + /** + * Called after the {@link WorldChunk chunk} entity data is saved. + * Guaranteed to exist in the chunk's entity storage container. + *
+ * Depending on the implementation, this event may be called off-thread. + */ + interface Post extends Save {} + } + } + + /** + * Called when a {@link WorldChunk chunk} was unloaded. + */ + interface Unload extends WorldScoped { + + /** + * Called before the {@link WorldChunk chunk} is unloaded. + */ + interface Pre extends Unload { /** * Gets the {@link WorldChunk chunk} being changed. @@ -106,16 +183,14 @@ interface Pre extends Save, Cancellable { * @return The chunk */ WorldChunk chunk(); - } /** - * Called after the {@link WorldChunk chunk} is saved. Guaranteed to exist in the chunk's - * storage container. - *
- * Depending on the implementation, this event may be called off-thread.
+ * Called after the {@link WorldChunk chunk} is unloaded.
*/
- interface Post extends Save {}
+ interface Post extends Unload {
+
+ }
}
/**
@@ -126,11 +201,8 @@ interface Generated extends WorldScoped {
}
/**
- * Called when a {@link WorldChunk chunk} is loaded. This can be called
- * outside the {@link World#engine() main} {@link Thread}. It is NOT safe
- * to perform modifications to the {@link World} or via
- * {@link org.spongepowered.api.world.server.ServerLocation} as this could
- * result in a deadlock.
+ * Called when a {@link WorldChunk chunk} is loaded. This is called
+ * from the main thread when the chunk is fully loaded and ready to tick.
*/
interface Load extends WorldScoped {
diff --git a/src/main/java/org/spongepowered/api/world/chunk/BlockChunk.java b/src/main/java/org/spongepowered/api/world/chunk/BlockChunk.java
new file mode 100644
index 0000000000..be3473aca8
--- /dev/null
+++ b/src/main/java/org/spongepowered/api/world/chunk/BlockChunk.java
@@ -0,0 +1,30 @@
+/*
+ * This file is part of SpongeAPI, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) SpongePowered