Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 17:10:13 +01:00
Handle negative bits per value in palette
Dieser Commit ist enthalten in:
Ursprung
53c54485eb
Commit
c8a010c390
@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class FlatItemType extends BaseItemType {
|
public class FlatItemType extends BaseItemType {
|
||||||
public FlatItemType() {
|
public FlatItemType() {
|
||||||
@ -33,7 +34,7 @@ public class FlatItemType extends BaseItemType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item read(ByteBuf buffer) throws Exception {
|
public @Nullable Item read(ByteBuf buffer) throws Exception {
|
||||||
short id = buffer.readShort();
|
short id = buffer.readShort();
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -47,7 +48,7 @@ public class FlatItemType extends BaseItemType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuf buffer, Item object) throws Exception {
|
public void write(ByteBuf buffer, @Nullable Item object) throws Exception {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
buffer.writeShort(-1);
|
buffer.writeShort(-1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.minecraft;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class FlatVarIntItemType extends BaseItemType {
|
public class FlatVarIntItemType extends BaseItemType {
|
||||||
public FlatVarIntItemType() {
|
public FlatVarIntItemType() {
|
||||||
@ -32,7 +33,7 @@ public class FlatVarIntItemType extends BaseItemType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item read(ByteBuf buffer) throws Exception {
|
public @Nullable Item read(ByteBuf buffer) throws Exception {
|
||||||
boolean present = buffer.readBoolean();
|
boolean present = buffer.readBoolean();
|
||||||
if (!present) {
|
if (!present) {
|
||||||
return null;
|
return null;
|
||||||
@ -46,7 +47,7 @@ public class FlatVarIntItemType extends BaseItemType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuf buffer, Item object) throws Exception {
|
public void write(ByteBuf buffer, @Nullable Item object) throws Exception {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
buffer.writeBoolean(false);
|
buffer.writeBoolean(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.minecraft;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class ItemType extends BaseItemType {
|
public class ItemType extends BaseItemType {
|
||||||
public ItemType() {
|
public ItemType() {
|
||||||
@ -32,7 +33,7 @@ public class ItemType extends BaseItemType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item read(ByteBuf buffer) throws Exception {
|
public @Nullable Item read(ByteBuf buffer) throws Exception {
|
||||||
short id = buffer.readShort();
|
short id = buffer.readShort();
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -47,7 +48,7 @@ public class ItemType extends BaseItemType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuf buffer, Item object) throws Exception {
|
public void write(ByteBuf buffer, @Nullable Item object) throws Exception {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
buffer.writeShort(-1);
|
buffer.writeShort(-1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,12 +42,8 @@ public final class PaletteType1_18 extends Type<DataPalette> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataPalette read(final ByteBuf buffer) throws Exception {
|
public DataPalette read(final ByteBuf buffer) throws Exception {
|
||||||
int bitsPerValue = buffer.readByte();
|
final int originalBitsPerValue = buffer.readByte();
|
||||||
final int originalBitsPerValue = bitsPerValue;
|
int bitsPerValue = originalBitsPerValue;
|
||||||
|
|
||||||
if (bitsPerValue > type.highestBitsPerValue()) {
|
|
||||||
bitsPerValue = globalPaletteBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read palette
|
// Read palette
|
||||||
final DataPaletteImpl palette;
|
final DataPaletteImpl palette;
|
||||||
@ -59,6 +55,12 @@ public final class PaletteType1_18 extends Type<DataPalette> {
|
|||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bitsPerValue < 0 || bitsPerValue > type.highestBitsPerValue()) {
|
||||||
|
bitsPerValue = globalPaletteBits;
|
||||||
|
} else if (type == PaletteType.BLOCKS && bitsPerValue < 4) {
|
||||||
|
bitsPerValue = 4; // Linear block palette values are always 4 bits
|
||||||
|
}
|
||||||
|
|
||||||
if (bitsPerValue != globalPaletteBits) {
|
if (bitsPerValue != globalPaletteBits) {
|
||||||
final int paletteLength = Type.VAR_INT.readPrimitive(buffer);
|
final int paletteLength = Type.VAR_INT.readPrimitive(buffer);
|
||||||
palette = new DataPaletteImpl(type.size(), paletteLength);
|
palette = new DataPaletteImpl(type.size(), paletteLength);
|
||||||
@ -70,14 +72,15 @@ public final class PaletteType1_18 extends Type<DataPalette> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read values
|
// Read values
|
||||||
final long[] values = new long[Type.VAR_INT.readPrimitive(buffer)];
|
final int valuesLength = Type.VAR_INT.readPrimitive(buffer);
|
||||||
if (values.length > 0) {
|
if (valuesLength > 0) {
|
||||||
final char valuesPerLong = (char) (64 / bitsPerValue);
|
final int valuesPerLong = (char) (64 / bitsPerValue);
|
||||||
final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong;
|
final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong;
|
||||||
if (values.length != expectedLength) {
|
if (valuesLength != expectedLength) {
|
||||||
throw new IllegalStateException("Palette data length (" + values.length + ") does not match expected length (" + expectedLength + ")! bitsPerValue=" + bitsPerValue + ", originalBitsPerValue=" + originalBitsPerValue);
|
throw new IllegalStateException("Palette data length (" + valuesLength + ") does not match expected length (" + expectedLength + ")! bitsPerValue=" + bitsPerValue + ", originalBitsPerValue=" + originalBitsPerValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final long[] values = new long[valuesLength];
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
values[i] = buffer.readLong();
|
values[i] = buffer.readLong();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren