Class BlockWorld

java.lang.Object
com.ardorcraft.world.BlockWorld
All Implemented Interfaces:
BlockProvider, ChunkModifier, LightProvider

public final class BlockWorld extends Object implements LightProvider, ChunkModifier
BlockWorld is the main class when it comes to building and rendering the block world. It handles asynchronous updating and rebuilding of the chunks after receiving chunk or block updates. It also handles light calculations.

In the simplest setup, the blockworld is just initialized with a WorldSettings object. Then the main node for rendering the world is extracted and added to your scenegraph. Finally when you have everything else setup, all the threads are kicked off to start processing.

blockWorld = new BlockWorld(settings);
root.attachChild(blockWorld.getWorldNode());
...
blockWorld.startThreads();

  • Field Details

    • WATER

      public static int WATER
  • Constructor Details

    • BlockWorld

      public BlockWorld(WorldSettings settings)
      Create a new BlockWorld instance based on the provided settings.
      Parameters:
      settings - the world settings
  • Method Details

    • startThreads

      public void startThreads()
      Start all processing threads. Currently a chunk updater and a light updater.
    • getWorldNode

      public Node getWorldNode()
      Get the Node used for rendering the block world.
      Returns:
      Node with block world
    • update

      public void update(ReadOnlyTimer timer)
      Issue world updates based on currently set player position/direction.
      Parameters:
      timer - the timer
    • postChunk

      public void postChunk(int x, int z, Chunk chunk)
      Specified by:
      postChunk in interface ChunkModifier
    • updatePlayer

      public void updatePlayer(ReadOnlyVector3 location, ReadOnlyVector3 direction)
      Let the block world know the current player position and direction.
      Parameters:
      location - the location
      direction - the direction
    • reloadAll

      public void reloadAll()
      Reload all chunks.
    • lookupLighting

      public float lookupLighting(int lighting)
      Get the exact float used global lighting.
      Parameters:
      lighting - the lighting
      Returns:
      the exact float used global lighting
    • getBlock

      public int getBlock(int x, int y, int z)
      Description copied from interface: BlockProvider
      Get block id for world coordinate x, y, z
      Specified by:
      getBlock in interface BlockProvider
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Block id at position
    • setBlock

      public void setBlock(int x, int y, int z, int blockId)
      Specified by:
      setBlock in interface ChunkModifier
    • setBlock

      public void setBlock(int x, int y, int z, int blockId, BlockSide orientation)
      Specified by:
      setBlock in interface ChunkModifier
    • setBlocks

      public void setBlocks(List<BlockEditData> blockList)
      Specified by:
      setBlocks in interface ChunkModifier
    • getBlockOrientation

      public BlockSide getBlockOrientation(int x, int y, int z)
      Get block orientation at coordinate x, y, z.
      Parameters:
      x - the x value
      y - the y value
      z - the z value
      Returns:
      Orientation
    • getBlockExtra

      public int getBlockExtra(int x, int y, int z)
      Description copied from interface: BlockProvider
      Get block extra data for world coordinate x, y, z.
      bits 0,1,2 = orientation
      bits 3,4,5,6 = age (or something else)
      bit 7 = whatever

      Specified by:
      getBlockExtra in interface BlockProvider
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Block id at position
    • getHeight

      public int getHeight()
    • tracePicking

      public void tracePicking(ReadOnlyVector3 curpos, ReadOnlyVector3 raydir, int maxIterations, IntersectionResult result)
    • traceCollision

      public void traceCollision(ReadOnlyVector3 curpos, ReadOnlyVector3 raydir, int maxIterations, IntersectionResult result)
    • stopThreads

      public void stopThreads()
      Stop all processing threads, and wait for them to finish.
    • getGlobalLight

      public float getGlobalLight()
    • setGlobalLight

      public void setGlobalLight(float globalLight)
      Set global light value (0-15) for day/night simulation.
      Parameters:
      globalLight - the global light value (0-15) for day/night simulation
    • getSettings

      public WorldSettings getSettings()
    • getBlockUtil

      public BlockUtil getBlockUtil()
    • getGlobalLighting

      public float getGlobalLighting(int x, int y, int z)
      Specified by:
      getGlobalLighting in interface LightProvider
    • getLocalLighting

      public float getLocalLighting(int x, int y, int z)
      Specified by:
      getLocalLighting in interface LightProvider
    • getLightTexture

      public Texture getLightTexture()
    • setLightTexture

      public void setLightTexture(Texture lightTexture)
    • getCaveLight

      public ReadOnlyColorRGBA getCaveLight()
    • setCaveLight

      public void setCaveLight(ColorRGBA caveLight)
    • getNightLight

      public ReadOnlyColorRGBA getNightLight()
    • setNightLight

      public void setNightLight(ColorRGBA nightLight)
    • getDayLight

      public ReadOnlyColorRGBA getDayLight()
    • setDayLight

      public void setDayLight(ColorRGBA dayLight)
    • getTorchLight

      public ReadOnlyColorRGBA getTorchLight()
    • setTorchLight

      public void setTorchLight(ColorRGBA torchLight)
    • getCurrentlyLoadedChunksCount

      public int getCurrentlyLoadedChunksCount()