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
    • paths

      WorldPaths paths()
      Returns the paths on disk where this world is stored.
      Returns:
      the paths on disk where this world is stored
      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
    • ticks

      Returns the ticks blocks and fluids scheduled in this world., saved with their chunks
      Returns:
      the ticks blocks and fluids scheduled 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

      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(BlockPosition 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(BlockPosition position, int stateId)
      Replaces the block state at a position, on the region thread owning it.
      Parameters:
      position - 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
    • chestAt

      Gets the chest at a position: a chest, a trapped chest or a copper chest.

      The inventory reads and writes the block entity of the chest; to see the large chest it may be half of, as players do, use ChestInventory.doubleChest(). Use it on the thread of the region owning the position.

      Parameters:
      position - the block position
      Returns:
      the slots of the chest, empty when there is no chest there or its chunk is not loaded
      Since:
      0.1.0
    • barrelAt

      Optional<BarrelInventory> barrelAt(BlockPosition position)
      Gets the barrel at a position.

      The inventory reads and writes the block entity of the barrel, and shows the rows the configuration of this world gives barrels. Use it on the thread of the region owning the position.

      Parameters:
      position - the block position
      Returns:
      the slots of the barrel, empty when there is no barrel there or its chunk is not loaded
      Since:
      0.1.0
    • hopperAt

      Optional<HopperInventory> hopperAt(BlockPosition position)
      Gets the hopper at a position.

      The inventory reads and writes the block entity of the hopper. Use it on the thread of the region owning the position.

      Parameters:
      position - the block position
      Returns:
      the slots of the hopper, empty when there is no hopper there or its chunk is not loaded
      Since:
      0.1.0
    • blockLight

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

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

      int lightLevel(BlockPosition position)
      Returns the effective light level at a position, the highest of block and sky light.
      Parameters:
      position - 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
    • dropItem

      ItemEntity dropItem(Location location, ItemStack item)
      Drops a stack of items on the ground, the way a broken block spills its contents: at location, with a small random push, picked up after 10 ticks.

      Callable from any thread: off the region thread owning location, the item is added to the world by that thread shortly after, and the returned entity is not in entities() until then.

      Parameters:
      location - where to drop the stack, in this world, in a loaded chunk
      item - the stack, not empty
      Returns:
      the item entity
      Throws:
      IllegalArgumentException - if item is empty, or location is in another world or in a chunk that is not loaded
      Since:
      0.1.0
    • dropExperience

      void dropExperience(Location location, int amount)
      Drops experience on the ground, the way a killed mob leaves it: split into orbs of vanilla's values, the biggest first, each thrown a little way from location. An orb of the same value already lying there may take the experience instead of a new one appearing.

      Callable from any thread: off the region thread owning location, the orbs are added to the world by that thread shortly after.

      Parameters:
      location - where to drop the experience, in this world, in a loaded chunk
      amount - how many experience points to drop; nothing happens when it is not positive
      Throws:
      IllegalArgumentException - if location is in another world or in a chunk that is not loaded
      Since:
      0.1.0
      See Also: