    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[] AMBIENT_OCCLUSIONS = 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 chatScale = 1.0F;
    081    public float chatWidth = 1.0F;
    082    public float chatHeightUnfocused = 0.44366196F;
    083    public float chatHeightFocused = 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    /**
    205     * Returns whether the specified key binding is currently being pressed.
    206     */
    207    public static boolean isKeyDown(KeyBinding par0KeyBinding)
    208    {
    209        return par0KeyBinding.keyCode < 0 ? Mouse.isButtonDown(par0KeyBinding.keyCode + 100) : Keyboard.isKeyDown(par0KeyBinding.keyCode);
    210    }
    211
    212    /**
    213     * Sets a key binding.
    214     */
    215    public void setKeyBinding(int par1, int par2)
    216    {
    217        this.keyBindings[par1].keyCode = par2;
    218        this.saveOptions();
    219    }
    220
    221    /**
    222     * If the specified option is controlled by a slider (float value), this will set the float value.
    223     */
    224    public void setOptionFloatValue(EnumOptions par1EnumOptions, float par2)
    225    {
    226        if (par1EnumOptions == EnumOptions.MUSIC)
    227        {
    228            this.musicVolume = par2;
    229            this.mc.sndManager.onSoundOptionsChanged();
    230        }
    231
    232        if (par1EnumOptions == EnumOptions.SOUND)
    233        {
    234            this.soundVolume = par2;
    235            this.mc.sndManager.onSoundOptionsChanged();
    236        }
    237
    238        if (par1EnumOptions == EnumOptions.SENSITIVITY)
    239        {
    240            this.mouseSensitivity = par2;
    241        }
    242
    243        if (par1EnumOptions == EnumOptions.FOV)
    244        {
    245            this.fovSetting = par2;
    246        }
    247
    248        if (par1EnumOptions == EnumOptions.GAMMA)
    249        {
    250            this.gammaSetting = par2;
    251        }
    252
    253        if (par1EnumOptions == EnumOptions.CHAT_OPACITY)
    254        {
    255            this.chatOpacity = par2;
    256            this.mc.ingameGUI.getChatGUI().func_96132_b();
    257        }
    258
    259        if (par1EnumOptions == EnumOptions.CHAT_HEIGHT_FOCUSED)
    260        {
    261            this.chatHeightFocused = par2;
    262            this.mc.ingameGUI.getChatGUI().func_96132_b();
    263        }
    264
    265        if (par1EnumOptions == EnumOptions.CHAT_HEIGHT_UNFOCUSED)
    266        {
    267            this.chatHeightUnfocused = par2;
    268            this.mc.ingameGUI.getChatGUI().func_96132_b();
    269        }
    270
    271        if (par1EnumOptions == EnumOptions.CHAT_WIDTH)
    272        {
    273            this.chatWidth = par2;
    274            this.mc.ingameGUI.getChatGUI().func_96132_b();
    275        }
    276
    277        if (par1EnumOptions == EnumOptions.CHAT_SCALE)
    278        {
    279            this.chatScale = par2;
    280            this.mc.ingameGUI.getChatGUI().func_96132_b();
    281        }
    282    }
    283
    284    /**
    285     * For non-float options. Toggles the option on/off, or cycles through the list i.e. render distances.
    286     */
    287    public void setOptionValue(EnumOptions par1EnumOptions, int par2)
    288    {
    289        if (par1EnumOptions == EnumOptions.INVERT_MOUSE)
    290        {
    291            this.invertMouse = !this.invertMouse;
    292        }
    293
    294        if (par1EnumOptions == EnumOptions.RENDER_DISTANCE)
    295        {
    296            this.renderDistance = this.renderDistance + par2 & 3;
    297        }
    298
    299        if (par1EnumOptions == EnumOptions.GUI_SCALE)
    300        {
    301            this.guiScale = this.guiScale + par2 & 3;
    302        }
    303
    304        if (par1EnumOptions == EnumOptions.PARTICLES)
    305        {
    306            this.particleSetting = (this.particleSetting + par2) % 3;
    307        }
    308
    309        if (par1EnumOptions == EnumOptions.VIEW_BOBBING)
    310        {
    311            this.viewBobbing = !this.viewBobbing;
    312        }
    313
    314        if (par1EnumOptions == EnumOptions.RENDER_CLOUDS)
    315        {
    316            this.clouds = !this.clouds;
    317        }
    318
    319        if (par1EnumOptions == EnumOptions.ADVANCED_OPENGL)
    320        {
    321            this.advancedOpengl = !this.advancedOpengl;
    322            this.mc.renderGlobal.loadRenderers();
    323        }
    324
    325        if (par1EnumOptions == EnumOptions.ANAGLYPH)
    326        {
    327            this.anaglyph = !this.anaglyph;
    328            this.mc.renderEngine.refreshTextures();
    329        }
    330
    331        if (par1EnumOptions == EnumOptions.FRAMERATE_LIMIT)
    332        {
    333            this.limitFramerate = (this.limitFramerate + par2 + 3) % 3;
    334        }
    335
    336        if (par1EnumOptions == EnumOptions.DIFFICULTY)
    337        {
    338            this.difficulty = this.difficulty + par2 & 3;
    339        }
    340
    341        if (par1EnumOptions == EnumOptions.GRAPHICS)
    342        {
    343            this.fancyGraphics = !this.fancyGraphics;
    344            this.mc.renderGlobal.loadRenderers();
    345        }
    346
    347        if (par1EnumOptions == EnumOptions.AMBIENT_OCCLUSION)
    348        {
    349            this.ambientOcclusion = (this.ambientOcclusion + par2) % 3;
    350            this.mc.renderGlobal.loadRenderers();
    351        }
    352
    353        if (par1EnumOptions == EnumOptions.CHAT_VISIBILITY)
    354        {
    355            this.chatVisibility = (this.chatVisibility + par2) % 3;
    356        }
    357
    358        if (par1EnumOptions == EnumOptions.CHAT_COLOR)
    359        {
    360            this.chatColours = !this.chatColours;
    361        }
    362
    363        if (par1EnumOptions == EnumOptions.CHAT_LINKS)
    364        {
    365            this.chatLinks = !this.chatLinks;
    366        }
    367
    368        if (par1EnumOptions == EnumOptions.CHAT_LINKS_PROMPT)
    369        {
    370            this.chatLinksPrompt = !this.chatLinksPrompt;
    371        }
    372
    373        if (par1EnumOptions == EnumOptions.USE_SERVER_TEXTURES)
    374        {
    375            this.serverTextures = !this.serverTextures;
    376        }
    377
    378        if (par1EnumOptions == EnumOptions.SNOOPER_ENABLED)
    379        {
    380            this.snooperEnabled = !this.snooperEnabled;
    381        }
    382
    383        if (par1EnumOptions == EnumOptions.SHOW_CAPE)
    384        {
    385            this.showCape = !this.showCape;
    386        }
    387
    388        if (par1EnumOptions == EnumOptions.TOUCHSCREEN)
    389        {
    390            this.touchscreen = !this.touchscreen;
    391        }
    392
    393        if (par1EnumOptions == EnumOptions.USE_FULLSCREEN)
    394        {
    395            this.fullScreen = !this.fullScreen;
    396
    397            if (this.mc.isFullScreen() != this.fullScreen)
    398            {
    399                this.mc.toggleFullscreen();
    400            }
    401        }
    402
    403        if (par1EnumOptions == EnumOptions.ENABLE_VSYNC)
    404        {
    405            this.enableVsync = !this.enableVsync;
    406            Display.setVSyncEnabled(this.enableVsync);
    407        }
    408
    409        this.saveOptions();
    410    }
    411
    412    public float getOptionFloatValue(EnumOptions par1EnumOptions)
    413    {
    414        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.chatHeightFocused : (par1EnumOptions == EnumOptions.CHAT_HEIGHT_UNFOCUSED ? this.chatHeightUnfocused : (par1EnumOptions == EnumOptions.CHAT_SCALE ? this.chatScale : (par1EnumOptions == EnumOptions.CHAT_WIDTH ? this.chatWidth : 0.0F)))))))));
    415    }
    416
    417    public boolean getOptionOrdinalValue(EnumOptions par1EnumOptions)
    418    {
    419        switch (EnumOptionsHelper.enumOptionsMappingHelperArray[par1EnumOptions.ordinal()])
    420        {
    421            case 1:
    422                return this.invertMouse;
    423            case 2:
    424                return this.viewBobbing;
    425            case 3:
    426                return this.anaglyph;
    427            case 4:
    428                return this.advancedOpengl;
    429            case 5:
    430                return this.clouds;
    431            case 6:
    432                return this.chatColours;
    433            case 7:
    434                return this.chatLinks;
    435            case 8:
    436                return this.chatLinksPrompt;
    437            case 9:
    438                return this.serverTextures;
    439            case 10:
    440                return this.snooperEnabled;
    441            case 11:
    442                return this.fullScreen;
    443            case 12:
    444                return this.enableVsync;
    445            case 13:
    446                return this.showCape;
    447            case 14:
    448                return this.touchscreen;
    449            default:
    450                return false;
    451        }
    452    }
    453
    454    /**
    455     * Returns the translation of the given index in the given String array. If the index is smaller than 0 or greater
    456     * than/equal to the length of the String array, it is changed to 0.
    457     */
    458    private static String getTranslation(String[] par0ArrayOfStr, int par1)
    459    {
    460        if (par1 < 0 || par1 >= par0ArrayOfStr.length)
    461        {
    462            par1 = 0;
    463        }
    464
    465        StringTranslate stringtranslate = StringTranslate.getInstance();
    466        return stringtranslate.translateKey(par0ArrayOfStr[par1]);
    467    }
    468
    469    /**
    470     * Gets a key binding.
    471     */
    472    public String getKeyBinding(EnumOptions par1EnumOptions)
    473    {
    474        StringTranslate stringtranslate = StringTranslate.getInstance();
    475        String s = stringtranslate.translateKey(par1EnumOptions.getEnumString()) + ": ";
    476
    477        if (par1EnumOptions.getEnumFloat())
    478        {
    479            float f = this.getOptionFloatValue(par1EnumOptions);
    480            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) + "%")))))));
    481        }
    482        else if (par1EnumOptions.getEnumBoolean())
    483        {
    484            boolean flag = this.getOptionOrdinalValue(par1EnumOptions);
    485            return flag ? s + stringtranslate.translateKey("options.on") : s + stringtranslate.translateKey("options.off");
    486        }
    487        else
    488        {
    489            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(AMBIENT_OCCLUSIONS, this.ambientOcclusion) : (par1EnumOptions == EnumOptions.GRAPHICS ? (this.fancyGraphics ? s + stringtranslate.translateKey("options.graphics.fancy") : s + stringtranslate.translateKey("options.graphics.fast")) : s)))))));
    490        }
    491    }
    492
    493    /**
    494     * Loads the options from the options file. It appears that this has replaced the previous 'loadOptions'
    495     */
    496    public void loadOptions()
    497    {
    498        try
    499        {
    500            if (!this.optionsFile.exists())
    501            {
    502                return;
    503            }
    504
    505            BufferedReader bufferedreader = new BufferedReader(new FileReader(this.optionsFile));
    506            String s = "";
    507
    508            while ((s = bufferedreader.readLine()) != null)
    509            {
    510                try
    511                {
    512                    String[] astring = s.split(":");
    513
    514                    if (astring[0].equals("music"))
    515                    {
    516                        this.musicVolume = this.parseFloat(astring[1]);
    517                    }
    518
    519                    if (astring[0].equals("sound"))
    520                    {
    521                        this.soundVolume = this.parseFloat(astring[1]);
    522                    }
    523
    524                    if (astring[0].equals("mouseSensitivity"))
    525                    {
    526                        this.mouseSensitivity = this.parseFloat(astring[1]);
    527                    }
    528
    529                    if (astring[0].equals("fov"))
    530                    {
    531                        this.fovSetting = this.parseFloat(astring[1]);
    532                    }
    533
    534                    if (astring[0].equals("gamma"))
    535                    {
    536                        this.gammaSetting = this.parseFloat(astring[1]);
    537                    }
    538
    539                    if (astring[0].equals("invertYMouse"))
    540                    {
    541                        this.invertMouse = astring[1].equals("true");
    542                    }
    543
    544                    if (astring[0].equals("viewDistance"))
    545                    {
    546                        this.renderDistance = Integer.parseInt(astring[1]);
    547                    }
    548
    549                    if (astring[0].equals("guiScale"))
    550                    {
    551                        this.guiScale = Integer.parseInt(astring[1]);
    552                    }
    553
    554                    if (astring[0].equals("particles"))
    555                    {
    556                        this.particleSetting = Integer.parseInt(astring[1]);
    557                    }
    558
    559                    if (astring[0].equals("bobView"))
    560                    {
    561                        this.viewBobbing = astring[1].equals("true");
    562                    }
    563
    564                    if (astring[0].equals("anaglyph3d"))
    565                    {
    566                        this.anaglyph = astring[1].equals("true");
    567                    }
    568
    569                    if (astring[0].equals("advancedOpengl"))
    570                    {
    571                        this.advancedOpengl = astring[1].equals("true");
    572                    }
    573
    574                    if (astring[0].equals("fpsLimit"))
    575                    {
    576                        this.limitFramerate = Integer.parseInt(astring[1]);
    577                    }
    578
    579                    if (astring[0].equals("difficulty"))
    580                    {
    581                        this.difficulty = Integer.parseInt(astring[1]);
    582                    }
    583
    584                    if (astring[0].equals("fancyGraphics"))
    585                    {
    586                        this.fancyGraphics = astring[1].equals("true");
    587                    }
    588
    589                    if (astring[0].equals("ao"))
    590                    {
    591                        if (astring[1].equals("true"))
    592                        {
    593                            this.ambientOcclusion = 2;
    594                        }
    595                        else if (astring[1].equals("false"))
    596                        {
    597                            this.ambientOcclusion = 0;
    598                        }
    599                        else
    600                        {
    601                            this.ambientOcclusion = Integer.parseInt(astring[1]);
    602                        }
    603                    }
    604
    605                    if (astring[0].equals("clouds"))
    606                    {
    607                        this.clouds = astring[1].equals("true");
    608                    }
    609
    610                    if (astring[0].equals("skin"))
    611                    {
    612                        this.skin = astring[1];
    613                    }
    614
    615                    if (astring[0].equals("lastServer") && astring.length >= 2)
    616                    {
    617                        this.lastServer = astring[1];
    618                    }
    619
    620                    if (astring[0].equals("lang") && astring.length >= 2)
    621                    {
    622                        this.language = astring[1];
    623                    }
    624
    625                    if (astring[0].equals("chatVisibility"))
    626                    {
    627                        this.chatVisibility = Integer.parseInt(astring[1]);
    628                    }
    629
    630                    if (astring[0].equals("chatColors"))
    631                    {
    632                        this.chatColours = astring[1].equals("true");
    633                    }
    634
    635                    if (astring[0].equals("chatLinks"))
    636                    {
    637                        this.chatLinks = astring[1].equals("true");
    638                    }
    639
    640                    if (astring[0].equals("chatLinksPrompt"))
    641                    {
    642                        this.chatLinksPrompt = astring[1].equals("true");
    643                    }
    644
    645                    if (astring[0].equals("chatOpacity"))
    646                    {
    647                        this.chatOpacity = this.parseFloat(astring[1]);
    648                    }
    649
    650                    if (astring[0].equals("serverTextures"))
    651                    {
    652                        this.serverTextures = astring[1].equals("true");
    653                    }
    654
    655                    if (astring[0].equals("snooperEnabled"))
    656                    {
    657                        this.snooperEnabled = astring[1].equals("true");
    658                    }
    659
    660                    if (astring[0].equals("fullscreen"))
    661                    {
    662                        this.fullScreen = astring[1].equals("true");
    663                    }
    664
    665                    if (astring[0].equals("enableVsync"))
    666                    {
    667                        this.enableVsync = astring[1].equals("true");
    668                    }
    669
    670                    if (astring[0].equals("hideServerAddress"))
    671                    {
    672                        this.hideServerAddress = astring[1].equals("true");
    673                    }
    674
    675                    if (astring[0].equals("advancedItemTooltips"))
    676                    {
    677                        this.advancedItemTooltips = astring[1].equals("true");
    678                    }
    679
    680                    if (astring[0].equals("pauseOnLostFocus"))
    681                    {
    682                        this.pauseOnLostFocus = astring[1].equals("true");
    683                    }
    684
    685                    if (astring[0].equals("showCape"))
    686                    {
    687                        this.showCape = astring[1].equals("true");
    688                    }
    689
    690                    if (astring[0].equals("touchscreen"))
    691                    {
    692                        this.touchscreen = astring[1].equals("true");
    693                    }
    694
    695                    if (astring[0].equals("overrideHeight"))
    696                    {
    697                        this.overrideHeight = Integer.parseInt(astring[1]);
    698                    }
    699
    700                    if (astring[0].equals("overrideWidth"))
    701                    {
    702                        this.overrideWidth = Integer.parseInt(astring[1]);
    703                    }
    704
    705                    if (astring[0].equals("heldItemTooltips"))
    706                    {
    707                        this.heldItemTooltips = astring[1].equals("true");
    708                    }
    709
    710                    if (astring[0].equals("chatHeightFocused"))
    711                    {
    712                        this.chatHeightFocused = this.parseFloat(astring[1]);
    713                    }
    714
    715                    if (astring[0].equals("chatHeightUnfocused"))
    716                    {
    717                        this.chatHeightUnfocused = this.parseFloat(astring[1]);
    718                    }
    719
    720                    if (astring[0].equals("chatScale"))
    721                    {
    722                        this.chatScale = this.parseFloat(astring[1]);
    723                    }
    724
    725                    if (astring[0].equals("chatWidth"))
    726                    {
    727                        this.chatWidth = this.parseFloat(astring[1]);
    728                    }
    729
    730                    for (int i = 0; i < this.keyBindings.length; ++i)
    731                    {
    732                        if (astring[0].equals("key_" + this.keyBindings[i].keyDescription))
    733                        {
    734                            this.keyBindings[i].keyCode = Integer.parseInt(astring[1]);
    735                        }
    736                    }
    737                }
    738                catch (Exception exception)
    739                {
    740                    this.mc.getLogAgent().logWarning("Skipping bad option: " + s);
    741                }
    742            }
    743
    744            KeyBinding.resetKeyBindingArrayAndHash();
    745            bufferedreader.close();
    746        }
    747        catch (Exception exception1)
    748        {
    749            this.mc.getLogAgent().logWarning("Failed to load options");
    750            exception1.printStackTrace();
    751        }
    752    }
    753
    754    /**
    755     * Parses a string into a float.
    756     */
    757    private float parseFloat(String par1Str)
    758    {
    759        return par1Str.equals("true") ? 1.0F : (par1Str.equals("false") ? 0.0F : Float.parseFloat(par1Str));
    760    }
    761
    762    /**
    763     * Saves the options to the options file.
    764     */
    765    public void saveOptions()
    766    {
    767        if (FMLClientHandler.instance().isLoading()) return;
    768        try
    769        {
    770            PrintWriter printwriter = new PrintWriter(new FileWriter(this.optionsFile));
    771            printwriter.println("music:" + this.musicVolume);
    772            printwriter.println("sound:" + this.soundVolume);
    773            printwriter.println("invertYMouse:" + this.invertMouse);
    774            printwriter.println("mouseSensitivity:" + this.mouseSensitivity);
    775            printwriter.println("fov:" + this.fovSetting);
    776            printwriter.println("gamma:" + this.gammaSetting);
    777            printwriter.println("viewDistance:" + this.renderDistance);
    778            printwriter.println("guiScale:" + this.guiScale);
    779            printwriter.println("particles:" + this.particleSetting);
    780            printwriter.println("bobView:" + this.viewBobbing);
    781            printwriter.println("anaglyph3d:" + this.anaglyph);
    782            printwriter.println("advancedOpengl:" + this.advancedOpengl);
    783            printwriter.println("fpsLimit:" + this.limitFramerate);
    784            printwriter.println("difficulty:" + this.difficulty);
    785            printwriter.println("fancyGraphics:" + this.fancyGraphics);
    786            printwriter.println("ao:" + this.ambientOcclusion);
    787            printwriter.println("clouds:" + this.clouds);
    788            printwriter.println("skin:" + this.skin);
    789            printwriter.println("lastServer:" + this.lastServer);
    790            printwriter.println("lang:" + this.language);
    791            printwriter.println("chatVisibility:" + this.chatVisibility);
    792            printwriter.println("chatColors:" + this.chatColours);
    793            printwriter.println("chatLinks:" + this.chatLinks);
    794            printwriter.println("chatLinksPrompt:" + this.chatLinksPrompt);
    795            printwriter.println("chatOpacity:" + this.chatOpacity);
    796            printwriter.println("serverTextures:" + this.serverTextures);
    797            printwriter.println("snooperEnabled:" + this.snooperEnabled);
    798            printwriter.println("fullscreen:" + this.fullScreen);
    799            printwriter.println("enableVsync:" + this.enableVsync);
    800            printwriter.println("hideServerAddress:" + this.hideServerAddress);
    801            printwriter.println("advancedItemTooltips:" + this.advancedItemTooltips);
    802            printwriter.println("pauseOnLostFocus:" + this.pauseOnLostFocus);
    803            printwriter.println("showCape:" + this.showCape);
    804            printwriter.println("touchscreen:" + this.touchscreen);
    805            printwriter.println("overrideWidth:" + this.overrideWidth);
    806            printwriter.println("overrideHeight:" + this.overrideHeight);
    807            printwriter.println("heldItemTooltips:" + this.heldItemTooltips);
    808            printwriter.println("chatHeightFocused:" + this.chatHeightFocused);
    809            printwriter.println("chatHeightUnfocused:" + this.chatHeightUnfocused);
    810            printwriter.println("chatScale:" + this.chatScale);
    811            printwriter.println("chatWidth:" + this.chatWidth);
    812
    813            for (int i = 0; i < this.keyBindings.length; ++i)
    814            {
    815                printwriter.println("key_" + this.keyBindings[i].keyDescription + ":" + this.keyBindings[i].keyCode);
    816            }
    817
    818            printwriter.close();
    819        }
    820        catch (Exception exception)
    821        {
    822            this.mc.getLogAgent().logWarning("Failed to save options");
    823            exception.printStackTrace();
    824        }
    825
    826        this.sendSettingsToServer();
    827    }
    828
    829    /**
    830     * Send a client info packet with settings information to the server
    831     */
    832    public void sendSettingsToServer()
    833    {
    834        if (this.mc.thePlayer != null)
    835        {
    836            this.mc.thePlayer.sendQueue.addToSendQueue(new Packet204ClientInfo(this.language, this.renderDistance, this.chatVisibility, this.chatColours, this.difficulty, this.showCape));
    837        }
    838    }
    839
    840    /**
    841     * Should render clouds
    842     */
    843    public boolean shouldRenderClouds()
    844    {
    845        return this.renderDistance < 2 && this.clouds;
    846    }
    847}