Interface IChunkOrWorld

All Superinterfaces:
IAdditionalDataProvider
All Known Subinterfaces:
IChunk, IWorld

public interface IChunkOrWorld extends IAdditionalDataProvider
This class represents a chunk or world. It is special due to two classes extending it that have slightly different behavior. As such, whenever the word world is mentioned in the documentation of this class, it can also refer to the chunk that is being accessed when callilng this method. As such, some behavior might be different or unexpected and it might cause crashes if you're not careful with how you use this class.

For instance, calling getState(int, int) in an IWorld will always return a valid TileState, however, calling the same method for an IChunk will cause a crash if the position is outside of the chunk's boundaries, as calling it from a chunk will still result in world-level coordinates being used. For that reason, IChunk provides a mulitude of methods like IChunk.getStateInner(int, int) that will allow you to get properties of a chunk without needing to know its position within the world.

To access the game's current world object, use IGameInstance.getWorld(). See IWorld and IChunk for greater documentation on the seperate behavior of chunks and worlds.

See Also:
  • Method Details

    • getState

      TileState getState(int x, int y)
      Gets the current TileState at any given position in the world on TileLayer.MAIN.
      Parameters:
      x - The x world coordinate
      y - The y world coordinate
      Returns:
      The state
    • getState

      TileState getState(TileLayer layer, int x, int y)
      Gets the current TileState at any given position in the world on the given layer
      Parameters:
      layer - The layer
      x - The x world coordinate
      y - The y world coordinate
      Returns:
      The state
    • setState

      void setState(int x, int y, TileState tile)
      Sets the TileState at any given position in the world on TileLayer.MAIN to the given state.
      Parameters:
      x - The x world coordinate
      y - The y word coordinate
      tile - The state to set
    • setState

      void setState(TileLayer layer, int x, int y, TileState tile)
      Sets the TileState at any given position in the world on the given layer to the given state.
      Parameters:
      layer - The layer
      x - The x world coordinate
      y - The y world coordinate
      tile - The state to set
    • addEntity

      void addEntity(Entity entity)
      Adds an Entity to the world for it to be updated (Entity.update(IGameInstance) and saved and loaded to and from disk. If this operation isn't done, an entity also will not render.
      Parameters:
      entity - The entity to add
    • addTileEntity

      @ApiInternal void addTileEntity(TileEntity tile)
      Adds a TileEntity to the world. This method is marked as internal, as using Tile.provideTileEntity(IWorld, int, int, TileLayer) if Tile.canProvideTileEntity() is true will make it automatically be added to the world. Do not manually add tile entities to the world.
      Parameters:
      tile - The tile entity to add
    • removeEntity

      void removeEntity(Entity entity)
      Removes an Entity from the world.
      Parameters:
      entity - The entity to remove
    • removeTileEntity

      @ApiInternal void removeTileEntity(TileLayer layer, int x, int y)
      Removes a TileEntity from the world. This method is marked as internal, as using Tile.provideTileEntity(IWorld, int, int, TileLayer) if Tile.canProvideTileEntity() is true will make it automatically be removed from the world as the tile is broken. Do not manually remove tile entities from the world.
      Parameters:
      layer - The layer
      x - The world x
      y - The world y
    • getTileEntity

      TileEntity getTileEntity(TileLayer layer, int x, int y)
      Gets the TileEntity at any given position in the world from the given layer. Note that this will return a generic tile entity. If you want to get a specific type and don't want to do an instanceof check yourself, you can use getTileEntity(TileLayer, int, int, Class).
      Parameters:
      layer - The layer
      x - The world x
      y - The world y
      Returns:
      The tile entity at that position, or null if there is none
      See Also:
    • getTileEntity

      TileEntity getTileEntity(int x, int y)
      Gets the TileEntity at any given position in the world from TileLayer.MAIN. Note that this will return a generic tile entity. If you want to get a specific type and don't want to do an instanceof check yourself, you can use getTileEntity(int, int, Class).
      Parameters:
      x - The world x
      y - The world y
      Returns:
      The tile entity at that position, or null if there is none
      See Also:
    • getTileEntity

      <T extends TileEntity> T getTileEntity(TileLayer layer, int x, int y, Class<T> tileClass)
      Gets the TileEntity at any given position in the world from the given layer. If the tile entity at that position is either null or it does not have the given class as a super class, this method will return null.
      Type Parameters:
      T - The generic type representing the type of tile entity that will be returned
      Parameters:
      layer - The layer
      x - The world x
      y - The world y
      tileClass - The class that the tile entity should be extending or an object of
      Returns:
      The tile entity at that position, or null if there is none or it is not of the provided type
    • getTileEntity

      <T extends TileEntity> T getTileEntity(int x, int y, Class<T> tileClass)
      Gets the TileEntity at any given position in the world from TileLayer.MAIN. If the tile entity at that position is either null or it does not have the given class as a super class, this method will return null.
      Type Parameters:
      T - The generic type representing the type of tile entity that will be returned
      Parameters:
      x - The world x
      y - The world y
      tileClass - The class that the tile entity should be extending or an object of
      Returns:
      The tile entity at that position, or null if there is none or it is not of the provided type
    • reevaluateTickBehavior

      void reevaluateTickBehavior(TileEntity tile)
      Reevaluates if a TileEntity should be in the list of ticking tile entities, and should, as such, be updated every tick or not. This method re-calls TileEntity.doesTick() and adds or removes it from or to the list of ticking tile entities as needed. Note that this very action is automatically done when adding a tile entity to the world and this method should not be needed to be called unless you want your tile entity to have very specific ticking and performance behavior.
      Parameters:
      tile - The tile entitiy to reevaluate the ticking behavior for
      See Also:
    • getAllEntities

      List<Entity> getAllEntities()
      Gets a list of all of the Entity objects in the world that are currently within loaded chunks. Note that directly adding or removing to or from this list will throw an UnsupportedOperationException.
      Returns:
      All entities
      See Also:
    • getAllTileEntities

      List<TileEntity> getAllTileEntities()
      Gets a list of all of the TileEntity objects in the world that are currently within loaded chunks. Note that directly adding or removing to or from this list will throw an UnsupportedOperationException.
      Returns:
      All tile entites
      See Also:
    • getAllTickingTileEntities

      List<TileEntity> getAllTickingTileEntities()
      Gets a list of all of the TileEntity objects in the world that were marked as TileEntity.doesTick() at the point of being added to the world. Note that directly adding or removing to or from this list will throw an UnsupportedOperationException.
      Returns:
      All ticking tile entities
      See Also:
    • getEntity

      Entity getEntity(UUID id)
      Gets an Entity that is currently in the world by its UUID.
      Parameters:
      id - The unique id
      Returns:
      The entity, or null if there is none
      See Also:
    • getEntities

      List<Entity> getEntities(BoundingBox area)
      Gets a list of all of the Entity objects that are currently in the given BoundingBox.
      Parameters:
      area - The area to check for entities
      Returns:
      All of the entities
    • getEntities

      List<Entity> getEntities(BoundingBox area, Predicate<Entity> test)
      Gets a list of all of the Entity objects that are currently in the given BoundingBox and for which the given Predicate applies.
      Parameters:
      area - The area to check for entities
      test - The predicate that needs to apply for them to be added to the list
      Returns:
      All of the entities
    • getEntities

      <T extends Entity> List<T> getEntities(BoundingBox area, Class<T> type)
      Gets a list of all of the Entity objects that are currently in the given BoundingBox that also are objects of or whose classes extend the given Class.
      Type Parameters:
      T - A generic type representing the type of entities that are being looked for
      Parameters:
      area - The area to check for entities
      type - The type that they need to be
      Returns:
      All of the entities
    • getEntities

      <T extends Entity> List<T> getEntities(BoundingBox area, Class<T> type, Predicate<T> test)
      Gets a list of all of the Entity objects that are currently in the given BoundingBox that also are objects of or whose classes extend the given Class and for which the given Predicate applies.
      Type Parameters:
      T - A generic type representing the type of entities that are being looked for
      Parameters:
      area - The area to check for entities
      type - The type that they need to be
      test - The predicate that needs to apply for them to be added to the list
      Returns:
      All of the entities
    • getEntities

      List<Entity> getEntities(List<BoundingBox> area)
      Gets a list of all of the Entity objects that are currently in the given List of BoundingBox.
      Parameters:
      area - The area to check for entities
      Returns:
      All of the entities
    • getEntities

      List<Entity> getEntities(List<BoundingBox> area, Predicate<Entity> test)
      Gets a list of all of the Entity objects that are currently in the given List of BoundingBox and for which the given Predicate applies.
      Parameters:
      area - The area to check for entities
      test - The predicate that needs to apply for them to be added to the list
      Returns:
      All of the entities
    • getEntities

      <T extends Entity> List<T> getEntities(List<BoundingBox> area, Class<T> type)
      Gets a list of all of the Entity objects that are currently in the given List of BoundingBox that also are objects of or whose classes extend the given Class.
      Type Parameters:
      T - A generic type representing the type of entities that are being looked for
      Parameters:
      area - The area to check for entities
      type - The type that they need to be
      Returns:
      All of the entities
    • getEntities

      <T extends Entity> List<T> getEntities(List<BoundingBox> area, Class<T> type, Predicate<T> test)
      Gets a list of all of the Entity objects that are currently in the given List of BoundingBox that also are objects of or whose classes extend the given Class and for which the given Predicate applies.
      Type Parameters:
      T - A generic type representing the type of entities that are being looked for
      Parameters:
      area - The area to check for entities
      type - The type that they need to be
      test - The predicate that needs to apply for them to be added to the list
      Returns:
      All of the entities
    • getCombinedLight

      byte getCombinedLight(int x, int y)
      Gets the combined light at the given position in the world. The combined light is a combination of getSkyLight(int, int), getArtificialLight(int, int) and the given IWorld.getCurrentTime().
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      Returns:
      The light at the given position
    • getSkyLight

      byte getSkyLight(int x, int y)
      Gets the sky light at the given position in the world.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      Returns:
      The sky light
    • getArtificialLight

      byte getArtificialLight(int x, int y)
      Gets the artificial light, meaning the light that is generated by tiles, at the given position in the world.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      Returns:
      The artificial light
    • setSkyLight

      @ApiInternal void setSkyLight(int x, int y, byte light)
      Set the sky light at the given position in the world to the given value. This method is marked as internal as you should use Tile.getLight(IWorld, int, int, TileLayer) to actually provide light to the world. If you just set light to any given position in the world, it will cause it to be uneven and non-dynamic.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      light - The light
    • setArtificialLight

      @ApiInternal void setArtificialLight(int x, int y, byte light)
      Set the artificial light at the given position in the world to the given value. This method is marked as internal as you should use Tile.getLight(IWorld, int, int, TileLayer) to actually provide light to the world. If you just set light to any given position in the world, it will cause it to be uneven and non-dynamic.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      light - The light
    • scheduleUpdate

      void scheduleUpdate(int x, int y, TileLayer layer, int scheduledMeta, int time)
      Schedules an update to be done after the given time has passed at the given position with the given metadata. After the time has passed, the Tile.onScheduledUpdate(IWorld, int, int, TileLayer, int) method of the tile at the given position will be called. Note that scheduled updates get saved when the chunk gets saved, so that, when reloading the world, a scheduled update whose time has not yet run out will continue to tick down its timer.

      Note that calling this method when the tile at the passed position is not your own tile can cause unexpected behavior and is, as such, highly discouraged.

      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      layer - The layer
      scheduledMeta - The metadata to pass to the tile's method to distinguish between different kinds of updates
      time - The time it should take in ticks for the update to happen
      See Also:
    • scheduleUpdate

      void scheduleUpdate(int x, int y, TileLayer layer, int time)
      Schedules an update to be done after the given time has passed at the given position. After the time has passed, the Tile.onScheduledUpdate(IWorld, int, int, TileLayer, int) method of the tile at the given position will be called. Note that scheduled updates get saved when the chunk gets saved, so that, when reloading the world, a scheduled update whose time has not yet run out will continue to tick down its timer.

      Note that calling this method when the tile at the passed position is not your own tile can cause unexpected behavior and is, as such, highly discouraged.

      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      layer - The layer
      time - The time it should take in ticks for the update to happen
      See Also:
    • setDirty

      void setDirty(int x, int y)
      Sets the chunk at the given world position dirty, meaning that it will be guaranteed to be saved to disk the next time the world will be saved.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
    • getChunkHeight

      int getChunkHeight(TileLayer layer, int x, int bottomY)
      Gets the height of the chunk at the given position. First of all, the chunk at the given position is queried and then the height of the terrain at the given x coordinate is returned. Note that bottomY does not have any direct influence on the actual height returned but that it is merely used to get the chunk to query the height of.
      Parameters:
      layer - The layer
      x - The world x coordinate
      bottomY - The world y coordiate whose chunk should be queried for the height
      Returns:
      The height of the chunk at the given x coordinate
    • getAverageChunkHeight

      int getAverageChunkHeight(TileLayer layer, int x, int bottomY)
      Gets the average height of the chunk at the given position. First of all, the chunk at the given position is queried and then the average hight of the chunk at that position is returned. Note that neither x nor bottomY have a direct influence on the actual flatness of the position, just the chunk at the position.
      Parameters:
      layer - The layer
      x - The world x coordinate
      bottomY - The world y coordiate whose chunk should be queried for the height
      Returns:
      The height of the chunk at the given x coordinate
    • getChunkFlatness

      float getChunkFlatness(TileLayer layer, int x, int y)
      Gets the flatness of the chunk at the given position. First of all, the chunk at the given position is queried and then the flatness of the chunk at that position is returned. Note that neither x nor y have a direct influence on the actual flatness of the position, just the chunk at the position.
      Parameters:
      layer - The layer
      x - The world x coordinate of the chunk to query
      y - The world y coordinate of the chunk to query
      Returns:
      The flatness of the chunk. This will be a number between 0 and 1, where 1 means that all of the heights in the chunk are the same, and 0 means that none of the heights in the chunk are the same.
    • getBiome

      Biome getBiome(int x, int y)
      Gets the Biome in the world at the given position.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      Returns:
      The biome
      See Also:
    • setBiome

      @ApiInternal void setBiome(int x, int y, Biome biome)
      Sets the Biome in the world at the given position to the given biome. This method is marked as internal as biomes should only be set by their generation rather than directly. If you add a biome, you should use its class' methods to determine where the biome should spawn in the world.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      biome - The biome to set
    • isClient

      boolean isClient()
      Returns:
      If the game is currently in client mode
      See Also:
    • isServer

      boolean isServer()
      Returns:
      If the game is currently in server mode
      See Also:
    • isDedicatedServer

      boolean isDedicatedServer()
      Returns:
      If the game is acting as a dedicated server
      See Also:
    • isLocalPlayer

      boolean isLocalPlayer(Entity entity)
      Returns true if the provided entity is the game's local player
      Parameters:
      entity - The entity
      Returns:
      If the entity is the local player
      See Also:
    • callRetroactiveGeneration

      void callRetroactiveGeneration()
      This method calls all of the IWorldGenerator objects that are marked as IWorldGenerator.generatesRetroactively() for retroactive generation, meaning their IWorldGenerator.generate(IWorld, IChunk) methods will be called again. Note that most retroactive generators can only generate once, so calling this method should generally have little impact.

      Note that retroactive generation is automatically done when a IChunk is loaded from disk.

    • getSeed

      long getSeed()
      Returns:
      The seed of this world with which to seed Random generators and INoiseGen objects for world generation. The seed of the world is persistent, meaning that two worlds with the same seed should also have the exact same terrain generation.
    • getExpectedBiome

      Biome getExpectedBiome(int x, int y)
      Gets the Biome at the given position in the world without loading the chunk at that position. This is useful in that, if you want to see which biome would be at which position in a chunk that might not be loaded or generated yet, you don't have to make it generate just to find out the biome. Using this method over getBiome(int, int) during world generation greatly increases performance.
      Parameters:
      x - The world x coordinate
      y - The world y coordinate
      Returns:
      The expected biome for that position
    • getExpectedBiomeLevel

      BiomeLevel getExpectedBiomeLevel(int x, int y)
    • getExpectedSurfaceHeight

      int getExpectedSurfaceHeight(TileLayer layer, int x)
      Gets the height at the given position in the world without loading the chunk at that position. The height of the world is calculated independently of biomes or any other world generation features.

      Note that, if caves or structures generate at any given position, the getChunkHeight(TileLayer, int, int) will be different from this method's return value. The same will be true if a player places tiles in the world.

      Parameters:
      layer - The layer
      x - The world x coordinate
      Returns:
      The expected height for that position
    • getExpectedAverageHeight

      int getExpectedAverageHeight(TileLayer layer, int startX, int endX)
      Gets the average height in the given interval in the world without loading the chunk at any position. The height of the world is calculated independently of biomes or any other world generation features.

      Note that, if caves or structures generate at any given position, the getAverageChunkHeight(TileLayer, int, int) will be different from this method's return value. The same will be true if a player places tiles in the world.

      Parameters:
      layer - The layer
      startX - The leftmost world x coordinate, inclusive
      endX - The rightmost world x coordinate, exclusive
      Returns:
      The expected average height for that interval
    • getExpectedSurfaceFlatness

      float getExpectedSurfaceFlatness(TileLayer layer, int startX, int endX)
      Gets the flatness in the given interval in the world without loading the chunk at any position. The height of the world is calculated independently of biomes or any other world generation features.

      Note that, if caves or structures generate at any given position, the getChunkFlatness(TileLayer, int, int) will be different from this method's return value. The same will be true if a player places tiles in the world.

      Parameters:
      layer - The layer
      startX - The leftmost world x coordinate, inclusive
      endX - The rightmost world x coordinate, exclusive
      Returns:
      The flatness in the interval. This will be a number between 0 and 1, where 1 means that all of the heights in the interval are the same, and 0 means that none of the heights in the interval are the same.