Merge remote-tracking branch 'origin/1.20' into 1.21.1

This commit is contained in:
embeddedt 2025-05-19 16:00:38 -04:00
commit 1921ec9eb8
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -2,16 +2,20 @@ package org.embeddedt.modernfix.render.font;
import net.minecraft.client.gui.font.providers.UnihexProvider;
import java.lang.reflect.Array;
/**
* Implements more compact storage for LineData contents.
*
* Credit for the idea of using flattened fields rather than a backing array goes to @AnAwesomGuy.
*/
public class CompactUnihexContents {
private static final boolean TEST_ROUNDTRIP = false;
private static long extract8Bytes(byte[] arr, int off) {
long l = 0;
for (int i = 0; i < 8; i++) {
l |= ((long)arr[off + i] << (i * 8));
l |= (((long)arr[off + i] & 0xFF) << (i * 8));
}
return l;
}
@ -23,7 +27,7 @@ public class CompactUnihexContents {
private static long extract4Shorts(short[] arr, int off) {
long l = 0;
for (int i = 0; i < 4; i++) {
l |= ((long)arr[off + i] << (i * 16));
l |= (((long)arr[off + i] & 0xFFFF) << (i * 16));
}
return l;
}
@ -32,6 +36,16 @@ public class CompactUnihexContents {
return (short)((compressed >> (off * 16)) & 0xFFFF);
}
private static void verifyRoundTrip(Object originalArray, UnihexProvider.LineData data, int shift) {
for(int i = 0; i < 16; i++) {
int val = Array.getInt(originalArray, i) << shift;
int actualVal = data.line(i);
if (val != actualVal) {
throw new AssertionError("Value at index %d differs. Expected %08x, got %08x".formatted(i, val, actualVal));
}
}
}
public static class Bytes implements UnihexProvider.LineData {
private final long b0;
private final long b8;
@ -39,6 +53,9 @@ public class CompactUnihexContents {
public Bytes(byte[] contents) {
this.b0 = extract8Bytes(contents, 0);
this.b8 = extract8Bytes(contents, 8);
if (TEST_ROUNDTRIP) {
verifyRoundTrip(contents, this, 24);
}
}
@Override
@ -70,6 +87,9 @@ public class CompactUnihexContents {
this.b4 = extract4Shorts(contents, 4);
this.b8 = extract4Shorts(contents, 8);
this.b12 = extract4Shorts(contents, 12);
if (TEST_ROUNDTRIP) {
verifyRoundTrip(contents, this, 16);
}
}
@Override