public final class ChunkSection extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY_SIZE
The number of blocks in a chunk section, and thus the number of elements in all arrays used
for it.
|
static byte |
DEFAULT_BLOCK_LIGHT
The default value for block light, used on new chunk sections.
|
static byte |
DEFAULT_SKYLIGHT
The default value for sky light, used on new chunk sections.
|
static byte |
EMPTY_BLOCK_LIGHT
Block light level to use for empty chunk sections.
|
static byte |
EMPTY_SKYLIGHT
Sky light level to use for empty chunk sections.
|
static int |
GLOBAL_PALETTE_BITS_PER_BLOCK
The number of bits per block used in the global palette.
|
Constructor and Description |
---|
ChunkSection()
Create a new, empty ChunkSection.
|
ChunkSection(char[] types)
Create a new, unlit chunk section with the specified chunk data.
|
ChunkSection(char[] types,
NibbleArray skyLight,
NibbleArray blockLight)
Create a ChunkSection with the specified chunk data.
|
ChunkSection(VariableValueArray data,
it.unimi.dsi.fastutil.ints.IntList palette,
NibbleArray skyLight,
NibbleArray blockLight)
Create a ChunkSection with the specified chunk data.
|
Modifier and Type | Method and Description |
---|---|
static ChunkSection |
fromIdArray(byte[] types)
Creates a new unlit chunk section containing the given types.
|
static ChunkSection |
fromIdArray(short[] types)
Creates a new unlit chunk section containing the given types.
|
static ChunkSection |
fromNbt(CompoundTag sectionTag)
Creates a new chunk section from the given NBT blob.
|
static ChunkSection |
fromStateArray(short[] types)
Creates a new unlit chunk section containing the given types.
|
NibbleArray |
getBlockLight()
The block light array.
|
byte |
getBlockLight(int x,
int y,
int z)
Gets the block light at the given block.
|
NibbleArray |
getSkyLight()
The sky light array.
|
byte |
getSkyLight(int x,
int y,
int z)
Gets the sky light at the given block.
|
char |
getType(int x,
int y,
int z)
Gets the type at the given coordinates.
|
char[] |
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(char[] types)
Loads the contents of this chunk section from the given type array, initializing the
palette.
|
void |
optimize()
Optimizes this chunk section, removing unneeded palette entries and recounting non-air
blocks.
|
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,
char value)
Sets the type at the given coordinates.
|
ChunkSection |
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.
|
public static final int ARRAY_SIZE
public static final byte EMPTY_BLOCK_LIGHT
public static final byte EMPTY_SKYLIGHT
public static final byte DEFAULT_BLOCK_LIGHT
public static final byte DEFAULT_SKYLIGHT
public static final int GLOBAL_PALETTE_BITS_PER_BLOCK
public ChunkSection()
public ChunkSection(char[] 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.
types
- An array of block state IDs for this chunk section (containing type and
metadata)public ChunkSection(char[] types, NibbleArray skyLight, NibbleArray blockLight)
Create a ChunkSection with the specified chunk data.
This ChunkSection assumes ownership of the arrays passed in, and they should not be further modified.
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.public ChunkSection(VariableValueArray data, @Nullable it.unimi.dsi.fastutil.ints.IntList palette, NibbleArray skyLight, NibbleArray blockLight)
Create a ChunkSection with the specified chunk data.
This ChunkSection assumes ownership of the arrays passed in, and they should not be further modified.
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.public static ChunkSection fromStateArray(short[] types)
types
- An array of block IDs, with metadatapublic static ChunkSection fromIdArray(short[] types)
types
- An array of block IDs, without metadata.public static ChunkSection fromIdArray(byte[] types)
types
- An array of block IDs, without metadata.public static ChunkSection fromNbt(CompoundTag sectionTag)
sectionTag
- The tag to read frompublic int index(int x, int y, int z)
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.public void loadTypeArray(char[] types)
types
- The type array.public void optimize()
Optimizes this chunk section, removing unneeded palette entries and recounting non-air blocks.
This is an expensive operation, but occasionally performing it will improve sending the section.
public void recount()
public ChunkSection snapshot()
public char getType(int x, int y, int z)
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.public void setType(int x, int y, int z, char value)
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.public char[] getTypes()
public byte getBlockLight(int x, int y, int z)
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.public void setBlockLight(int x, int y, int z, byte light)
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.public byte getSkyLight(int x, int y, int z)
x
- The x coordinate, for east and west.y
- The y coordinate, for up and down.z
- The z coordinate, for north and south.public void setSkyLight(int x, int y, int z, byte light)
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.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.
public void writeToBuf(io.netty.buffer.ByteBuf buf, boolean skylight) throws IllegalStateException
buf
- The buffer to write to.skylight
- True if skylight should be included.IllegalStateException
- If this chunk section is emptypublic void writeToNbt(CompoundTag sectionTag)
sectionTag
- The tag to write topublic NibbleArray getSkyLight()
public NibbleArray getBlockLight()
Copyright © 2021. All rights reserved.