Draylar / tiered

Adds tiers/modifiers to tools.
https://www.curseforge.com/minecraft/mc-mods/tiered
MIT License
11 stars 43 forks source link

Fix NoSuchFieldException: MAINHAND crash on load #27

Closed Fourmisain closed 3 years ago

Fourmisain commented 3 years ago

Fixes #26.

My guess as to what's happening: Gson wants to ultimately serialize EquipmentSlot here https://github.com/Draylar/tiered/blob/cbaf6f6e4eb8f31b4e3006f8c1537c822cf99ac6/src/main/java/draylar/tiered/Tiered.java#L109 and by default uses the EnumTypeAdapter. This specifically runs

          String name = constant.name();
          SerializedName annotation = classOfT.getField(name).getAnnotation(SerializedName.class);

So classOfT.getField(name) searches for the field MAINHAND inside the class EquipmentSlot.

What's the issue? Obfuscation. There is no field with the name MAINHAND, but it's field_6173 (in intermediary).

The fix is to add a straight forward serializer for the enum.

Fourmisain commented 3 years ago

Some more information:

I could reproduce #26 with a "vanilla" client (only Fabric, Fabric API and Tiered) on every world load.

Interestingly, I couldn't reproduce it in the dev environment.

Was wondering why, so I tested EquipmentSlot.class.getField("MAINHAND") on both; it failed when running normally, but succeeded in the dev environment, which can only mean that it's actually running the client "unobfuscated" (with yarn mappings).

I never use the dev env and I guess this is another reason to not use it on the daily.

Draylar commented 3 years ago

Yep, just a simple mapping issue. It worked previously because I was never using my GSON instance to serialize (and the data files had the proper slot name, which deserialized fine in-code), but I forgot to add the slot serializer after serializing in my sync packet.

Thanks for the fix!