Improve (Multiblock) Server Side Number Formatting #1670
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.
What:
In #1467 the client side number formatting was improved by adding %,d and %,f to the language file for numbers.
This was not possible for the serverside because TextComponentTranslatable doesn't support anything except the %s format.
This was recently mentioned here: Shadows-of-Fire/Shadows-of-Greg#151
How solved:
Implement an EnhancedTextComponentTranslatable that knows how to do all the formatting supported by java.util.Formatter
This enhanced version is not used directly, instead a subclass of the ITextComponent.Serializer automatically swaps the
normal TextComponentTranslatable for the enhanced version during deserialization on the client.
Additionally, it also tries to parse the arguments deserialzed as integers/floats - the default serializer serializes them using String.valueof() and on the client side it does a dance where it effectively does
The AdvancedTextWidget has been changed to use this new enhanced serializer.
This is used by Multiblock controllers amongst other things.
Outcome:
Multiblock displays can now use formats like %,d
Additional info:
To demonstrate the capability, I have changed the multiblock EU output in the lang file to use %,d see image.
I changed both the serialize and deserialize to use the enhanced version in AdvancedTextWidget.
This is just for symmetry. The change in behaviour is entirely in deserialize on the client.
Possible compatibility issue:
None expected. To enable this feature, the lang file will need to be updated to use something other than %s.