fix(registries): emit canonical Int/Float/Byte NBT tags for registry entries - #77
Open
rayanbzd wants to merge 1 commit into
Open
fix(registries): emit canonical Int/Float/Byte NBT tags for registry entries#77rayanbzd wants to merge 1 commit into
rayanbzd wants to merge 1 commit into
Conversation
Owner
|
Can you please check if this is still relevant as this should be fixed in Packet Events v2.12.2? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PacketEvents 2.12.x logs
IllegalStateException: Error while reading registry minecraft:timelineon every connect from a 1.21.11+ client (retrooper/packetevents#1482).Root cause
json_to_nbtwas picking the smallest int type that fits each value (0→ Byte,1000→ Short,24000→ Short...) and routing lossy floats to Double to preserve precision. Vanilla doesn't do that.NbtOps.createInt(int)always returnsIntTag,createFloat(float)always returnsFloatTag, andcreateBoolean(boolean)staysByteTag. The vanilla client is lenient w/ wider tags; PE's mirror codec isn't.Checked the 26.1.2 server jar directly (mojmap is in the clear nowadays, so this is verifiable):
NbtOps.createInt(I)->IntTag.valueOf(I)no downcastNbtOps.createFloat(F)->FloatTag.valueOf(F)never promoted to DoubleTimeline.DIRECT_CODECtiesperiod_tickstoExtraCodecs.POSITIVE_INT(aCodec<Integer>overCodec.INT) -> emitsIntTag(24000), notShortTag(24000)EasingType$CubicBezierControlsis a record w/ fourfloatfields ->Codec.FLOAT->FloatTagIt's what Mojang's typed
CodecAPI emits when serializing registry classes throughNbtOps.INSTANCE.Fix
New opt-in
NbtOptions::numeric_wideningflag + ajson_to_nbt_with_optionsentry point. With the flag on:Int(orLongon i32 overflow) - no Byte/Short downcastFloat, even when the f64 doesn't round-trip exactlyIntArray/LongArray, noByteArrayByte, same asNbtOps.createBooleanjson_to_nbt's default behaviour is untouched. Onlypico_registriesopts in when loading the generated data reports, so nothing outside the registry loader moves.Test
An integration test at
pico_libraries/pico_registries/tests/registry_widening.rspins the expected types against the realV26_1/timeline/day.jsondata report (period_ticks: Int(24000), markerticks: Int(1000),show_in_commands: Byte(1),cubic_bezier[0]: Float(~0.362)etc), so a future regression on the canonical encoding hits CI.Scope
The non-canonical encoding affected every registry PicoLimbo emits, not just
minecraft:timeline. Timeline just happens to be where PE's stricter codec trips first. Fixing at the converter level covers all registries in one go.No version gating needed, the change is purely about how data reports get loaded into NBT.