-
Notifications
You must be signed in to change notification settings - Fork 146
Open
Description
Unsure if this'll get noticed, but I might as well try.
When working with order specific values, any RecordCodecBuilders with 5 fields or above will flip the field locations in half when encoding.
The top half of the fields will appear at the bottom half of the structure. If the field count is an odd number, the value after the whole value will also be moved to the bottom.
While I don't think this is that important for any current ops that Mojang utilizes, I have ran into issues within custom implementation where order is important due to this issue.
In Practice
Say I have this RecordCodec.
RecordCodecBuilder.mapCodec(inst -> inst.group(
Codec.INT.fieldOf("silly"),
.forGetter(CommonValues::silly),
ENCHANTMENT_OPINION_CODEC.fieldOf("enchantment_opinion")
.forGetter(CommonValues::enchantmentOpinion),
Codec.INT.fieldOf("red_number")
.forGetter(CommonValues::redNumber),
Codec.FLOAT.fieldOf("green_number")
.forGetter(CommonValues::greenNumber),
TextColor.CODEC.fieldOf("color")
.forGetter(CommonValues::color),
).apply(inst, CommonValues::new))What I expect.
{
"silly": 1,
"enchantment_opinion": {
"enchantment": "minecraft:frost_walker",
"opinion": "like"
},
"red_number": 4,
"green_number": 6.66
"color": "#FFFFFF"
}What actually encoded.
{
"green_number": 6.66
"color": "#FFFFFF",
"silly": 1,
"enchantment_opinion": {
"enchantment": "minecraft:frost_walker",
"opinion": "like"
},
"red_number": 4
}Metadata
Metadata
Assignees
Labels
No labels