[1.17.0-5.0.34] Arrays and Maps do not keep their changes when edited in config file
TelepathicGrunt opened this issue ยท 2 comments
I know I already contacted you about this and this issue was known but I still think making an issue report is good so that this is recorded somewhere and others won't keep asking about it lol.
So with 1.17 v5.0.34 Cloth Config API, I noticed that using arrays and maps of only strings will not save and keep their changes done to them even when I do @ConfigEntry.Gui.Excluded
.
A mod with a list config that has the issue: https://github.com/TelepathicGrunt/WorldBlender-Fabric/blob/138a727787fa3ab00b30d957b48cbcd633afc1fa/src/main/java/com/telepathicgrunt/worldblender/configs/WBDimensionConfigs.java#L76
A mod with the map config that has the issue: https://github.com/TelepathicGrunt/RepurposedStructures-Fabric/blob/f2bd3b3f3a6ddda278869d839fdc5a2d96175fa7/src/main/java/com/telepathicgrunt/repurposedstructures/configs/RSAllowDisallowConfig.java#L76
In both the array and map, Cloth Config API is able to write the default values to the json file. But editing this value in the file directly causes Cloth Config API to reset the entry back to the default values always.
Let me know if you need me to do more tests or give more info.
Through debugging and many breakpoints later, I found that the following lines are to blame, at least for the JanksonConfigSerializer
which uses Jankson under the hood -
I noticed that the actual Map<Object, Object> map
argument passed was immutable, and upon further reading -
The Map.of, Map.ofEntries, and Map.copyOf static factory methods provide a convenient way to create unmodifiable maps.
You can easily work around this by replacing your direct assignment of Map.of
, etc. with new HashMap<>(Map.of);
, for example -
@Comment("A mapping of Minecraft dimension IDs to their respective names")
public Map<String, String> worldNames = new HashMap<>(Map.ofEntries(
Map.entry("minecraft:overworld", "Overworld"),
Map.entry("minecraft:the_nether", "Nether"),
Map.entry("minecraft:the_end", "The End")
));
Hope this helps! ๐