Print data component type on encoding error

This commit is contained in:
Nassim Jahnke 2024-05-09 15:11:34 +02:00
parent b50682ab2b
commit aabe9f5264

View file

@ -9,16 +9,22 @@
}); });
public static final StreamCodec<RegistryFriendlyByteBuf, DataComponentPatch> STREAM_CODEC = new StreamCodec<RegistryFriendlyByteBuf, DataComponentPatch>() { public static final StreamCodec<RegistryFriendlyByteBuf, DataComponentPatch> STREAM_CODEC = new StreamCodec<RegistryFriendlyByteBuf, DataComponentPatch>() {
public DataComponentPatch decode(RegistryFriendlyByteBuf registryfriendlybytebuf) { public DataComponentPatch decode(RegistryFriendlyByteBuf registryfriendlybytebuf) {
@@ -144,7 +144,7 @@ @@ -144,7 +144,13 @@
} }
private static <T> void encodeComponent(RegistryFriendlyByteBuf buf, DataComponentType<T> type, Object value) { private static <T> void encodeComponent(RegistryFriendlyByteBuf buf, DataComponentType<T> type, Object value) {
- type.streamCodec().encode(buf, value); - type.streamCodec().encode(buf, value);
+ // Paper start - codec errors of random anonymous classes are useless
+ try {
+ type.streamCodec().encode(buf, (T) value); // CraftBukkit - decompile error + type.streamCodec().encode(buf, (T) value); // CraftBukkit - decompile error
+ } catch (final Exception e) {
+ throw new RuntimeException("Error encoding component " + type, e);
+ }
+ // Paper end - codec errors of random anonymous classes are useless
} }
}; };
private static final String REMOVED_PREFIX = "!"; private static final String REMOVED_PREFIX = "!";
@@ -270,7 +270,43 @@ @@ -270,7 +276,43 @@
private final Reference2ObjectMap<DataComponentType<?>, Optional<?>> map = new Reference2ObjectArrayMap(); private final Reference2ObjectMap<DataComponentType<?>, Optional<?>> map = new Reference2ObjectArrayMap();
Builder() {} Builder() {}