-
-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add region files API #2466
Add region files API #2466
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* 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.data.persistence.DataContainer; | ||
import org.spongepowered.api.data.persistence.DataSerializable; | ||
import org.spongepowered.math.vector.Vector3i; | ||
|
||
/** | ||
* Represents an offline chunk and its data. | ||
* The chunk may also be currently loaded! | ||
*/ | ||
public interface OfflineChunk extends DataSerializable { | ||
|
||
/** | ||
* Returns the chunk position. | ||
* | ||
* @return the chunk position | ||
*/ | ||
Vector3i chunkPosition(); | ||
|
||
/** | ||
* Returns the offline chunk data. | ||
* | ||
* @return the offline chunk data | ||
*/ | ||
@Override | ||
DataContainer toContainer(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.spongepowered.api.world.World; | ||
import org.spongepowered.api.world.WorldType; | ||
import org.spongepowered.api.world.WorldTypes; | ||
import org.spongepowered.api.world.chunk.OfflineChunk; | ||
import org.spongepowered.api.world.chunk.WorldChunk; | ||
import org.spongepowered.api.world.explosion.Explosion; | ||
import org.spongepowered.api.world.generation.ChunkGenerator; | ||
|
@@ -50,6 +51,7 @@ | |
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
public interface ServerWorld extends World<ServerWorld, ServerLocation>, Identifiable, InteractableVolume, | ||
ServerLocationCreator, WeatherUniverse.Mutable { | ||
|
@@ -235,4 +237,29 @@ default boolean restoreSnapshot(final Vector3i position, final BlockSnapshot sna | |
*/ | ||
ChunkManager chunkManager(); | ||
|
||
/** | ||
* Returns a stream of existing chunk positions for this world. | ||
* <p> | ||
* Note that consuming the stream is slow, consider consuming it asynchronously. | ||
* <p> | ||
* The stream must be closed or fully consumed otherwise file handles may stay open. | ||
* | ||
* @return The stream of existing chunk positions. | ||
*/ | ||
Stream<Vector3i> chunkPositions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so how about this instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems fine |
||
|
||
|
||
/** | ||
* Returns a stream of existing chunks for this world. | ||
* <p> | ||
* Note that consuming the stream is very slow, consider consuming it asynchronously. | ||
* <p> | ||
* The stream must be closed or fully consumed otherwise file handles may stay open. | ||
* <p> | ||
* You should not modify data of currently loaded chunks. | ||
* | ||
* @return The stream of existing chunks. | ||
*/ | ||
Stream<OfflineChunk> offlineChunks(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this if you want the chunk data too |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd almost want to have a StorageHandler interface to deal with this so that it's not directly exposed in the API, but can be something exposed for "vanilla" kinds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not always guaranteed that the world has region files (like mods) that could be storing chunks in a different region handler that we simply won't be able to directly interface with.