Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
fix 1.13 chunk reading, fix 1.9 chunk type not using global palette
Dieser Commit ist enthalten in:
Ursprung
318db58be1
Commit
3063538ad0
@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
||||||
|
private static final int GLOBAL_PALETTE = 14;
|
||||||
|
|
||||||
public ChunkSectionType1_13() {
|
public ChunkSectionType1_13() {
|
||||||
super("Chunk Section Type", ChunkSection.class);
|
super("Chunk Section Type", ChunkSection.class);
|
||||||
@ -16,18 +17,15 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
|||||||
|
|
||||||
// Reaad bits per block
|
// Reaad bits per block
|
||||||
int bitsPerBlock = buffer.readUnsignedByte();
|
int bitsPerBlock = buffer.readUnsignedByte();
|
||||||
|
int originalBitsPerBlock = bitsPerBlock;
|
||||||
|
|
||||||
|
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
|
||||||
|
bitsPerBlock = GLOBAL_PALETTE;
|
||||||
|
}
|
||||||
|
|
||||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
|
||||||
if (bitsPerBlock == 0) {
|
int paletteLength = bitsPerBlock == GLOBAL_PALETTE ? 0 : Type.VAR_INT.read(buffer);
|
||||||
bitsPerBlock = 14;
|
|
||||||
}
|
|
||||||
if (bitsPerBlock < 4) {
|
|
||||||
bitsPerBlock = 4;
|
|
||||||
}
|
|
||||||
if (bitsPerBlock > 8) {
|
|
||||||
bitsPerBlock = 14;
|
|
||||||
}
|
|
||||||
int paletteLength = bitsPerBlock == 14 ? 0 : Type.VAR_INT.read(buffer);
|
|
||||||
// Read palette
|
// Read palette
|
||||||
chunkSection.clearPalette();
|
chunkSection.clearPalette();
|
||||||
for (int i = 0; i < paletteLength; i++) {
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
@ -37,6 +35,11 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
|||||||
// Read blocks
|
// Read blocks
|
||||||
long[] blockData = new long[Type.VAR_INT.read(buffer)];
|
long[] blockData = new long[Type.VAR_INT.read(buffer)];
|
||||||
if (blockData.length > 0) {
|
if (blockData.length > 0) {
|
||||||
|
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||||
|
if (blockData.length != expectedLength) {
|
||||||
|
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < blockData.length; i++) {
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
blockData[i] = buffer.readLong();
|
blockData[i] = buffer.readLong();
|
||||||
}
|
}
|
||||||
@ -53,7 +56,7 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
|||||||
val = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
|
val = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitsPerBlock == 14) {
|
if (bitsPerBlock == GLOBAL_PALETTE) {
|
||||||
chunkSection.setFlatBlock(i, val);
|
chunkSection.setFlatBlock(i, val);
|
||||||
} else {
|
} else {
|
||||||
chunkSection.setPaletteIndex(i, val);
|
chunkSection.setPaletteIndex(i, val);
|
||||||
@ -72,15 +75,14 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bitsPerBlock > 8) {
|
if (bitsPerBlock > 8) {
|
||||||
bitsPerBlock = 14;
|
bitsPerBlock = GLOBAL_PALETTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
buffer.writeByte(bitsPerBlock);
|
buffer.writeByte(bitsPerBlock);
|
||||||
|
|
||||||
|
|
||||||
// Write pallet (or not)
|
// Write pallet (or not)
|
||||||
if (bitsPerBlock != 14) {
|
if (bitsPerBlock != GLOBAL_PALETTE) {
|
||||||
Type.VAR_INT.write(buffer, chunkSection.getPaletteSize());
|
Type.VAR_INT.write(buffer, chunkSection.getPaletteSize());
|
||||||
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
||||||
Type.VAR_INT.write(buffer, chunkSection.getPaletteEntry(i));
|
Type.VAR_INT.write(buffer, chunkSection.getPaletteEntry(i));
|
||||||
@ -91,7 +93,7 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
|||||||
Type.VAR_INT.write(buffer, length);
|
Type.VAR_INT.write(buffer, length);
|
||||||
long[] data = new long[length];
|
long[] data = new long[length];
|
||||||
for (int index = 0; index < ChunkSection.SIZE; index++) {
|
for (int index = 0; index < ChunkSection.SIZE; index++) {
|
||||||
int value = bitsPerBlock == 14 ? chunkSection.getFlatBlock(index) : chunkSection.getPaletteIndex(index);
|
int value = bitsPerBlock == GLOBAL_PALETTE ? chunkSection.getFlatBlock(index) : chunkSection.getPaletteIndex(index);
|
||||||
int bitIndex = index * bitsPerBlock;
|
int bitIndex = index * bitsPerBlock;
|
||||||
int startIndex = bitIndex / 64;
|
int startIndex = bitIndex / 64;
|
||||||
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package us.myles.ViaVersion.api.type.types.version;
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
||||||
|
private static final int GLOBAL_PALETTE = 13;
|
||||||
|
|
||||||
public ChunkSectionType1_9() {
|
public ChunkSectionType1_9() {
|
||||||
super("Chunk Section Type", ChunkSection.class);
|
super("Chunk Section Type", ChunkSection.class);
|
||||||
@ -17,22 +17,23 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
|||||||
|
|
||||||
// Reaad bits per block
|
// Reaad bits per block
|
||||||
int bitsPerBlock = buffer.readUnsignedByte();
|
int bitsPerBlock = buffer.readUnsignedByte();
|
||||||
|
int originalBitsPerBlock = bitsPerBlock;
|
||||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
|
||||||
if (bitsPerBlock == 0) {
|
if (bitsPerBlock == 0) {
|
||||||
bitsPerBlock = 13;
|
bitsPerBlock = GLOBAL_PALETTE;
|
||||||
}
|
}
|
||||||
if (bitsPerBlock < 4) {
|
if (bitsPerBlock < 4) {
|
||||||
bitsPerBlock = 4;
|
bitsPerBlock = 4;
|
||||||
}
|
}
|
||||||
if (bitsPerBlock > 8) {
|
if (bitsPerBlock > 8) {
|
||||||
bitsPerBlock = 13;
|
bitsPerBlock = GLOBAL_PALETTE;
|
||||||
}
|
}
|
||||||
int paletteLength = Type.VAR_INT.read(buffer);
|
int paletteLength = Type.VAR_INT.read(buffer);
|
||||||
// Read palette
|
// Read palette
|
||||||
chunkSection.clearPalette();
|
chunkSection.clearPalette();
|
||||||
for (int i = 0; i < paletteLength; i++) {
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
if (bitsPerBlock != 13) {
|
if (bitsPerBlock != GLOBAL_PALETTE) {
|
||||||
chunkSection.addPaletteEntry(Type.VAR_INT.read(buffer));
|
chunkSection.addPaletteEntry(Type.VAR_INT.read(buffer));
|
||||||
} else {
|
} else {
|
||||||
Type.VAR_INT.read(buffer);
|
Type.VAR_INT.read(buffer);
|
||||||
@ -42,6 +43,11 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
|||||||
// Read blocks
|
// Read blocks
|
||||||
long[] blockData = new long[Type.VAR_INT.read(buffer)];
|
long[] blockData = new long[Type.VAR_INT.read(buffer)];
|
||||||
if (blockData.length > 0) {
|
if (blockData.length > 0) {
|
||||||
|
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||||
|
if (blockData.length != expectedLength) {
|
||||||
|
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < blockData.length; i++) {
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
blockData[i] = buffer.readLong();
|
blockData[i] = buffer.readLong();
|
||||||
}
|
}
|
||||||
@ -58,7 +64,7 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
|||||||
val = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
|
val = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitsPerBlock == 13) {
|
if (bitsPerBlock == GLOBAL_PALETTE) {
|
||||||
chunkSection.setBlock(i, val >> 4, val & 0xF);
|
chunkSection.setBlock(i, val >> 4, val & 0xF);
|
||||||
} else {
|
} else {
|
||||||
chunkSection.setPaletteIndex(i, val);
|
chunkSection.setPaletteIndex(i, val);
|
||||||
@ -75,20 +81,29 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
|||||||
while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) {
|
while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) {
|
||||||
bitsPerBlock += 1;
|
bitsPerBlock += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bitsPerBlock > 8) {
|
||||||
|
bitsPerBlock = GLOBAL_PALETTE;
|
||||||
|
}
|
||||||
|
|
||||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
buffer.writeByte(bitsPerBlock);
|
buffer.writeByte(bitsPerBlock);
|
||||||
|
|
||||||
// Write pallet
|
// Write pallet (or not)
|
||||||
|
if (bitsPerBlock != GLOBAL_PALETTE) {
|
||||||
Type.VAR_INT.write(buffer, chunkSection.getPaletteSize());
|
Type.VAR_INT.write(buffer, chunkSection.getPaletteSize());
|
||||||
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
||||||
Type.VAR_INT.write(buffer, chunkSection.getPaletteEntry(i));
|
Type.VAR_INT.write(buffer, chunkSection.getPaletteEntry(i));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Type.VAR_INT.write(buffer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int length = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
int length = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||||
Type.VAR_INT.write(buffer, length);
|
Type.VAR_INT.write(buffer, length);
|
||||||
long[] data = new long[length];
|
long[] data = new long[length];
|
||||||
for (int index = 0; index < ChunkSection.SIZE; index++) {
|
for (int index = 0; index < ChunkSection.SIZE; index++) {
|
||||||
int value = chunkSection.getPaletteIndex(index);
|
int value = bitsPerBlock == GLOBAL_PALETTE ? chunkSection.getFlatBlock(index) : chunkSection.getPaletteIndex(index);
|
||||||
int bitIndex = index * bitsPerBlock;
|
int bitIndex = index * bitsPerBlock;
|
||||||
int startIndex = bitIndex / 64;
|
int startIndex = bitIndex / 64;
|
||||||
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren