    001package net.minecraft.client.settings;
    002
    003import cpw.mods.fml.client.FMLClientHandler;
    004import cpw.mods.fml.relauncher.Side;
    005import cpw.mods.fml.relauncher.SideOnly;
    006import java.io.BufferedReader;
    007import java.io.File;
    008import java.io.FileReader;
    009import java.io.FileWriter;
    010import java.io.PrintWriter;
    011import net.minecraft.client.Minecraft;
    012import net.minecraft.client.gui.GuiNewChat;
    013import net.minecraft.network.packet.Packet204ClientInfo;
    014import net.minecraft.util.StatCollector;
    015import net.minecraft.util.StringTranslate;
    016import org.lwjgl.input.Keyboard;
    017import org.lwjgl.input.Mouse;
    018import org.lwjgl.opengl.Display;
    019
    020@SideOnly(Side.CLIENT)
    021public class GameSettings
    022{
    023    private static final String[] RENDER_DISTANCES = new String[] {"options.renderDistance.far", "options.renderDistance.normal", "options.renderDistance.short", "options.renderDistance.tiny"};
    024    private static final String[] DIFFICULTIES = new String[] {"options.difficulty.peaceful", "options.difficulty.easy", "options.difficulty.normal", "options.difficulty.hard"};
    025
    026    /** GUI scale values */
    027    private static final String[] GUISCALES = new String[] {"options.guiScale.auto", "options.guiScale.small", "options.guiScale.normal", "options.guiScale.large"};
    028    private static final String[] CHAT_VISIBILITIES = new String[] {"options.chat.visibility.full", "options.chat.visibility.system", "options.chat.visibility.hidden"};
    029    private static final String[] PARTICLES = new String[] {"options.particles.all", "options.particles.decreased", "options.particles.minimal"};
    030
    031    /** Limit framerate labels */
    032    private static final String[] LIMIT_FRAMERATES = new String[] {"performance.max", "performance.balanced", "performance.powersaver"};
    033    private static final String[] field_98303_au = new String[] {"options.ao.off", "options.ao.min", "options.ao.max"};
    034    public float musicVolume = 1.0F;
    035    public float soundVolume = 1.0F;
    036    public float mouseSensitivity = 0.5F;
    037    public boolean invertMouse = false;
    038    public int renderDistance = 0;
    039    public boolean viewBobbing = true;
    040    public boolean anaglyph = false;
    041
    042    /** Advanced OpenGL */
    043    public boolean advancedOpengl = false;
    044    public int limitFramerate = 1;
    045    public boolean fancyGraphics = true;
    046
    047    /** Smooth Lighting */
    048    public int ambientOcclusion = 2;
    049
    050    /** Clouds flag */
    051    public boolean clouds = true;
    052
    053    /** The name of the selected texture pack. */
    054    public String skin = "Default";
    055    public int chatVisibility = 0;
    056    public boolean chatColours = true;
    057    public boolean chatLinks = true;
    058    public boolean chatLinksPrompt = true;
    059    public float chatOpacity = 1.0F;
    060    public boolean serverTextures = true;
    061    public boolean snooperEnabled = true;
    062    public boolean fullScreen = false;
    063    public boolean enableVsync = true;
    064    public boolean hideServerAddress = false;
    065
    066    /**
    067     * Whether to show advanced information on item tooltips, toggled by F3+H
    068     */
    069    public boolean advancedItemTooltips = false;
    070
    071    /** Whether to pause when the game loses focus, toggled by F3+P */
    072    public boolean pauseOnLostFocus = true;
    073
    074    /** Whether to show your cape */
    075    public boolean showCape = true;
    076    public boolean touchscreen = false;
    077    public int overrideWidth = 0;
    078    public int overrideHeight = 0;
    079    public boolean heldItemTooltips = true;
    080    public float field_96691_E = 1.0F;
    081    public float field_96692_F = 1.0F;
    082    public float field_96693_G = 0.44366196F;
    083    public float field_96694_H = 1.0F;
    084    public KeyBinding keyBindForward = new KeyBinding("key.forward", 17);
    085    public KeyBinding keyBindLeft = new KeyBinding("key.left", 30);
    086    public KeyBinding keyBindBack = new KeyBinding("key.back", 31);
    087    public KeyBinding keyBindRight = new KeyBinding("key.right", 32);
    088    public KeyBinding keyBindJump = new KeyBinding("key.jump", 57);
    089    public KeyBinding keyBindInventory = new KeyBinding("key.inventory", 18);
    090    public KeyBinding keyBindDrop = new KeyBinding("key.drop", 16);
    091    public KeyBinding keyBindChat = new KeyBinding("key.chat", 20);
    092    public KeyBinding keyBindSneak = new KeyBinding("key.sneak", 42);
    093    public KeyBinding keyBindAttack = new KeyBinding("key.attack", -100);
    094    public KeyBinding keyBindUseItem = new KeyBinding("key.use", -99);
    095    public KeyBinding keyBindPlayerList = new KeyBinding("key.playerlist", 15);
    096    public KeyBinding keyBindPickBlock = new KeyBinding("key.pickItem", -98);
    097    public KeyBinding keyBindCommand = new KeyBinding("key.command", 53);
    098    public KeyBinding[] keyBindings;
    099    protected Minecraft mc;
    100    private File optionsFile;
    101    public int difficulty;
    102    public boolean hideGUI;
    103    public int thirdPersonView;
    104
    105    /** true if debug info should be displayed instead of version */
    106    public boolean showDebugInfo;
    107    public boolean showDebugProfilerChart;
    108
    109    /** The lastServer string. */
    110    public String lastServer;
    111
    112    /** No clipping for singleplayer */
    113    public boolean noclip;
    114
    115    /** Smooth Camera Toggle */
    116    public boolean smoothCamera;
    117    public boolean debugCamEnable;
    118
    119    /** No clipping movement rate */
    120    public float noclipRate;
    121
    122    /** Change rate for debug camera */
    123    public float debugCamRate;
    124    public float fovSetting;
    125    public float gammaSetting;
    126
    127    /** GUI scale */
    128    public int guiScale;
    129
    130    /** Determines amount of particles. 0 = All, 1 = Decreased, 2 = Minimal */
    131    public int particleSetting;
    132
    133    /** Game settings language */
    134    public String language;
    135
    136    public GameSettings(Minecraft par1Minecraft, File par2File)
    137    {
    138        this.keyBindings = new KeyBinding[] {this.keyBindAttack, this.keyBindUseItem, this.keyBindForward, this.keyBindLeft, this.keyBindBack, this.keyBindRight, this.keyBindJump, this.keyBindSneak, this.keyBindDrop, this.keyBindInventory, this.keyBindChat, this.keyBindPlayerList, this.keyBindPickBlock, this.keyBindCommand};
    139        this.difficulty = 2;
    140        this.hideGUI = false;
    141        this.thirdPersonView = 0;
    142        this.showDebugInfo = false;
    143        this.showDebugProfilerChart = false;
    144        this.lastServer = "";
    145        this.noclip = false;
    146        this.smoothCamera = false;
    147        this.debugCamEnable = false;
    148        this.noclipRate = 1.0F;
    149        this.debugCamRate = 1.0F;
    150        this.fovSetting = 0.0F;
    151        this.gammaSetting = 0.0F;
    152        this.guiScale = 0;
    153        this.particleSetting = 0;
    154        this.language = "en_US";
    155        this.mc = par1Minecraft;
    156        this.optionsFile = new File(par2File, "options.txt");
    157        this.loadOptions();
    158    }
    159
    160    public GameSettings()
    161    {
    162        this.keyBindings = new KeyBinding[] {this.keyBindAttack, this.keyBindUseItem, this.keyBindForward, this.keyBindLeft, this.keyBindBack, this.keyBindRight, this.keyBindJump, this.keyBindSneak, this.keyBindDrop, this.keyBindInventory, this.keyBindChat, this.keyBindPlayerList, this.keyBindPickBlock, this.keyBindCommand};
    163        this.difficulty = 2;
    164        this.hideGUI = false;
    165        this.thirdPersonView = 0;
    166        this.showDebugInfo = false;
    167        this.showDebugProfilerChart = false;
    168        this.lastServer = "";
    169        this.noclip = false;
    170        this.smoothCamera = false;
    171        this.debugCamEnable = false;
    172        this.noclipRate = 1.0F;
    173        this.debugCamRate = 1.0F;
    174        this.fovSetting = 0.0F;
    175        this.gammaSetting = 0.0F;
    176        this.guiScale = 0;
    177        this.particleSetting = 0;
    178        this.language = "en_US";
    179    }
    180
    181    public String getKeyBindingDescription(int par1)
    182    {
    183        StringTranslate stringtranslate = StringTranslate.getInstance();
    184        return stringtranslate.translateKey(this.keyBindings[par1].keyDescription);
    185    }
    186
    187    /**
    188     * The string that appears inside the button/slider in the options menu.
    189     */
    190    public String getOptionDisplayString(int par1)
    191    {
    192        int j = this.keyBindings[par1].keyCode;
    193        return getKeyDisplayString(j);
    194    }
    195
    196    /**
    197     * Represents a key or mouse button as a string. Args: key
    198     */
    199    public static String getKeyDisplayString(int par0)
    200    {
    201        return par0 < 0 ? StatCollector.translateToLocalFormatted("key.mouseButton", new Object[] {Integer.valueOf(par0 + 101)}): Keyboard.getKeyName(par0);
    202    }
    203
    204    public static boolean func_100015_a(KeyBinding par0KeyBinding)
    205    {
    206        return par0KeyBinding.keyCode < 0 ? Mouse.isButtonDown(par0KeyBinding.keyCode + 100) : Keyboard.isKeyDown(par0KeyBinding.keyCode);
    207    }
    208
    209    /**
    210     * Sets a key binding.
    211     */
    212    public void setKeyBinding(int par1, int par2)
    213    {
    214        this.keyBindings[par1].keyCode = par2;
    215        this.saveOptions();
    216    }
    217
    218    /**
    219     * If the specified option is controlled by a slider (float value), this will set the float value.
    220     */
    221    public void setOptionFloatValue(EnumOptions par1EnumOptions, float par2)
    222    {
    223        if (par1EnumOptions == EnumOptions.MUSIC)
    224        {
    225            this.musicVolume = par2;
    226            this.mc.sndManager.onSoundOptionsChanged();
    227        }
    228
    229        if (par1EnumOptions == EnumOptions.SOUND)
    230        {
    231            this.soundVolume = par2;
    232            this.mc.sndManager.onSoundOptionsChanged();
    233        }
    234
    235        if (par1EnumOptions == EnumOptions.SENSITIVITY)
    236        {
    237            this.mouseSensitivity = par2;
    238        }
    239
    240        if (par1EnumOptions == EnumOptions.FOV)
    241        {
    242            this.fovSetting = par2;
    243        }
    244
    245        if (par1EnumOptions == EnumOptions.GAMMA)
    246        {
    247            this.gammaSetting = par2;
    248        }
    249
    250        if (par1EnumOptions == EnumOptions.CHAT_OPACITY)
    251        {
    252            this.chatOpacity = par2;
    253            this.mc.ingameGUI.getChatGUI().func_96132_b();
    254        }
    255
    256        if (par1EnumOptions == EnumOptions.CHAT_HEIGHT_FOCUSED)
    257        {
    258            this.field_96694_H = par2;
    259            this.mc.ingameGUI.getChatGUI().func_96132_b();
    260        }
    261
    262        if (par1EnumOptions == EnumOptions.CHAT_HEIGHT_UNFOCUSED)
    263        {
    264            this.field_96693_G = par2;
    265            this.mc.ingameGUI.getChatGUI().func_96132_b();
    266        }
    267
    268        if (par1EnumOptions == EnumOptions.CHAT_WIDTH)
    269        {
    270            this.field_96692_F = par2;
    271            this.mc.ingameGUI.getChatGUI().func_96132_b();
    272        }
    273
    274        if (par1EnumOptions == EnumOptions.CHAT_SCALE)
    275        {
    276            this.field_96691_E = par2;
    277            this.mc.ingameGUI.getChatGUI().func_96132_b();
    278        }
    279    }
    280
    281    /**
    282     * For non-float options. Toggles the option on/off, or cycles through the list i.e. render distances.
    283     */
    284    public void setOptionValue(EnumOptions par1EnumOptions, int par2)
    285    {
    286        if (par1EnumOptions == EnumOptions.INVERT_MOUSE)
    287        {
    288            this.invertMouse = !this.invertMouse;
    289        }
    290
    291        if (par1EnumOptions == EnumOptions.RENDER_DISTANCE)
    292        {
    293            this.renderDistance = this.renderDistance + par2 & 3;
    294        }
    295
    296        if (par1EnumOptions == EnumOptions.GUI_SCALE)
    297        {
    298            this.guiScale = this.guiScale + par2 & 3;
    299        }
    300
    301        if (par1EnumOptions == EnumOptions.PARTICLES)
    302        {
    303            this.particleSetting = (this.particleSetting + par2) % 3;
    304        }
    305
    306        if (par1EnumOptions == EnumOptions.VIEW_BOBBING)
    307        {
    308            this.viewBobbing = !this.viewBobbing;
    309        }
    310
    311        if (par1EnumOptions == EnumOptions.RENDER_CLOUDS)
    312        {
    313            this.clouds = !this.clouds;
    314        }
    315
    316        if (par1EnumOptions == EnumOptions.ADVANCED_OPENGL)
    317        {
    318            this.advancedOpengl = !this.advancedOpengl;
    319            this.mc.renderGlobal.loadRenderers();
    320        }
    321
    322        if (par1EnumOptions == EnumOptions.ANAGLYPH)
    323        {
    324            this.anaglyph = !this.anaglyph;
    325            this.mc.renderEngine.refreshTextures();
    326        }
    327
    328        if (par1EnumOptions == EnumOptions.FRAMERATE_LIMIT)
    329        {
    330            this.limitFramerate = (this.limitFramerate + par2 + 3) % 3;
    331        }
    332
    333        if (par1EnumOptions == EnumOptions.DIFFICULTY)
    334        {
    335            this.difficulty = this.difficulty + par2 & 3;
    336        }
    337
    338        if (par1EnumOptions == EnumOptions.GRAPHICS)
    339        {
    340            this.fancyGraphics = !this.fancyGraphics;
    341            this.mc.renderGlobal.loadRenderers();
    342        }
    343
    344        if (par1EnumOptions == EnumOptions.AMBIENT_OCCLUSION)
    345        {
    346            this.ambientOcclusion = (this.ambientOcclusion + par2) % 3;
    347            this.mc.renderGlobal.loadRenderers();
    348        }
    349
    350        if (par1EnumOptions == EnumOptions.CHAT_VISIBILITY)
    351        {
    352            this.chatVisibility = (this.chatVisibility + par2) % 3;
    353        }
    354
    355        if (par1EnumOptions == EnumOptions.CHAT_COLOR)
    356        {
    357            this.chatColours = !this.chatColours;
    358        }
    359
    360        if (par1EnumOptions == EnumOptions.CHAT_LINKS)
    361        {
    362            this.chatLinks = !this.chatLinks;
    363        }
    364
    365        if (par1EnumOptions == EnumOptions.CHAT_LINKS_PROMPT)
    366        {
    367            this.chatLinksPrompt = !this.chatLinksPrompt;
    368        }
    369
    370        if (par1EnumOptions == EnumOptions.USE_SERVER_TEXTURES)
    371        {
    372            this.serverTextures = !this.serverTextures;
    373        }
    374
    375        if (par1EnumOptions == EnumOptions.SNOOPER_ENABLED)
    376        {
    377            this.snooperEnabled = !this.snooperEnabled;
    378        }
    379
    380        if (par1EnumOptions == EnumOptions.SHOW_CAPE)
    381        {
    382            this.showCape = !this.showCape;
    383        }
    384
    385        if (par1EnumOptions == EnumOptions.TOUCHSCREEN)
    386        {
    387            this.touchscreen = !this.touchscreen;
    388        }
    389
    390        if (par1EnumOptions == EnumOptions.USE_FULLSCREEN)
    391        {
    392            this.fullScreen = !this.fullScreen;
    393
    394            if (this.mc.isFullScreen() != this.fullScreen)
    395            {
    396                this.mc.toggleFullscreen();
    397            }
    398        }
    399
    400        if (par1EnumOptions == EnumOptions.ENABLE_VSYNC)
    401        {
    402            this.enableVsync = !this.enableVsync;
    403            Display.setVSyncEnabled(this.enableVsync);
    404        }
    405
    406        this.saveOptions();
    407    }
    408
    409    public float getOptionFloatValue(EnumOptions par1EnumOptions)
    410    {
    411        return par1EnumOptions == EnumOptions.FOV ? this.fovSetting : (par1EnumOptions == EnumOptions.GAMMA ? this.gammaSetting : (par1EnumOptions == EnumOptions.MUSIC ? this.musicVolume : (par1EnumOptions == EnumOptions.SOUND ? this.soundVolume : (par1EnumOptions == EnumOptions.SENSITIVITY ? this.mouseSensitivity : (par1EnumOptions == EnumOptions.CHAT_OPACITY ? this.chatOpacity : (par1EnumOptions == EnumOptions.CHAT_HEIGHT_FOCUSED ? this.field_96694_H : (par1EnumOptions == EnumOptions.CHAT_HEIGHT_UNFOCUSED ? this.field_96693_G : (par1EnumOptions == EnumOptions.CHAT_SCALE ? this.field_96691_E : (par1EnumOptions == EnumOptions.CHAT_WIDTH ? this.field_96692_F : 0.0F)))))))));
    412    }
    413
    414    public boolean getOptionOrdinalValue(EnumOptions par1EnumOptions)
    415    {
    416        switch (EnumOptionsHelper.enumOptionsMappingHelperArray[par1EnumOptions.ordinal()])
    417        {
    418            case 1:
    419                return this.invertMouse;
    420            case 2:
    421                return this.viewBobbing;
    422            case 3:
    423                return this.anaglyph;
    424            case 4:
    425                return this.advancedOpengl;
    426            case 5:
    427                return this.clouds;
    428            case 6:
    429                return this.chatColours;
    430            case 7:
    431                return this.chatLinks;
    432            case 8:
    433                return this.chatLinksPrompt;
    434            case 9:
    435                return this.serverTextures;
    436            case 10:
    437                return this.snooperEnabled;
    438            case 11:
    439                return this.fullScreen;
    440            case 12:
    441                return this.enableVsync;
    442            case 13:
    443                return this.showCape;
    444            case 14:
    445                return this.touchscreen;
    446            default:
    447                return false;
    448        }
    449    }
    450
    451    /**
    452     * Returns the translation of the given index in the given String array. If the index is smaller than 0 or greater
    453     * than/equal to the length of the String array, it is changed to 0.
    454     */
    455    private static String getTranslation(String[] par0ArrayOfStr, int par1)
    456    {
    457        if (par1 < 0 || par1 >= par0ArrayOfStr.length)
    458        {
    459            par1 = 0;
    460        }
    461
    462        StringTranslate stringtranslate = StringTranslate.getInstance();
    463        return stringtranslate.translateKey(par0ArrayOfStr[par1]);
    464    }
    465
    466    /**
    467     * Gets a key binding.
    468     */
    469    public String getKeyBinding(EnumOptions par1EnumOptions)
    470    {
    471        StringTranslate stringtranslate = StringTranslate.getInstance();
    472        String s = stringtranslate.translateKey(par1EnumOptions.getEnumString()) + ": ";
    473
    474        if (par1EnumOptions.getEnumFloat())
    475        {
    476            float f = this.getOptionFloatValue(par1EnumOptions);
    477            return par1EnumOptions == EnumOptions.SENSITIVITY ? (f == 0.0F ? s + stringtranslate.translateKey("options.sensitivity.min") : (f == 1.0F ? s + stringtranslate.translateKey("options.sensitivity.max") : s + (int)(f * 200.0F) + "%")) : (par1EnumOptions == EnumOptions.FOV ? (f == 0.0F ? s + stringtranslate.translateKey("options.fov.min") : (f == 1.0F ? s + stringtranslate.translateKey("options.fov.max") : s + (int)(70.0F + f * 40.0F))) : (par1EnumOptions == EnumOptions.GAMMA ? (f == 0.0F ? s + stringtranslate.translateKey("options.gamma.min") : (f == 1.0F ? s + stringtranslate.translateKey("options.gamma.max") : s + "+" + (int)(f * 100.0F) + "%")) : (par1EnumOptions == EnumOptions.CHAT_OPACITY ? s + (int)(f * 90.0F + 10.0F) + "%" : (par1EnumOptions == EnumOptions.CHAT_HEIGHT_UNFOCUSED ? s + GuiNewChat.func_96130_b(f) + "px" : (par1EnumOptions == EnumOptions.CHAT_HEIGHT_FOCUSED ? s + GuiNewChat.func_96130_b(f) + "px" : (par1EnumOptions == EnumOptions.CHAT_WIDTH ? s + GuiNewChat.func_96128_a(f) + "px" : (f == 0.0F ? s + stringtranslate.translateKey("options.off") : s + (int)(f * 100.0F) + "%")))))));
    478        }
    479        else if (par1EnumOptions.getEnumBoolean())
    480        {
    481            boolean flag = this.getOptionOrdinalValue(par1EnumOptions);
    482            return flag ? s + stringtranslate.translateKey("options.on") : s + stringtranslate.translateKey("options.off");
    483        }
    484        else
    485        {
    486            return par1EnumOptions == EnumOptions.RENDER_DISTANCE ? s + getTranslation(RENDER_DISTANCES, this.renderDistance) : (par1EnumOptions == EnumOptions.DIFFICULTY ? s + getTranslation(DIFFICULTIES, this.difficulty) : (par1EnumOptions == EnumOptions.GUI_SCALE ? s + getTranslation(GUISCALES, this.guiScale) : (par1EnumOptions == EnumOptions.CHAT_VISIBILITY ? s + getTranslation(CHAT_VISIBILITIES, this.chatVisibility) : (par1EnumOptions == EnumOptions.PARTICLES ? s + getTranslation(PARTICLES, this.particleSetting) : (par1EnumOptions == EnumOptions.FRAMERATE_LIMIT ? s + getTranslation(LIMIT_FRAMERATES, this.limitFramerate) : (par1EnumOptions == EnumOptions.AMBIENT_OCCLUSION ? s + getTranslation(field_98303_au, this.ambientOcclusion) : (par1EnumOptions == EnumOptions.GRAPHICS ? (this.fancyGraphics ? s + stringtranslate.translateKey("options.graphics.fancy") : s + stringtranslate.translateKey("options.graphics.fast")) : s)))))));
    487        }
    488    }
    489
    490    /**
    491     * Loads the options from the options file. It appears that this has replaced the previous 'loadOptions'
    492     */
    493    public void loadOptions()
    494    {
    495        try
    496        {
    497            if (!this.optionsFile.exists())
    498            {
    499                return;
    500            }
    501
    502            BufferedReader bufferedreader = new BufferedReader(new FileReader(this.optionsFile));
    503            String s = "";
    504
    505            while ((s = bufferedreader.readLine()) != null)
    506            {
    507                try
    508                {
    509                    String[] astring = s.split(":");
    510
    511                    if (astring[0].equals("music"))
    512                    {
    513                        this.musicVolume = this.parseFloat(astring[1]);
    514                    }
    515
    516                    if (astring[0].equals("sound"))
    517                    {
    518                        this.soundVolume = this.parseFloat(astring[1]);
    519                    }
    520
    521                    if (astring[0].equals("mouseSensitivity"))
    522                    {
    523                        this.mouseSensitivity = this.parseFloat(astring[1]);
    524                    }
    525
    526                    if (astring[0].equals("fov"))
    527                    {
    528                        this.fovSetting = this.parseFloat(astring[1]);
    529                    }
    530
    531                    if (astring[0].equals("gamma"))
    532                    {
    533                        this.gammaSetting = this.parseFloat(astring[1]);
    534                    }
    535
    536                    if (astring[0].equals("invertYMouse"))
    537                    {
    538                        this.invertMouse = astring[1].equals("true");
    539                    }
    540
    541                    if (astring[0].equals("viewDistance"))
    542                    {
    543                        this.renderDistance = Integer.parseInt(astring[1]);
    544                    }
    545
    546                    if (astring[0].equals("guiScale"))
    547                    {
    548                        this.guiScale = Integer.parseInt(astring[1]);
    549                    }
    550
    551                    if (astring[0].equals("particles"))
    552                    {
    553                        this.particleSetting = Integer.parseInt(astring[1]);
    554                    }
    555
    556                    if (astring[0].equals("bobView"))
    557                    {
    558                        this.viewBobbing = astring[1].equals("true");
    559                    }
    560
    561                    if (astring[0].equals("anaglyph3d"))
    562                    {
    563                        this.anaglyph = astring[1].equals("true");
    564                    }
    565
    566                    if (astring[0].equals("advancedOpengl"))
    567                    {
    568                        this.advancedOpengl = astring[1].equals("true");
    569                    }
    570
    571                    if (astring[0].equals("fpsLimit"))
    572                    {
    573                        this.limitFramerate = Integer.parseInt(astring[1]);
    574                    }
    575
    576                    if (astring[0].equals("difficulty"))
    577                    {
    578                        this.difficulty = Integer.parseInt(astring[1]);
    579                    }
    580
    581                    if (astring[0].equals("fancyGraphics"))
    582                    {
    583                        this.fancyGraphics = astring[1].equals("true");
    584                    }
    585
    586                    if (astring[0].equals("ao"))
    587                    {
    588                        if (astring[1].equals("true"))
    589                        {
    590                            this.ambientOcclusion = 2;
    591                        }
    592                        else if (astring[1].equals("false"))
    593                        {
    594                            this.ambientOcclusion = 0;
    595                        }
    596                        else
    597                        {
    598                            this.ambientOcclusion = Integer.parseInt(astring[1]);
    599                        }
    600                    }
    601
    602                    if (astring[0].equals("clouds"))
    603                    {
    604                        this.clouds = astring[1].equals("true");
    605                    }
    606
    607                    if (astring[0].equals("skin"))
    608                    {
    609                        this.skin = astring[1];
    610                    }
    611
    612                    if (astring[0].equals("lastServer") && astring.length >= 2)
    613                    {
    614                        this.lastServer = astring[1];
    615                    }
    616
    617                    if (astring[0].equals("lang") && astring.length >= 2)
    618                    {
    619                        this.language = astring[1];
    620                    }
    621
    622                    if (astring[0].equals("chatVisibility"))
    623                    {
    624                        this.chatVisibility = Integer.parseInt(astring[1]);
    625                    }
    626
    627                    if (astring[0].equals("chatColors"))
    628                    {
    629                        this.chatColours = astring[1].equals("true");
    630                    }
    631
    632                    if (astring[0].equals("chatLinks"))
    633                    {
    634                        this.chatLinks = astring[1].equals("true");
    635                    }
    636
    637                    if (astring[0].equals("chatLinksPrompt"))
    638                    {
    639                        this.chatLinksPrompt = astring[1].equals("true");
    640                    }
    641
    642                    if (astring[0].equals("chatOpacity"))
    643                    {
    644                        this.chatOpacity = this.parseFloat(astring[1]);
    645                    }
    646
    647                    if (astring[0].equals("serverTextures"))
    648                    {
    649                        this.serverTextures = astring[1].equals("true");
    650                    }
    651
    652                    if (astring[0].equals("snooperEnabled"))
    653                    {
    654                        this.snooperEnabled = astring[1].equals("true");
    655                    }
    656
    657                    if (astring[0].equals("fullscreen"))
    658                    {
    659                        this.fullScreen = astring[1].equals("true");
    660                    }
    661
    662                    if (astring[0].equals("enableVsync"))
    663                    {
    664                        this.enableVsync = astring[1].equals("true");
    665                    }
    666
    667                    if (astring[0].equals("hideServerAddress"))
    668                    {
    669                        this.hideServerAddress = astring[1].equals("true");
    670                    }
    671
    672                    if (astring[0].equals("advancedItemTooltips"))
    673                    {
    674                        this.advancedItemTooltips = astring[1].equals("true");
    675                    }
    676
    677                    if (astring[0].equals("pauseOnLostFocus"))
    678                    {
    679                        this.pauseOnLostFocus = astring[1].equals("true");
    680                    }
    681
    682                    if (astring[0].equals("showCape"))
    683                    {
    684                        this.showCape = astring[1].equals("true");
    685                    }
    686
    687                    if (astring[0].equals("touchscreen"))
    688                    {
    689                        this.touchscreen = astring[1].equals("true");
    690                    }
    691
    692                    if (astring[0].equals("overrideHeight"))
    693                    {
    694                        this.overrideHeight = Integer.parseInt(astring[1]);
    695                    }
    696
    697                    if (astring[0].equals("overrideWidth"))
    698                    {
    699                        this.overrideWidth = Integer.parseInt(astring[1]);
    700                    }
    701
    702                    if (astring[0].equals("heldItemTooltips"))
    703                    {
    704                        this.heldItemTooltips = astring[1].equals("true");
    705                    }
    706
    707                    if (astring[0].equals("chatHeightFocused"))
    708                    {
    709                        this.field_96694_H = this.parseFloat(astring[1]);
    710                    }
    711
    712                    if (astring[0].equals("chatHeightUnfocused"))
    713                    {
    714                        this.field_96693_G = this.parseFloat(astring[1]);
    715                    }
    716
    717                    if (astring[0].equals("chatScale"))
    718                    {
    719                        this.field_96691_E = this.parseFloat(astring[1]);
    720                    }
    721
    722                    if (astring[0].equals("chatWidth"))
    723                    {
    724                        this.field_96692_F = this.parseFloat(astring[1]);
    725                    }
    726
    727                    for (int i = 0; i < this.keyBindings.length; ++i)
    728                    {
    729                        if (astring[0].equals("key_" + this.keyBindings[i].keyDescription))
    730                        {
    731                            this.keyBindings[i].keyCode = Integer.parseInt(astring[1]);
    732                        }
    733                    }
    734                }
    735                catch (Exception exception)
    736                {
    737                    this.mc.func_98033_al().func_98236_b("Skipping bad option: " + s);
    738                }
    739            }
    740
    741            KeyBinding.resetKeyBindingArrayAndHash();
    742            bufferedreader.close();
    743        }
    744        catch (Exception exception1)
    745        {
    746            this.mc.func_98033_al().func_98236_b("Failed to load options");
    747            exception1.printStackTrace();
    748        }
    749    }
    750
    751    /**
    752     * Parses a string into a float.
    753     */
    754    private float parseFloat(String par1Str)
    755    {
    756        return par1Str.equals("true") ? 1.0F : (par1Str.equals("false") ? 0.0F : Float.parseFloat(par1Str));
    757    }
    758
    759    /**
    760     * Saves the options to the options file.
    761     */
    762    public void saveOptions()
    763    {
    764        if (FMLClientHandler.instance().isLoading()) return;
    765        try
    766        {
    767            PrintWriter printwriter = new PrintWriter(new FileWriter(this.optionsFile));
    768            printwriter.println("music:" + this.musicVolume);
    769            printwriter.println("sound:" + this.soundVolume);
    770            printwriter.println("invertYMouse:" + this.invertMouse);
    771            printwriter.println("mouseSensitivity:" + this.mouseSensitivity);
    772            printwriter.println("fov:" + this.fovSetting);
    773            printwriter.println("gamma:" + this.gammaSetting);
    774            printwriter.println("viewDistance:" + this.renderDistance);
    775            printwriter.println("guiScale:" + this.guiScale);
    776            printwriter.println("particles:" + this.particleSetting);
    777            printwriter.println("bobView:" + this.viewBobbing);
    778            printwriter.println("anaglyph3d:" + this.anaglyph);
    779            printwriter.println("advancedOpengl:" + this.advancedOpengl);
    780            printwriter.println("fpsLimit:" + this.limitFramerate);
    781            printwriter.println("difficulty:" + this.difficulty);
    782            printwriter.println("fancyGraphics:" + this.fancyGraphics);
    783            printwriter.println("ao:" + this.ambientOcclusion);
    784            printwriter.println("clouds:" + this.clouds);
    785            printwriter.println("skin:" + this.skin);
    786            printwriter.println("lastServer:" + this.lastServer);
    787            printwriter.println("lang:" + this.language);
    788            printwriter.println("chatVisibility:" + this.chatVisibility);
    789            printwriter.println("chatColors:" + this.chatColours);
    790            printwriter.println("chatLinks:" + this.chatLinks);
    791            printwriter.println("chatLinksPrompt:" + this.chatLinksPrompt);
    792            printwriter.println("chatOpacity:" + this.chatOpacity);
    793            printwriter.println("serverTextures:" + this.serverTextures);
    794            printwriter.println("snooperEnabled:" + this.snooperEnabled);
    795            printwriter.println("fullscreen:" + this.fullScreen);
    796            printwriter.println("enableVsync:" + this.enableVsync);
    797            printwriter.println("hideServerAddress:" + this.hideServerAddress);
    798            printwriter.println("advancedItemTooltips:" + this.advancedItemTooltips);
    799            printwriter.println("pauseOnLostFocus:" + this.pauseOnLostFocus);
    800            printwriter.println("showCape:" + this.showCape);
    801            printwriter.println("touchscreen:" + this.touchscreen);
    802            printwriter.println("overrideWidth:" + this.overrideWidth);
    803            printwriter.println("overrideHeight:" + this.overrideHeight);
    804            printwriter.println("heldItemTooltips:" + this.heldItemTooltips);
    805            printwriter.println("chatHeightFocused:" + this.field_96694_H);
    806            printwriter.println("chatHeightUnfocused:" + this.field_96693_G);
    807            printwriter.println("chatScale:" + this.field_96691_E);
    808            printwriter.println("chatWidth:" + this.field_96692_F);
    809
    810            for (int i = 0; i < this.keyBindings.length; ++i)
    811            {
    812                printwriter.println("key_" + this.keyBindings[i].keyDescription + ":" + this.keyBindings[i].keyCode);
    813            }
    814
    815            printwriter.close();
    816        }
    817        catch (Exception exception)
    818        {
    819            this.mc.func_98033_al().func_98236_b("Failed to save options");
    820            exception.printStackTrace();
    821        }
    822
    823        this.sendSettingsToServer();
    824    }
    825
    826    /**
    827     * Send a client info packet with settings information to the server
    828     */
    829    public void sendSettingsToServer()
    830    {
    831        if (this.mc.thePlayer != null)
    832        {
    833            this.mc.thePlayer.sendQueue.addToSendQueue(new Packet204ClientInfo(this.language, this.renderDistance, this.chatVisibility, this.chatColours, this.difficulty, this.showCape));
    834        }
    835    }
    836
    837    /**
    838     * Should render clouds
    839     */
    840    public boolean shouldRenderClouds()
    841    {
    842        return this.renderDistance < 2 && this.clouds;
    843    }
    844}