Interface World

All Superinterfaces:
Audience, ForwardingAudience, Keyed, Pointered

public interface World extends Keyed, ForwardingAudience
A loaded world, identified by its key.

As a ForwardingAudience, a world forwards anything sent to it to the players it currently holds. Block reads may be issued from any thread; block writes are queued on the region thread owning the position and complete asynchronously.

Since:
0.1.0
See Also:
  • Method Details

    • minY

      int minY()
      Returns the lowest block Y coordinate of this world, inclusive.
      Returns:
      the lowest block Y coordinate of this world, inclusive
      Since:
      0.1.0
    • height

      int height()
      Returns the number of block layers of this world, starting at minY().
      Returns:
      the number of block layers of this world, starting at minY()
      Since:
      0.1.0
    • dimensionType

      DimensionTypeDefinition dimensionType()
      Returns this world's dimension type.
      Returns:
      this world's dimension type
      Since:
      0.1.0
    • dayNightCycle

      DayNightCycle dayNightCycle()
      Returns the clock driving the time of day of this world.
      Returns:
      the clock driving the time of day of this world
      Since:
      0.1.0
    • gameRules

      WorldGameRules gameRules()
      The game rules in effect in this world: the base values held by the overworld, except for the rules this world overrides.
      Returns:
      the game rules of this world
      Since:
      0.1.0
    • weather

      WeatherManager weather()
      The weather of this world. Every world has its own weather; it only changes on its own in worlds whose dimension type has a skylight, while the advance_weather game rule allows it.
      Returns:
      the weather of this world
      Since:
      0.1.0
    • scheduler

      RegionizedScheduler scheduler()
      Returns the scheduler responsible for running tasks against positions in this world.
      Returns:
      the scheduler responsible for running tasks against positions in this world
      Since:
      0.1.0
    • chunkAsync

      CompletableFuture<Chunk> chunkAsync(int chunkX, int chunkZ)
      Gets a chunk, loading or generating it when needed.
      Parameters:
      chunkX - the chunk X coordinate
      chunkZ - the chunk Z coordinate
      Returns:
      a future completing with the chunk, or exceptionally if it could not be read
      Since:
      0.1.0
    • chunkAsync

      default CompletableFuture<Chunk> chunkAsync(ChunkPos pos)
      Gets a chunk, loading or generating it when needed.
      Parameters:
      pos - the chunk position
      Returns:
      a future completing with the chunk, or exceptionally if it could not be read
      Since:
      0.1.0
    • chunkIfLoaded

      Optional<Chunk> chunkIfLoaded(int chunkX, int chunkZ)
      Gets a chunk only if it is already loaded, without triggering any load.
      Parameters:
      chunkX - the chunk X coordinate
      chunkZ - the chunk Z coordinate
      Returns:
      the chunk, or empty if it is not loaded
      Since:
      0.1.0
    • chunkIfLoaded

      default Optional<Chunk> chunkIfLoaded(ChunkPos pos)
      Gets a chunk only if it is already loaded, without triggering any load.
      Parameters:
      pos - the chunk position
      Returns:
      the chunk, or empty if it is not loaded
      Since:
      0.1.0
    • isChunkLoaded

      default boolean isChunkLoaded(int chunkX, int chunkZ)
      Checks whether a chunk is currently loaded.
      Parameters:
      chunkX - the chunk X coordinate
      chunkZ - the chunk Z coordinate
      Returns:
      true if the chunk is loaded
      Since:
      0.1.0
    • unloadChunkAsync

      CompletableFuture<Boolean> unloadChunkAsync(int chunkX, int chunkZ)
      Unloads a chunk, saving it first.

      The request is refused when the chunk is not loaded, is force-loaded, or is still viewed by a player.

      Parameters:
      chunkX - the chunk X coordinate
      chunkZ - the chunk Z coordinate
      Returns:
      a future completing with true once the chunk is unloaded, or false if the request was refused
      Since:
      0.1.0
    • unloadChunkAsync

      default CompletableFuture<Boolean> unloadChunkAsync(ChunkPos pos)
      Unloads a chunk, saving it first.
      Parameters:
      pos - the chunk position
      Returns:
      a future completing with true once the chunk is unloaded, or false if the request was refused
      Since:
      0.1.0
      See Also:
    • isChunkForceLoaded

      boolean isChunkForceLoaded(int chunkX, int chunkZ)
      Whether a chunk is force-loaded.
      Parameters:
      chunkX - the chunk X coordinate
      chunkZ - the chunk Z coordinate
      Returns:
      true if the chunk is force-loaded
      Since:
      0.1.0
    • isChunkForceLoaded

      default boolean isChunkForceLoaded(ChunkPos pos)
      Whether a chunk is force-loaded.
      Parameters:
      pos - the chunk position
      Returns:
      true if the chunk is force-loaded
      Since:
      0.1.0
      See Also:
    • setChunkForceLoaded

      boolean setChunkForceLoaded(int chunkX, int chunkZ, boolean forced)
      Sets the force-loaded state of a chunk. A force-loaded chunk is loaded right away and stays loaded, across restarts, until it is released.
      Parameters:
      chunkX - the chunk X coordinate
      chunkZ - the chunk Z coordinate
      forced - true to force-load the chunk, false to release it
      Returns:
      true if the force-loaded state changed
      Since:
      0.1.0
    • forceLoadedChunks

      Set<ChunkPos> forceLoadedChunks()
      Returns an immutable snapshot of the force-loaded chunks of this world.
      Returns:
      an immutable snapshot of the force-loaded chunks of this world
      Since:
      0.1.0
    • blockKeyAt

      Optional<Key> blockKeyAt(BlockPos pos)
      Gets the type of the block at a position.
      Parameters:
      pos - the block position
      Returns:
      the block key, or empty for any kind of air
      Since:
      0.1.0
    • blockStateId

      int blockStateId(BlockPos pos)
      Gets the block state at a position, loading the chunk when needed.
      Parameters:
      pos - the block position
      Returns:
      the network identifier of the block state
      Throws:
      UncheckedIOException - if the chunk could not be read
      Since:
      0.1.0
      See Also:
    • setBlockStateId

      CompletableFuture<Boolean> setBlockStateId(BlockPos pos, int stateId)
      Replaces the block state at a position, on the region thread owning it.
      Parameters:
      pos - the block position
      stateId - the network identifier of the new block state
      Returns:
      a future completing with true if the block changed, false if it already held that state or the write could not be scheduled
      Since:
      0.1.0
    • blockLight

      int blockLight(BlockPos pos)
      Returns the block light level at a position, between 0 and 15.
      Parameters:
      pos - the block position
      Returns:
      the block light level at a position, between 0 and 15
      Since:
      0.1.0
    • skyLight

      int skyLight(BlockPos pos)
      Returns the sky light level at a position, between 0 and 15.
      Parameters:
      pos - the block position
      Returns:
      the sky light level at a position, between 0 and 15
      Since:
      0.1.0
    • lightLevel

      int lightLevel(BlockPos pos)
      Returns the effective light level at a position, the highest of block and sky light.
      Parameters:
      pos - the block position
      Returns:
      the effective light level at a position, the highest of block and sky light
      Since:
      0.1.0
    • entities

      Collection<? extends Entity> entities()
      Returns the entities currently in this world, players included.
      Returns:
      the entities currently in this world, players included
      Since:
      0.1.0
    • entity

      Optional<? extends Entity> entity(UUID uuid)
      Looks up an entity of this world by identity.
      Parameters:
      uuid - the entity identity
      Returns:
      the entity, or empty if this world holds no entity with that identity
      Since:
      0.1.0
    • entity

      Optional<? extends Entity> entity(int entityId)
      Looks up an entity of this world by network identifier.
      Parameters:
      entityId - the network identifier, as returned by Entity.entityId()
      Returns:
      the entity, or empty if this world holds no entity with that identifier
      Since:
      0.1.0