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 + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.world.chunk; + +import org.spongepowered.api.world.volume.block.BlockVolume; + +public interface BlockChunk extends BlockVolume { +} diff --git a/src/main/java/org/spongepowered/api/world/chunk/EntityChunk.java b/src/main/java/org/spongepowered/api/world/chunk/EntityChunk.java new file mode 100644 index 0000000000..0ee773db0a --- /dev/null +++ b/src/main/java/org/spongepowered/api/world/chunk/EntityChunk.java @@ -0,0 +1,33 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.world.chunk; + +import org.spongepowered.api.world.volume.entity.EntityVolume; + +/** + * An entity chunk is a portion of a {@link WorldChunk}. + */ +public interface EntityChunk extends EntityVolume.Modifiable { +} diff --git a/src/main/java/org/spongepowered/api/world/volume/entity/EntityVolume.java b/src/main/java/org/spongepowered/api/world/volume/entity/EntityVolume.java index 7d46f1ae8c..3132e5b74d 100644 --- a/src/main/java/org/spongepowered/api/world/volume/entity/EntityVolume.java +++ b/src/main/java/org/spongepowered/api/world/volume/entity/EntityVolume.java @@ -167,7 +167,7 @@ interface Streamable> extends EntityVolume { } - interface Modifiable> extends Streamable, MutableVolume, BlockVolume.Modifiable { + interface Modifiable> extends Streamable, MutableVolume { /** * Create an entity instance at the given position.