mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-15 20:51:34 +01:00
Created PaletteStorage#clean
This commit is contained in:
parent
f67328c7a7
commit
47a18fc305
@ -91,7 +91,7 @@ public final class BenchmarkManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the memory used by the server in bytes.
|
||||
* Gets the heap memory used by the server in bytes.
|
||||
*
|
||||
* @return the memory used by the server
|
||||
*/
|
||||
|
@ -181,7 +181,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
/**
|
||||
* Called each tick.
|
||||
*
|
||||
* @param time the time of update in milliseconds
|
||||
* @param time time of the update in milliseconds
|
||||
*/
|
||||
public abstract void update(long time);
|
||||
|
||||
|
@ -112,6 +112,33 @@ public class PaletteStorage {
|
||||
return sectionBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops through all the sections and blocks to find unused array (empty chunk section)
|
||||
* <p>
|
||||
* Useful after clearing one or multiple sections of a chunk. Can be unnecessarily expensive if the chunk
|
||||
* is composed of almost-empty sections since the loop will not stop until a non-air block is discovered.
|
||||
*/
|
||||
public synchronized void clean() {
|
||||
for (int i = 0; i < sectionBlocks.length; i++) {
|
||||
long[] section = sectionBlocks[i];
|
||||
|
||||
if (section.length != 0) {
|
||||
boolean canClear = true;
|
||||
for (long blockGroup : section) {
|
||||
if (blockGroup != 0) {
|
||||
canClear = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (canClear) {
|
||||
sectionBlocks[i] = new long[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public PaletteStorage copy() {
|
||||
PaletteStorage paletteStorage = new PaletteStorage(bitsPerEntry, bitsIncrement);
|
||||
paletteStorage.sectionBlocks = sectionBlocks.clone();
|
||||
|
@ -149,7 +149,7 @@ public final class PacketProcessor {
|
||||
* @param reader the buffer containing the packet
|
||||
*/
|
||||
private void safeRead(@NotNull PlayerConnection connection, @NotNull Readable readable, @NotNull BinaryReader reader) {
|
||||
final int readableBytes = reader.getBuffer().readableBytes();
|
||||
final int readableBytes = reader.available();
|
||||
|
||||
// Check if there is anything to read
|
||||
if (readableBytes == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user