|
29 | 29 | import org.spongepowered.api.effect.Viewer; |
30 | 30 | import org.spongepowered.api.entity.Entity; |
31 | 31 | import org.spongepowered.api.entity.living.player.Player; |
| 32 | +import org.spongepowered.api.event.CauseStackManager; |
32 | 33 | import org.spongepowered.api.registry.RegistryHolder; |
| 34 | +import org.spongepowered.api.scheduler.Scheduler; |
33 | 35 | import org.spongepowered.api.service.context.ContextSource; |
34 | 36 | import org.spongepowered.api.util.annotation.DoNotStore; |
35 | 37 | import org.spongepowered.api.world.chunk.WorldChunk; |
@@ -227,4 +229,38 @@ default Optional<WorldChunk> loadChunk(final Vector3i chunkPosition, final boole |
227 | 229 | */ |
228 | 230 | Iterable<WorldChunk> loadedChunks(); |
229 | 231 |
|
| 232 | + /** |
| 233 | + * Gets the {@link Scheduler} used to schedule sync tasks on this {@link World}. |
| 234 | + * |
| 235 | + * <p><strong>Note:</strong> Accessing objects outside of this {@link World} |
| 236 | + * from the scheduled tasks can lead to hard to diagnose problems |
| 237 | + * or unrecoverable crashes.</p> |
| 238 | + * |
| 239 | + * @return The sync scheduler |
| 240 | + */ |
| 241 | + default Scheduler scheduler() { |
| 242 | + return this.engine().scheduler(); |
| 243 | + } |
| 244 | + |
| 245 | + /** |
| 246 | + * Gets the {@link CauseStackManager} for handling the current event cause |
| 247 | + * stack and context information. |
| 248 | + * |
| 249 | + * <p><strong>Note:</strong> Accessing this outside of {@link World#onWorldThread()} |
| 250 | + * can lead to hard to diagnose problems or unrecoverable crashes.</p> |
| 251 | + * |
| 252 | + * @return The cause stack manager |
| 253 | + */ |
| 254 | + default CauseStackManager causeStackManager() { |
| 255 | + return this.engine().causeStackManager(); |
| 256 | + } |
| 257 | + |
| 258 | + /** |
| 259 | + * Checks if the {@link Thread#currentThread() current thread} is the main thread of the world. |
| 260 | + * |
| 261 | + * @return {@code true} if main thread, {@code false} if not |
| 262 | + */ |
| 263 | + default boolean onWorldThread() { |
| 264 | + return this.engine().onMainThread(); |
| 265 | + } |
230 | 266 | } |
0 commit comments