mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-13 19:51:27 +01:00
Fix bits per entry value during palette resize
This commit is contained in:
parent
97a29c6ccf
commit
d6a3b18f04
@ -752,8 +752,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
*/
|
||||
@Nullable
|
||||
public Chunk getChunkAt(float x, float z) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate((int) Math.floor(x));
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate((int) Math.floor(z));
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate((int) x);
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate((int) z);
|
||||
return getChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
|
@ -61,12 +61,7 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
*/
|
||||
public PaletteStorage(int bitsPerEntry, int bitsIncrement) {
|
||||
Check.argCondition(bitsPerEntry > MAXIMUM_BITS_PER_ENTRY, "The maximum bits per entry is 15");
|
||||
// Change the bitsPerEntry to be valid
|
||||
if (bitsPerEntry < MINIMUM_BITS_PER_ENTRY) {
|
||||
bitsPerEntry = MINIMUM_BITS_PER_ENTRY;
|
||||
} else if (MathUtils.isBetween(bitsPerEntry, 9, 14)) {
|
||||
bitsPerEntry = MAXIMUM_BITS_PER_ENTRY;
|
||||
}
|
||||
bitsPerEntry = fixBitsPerEntry(bitsPerEntry);
|
||||
|
||||
this.bitsPerEntry = bitsPerEntry;
|
||||
this.bitsIncrement = bitsIncrement;
|
||||
@ -230,6 +225,7 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
* @param newBitsPerEntry the new bits per entry count
|
||||
*/
|
||||
private synchronized void resize(int newBitsPerEntry) {
|
||||
newBitsPerEntry = fixBitsPerEntry(newBitsPerEntry);
|
||||
PaletteStorage paletteStorageCache = new PaletteStorage(newBitsPerEntry, bitsIncrement);
|
||||
paletteStorageCache.paletteBlockMaps = paletteBlockMaps;
|
||||
paletteStorageCache.blockPaletteMaps = blockPaletteMaps;
|
||||
@ -404,4 +400,21 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes invalid bitsPerEntry values.
|
||||
* <p>
|
||||
* See https://wiki.vg/Chunk_Format#Direct
|
||||
*
|
||||
* @param bitsPerEntry the bits per entry value before fixing
|
||||
* @return the fixed bits per entry value
|
||||
*/
|
||||
private static int fixBitsPerEntry(int bitsPerEntry) {
|
||||
if (bitsPerEntry < MINIMUM_BITS_PER_ENTRY) {
|
||||
return MINIMUM_BITS_PER_ENTRY;
|
||||
} else if (MathUtils.isBetween(bitsPerEntry, 9, 14)) {
|
||||
return MAXIMUM_BITS_PER_ENTRY;
|
||||
}
|
||||
return bitsPerEntry;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public abstract class PlayerConnection {
|
||||
protected static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
|
||||
|
||||
private Player player;
|
||||
private ConnectionState connectionState;
|
||||
private volatile ConnectionState connectionState;
|
||||
private boolean online;
|
||||
|
||||
// Text used to kick client sending too many packets
|
||||
|
Loading…
Reference in New Issue
Block a user