BlakeBr0 / MysticalCustomization

Allows modpack creators to add new content and modify existing content in Mystical Agriculture.
https://blakesmods.com/mystical-customization
MIT License
6 stars 6 forks source link

Gibberish text when displaying Crop Tier #17

Closed SihenZhang closed 2 years ago

SihenZhang commented 3 years ago

Describe the bug I was playing ATM 6 - To the Sky and I found the crop tier of the custom crops is displayed as gibberish text. Gibberish Text

Expected behavior After reading the source code, I found that the script is read via FileReader that uses Java's platform default encoding. https://github.com/BlakeBr0/MysticalCustomization/blob/a83bd4a6f3907ceb4661394a1c8e92cfb8cb2201/src/main/java/com/blakebr0/mysticalcustomization/loader/CropTierLoader.java#L51-L70 My operating system is Windows 11 in Simplified Chinese, and its default encoding is GBK, while the encoding of the script file is UTF-8. Therefore, it displays the gibberish text. Since Java 11 FileReader has gained constructors that accept an encoding: new FileReader(file, charset) and new FileReader(fileName, charset). In earlier versions of java, you need to use new InputStreamReader(new FileInputStream(pathToFile), <encoding>).

Screenshots / Scripts / Logs magical.json

{
    "name": "§bMagical",
    "value": 8,
    "farmland": "mysticalagradditions:insanium_farmland",
    "essence": "mysticalagradditions:insanium_block",
    "fertilizable": false,
    "secondarySeedDrop": false
}

Versions (please complete the following information):

BlakeBr0 commented 2 years ago

You should be able to encode the file in UTF-8. I remember back in the day I had this issue with minecraft translation files and having to re-encode them using notepad++.

SeraphJACK commented 2 years ago

Did you really read what he said?

The language file is encoded in UTF-8, but you have not specified to use UTF-8 to read the file, which in the Chinese area defaults to using GBK encoding to decode.

Related code: https://github.com/BlakeBr0/MysticalCustomization/blob/a83bd4a6f3907ceb4661394a1c8e92cfb8cb2201/src/main/java/com/blakebr0/mysticalcustomization/loader/CropTierLoader.java#L51-L70