Skip to content

Commit f8f8e28

Browse files
author
Daniel Naylor
committed
Refactor Chunk and Volume
There have been multiple renames to more accurately reflect what the objects represent. Particularly of note: * ProtoWorld is now WorldLike * Chunk is now WorldChunk * ProtoChunk is now Chunk (as it is the basic chunk) * PrimitiveChunk is now a GenerationChunk * ChunkVolume no longer implements BlockVolume, just Volume * Volume methods that return block co-ordinates are renamed to not include the word "block" to reduce confusion, as they return positions, not blocks * ChunkEvent has a WorldScoped subinterface that most chunk events now implement. * regenerateChunk has been moved from ServerLevel to ChunkManager and now returns a completable future.
1 parent 3d6d04b commit f8f8e28

File tree

21 files changed

+542
-422
lines changed

21 files changed

+542
-422
lines changed

src/main/java/org/spongepowered/api/event/cause/entity/SpawnTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.spongepowered.api.registry.RegistryScopes;
4242
import org.spongepowered.api.registry.RegistryTypes;
4343
import org.spongepowered.api.world.World;
44-
import org.spongepowered.api.world.chunk.Chunk;
44+
import org.spongepowered.api.world.chunk.WorldChunk;
4545
import org.spongepowered.api.world.weather.WeatherType;
4646
import org.spongepowered.plugin.PluginContainer;
4747

