Class Chunk

java.lang.Object
com.zenith.feature.pathfinder.process.elytra.pathfinder.Chunk

public final class Chunk extends Object
A 16 by 384 by 16 column of blocks, one bit each, laid out as an octree so that a cube of 2, 4, 8 or 16 blocks can be tested for emptiness with a few long reads. The layout is the native library's: 24 sections of 16x16x16 blocks (512 bytes each); a section is 8 x8 cubes of 64 bytes; an x8 is 8 x4 cubes of 8 bytes; an x4 is 8 x2 cubes of one byte; the 8 bits of that byte are the blocks. A section in which no block has been set is not allocated. Beside the sections, one byte per section says which of its x8 cubes hold a block, so that the question a search asks first and a ray asks of every x16 and x8 it enters, whether a cube that big is empty, is a bit test rather than a scan of 64 or 8 longs.

Nothing here is synchronized, as nothing was in the native library: NetherPathfinderContext's lock keeps writers and readers apart, and its comment says who takes which side. A read that races a write anyway sees some blocks from before it and some from after, never an exception, since every read takes its section once and checks it for null.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Chunk
    A chunk with no blocks.
    static final int
     
    static final int
     
    static final Chunk
    A chunk with every block solid.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    fillSection(int section, boolean solid)
    Sets every block of one 16x16x16 section (0..23) at once.
    boolean
    isEmpty(com.zenith.feature.pathfinder.process.elytra.pathfinder.Size size, int x, int y, int z)
     
    boolean
    isEmptyX16(int y)
     
    boolean
    isEmptyX2(int x, int y, int z)
     
    boolean
    isEmptyX4(int x, int y, int z)
     
    boolean
    isEmptyX8(int x, int y, int z)
     
    boolean
    isSolid(int x, int y, int z)
    Coordinates are chunk relative: x and z in 0..15, y in 0..383.
    void
    setBlock(int x, int y, int z, boolean solid)
    Coordinates are chunk relative: x and z in 0..15, y in 0..383.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HEIGHT

      public static final int HEIGHT
      See Also:
    • SECTIONS

      public static final int SECTIONS
      See Also:
    • AIR

      public static final Chunk AIR
      A chunk with no blocks. Shared; writes to it throw.
    • SOLID

      public static final Chunk SOLID
      A chunk with every block solid. Shared; writes to it throw.
  • Constructor Details

    • Chunk

      public Chunk()
  • Method Details

    • isSolid

      public boolean isSolid(int x, int y, int z)
      Coordinates are chunk relative: x and z in 0..15, y in 0..383.
    • setBlock

      public void setBlock(int x, int y, int z, boolean solid)
      Coordinates are chunk relative: x and z in 0..15, y in 0..383. A clear that empties its x8 cube also clears the cube's bit in filled, which costs a scan of the cube's eight longs; the callers that fill a whole chunk only ever set blocks, so they never pay it.
    • fillSection

      public void fillSection(int section, boolean solid)
      Sets every block of one 16x16x16 section (0..23) at once.
    • isEmpty

      public boolean isEmpty(com.zenith.feature.pathfinder.process.elytra.pathfinder.Size size, int x, int y, int z)
    • isEmptyX16

      public boolean isEmptyX16(int y)
    • isEmptyX8

      public boolean isEmptyX8(int x, int y, int z)
    • isEmptyX4

      public boolean isEmptyX4(int x, int y, int z)
    • isEmptyX2

      public boolean isEmptyX2(int x, int y, int z)