Skip to content

Commit

Permalink
Deserialize components in registration order
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Nov 22, 2020
1 parent b8aa8ea commit 3bfca31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException;

import javax.annotation.Nullable;
import java.util.AbstractMap;
Expand Down Expand Up @@ -144,6 +143,7 @@ public C get(@Nullable Object key) {

@Override
public abstract C put(ComponentType<?> key, C value);

/**
* {@inheritDoc}
*
Expand All @@ -170,21 +170,21 @@ public void fromTag(CompoundTag tag) {
}
} else if (tag.contains("cardinal_components", NbtType.COMPOUND)) {
CompoundTag componentMap = tag.getCompound(NBT_KEY);
for (String keyId : componentMap.getKeys()) {
try {
ComponentKey<?> key = ComponentRegistry.INSTANCE.get(new Identifier(keyId));
if (key != null) {
Component component = key.getInternal(this);
if (component != null) {
component.fromTag(componentMap.getCompound(keyId));
}
} else {
ComponentsInternals.LOGGER.warn("Failed to deserialize component: unregistered key " + keyId);
}
} catch (InvalidIdentifierException e) {
ComponentsInternals.LOGGER.warn("Failed to deserialize component: invalid id " + keyId);

for (ComponentKey<?> key : this.keys()) {
String keyId = key.getId().toString();

if (componentMap.contains(keyId, NbtType.COMPOUND)) {
Component component = key.getInternal(this);
assert component != null;
component.fromTag(componentMap.getCompound(keyId));
componentMap.remove(keyId);
}
}

for (String missedKeyId : componentMap.getKeys()) {
ComponentsInternals.LOGGER.warn("Failed to deserialize component: unregistered key " + missedKeyId);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 2.7.7
------------------------------------------------------
Fixes
- Fixed NBT deserialization not respecting component registration order

------------------------------------------------------
Version 2.7.6
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.10.6+build.214
fabric_api_version=0.25.1+build.416-1.16

#Publishing
mod_version = 2.7.6
mod_version = 2.7.7
curseforge_id = 318449
curseforge_versions = 1.16.2; 1.16.3; 1.16.4
changelog_url = https://github.com/OnyxStudios/Cardinal-Components-API/blob/master/changelog.md
Expand Down

0 comments on commit 3bfca31

Please sign in to comment.