Add more jd to Chunk, ChunkSection, and ChunkSectionLight

This commit is contained in:
KennyTV 2021-05-20 19:23:29 +02:00
parent cf2adab728
commit 1fe76dbb77
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
5 changed files with 162 additions and 29 deletions

View File

@ -134,7 +134,7 @@ public class BaseChunk implements Chunk {
}
@Override
public CompoundTag getHeightMap() {
public @Nullable CompoundTag getHeightMap() {
return heightMap;
}

View File

@ -30,8 +30,18 @@ import java.util.List;
public interface Chunk {
/**
* Returns the chunk x coordinate.
*
* @return chunk x coordinate
*/
int getX();
/**
* Returns the chunk z coordinate.
*
* @return chunk z coordinate
*/
int getZ();
/**
@ -72,17 +82,37 @@ public interface Chunk {
void setChunkMask(BitSet chunkSectionMask);
ChunkSection[] getSections();
/**
* Returns an array of nullable chunk section entries.
*
* @return array of nullable chunk sections
*/
@Nullable ChunkSection[] getSections();
void setSections(ChunkSection[] sections);
/**
* Returns the chunk's raw biome data. The format the biomes are stored may vary.
*
* @return raw biome data
*/
int @Nullable [] getBiomeData();
void setBiomeData(int @Nullable [] biomeData);
CompoundTag getHeightMap();
/**
* Returns a compoundtag containing the chunk's heightmaps if present.
*
* @return compoundtag containing heightmaps if present
*/
@Nullable CompoundTag getHeightMap();
void setHeightMap(CompoundTag heightMap);
void setHeightMap(@Nullable CompoundTag heightMap);
/**
* Returns a list of block entities.
*
* @return list of block entities
*/
List<CompoundTag> getBlockEntities();
}

View File

@ -43,21 +43,46 @@ public interface ChunkSection {
return y << 8 | z << 4 | x;
}
/**
* Returns the block state of the given index.
*
* @param idx block index within the section
* @return block state of the given index
*/
int getFlatBlock(int idx);
int getFlatBlock(int x, int y, int z);
/**
* Returns the block state of the section coordinate.
*
* @param x section x
* @param y section y
* @param z section z
* @return block state of the given section coordinate
*/
default int getFlatBlock(int x, int y, int z) {
return getFlatBlock(index(x, y, z));
}
/**
* Set a block state in the chunk
* This method will not update non-air blocks count
* Set a block state in the chunk section.
* This method will not update non-air blocks count.
*
* @param idx Index
* @param id The raw or flat id of the block
* @param idx block index within the section
* @param id raw or flat id of the block state
*/
void setFlatBlock(int idx, int id);
default void setFlatBlock(int x, int y, int z, int type) {
setFlatBlock(index(x, y, z), type);
/**
* Set a block state in the chunk section.
* This method will not update non-air blocks count.
*
* @param x section x
* @param y section y
* @param z section z
* @param id raw or flat id of the block state
*/
default void setFlatBlock(int x, int y, int z, int id) {
setFlatBlock(index(x, y, z), id);
}
default int getBlockWithoutData(int x, int y, int z) {
@ -69,8 +94,8 @@ public interface ChunkSection {
}
/**
* Set a block in the chunks
* This method will not update non-air blocks count
* Set a block in the chunks.
* This method will not update non-air blocks count.
*
* @param x Block X
* @param y Block Y
@ -86,26 +111,80 @@ public interface ChunkSection {
setFlatBlock(idx, type << 4 | (data & 0xF));
}
/**
* Sets a block to the given palette index.
*
* @param idx block index
* @param index palette index
*/
void setPaletteIndex(int idx, int index);
/**
* Returns the palette index of the given block index.
*
* @param idx block index
* @return palette index of the given block index
*/
int getPaletteIndex(int idx);
/**
* Returns the size of the palette.
*
* @return palette size
*/
int getPaletteSize();
/**
* Returns the block state assigned to the given palette index.
*
* @param index palette index
* @return block state assigned to the given palette index
*/
int getPaletteEntry(int index);
/**
* Assigns a block state assigned to the given palette index.
*
* @param index palette index
* @param id block state
*/
void setPaletteEntry(int index, int id);
/**
* Replaces a block state in the palette.
*
* @param oldId old block state
* @param newId new block state
*/
void replacePaletteEntry(int oldId, int newId);
/**
* Adds a new block state to the palette.
*
* @param id block state
*/
void addPaletteEntry(int id);
/**
* Clears the palette.
*/
void clearPalette();
/**
* Returns the number of non-air blocks in this section.
*
* @return non-air blocks in this section
*/
int getNonAirBlocksCount();
void setNonAirBlocksCount(int nonAirBlocksCount);
/**
* Returns whether this section holds light data.
* Only true for &lt 1.14 clients.
*
* @return whether this section holds light data
*/
default boolean hasLight() {
return getLight() != null;
}

View File

@ -64,12 +64,6 @@ public class ChunkSectionImpl implements ChunkSection {
return palette.getInt(index);
}
@Override
public int getFlatBlock(int x, int y, int z) {
int index = blocks[ChunkSection.index(x, y, z)];
return palette.getInt(index);
}
@Override
public void setFlatBlock(int idx, int id) {
int index = inversePalette.get(id);

View File

@ -33,36 +33,66 @@ public interface ChunkSectionLight {
int LIGHT_LENGTH = 16 * 16 * 16 / 2; // Dimensions / 2 (nibble bit count)
/**
* Check if sky light is present
* Returns whether the section has sky light.
*
* @return True if skylight is present
* @return true if skylight is present
*/
boolean hasSkyLight();
/**
* Returns whether the section has block light.
* This returns true unless specifically set to null.
*
* @return true if skylight is present
*/
boolean hasBlockLight();
/**
* Returns the nibblearray's raw sky light byte array if present.
*
* @return the nibblearray's raw sky light byte array if present
* @see #hasSkyLight()
*/
byte @Nullable [] getSkyLight();
/**
* Returns the nibblearray's raw block light byte array if present.
*
* @return the nibblearray's raw block light byte array if present
* @see #hasBlockLight()
*/
byte @Nullable [] getBlockLight();
/**
* Set the sky light array
* Set the sky light array.
*
* @param data The value to set the sky light to
* @param data raw sky light data
*/
void setSkyLight(byte[] data);
/**
* Set the block light array
* Set the block light array.
*
* @param data The value to set the block light to
* @param data raw block light data
*/
void setBlockLight(byte[] data);
@Nullable NibbleArray getBlockLightNibbleArray();
/**
* Returns the sky light nibblearray.
*
* @return sky light nibblearray
* @see #hasSkyLight()
*/
@Nullable NibbleArray getSkyLightNibbleArray();
/**
* Returns the block light nibblearray.
*
* @return block light nibblearray
* @see #hasBlockLight()
*/
@Nullable NibbleArray getBlockLightNibbleArray();
void readSkyLight(ByteBuf input);
void readBlockLight(ByteBuf input);
@ -70,14 +100,14 @@ public interface ChunkSectionLight {
/**
* Write the sky light to a buffer.
*
* @param output The buffer to write to
* @param output buffer to write to
*/
void writeSkyLight(ByteBuf output);
/**
* Write the block light to a buffer.
*
* @param output The buffer to write to
* @param output buffer to write to
*/
void writeBlockLight(ByteBuf output);
}