Class ChunkSection
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The number of blocks in a chunk section, and thus the number of elements in all arrays used for it.static final byte
The default value for block light, used on new chunk sections.static final byte
The default value for sky light, used on new chunk sections.static final byte
Block light level to use for empty chunk sections.static final byte
Sky light level to use for empty chunk sections.static final int
The number of bits per block used in the global palette. -
Constructor Summary
ConstructorDescriptionCreate a new, empty ChunkSection.ChunkSection
(int[] types) Create a new, unlit chunk section with the specified chunk data.ChunkSection
(int[] types, NibbleArray skyLight, NibbleArray blockLight) Deprecated.ChunkSection
(VariableValueArray data, it.unimi.dsi.fastutil.ints.IntList palette, NibbleArray skyLight, NibbleArray blockLight) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic ChunkSection
fromNbt
(CompoundTag sectionTag) Creates a new chunk section from the given NBT blob.static ChunkSection
fromStateArray
(int[] types) Deprecated.org.bukkit.block.data.BlockData
getBlockData
(int x, int y, int z) The block light array.byte
getBlockLight
(int x, int y, int z) Gets the block light at the given block.The sky light array.byte
getSkyLight
(int x, int y, int z) Gets the sky light at the given block.int
getType
(int x, int y, int z) Gets the type at the given coordinates.int[]
getTypes()
Returns the block type array.int
index
(int x, int y, int z) Calculate the index into internal arrays for the given coordinates.boolean
isEmpty()
Checks whether this chunk section is empty, IE doesn't need to be sent or saved.void
loadTypeArray
(int[] types) Loads the contents of this chunk section from the given type array, initializing the palette.void
recount()
Recount the amount of non-air blocks in the chunk section.void
setBlockLight
(int x, int y, int z, byte light) Sets the block light at the given block.void
setSkyLight
(int x, int y, int z, byte light) Sets the sky light at the given block.void
setType
(int x, int y, int z, int value) Sets the type at the given coordinates.snapshot()
Take a snapshot of this section which will not reflect future changes.void
writeToBuf
(io.netty.buffer.ByteBuf buf, boolean skylight) Writes this chunk section to the given ByteBuf.void
writeToNbt
(CompoundTag sectionTag) Writes this chunk section to a NBT compound.
-
Field Details
-
ARRAY_SIZE
public static final int ARRAY_SIZEThe number of blocks in a chunk section, and thus the number of elements in all arrays used for it.- See Also:
-
EMPTY_BLOCK_LIGHT
public static final byte EMPTY_BLOCK_LIGHTBlock light level to use for empty chunk sections.- See Also:
-
EMPTY_SKYLIGHT
public static final byte EMPTY_SKYLIGHTSky light level to use for empty chunk sections.- See Also:
-
DEFAULT_BLOCK_LIGHT
public static final byte DEFAULT_BLOCK_LIGHTThe default value for block light, used on new chunk sections.- See Also:
-
DEFAULT_SKYLIGHT
public static final byte DEFAULT_SKYLIGHTThe default value for sky light, used on new chunk sections.- See Also:
-
GLOBAL_PALETTE_BITS_PER_BLOCK
public static final int GLOBAL_PALETTE_BITS_PER_BLOCKThe number of bits per block used in the global palette.- See Also:
-
-
Constructor Details
-
ChunkSection
public ChunkSection()Create a new, empty ChunkSection. -
ChunkSection
public ChunkSection(int[] types) Create a new, unlit chunk section with the specified chunk data.
This ChunkSection assumes ownership of the arrays passed in, and they should not be further modified.
- Parameters:
types
- An array of block state IDs for this chunk section (containing type and metadata)
-
ChunkSection
Deprecated.Create a ChunkSection with the specified chunk data.
This ChunkSection assumes ownership of the arrays passed in, and they should not be further modified.
- Parameters:
types
- An array of block types for this chunk section.skyLight
- An array for skylight data for this chunk section.blockLight
- An array for blocklight data for this chunk section.
-
ChunkSection
@Deprecated public ChunkSection(VariableValueArray data, @Nullable it.unimi.dsi.fastutil.ints.IntList palette, NibbleArray skyLight, NibbleArray blockLight) Deprecated.Create a ChunkSection with the specified chunk data.
This ChunkSection assumes ownership of the arrays passed in, and they should not be further modified.
- Parameters:
data
- An array of blocks in this section.palette
- The palette that is associated with that data. If null, the global palette is used.skyLight
- An array for skylight data for this chunk section.blockLight
- An array for blocklight data for this chunk section.
-
-
Method Details
-
fromStateArray
Deprecated.Creates a new unlit chunk section containing the given types.- Parameters:
types
- An array of block IDs- Returns:
- A matching chunk section.
-
loadTypeArray
public void loadTypeArray(int[] types) Loads the contents of this chunk section from the given type array, initializing the palette.- Parameters:
types
- The type array.
-
fromNbt
Creates a new chunk section from the given NBT blob.- Parameters:
sectionTag
- The tag to read from- Returns:
- The section
-
index
public int index(int x, int y, int z) Calculate the index into internal arrays for the given coordinates.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.- Returns:
- The index.
-
recount
public void recount()Recount the amount of non-air blocks in the chunk section. -
snapshot
Take a snapshot of this section which will not reflect future changes.- Returns:
- The snapshot for this section.
-
getBlockData
public org.bukkit.block.data.BlockData getBlockData(int x, int y, int z) -
getType
public int getType(int x, int y, int z) Gets the type at the given coordinates.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.- Returns:
- A type ID
-
setType
public void setType(int x, int y, int z, int value) Sets the type at the given coordinates.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.value
- The new type ID for that coordinate.
-
getTypes
public int[] getTypes()Returns the block type array. Do not modify this array.- Returns:
- The block type array.
-
getBlockLight
public byte getBlockLight(int x, int y, int z) Gets the block light at the given block.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.- Returns:
- The block light at the given coordinates.
-
setBlockLight
public void setBlockLight(int x, int y, int z, byte light) Sets the block light at the given block.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.light
- The new light level.
-
getSkyLight
public byte getSkyLight(int x, int y, int z) Gets the sky light at the given block.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.- Returns:
- The sky light at the given coordinates.
-
setSkyLight
public void setSkyLight(int x, int y, int z, byte light) Sets the sky light at the given block.- Parameters:
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.light
- The new light level.
-
isEmpty
public boolean isEmpty()Checks whether this chunk section is empty, IE doesn't need to be sent or saved.
This implementation has the same issue that causes MC-80966:
It assumes that a chunk section with only air blocks has no meaningful data. This assumption is incorrect for sections near light sources, which can create lighting bugs. However, it is more expensive to send additional sections with just light data.
- Returns:
- True if this chunk section is empty and can be removed.
-
writeToBuf
Writes this chunk section to the given ByteBuf.- Parameters:
buf
- The buffer to write to.skylight
- True if skylight should be included.- Throws:
IllegalStateException
- If this chunk section is empty
-
writeToNbt
Writes this chunk section to a NBT compound. Note that the Y coordinate is not written.- Parameters:
sectionTag
- The tag to write to
-
getSkyLight
The sky light array. This array is always set, even in dimensions without skylight.- Returns:
- The sky light array. If the dimension of this chunk section's chunk's world is not the overworld, this array contains only maximum light levels.
-
getBlockLight
The block light array.
-