3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-08 13:52:50 +02:00

Fix <= 1.14 position y sign reading (#3381)

Dieser Commit ist enthalten in:
RK_01 2023-07-12 19:10:49 +02:00 committet von GitHub
Ursprung b22907748a
Commit 2ec6185c46
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -28,26 +28,24 @@ import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class PositionType extends Type<Position> { public class PositionType extends Type<Position> {
public PositionType() { public PositionType() {
super(Position.class); super(Position.class);
} }
@Override @Override
public Position read(ByteBuf buffer) { public Position read(ByteBuf buffer) {
long val = buffer.readLong(); final long val = buffer.readLong();
long x = (val >> 38); // signed final long x = (val >> 38);
long y = (val >> 26) & 0xfff; // unsigned final long y = (val << 26) >> 52;
// this shifting madness is used to preserve sign final long z = (val << 38) >> 38;
long z = (val << 38) >> 38; // signed
return new Position((int) x, (short) y, (int) z); return new Position((int) x, (short) y, (int) z);
} }
@Override @Override
public void write(ByteBuf buffer, Position object) { public void write(ByteBuf buffer, Position object) {
buffer.writeLong((((long) object.x() & 0x3ffffff) << 38) buffer.writeLong((object.x() & 0X3FFFFFFL) << 38 | (object.y() & 0XFFFL) << 26 | (object.z() & 0X3FFFFFFL));
| ((((long) object.y()) & 0xfff) << 26)
| (object.z() & 0x3ffffff));
} }
public static final class OptionalPositionType extends OptionalType<Position> { public static final class OptionalPositionType extends OptionalType<Position> {