Interface NMSChunk
- All Superinterfaces:
NMSObject
- All Known Subinterfaces:
NMSChunkDef
This interface provides a version-independent abstraction for working with Minecraft's internal chunk representation. Chunks are 16x16 block columns that extend from the world's minimum height to maximum height, divided into sections for efficient storage and processing.
The wrapper provides access to chunk sections, tile entities, and chunk management operations while hiding the complexity of version-specific NMS implementations. It maintains references to both the underlying NMS chunk object and its associated Bukkit representation.
Example usage:
// Get NMS chunk wrapper
NMSChunk nmsChunk = chunkProvider.wrap(bukkitChunk);
// Work with chunk sections
NMSChunkSection section = nmsChunk.getSection(64); // Y level 64
section.setType(0, 0, 0, Material.STONE);
// Update clients
nmsChunk.sendUpdatePacket(player);
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Removes all tile entities from this chunk.@NotNull Chunk
Retrieves the Bukkit chunk representation of this NMS chunk.@NotNull NMSChunkProvider
Retrieves the chunk provider that manages this chunk.@NotNull NMSChunkSection
getOrCreateSection
(int y) Retrieves or creates the chunk section at the specified Y coordinate.@NotNull NMSChunkSection
getSection
(int y) Retrieves the chunk section at the specified Y coordinate.int
getX()
Retrieves the X coordinate of this chunk in chunk coordinates.int
getZ()
Retrieves the Z coordinate of this chunk in chunk coordinates.void
Saves the chunk to disk and refreshes it for all players.void
sendUpdatePacket
(@NotNull Player player) Sends a chunk update packet to the specified player.
-
Method Details
-
getNMSChunkProvider
Retrieves the chunk provider that manages this chunk.The chunk provider is responsible for chunk loading, saving, and management operations. It maintains the relationship between chunks and their world context.
- Returns:
- the
NMSChunkProvider
that manages this chunk
-
getBukkitChunk
Retrieves the Bukkit chunk representation of this NMS chunk.This method provides access to the Bukkit API representation of the same chunk, allowing for integration with Bukkit-based code and plugins that expect Bukkit chunk objects.
- Returns:
- the Bukkit
Chunk
representation
-
getSection
Retrieves the chunk section at the specified Y coordinate.Chunk sections are 16x16x16 block cubes that divide chunks vertically. The Y coordinate should be the section's base Y level (typically multiples of 16). If no section exists at the specified Y level, this method's behavior is implementation-dependent.
- Parameters:
y
- the Y coordinate of the section's base level- Returns:
- the
NMSChunkSection
at the specified Y level
-
getOrCreateSection
Retrieves or creates the chunk section at the specified Y coordinate.This method ensures that a chunk section exists at the specified Y level, creating one if necessary. This is useful when placing blocks in previously empty sections or when working with newly generated chunks.
- Parameters:
y
- the Y coordinate of the section's base level- Returns:
- the existing or newly created
NMSChunkSection
-
clearTileEntities
void clearTileEntities()Removes all tile entities from this chunk.Tile entities represent blocks with complex state (chests, furnaces, signs, etc.). This method clears all such entities from the chunk, which is useful for chunk reset operations or when replacing all blocks in a chunk.
Warning: This operation cannot be undone and will permanently remove all tile entity data in the chunk.
-
sendUpdatePacket
Sends a chunk update packet to the specified player.This method forces the client to update their view of this chunk, ensuring that any changes made through NMS operations are visible to the player. This is typically necessary after direct chunk modifications that bypass Bukkit's change notification system.
- Parameters:
player
- thePlayer
to send the update packet to
-
getX
int getX()Retrieves the X coordinate of this chunk in chunk coordinates.Chunk coordinates are the chunk's position in the world grid, where each unit represents a 16x16 block area. This is different from block coordinates, which represent individual block positions.
- Returns:
- the X coordinate in chunk coordinates
-
getZ
int getZ()Retrieves the Z coordinate of this chunk in chunk coordinates.Chunk coordinates are the chunk's position in the world grid, where each unit represents a 16x16 block area. This is different from block coordinates, which represent individual block positions.
- Returns:
- the Z coordinate in chunk coordinates
-
saveAndRefresh
void saveAndRefresh()Saves the chunk to disk and refreshes it for all players.This method performs a complete save and refresh cycle for the chunk, ensuring that all changes are persisted to disk and that all players see the updated chunk state. The implementation may vary between versions but typically involves marking the chunk as dirty, saving it, and sending update packets to relevant players.
This operation is useful after making extensive modifications to a chunk to ensure data persistence and visual consistency.
-