Record Class BukkitSnapshotChunkData

java.lang.Object
java.lang.Record
dev.wyck.renderer.packet.data.BukkitSnapshotChunkData
All Implemented Interfaces:
SnapshotChunkData

@NullMarked @AsOf("2.2.0") public record BukkitSnapshotChunkData(ChunkLocation location, ChunkSnapshot snapshot) extends Record implements SnapshotChunkData
A SnapshotChunkData backed by a real Bukkit ChunkSnapshot.

This backing exposes full block data, but it can only be constructed by a caller that already holds a snapshot. Obtaining a snapshot (world.getChunkAt(...).getChunkSnapshot()) touches the live world and must be done on the main thread never on the Netty thread inside a packet listener. Use this only when you legitimately have a snapshot in hand; otherwise the packet-backed NmsSnapshotChunkData is the correct, safe choice.

Since:
2.2.0
  • Constructor Details

    • BukkitSnapshotChunkData

      public BukkitSnapshotChunkData(ChunkLocation location, ChunkSnapshot snapshot)
      Creates an instance of a BukkitSnapshotChunkData record class.
      Parameters:
      location - the value for the location record component
      snapshot - the value for the snapshot record component
  • Method Details

    • centerBiome

      public Biome centerBiome()
      Description copied from interface: SnapshotChunkData
      The biome currently in the packet at the legacy "center" sample (block 7, 0, 7). Lazily computed and memoized.
      Specified by:
      centerBiome in interface SnapshotChunkData
      Returns:
      the source biome at the chunk center
    • biomeAt

      public Biome biomeAt(int x, int y, int z)
      Description copied from interface: SnapshotChunkData
      The biome at the given chunk-relative block coordinates. y is relative to the bottom of the chunk column (section 0), not world Y.
      Specified by:
      biomeAt in interface SnapshotChunkData
      Parameters:
      x - chunk-relative block X (0-15)
      y - chunk-relative block Y (0 .. sectionCount*16 - 1)
      z - chunk-relative block Z (0-15)
      Returns:
      the source biome at those coordinates
    • bukkitSnapshot

      public Optional<ChunkSnapshot> bukkitSnapshot()
      Description copied from interface: SnapshotChunkData
      The full Bukkit ChunkSnapshot, if one is available.

      Expensive / restricted. The packet-backed implementation returns Optional.empty() on purpose building a real snapshot requires touching the live world chunk, which is not safe on the Netty thread. A snapshot is only present when the caller explicitly constructed a BukkitSnapshotChunkData from a snapshot they obtained on the main thread. Most conditionals should prefer SnapshotChunkData.centerBiome() or SnapshotChunkData.biomeAt(int, int, int) instead.

      Specified by:
      bukkitSnapshot in interface SnapshotChunkData
      Returns:
      the snapshot, or empty if none is available
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • location

      public ChunkLocation location()
      Returns the value of the location record component.
      Specified by:
      location in interface SnapshotChunkData
      Returns:
      the value of the location record component
    • snapshot

      public ChunkSnapshot snapshot()
      Returns the value of the snapshot record component.
      Returns:
      the value of the snapshot record component