Class NetherPathfinder

java.lang.Object
com.zenith.feature.pathfinder.process.elytra.pathfinder.NetherPathfinder
All Implemented Interfaces:
AutoCloseable

public final class NetherPathfinder extends Object implements AutoCloseable
A pathfinder and raytracer over a cache of one-bit-per-block chunks, for flying the nether by elytra. One instance is what the native library called a context: a world's dimension, the loaded chunks it has been given, and a search that can be cancelled.

The method names are the ones the native API had, with objects where it had pointers: a chunk is a Chunk that stays valid for as long as it is referenced, and there is nothing to free. Lookups, inserts, the search and rays may all run at the same time from different threads.

  • Constructor Details

    • NetherPathfinder

      public NetherPathfinder(NetherPathfinder.Dimension dimension, int maxHeight)
      Parameters:
      dimension - the dimension the chunks are from, which decides their height
      maxHeight - the height the search and rays stay under, 1 to 384
  • Method Details

    • getDimension

      public NetherPathfinder.Dimension getDimension()
    • getMaxHeight

      public int getMaxHeight()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • allocateAndInsertChunk

      public Chunk allocateAndInsertChunk(int x, int z)
      Inserts a new, empty chunk from the game at (x, z), replacing any chunk there, and returns it to be filled.
    • getChunkOrDefault

      public Chunk getChunkOrDefault(int x, int z, boolean solid)
      The chunk at (x, z), or the shared all-solid or all-air chunk if there is none. Do not write to the shared ones.
    • getChunk

      public Chunk getChunk(int x, int z)
      The chunk at (x, z), or null.
    • hasChunkFromCaller

      public boolean hasChunkFromCaller(int x, int z)
    • cullFarChunks

      public void cullFarChunks(int chunkX, int chunkZ, int maxDistanceBlocks)
      Forgets every chunk more than maxDistanceBlocks (in whole chunks) from (chunkX, chunkZ).
    • chunkCount

      public int chunkCount()
      How many chunks the table holds.
    • pathFind

      public PathSegment pathFind(int x1, int y1, int z1, int x2, int y2, int z2, boolean atLeastX4, boolean refine, int failTimeoutInMillis, boolean defaultAir, double fakeChunkCost)
      A path from (x1, y1, z1) towards (x2, y2, z2), or null if none was found in time or the search was cancelled. The segment is finished if it reached the goal.
      Parameters:
      atLeastX4 - do not squeeze through cubes smaller than 4 blocks
      refine - drop points that are visible from an earlier one
      failTimeoutInMillis - give up after this long with nothing; 0 for 30 seconds
      defaultAir - treat unknown chunks as air for provisional route planning
      fakeChunkCost - the cost of a step through a chunk that was not given by the game, against 1 for one that was
    • cancel

      public boolean cancel()
      Asks a running search to stop. Returns whether it had already been asked.
    • removeChunk

      public void removeChunk(int cx, int cz)