@@ -68,7 +68,7 @@ public final class SpawnTypes {
6868
public static final DefaultedRegistryReference<SpawnType> BREEDING = SpawnTypes.key(ResourceKey.sponge("breeding"));
6969

7070
/**
71-
* An entity spawned due to a {@link Chunk} being loaded.
71+
* An entity spawned due to a {@link WorldChunk} being loaded.
7272
*/
7373
public static final DefaultedRegistryReference<SpawnType> CHUNK_LOAD = SpawnTypes.key(ResourceKey.sponge("chunk_load"));
7474

src/main/java/org/spongepowered/api/event/world/chunk/ChunkEvent.java

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,71 @@
2727
import org.spongepowered.api.ResourceKey;
2828
import org.spongepowered.api.event.Cancellable;
2929
import org.spongepowered.api.event.Event;
30-
import org.spongepowered.api.world.World;
30+
import org.spongepowered.api.util.annotation.eventgen.NoFactoryMethod;
3131
import org.spongepowered.api.world.chunk.Chunk;
32+
import org.spongepowered.api.world.chunk.WorldChunk;
33+
import org.spongepowered.api.world.server.ServerWorld;
3234
import org.spongepowered.math.vector.Vector3i;
3335

3436
public interface ChunkEvent extends Event {
3537

3638
/**
37-
* Gets the {@link ResourceKey} of the {@link World} that the {@link Chunk} resides in.
39+
* Gets the position of the {@link Chunk}, in chunk co-ordinates.
3840
*
39-
* @return The key
41+
* @return the position
4042
*/
41-
ResourceKey chunkWorld();
43+
Vector3i chunkPosition();
4244

4345
/**
44-
* Gets the position of the {@link Chunk}.
45-
*
46-
* @return the position
46+
* Represents an event that has knowledge about the {@link ServerWorld} that
47+
* is being operated upon.
4748
*/
48-
Vector3i chunkPosition();
49+
@NoFactoryMethod
50+
interface WorldScoped extends ChunkEvent {
51+
52+
/**
53+
* Gets the {@link ResourceKey} of the {@link WorldScoped} that the
54+
* {@link WorldChunk} resides in.
55+
*
56+
* <p>Be careful when retrieving the {@link ServerWorld} within this
57+
* event as some events may not fire on the main thread and such world
58+
* access is not thread safe.</p>
59+
*
60+
* @return The world's {@link ResourceKey}
61+
*/
62+
ResourceKey worldKey();
63+
64+
}
4965

5066
/**
51-
* Called when a {@link Chunk} was unloaded.
67+
* Called when a {@link WorldChunk} was unloaded.
5268
*/
53-
interface Unload extends ChunkEvent {
69+
interface Unload extends WorldScoped {
5470

5571
}
5672

5773
/**
58-
* Called when a {@link Chunk} is performing a save.
74+
* Called when a {@link WorldChunk} is performing a save.
5975
*/
60-
interface Save extends ChunkEvent {
76+
interface Save extends WorldScoped {
6177

6278
/**
63-
* Called before the {@link Chunk} is saved. Cancelling this will prevent any of
79+
* Called before the {@link WorldChunk} is saved. Cancelling this will prevent any of
6480
* the chunk's data being written to it's storage container.
6581
*/
6682
interface Pre extends Save, Cancellable {
6783

6884
/**
69-
* Gets the {@link Chunk} being changed.
85+
* Gets the {@link WorldChunk} being changed.
7086
*
7187
* @return The Chunk
7288
*/
73-
Chunk targetChunk();
89+
WorldChunk targetChunk();
7490

7591
}
7692

7793
/**
78-
* Called after the {@link Chunk} is saved. Guaranteed to exist in the chunk's
94+
* Called after the {@link WorldChunk} is saved. Guaranteed to exist in the chunk's
7995
* storage container.
8096
*
8197
* Depending on the implementation, this event may be called off-thread.
@@ -84,22 +100,22 @@ interface Post extends Save {}
84100
}
85101

86102
/**
87-
* Called when a new {@link Chunk} was generated.
103+
* Called when a new {@link WorldChunk} was generated.
88104
*/
89-
interface Generated extends ChunkEvent {
105+
interface Generated extends WorldScoped {
90106

91107
}
92108

93109
/**
94-
* Called when a {@link Chunk} is done loading.
110+
* Called when a {@link WorldChunk} is done loading.
95111
*/
96-
interface Load extends ChunkEvent {
112+
interface Load extends WorldScoped {
97113

98114
/**
99-
* Gets the {@link Chunk} being changed.
115+
* Gets the {@link WorldChunk} being changed.
100116
*
101117
* @return The Chunk
102118
*/
103-
Chunk targetChunk();
119+
WorldChunk targetChunk();
104120
}
105121
}

src/main/java/org/spongepowered/api/world/World.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.spongepowered.api.registry.ScopedRegistryHolder;
3434
import org.spongepowered.api.service.context.ContextSource;
3535
import org.spongepowered.api.util.annotation.DoNotStore;
36-
import org.spongepowered.api.world.chunk.Chunk;
36+
import org.spongepowered.api.world.chunk.WorldChunk;
3737
import org.spongepowered.api.world.storage.WorldProperties;
3838
import org.spongepowered.api.world.volume.archetype.ArchetypeVolumeCreator;
3939
import org.spongepowered.api.world.volume.block.PhysicsAwareMutableBlockVolume;
@@ -52,7 +52,7 @@
5252
@DoNotStore
5353
public interface World<W extends World<W, L>, L extends Location<W, L>> extends
5454
ForwardingAudience,
55-
ProtoWorld<W>,
55+
WorldLike<W>,
5656
LocationCreator<W, L>,
5757
PhysicsAwareMutableBlockVolume<W>,
5858
ContextSource,
@@ -128,8 +128,8 @@ default Optional<? extends Player> closestPlayer(final int x, final int y, final
128128

129129
/**
130130
* {@inheritDoc}
131-
* This gets a guaranteed {@link Chunk} at the desired block position; however,
132-
* the {@link Chunk} instance may be {@link Chunk#isEmpty() empty}, and
131+
* This gets a guaranteed {@link WorldChunk} at the desired block position; however,
132+
* the {@link WorldChunk} instance may be {@link WorldChunk#isEmpty() empty}, and
133133
* likewise, may not be generated, valid, pre-existing. It is important to
134134
* check for these cases prior to attempting to modify the chunk.
135135
*
@@ -141,12 +141,12 @@ default Optional<? extends Player> closestPlayer(final int x, final int y, final
141141
* @return The available chunk at that position
142142
*/
143143
@Override
144-
Chunk chunkAtBlock(final Vector3i blockPosition);
144+
WorldChunk chunkAtBlock(final Vector3i blockPosition);
145145

146146
/**
147147
* {@inheritDoc}
148-
* This gets a guaranteed {@link Chunk} at the desired block position; however,
149-
* the {@link Chunk} instance may be {@link Chunk#isEmpty() empty}, and
148+
* This gets a guaranteed {@link WorldChunk} at the desired block position; however,
149+
* the {@link WorldChunk} instance may be {@link WorldChunk#isEmpty() empty}, and
150150
* likewise, may not be generated, valid, pre-existing. It is important to
151151
* check for these cases prior to attempting to modify the chunk.
152152
*
@@ -160,28 +160,28 @@ default Optional<? extends Player> closestPlayer(final int x, final int y, final
160160
* @return The available chunk at that position
161161
*/
162162
@Override
163-
Chunk chunkAtBlock(int bx, int by, int bz);
163+
WorldChunk chunkAtBlock(int bx, int by, int bz);
164164

165165
/**
166166
* {@inheritDoc}
167-
* This gets a guaranteed {@link Chunk} at the desired chunk position; however,
168-
* the {@link Chunk} instance may be {@link Chunk#isEmpty() empty}, and
167+
* This gets a guaranteed {@link WorldChunk} at the desired chunk position; however,
168+
* the {@link WorldChunk} instance may be {@link WorldChunk#isEmpty() empty}, and
169169
* likewise, may not be generated, valid, pre-existing. It is important to
170170
* check for these cases prior to attempting to modify the chunk.
171171
*
172172
* @param chunkPos The chunk position relative to the {@link Server#chunkLayout() chunk layout}
173173
* @return The available chunk at that position
174174
*/
175175
@Override
176-
default Chunk chunk(final Vector3i chunkPos) {
176+
default WorldChunk chunk(final Vector3i chunkPos) {
177177
Objects.requireNonNull(chunkPos, "chunkPos");
178178
return this.chunk(chunkPos.x(), chunkPos.y(), chunkPos.z());
179179
}
180180

181181
/**
182182
* {@inheritDoc}
183-
* This gets a guaranteed {@link Chunk} at the desired chunk position; however,
184-
* the {@link Chunk} instance may be {@link Chunk#isEmpty() empty}, and
183+
* This gets a guaranteed {@link WorldChunk} at the desired chunk position; however,
184+
* the {@link WorldChunk} instance may be {@link WorldChunk#isEmpty() empty}, and
185185
* likewise, may not be generated, valid, pre-existing. It is important to
186186
* check for these cases prior to attempting to modify the chunk.
187187
*
@@ -191,7 +191,7 @@ default Chunk chunk(final Vector3i chunkPos) {
191191
* @return The available chunk at the chunk position
192192
*/
193193
@Override
194-
Chunk chunk(int cx, int cy, int cz);
194+
WorldChunk chunk(int cx, int cy, int cz);
195195

196196
/**
197197
* Gets the chunk at the given chunk coordinate position if it exists or if
@@ -201,7 +201,7 @@ default Chunk chunk(final Vector3i chunkPos) {
201201
* @param shouldGenerate True to generate a new chunk
202202
* @return The loaded or generated chunk, if already generated
203203
*/
204-
default Optional<Chunk> loadChunk(final Vector3i chunkPosition, final boolean shouldGenerate) {
204+
default Optional<WorldChunk> loadChunk(final Vector3i chunkPosition, final boolean shouldGenerate) {
205205
Objects.requireNonNull(chunkPosition, "chunkPosition");
206206
return this.loadChunk(chunkPosition.x(), chunkPosition.y(), chunkPosition.z(), shouldGenerate);
207207
}
@@ -218,7 +218,7 @@ default Optional<Chunk> loadChunk(final Vector3i chunkPosition, final boolean sh
218218
* @param shouldGenerate True to generate a new chunk
219219
* @return The loaded or generated chunk, if already generated
220220
*/
221-
Optional<Chunk> loadChunk(int cx, int cy, int cz, boolean shouldGenerate);
221+
Optional<WorldChunk> loadChunk(int cx, int cy, int cz, boolean shouldGenerate);
222222

223223
/**
224224
* Returns a Collection of all actively loaded chunks in this world.
@@ -227,6 +227,6 @@ default Optional<Chunk> loadChunk(final Vector3i chunkPosition, final boolean sh
227227
*
228228
* @return The loaded chunks
229229
*/
230-
Iterable<Chunk> loadedChunks();
230+
Iterable<WorldChunk> loadedChunks();
231231

232232
}

src/main/java/org/spongepowered/api/world/ProtoWorld.java renamed to src/main/java/org/spongepowered/api/world/WorldLike.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import java.util.Objects;
4444

45-
public interface ProtoWorld<P extends ProtoWorld<P>> extends
45+
public interface WorldLike<P extends WorldLike<P>> extends
4646
Region<P>,
4747
BiomeVolume.Modifiable<P>, // Because this is mutable
4848
BlockVolume.Modifiable<P>, // Because this is mutable

0 commit comments

Comments
 (0)