Skip to content

Commit

Permalink
Add validation around serialization in AttachmentHolder
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <[email protected]>
  • Loading branch information
TheSilkMiner committed Feb 11, 2025
1 parent a0130d3 commit 9782956
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ public final CompoundTag serializeAttachments(HolderLookup.Provider provider) {
CompoundTag tag = null;
for (var entry : attachments.entrySet()) {
var type = entry.getKey();
var key = NeoForgeRegistries.ATTACHMENT_TYPES.getKey(type);
if (type.serializer != null) {
Tag serialized = ((IAttachmentSerializer<?, Object>) type.serializer).write(entry.getValue(), provider);
if (serialized != null) {
if (tag == null)
tag = new CompoundTag();
tag.put(NeoForgeRegistries.ATTACHMENT_TYPES.getKey(type).toString(), serialized);
try {
Tag serialized = ((IAttachmentSerializer<?, Object>) type.serializer).write(entry.getValue(), provider);
if (serialized != null) {
if (tag == null)
tag = new CompoundTag();
tag.put(key.toString(), serialized);
}
} catch (Exception exception) {
LOGGER.error("Failed to serialize data attachment {}. Skipping.", key, exception);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ public Tag write(T attachment, HolderLookup.Provider provider) {
}

private RuntimeException buildException(final String operation, final String error) {
// TODO: Maybe find a way to let the user know *which* attachment has exploded?
return new IllegalStateException("Unable to " + operation + " attachment due to an internal codec error: " + error);
}
});
Expand Down

0 comments on commit 9782956

Please sign in to comment.