Interface NMSChunkSection
- All Superinterfaces:
NMSObject
This interface provides a version-independent abstraction for working with chunk sections, which are 16x16x16 block cubes that make up chunks. Chunk sections are the fundamental storage units for blocks in Minecraft, providing efficient storage and manipulation of block data within chunks.
Each chunk section covers a 16-block-high slice of a chunk, with sections stacked vertically from the world's minimum height to maximum height. Sections can be empty (containing only air) or populated with various block types and states.
The wrapper provides direct block manipulation within the section coordinate space (0-15 for X and Z, section-relative for Y) and abstracts away the complexity of version-specific block storage formats.
Example usage:
// Get chunk section
NMSChunkSection section = chunk.getOrCreateSection(64);
// Set blocks within the section
section.setType(0, 0, 0, Material.STONE);
section.setType(15, 15, 15, customBlockData);
// Check if section is empty
if (!section.isEmpty()) {
// Process non-empty section
}
-
Method Summary
Modifier and TypeMethodDescription@NotNull NMSChunk
Retrieves the parent chunk that contains this section.boolean
isEmpty()
Checks if this chunk section is empty.void
setType
(int x, int y, int z, @NotNull XBlockData blockData) Sets the block type and data at the specified coordinates within this section.
USESPlaceType.NMS
for fastest placement.void
Sets the block type at the specified coordinates within this section.
USESPlaceType.NMS
for fastest placement.
-
Method Details
-
getNMSChunk
Retrieves the parent chunk that contains this section.This method provides access to the chunk that this section belongs to, enabling access to chunk-level operations and maintaining the hierarchical relationship between chunks and their sections.
- Returns:
- the
NMSChunk
that contains this section
-
setType
Sets the block type at the specified coordinates within this section.
USESPlaceType.NMS
for fastest placement. Don't use the NMSChunk API if you want physics or updates.This method places a block of the specified material at the given coordinates within the section. Coordinates are relative to the section (0-15 for X and Z, section-relative for Y).
This is a simplified block placement method that uses the material's default block state. For more complex block data, use the
setType(int, int, int, XBlockData)
overload.- Parameters:
x
- the X coordinate within the section (0-15)y
- the Y coordinate within the section (section-relative)z
- the Z coordinate within the section (0-15)material
- theMaterial
to place at the specified location
-
setType
Sets the block type and data at the specified coordinates within this section.
USESPlaceType.NMS
for fastest placement. Don't use the NMSChunk API if you want physics or updates.This method places a block with the specified block data at the given coordinates within the section. The
XBlockData
provides cross-version compatibility for block states, properties, and legacy data values.This method should be used when placing blocks that require specific properties, orientations, or states that cannot be represented by a simple material type.
- Parameters:
x
- the X coordinate within the section (0-15)y
- the Y coordinate within the section (section-relative)z
- the Z coordinate within the section (0-15)blockData
- theXBlockData
containing material and state information
-
isEmpty
boolean isEmpty()Checks if this chunk section is empty.An empty section contains only air blocks and has no meaningful block data. Empty sections are often optimized by the Minecraft engine to save memory and processing time.
This method is useful for determining whether a section needs processing or can be skipped in bulk operations.
- Returns:
true
if the section contains only air blocks,false
otherwise
-