package net.minecraft.client;

import java.lang.reflect.ParameterizedType;
import org.apache.logging.log4j.LogManager;
import net.minecraft.client.resources.UnopenedResourcePack;
import net.minecraft.server.packs.repository.PackRepository;
import java.util.Collection;
import com.google.common.collect.ImmutableSet;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ServerboundClientInformationPacket;
import com.mojang.blaze3d.platform.VideoMode;
import net.minecraft.SharedConstants;
import java.io.Writer;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.io.FileOutputStream;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.util.datafix.DataFixTypes;
import java.util.Iterator;
import java.io.BufferedReader;
import net.minecraft.util.GsonHelper;
import com.google.common.io.Files;
import com.google.common.base.Charsets;
import net.minecraft.nbt.CompoundTag;
import org.apache.commons.lang3.ArrayUtils;
import com.mojang.blaze3d.platform.InputConstants;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Lists;
import net.minecraft.world.Difficulty;
import java.io.File;
import net.minecraft.client.tutorial.TutorialSteps;
import net.minecraft.sounds.SoundSource;
import java.util.Map;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.player.PlayerModelPart;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.world.entity.player.ChatVisiblity;
import java.util.List;
import com.google.common.base.Splitter;
import java.lang.reflect.Type;
import com.google.gson.Gson;
import org.apache.logging.log4j.Logger;

public class Options {
    private static final Logger LOGGER;
    private static final Gson GSON;
    private static final Type RESOURCE_PACK_TYPE;
    private static final Splitter OPTION_SPLITTER;
    public double sensitivity;
    public int renderDistance;
    public int framerateLimit;
    public CloudStatus renderClouds;
    public boolean fancyGraphics;
    public AmbientOcclusionStatus ambientOcclusion;
    public List<String> resourcePacks;
    public List<String> incompatibleResourcePacks;
    public ChatVisiblity chatVisibility;
    public double chatOpacity;
    public double textBackgroundOpacity;
    @Nullable
    public String fullscreenVideoModeString;
    public boolean hideServerAddress;
    public boolean advancedItemTooltips;
    public boolean pauseOnLostFocus;
    private final Set<PlayerModelPart> modelParts;
    public HumanoidArm mainHand;
    public int overrideWidth;
    public int overrideHeight;
    public boolean heldItemTooltips;
    public double chatScale;
    public double chatWidth;
    public double chatHeightUnfocused;
    public double chatHeightFocused;
    public int mipmapLevels;
    private final Map<SoundSource, Float> sourceVolumes;
    public boolean useNativeTransport;
    public AttackIndicatorStatus attackIndicator;
    public TutorialSteps tutorialStep;
    public int biomeBlendRadius;
    public double mouseWheelSensitivity;
    public boolean rawMouseInput;
    public int glDebugVerbosity;
    public boolean autoJump;
    public boolean autoSuggestions;
    public boolean chatColors;
    public boolean chatLinks;
    public boolean chatLinksPrompt;
    public boolean enableVsync;
    public boolean entityShadows;
    public boolean forceUnicodeFont;
    public boolean invertYMouse;
    public boolean discreteMouseScroll;
    public boolean realmsNotifications;
    public boolean reducedDebugInfo;
    public boolean snooperEnabled;
    public boolean showSubtitles;
    public boolean backgroundForChatOnly;
    public boolean touchscreen;
    public boolean fullscreen;
    public boolean bobView;
    public boolean toggleCrouch;
    public boolean toggleSprint;
    public boolean skipMultiplayerWarning;
    public final KeyMapping keyUp;
    public final KeyMapping keyLeft;
    public final KeyMapping keyDown;
    public final KeyMapping keyRight;
    public final KeyMapping keyJump;
    public final KeyMapping keyShift;
    public final KeyMapping keySprint;
    public final KeyMapping keyInventory;
    public final KeyMapping keySwapHands;
    public final KeyMapping keyDrop;
    public final KeyMapping keyUse;
    public final KeyMapping keyAttack;
    public final KeyMapping keyPickItem;
    public final KeyMapping keyChat;
    public final KeyMapping keyPlayerList;
    public final KeyMapping keyCommand;
    public final KeyMapping keyScreenshot;
    public final KeyMapping keyTogglePerspective;
    public final KeyMapping keySmoothCamera;
    public final KeyMapping keyFullscreen;
    public final KeyMapping keySpectatorOutlines;
    public final KeyMapping keyAdvancements;
    public final KeyMapping[] keyHotbarSlots;
    public final KeyMapping keySaveHotbarActivator;
    public final KeyMapping keyLoadHotbarActivator;
    public final KeyMapping[] keyMappings;
    protected Minecraft minecraft;
    private final File optionsFile;
    public Difficulty difficulty;
    public boolean hideGui;
    public int thirdPersonView;
    public boolean renderDebug;
    public boolean renderDebugCharts;
    public boolean renderFpsChart;
    public String lastMpIp;
    public boolean smoothCamera;
    public double fov;
    public double gamma;
    public int guiScale;
    public ParticleStatus particles;
    public NarratorStatus narratorStatus;
    public String languageCode;
    
    public Options(final Minecraft dbn, final File file) {
        this.sensitivity = 0.5;
        this.renderDistance = -1;
        this.framerateLimit = 120;
        this.renderClouds = CloudStatus.FANCY;
        this.fancyGraphics = true;
        this.ambientOcclusion = AmbientOcclusionStatus.MAX;
        this.resourcePacks = Lists.newArrayList();
        this.incompatibleResourcePacks = Lists.newArrayList();
        this.chatVisibility = ChatVisiblity.FULL;
        this.chatOpacity = 1.0;
        this.textBackgroundOpacity = 0.5;
        this.pauseOnLostFocus = true;
        this.modelParts = Sets.<PlayerModelPart>newHashSet(PlayerModelPart.values());
        this.mainHand = HumanoidArm.RIGHT;
        this.heldItemTooltips = true;
        this.chatScale = 1.0;
        this.chatWidth = 1.0;
        this.chatHeightUnfocused = 0.44366195797920227;
        this.chatHeightFocused = 1.0;
        this.mipmapLevels = 4;
        this.sourceVolumes = Maps.newEnumMap(SoundSource.class);
        this.useNativeTransport = true;
        this.attackIndicator = AttackIndicatorStatus.CROSSHAIR;
        this.tutorialStep = TutorialSteps.MOVEMENT;
        this.biomeBlendRadius = 2;
        this.mouseWheelSensitivity = 1.0;
        this.rawMouseInput = true;
        this.glDebugVerbosity = 1;
        this.autoJump = true;
        this.autoSuggestions = true;
        this.chatColors = true;
        this.chatLinks = true;
        this.chatLinksPrompt = true;
        this.enableVsync = true;
        this.entityShadows = true;
        this.realmsNotifications = true;
        this.snooperEnabled = true;
        this.backgroundForChatOnly = true;
        this.bobView = true;
        this.keyUp = new KeyMapping("key.forward", 87, "key.categories.movement");
        this.keyLeft = new KeyMapping("key.left", 65, "key.categories.movement");
        this.keyDown = new KeyMapping("key.back", 83, "key.categories.movement");
        this.keyRight = new KeyMapping("key.right", 68, "key.categories.movement");
        this.keyJump = new KeyMapping("key.jump", 32, "key.categories.movement");
        this.keyShift = new ToggleKeyMapping("key.sneak", 340, "key.categories.movement", () -> this.toggleCrouch);
        this.keySprint = new ToggleKeyMapping("key.sprint", 341, "key.categories.movement", () -> this.toggleSprint);
        this.keyInventory = new KeyMapping("key.inventory", 69, "key.categories.inventory");
        this.keySwapHands = new KeyMapping("key.swapHands", 70, "key.categories.inventory");
        this.keyDrop = new KeyMapping("key.drop", 81, "key.categories.inventory");
        this.keyUse = new KeyMapping("key.use", InputConstants.Type.MOUSE, 1, "key.categories.gameplay");
        this.keyAttack = new KeyMapping("key.attack", InputConstants.Type.MOUSE, 0, "key.categories.gameplay");
        this.keyPickItem = new KeyMapping("key.pickItem", InputConstants.Type.MOUSE, 2, "key.categories.gameplay");
        this.keyChat = new KeyMapping("key.chat", 84, "key.categories.multiplayer");
        this.keyPlayerList = new KeyMapping("key.playerlist", 258, "key.categories.multiplayer");
        this.keyCommand = new KeyMapping("key.command", 47, "key.categories.multiplayer");
        this.keyScreenshot = new KeyMapping("key.screenshot", 291, "key.categories.misc");
        this.keyTogglePerspective = new KeyMapping("key.togglePerspective", 294, "key.categories.misc");
        this.keySmoothCamera = new KeyMapping("key.smoothCamera", InputConstants.UNKNOWN.getValue(), "key.categories.misc");
        this.keyFullscreen = new KeyMapping("key.fullscreen", 300, "key.categories.misc");
        this.keySpectatorOutlines = new KeyMapping("key.spectatorOutlines", InputConstants.UNKNOWN.getValue(), "key.categories.misc");
        this.keyAdvancements = new KeyMapping("key.advancements", 76, "key.categories.misc");
        this.keyHotbarSlots = new KeyMapping[] { new KeyMapping("key.hotbar.1", 49, "key.categories.inventory"), new KeyMapping("key.hotbar.2", 50, "key.categories.inventory"), new KeyMapping("key.hotbar.3", 51, "key.categories.inventory"), new KeyMapping("key.hotbar.4", 52, "key.categories.inventory"), new KeyMapping("key.hotbar.5", 53, "key.categories.inventory"), new KeyMapping("key.hotbar.6", 54, "key.categories.inventory"), new KeyMapping("key.hotbar.7", 55, "key.categories.inventory"), new KeyMapping("key.hotbar.8", 56, "key.categories.inventory"), new KeyMapping("key.hotbar.9", 57, "key.categories.inventory") };
        this.keySaveHotbarActivator = new KeyMapping("key.saveToolbarActivator", 67, "key.categories.creative");
        this.keyLoadHotbarActivator = new KeyMapping("key.loadToolbarActivator", 88, "key.categories.creative");
        this.keyMappings = (KeyMapping[])ArrayUtils.addAll((Object[])new KeyMapping[] { this.keyAttack, this.keyUse, this.keyUp, this.keyLeft, this.keyDown, this.keyRight, this.keyJump, this.keyShift, this.keySprint, this.keyDrop, this.keyInventory, this.keyChat, this.keyPlayerList, this.keyPickItem, this.keyCommand, this.keyScreenshot, this.keyTogglePerspective, this.keySmoothCamera, this.keyFullscreen, this.keySpectatorOutlines, this.keySwapHands, this.keySaveHotbarActivator, this.keyLoadHotbarActivator, this.keyAdvancements }, (Object[])this.keyHotbarSlots);
        this.difficulty = Difficulty.NORMAL;
        this.lastMpIp = "";
        this.fov = 70.0;
        this.particles = ParticleStatus.ALL;
        this.narratorStatus = NarratorStatus.OFF;
        this.languageCode = "en_us";
        this.minecraft = dbn;
        this.optionsFile = new File(file, "options.txt");
        if (dbn.is64Bit() && Runtime.getRuntime().maxMemory() >= 1000000000L) {
            Option.RENDER_DISTANCE.setMaxValue(32.0f);
        }
        else {
            Option.RENDER_DISTANCE.setMaxValue(16.0f);
        }
        this.renderDistance = (dbn.is64Bit() ? 12 : 8);
        this.load();
    }
    
    public float getBackgroundOpacity(final float float1) {
        return this.backgroundForChatOnly ? float1 : ((float)this.textBackgroundOpacity);
    }
    
    public int getBackgroundColor(final float float1) {
        return (int)(this.getBackgroundOpacity(float1) * 255.0f) << 24 & 0xFF000000;
    }
    
    public int getBackgroundColor(final int integer) {
        return this.backgroundForChatOnly ? integer : ((int)(this.textBackgroundOpacity * 255.0) << 24 & 0xFF000000);
    }
    
    public void setKey(final KeyMapping dbk, final InputConstants.Key a) {
        dbk.setKey(a);
        this.save();
    }
    
    public void load() {
        try {
            if (!this.optionsFile.exists()) {
                return;
            }
            this.sourceVolumes.clear();
            final CompoundTag jt2 = new CompoundTag();
            try (final BufferedReader bufferedReader3 = Files.newReader(this.optionsFile, Charsets.UTF_8)) {
                Iterator<String> iterator3;
                final CompoundTag compoundTag;
                bufferedReader3.lines().forEach(string -> {
                    try {
                        iterator3 = Options.OPTION_SPLITTER.split(string).iterator();
                        compoundTag.putString(iterator3.next(), iterator3.next());
                    }
                    catch (Exception exception3) {
                        Options.LOGGER.warn("Skipping bad option: {}", string);
                    }
                    return;
                });
            }
            final CompoundTag jt3 = this.dataFix(jt2);
            for (final String string2 : jt3.getAllKeys()) {
                final String string3 = jt3.getString(string2);
                try {
                    if ("autoJump".equals(string2)) {
                        Option.AUTO_JUMP.set(this, string3);
                    }
                    if ("autoSuggestions".equals(string2)) {
                        Option.AUTO_SUGGESTIONS.set(this, string3);
                    }
                    if ("chatColors".equals(string2)) {
                        Option.CHAT_COLOR.set(this, string3);
                    }
                    if ("chatLinks".equals(string2)) {
                        Option.CHAT_LINKS.set(this, string3);
                    }
                    if ("chatLinksPrompt".equals(string2)) {
                        Option.CHAT_LINKS_PROMPT.set(this, string3);
                    }
                    if ("enableVsync".equals(string2)) {
                        Option.ENABLE_VSYNC.set(this, string3);
                    }
                    if ("entityShadows".equals(string2)) {
                        Option.ENTITY_SHADOWS.set(this, string3);
                    }
                    if ("forceUnicodeFont".equals(string2)) {
                        Option.FORCE_UNICODE_FONT.set(this, string3);
                    }
                    if ("discrete_mouse_scroll".equals(string2)) {
                        Option.DISCRETE_MOUSE_SCROLL.set(this, string3);
                    }
                    if ("invertYMouse".equals(string2)) {
                        Option.INVERT_MOUSE.set(this, string3);
                    }
                    if ("realmsNotifications".equals(string2)) {
                        Option.REALMS_NOTIFICATIONS.set(this, string3);
                    }
                    if ("reducedDebugInfo".equals(string2)) {
                        Option.REDUCED_DEBUG_INFO.set(this, string3);
                    }
                    if ("showSubtitles".equals(string2)) {
                        Option.SHOW_SUBTITLES.set(this, string3);
                    }
                    if ("snooperEnabled".equals(string2)) {
                        Option.SNOOPER_ENABLED.set(this, string3);
                    }
                    if ("touchscreen".equals(string2)) {
                        Option.TOUCHSCREEN.set(this, string3);
                    }
                    if ("fullscreen".equals(string2)) {
                        Option.USE_FULLSCREEN.set(this, string3);
                    }
                    if ("bobView".equals(string2)) {
                        Option.VIEW_BOBBING.set(this, string3);
                    }
                    if ("toggleCrouch".equals(string2)) {
                        this.toggleCrouch = "true".equals(string3);
                    }
                    if ("toggleSprint".equals(string2)) {
                        this.toggleSprint = "true".equals(string3);
                    }
                    if ("mouseSensitivity".equals(string2)) {
                        this.sensitivity = readFloat(string3);
                    }
                    if ("fov".equals(string2)) {
                        this.fov = readFloat(string3) * 40.0f + 70.0f;
                    }
                    if ("gamma".equals(string2)) {
                        this.gamma = readFloat(string3);
                    }
                    if ("renderDistance".equals(string2)) {
                        this.renderDistance = Integer.parseInt(string3);
                    }
                    if ("guiScale".equals(string2)) {
                        this.guiScale = Integer.parseInt(string3);
                    }
                    if ("particles".equals(string2)) {
                        this.particles = ParticleStatus.byId(Integer.parseInt(string3));
                    }
                    if ("maxFps".equals(string2)) {
                        this.framerateLimit = Integer.parseInt(string3);
                        if (this.minecraft.getWindow() != null) {
                            this.minecraft.getWindow().setFramerateLimit(this.framerateLimit);
                        }
                    }
                    if ("difficulty".equals(string2)) {
                        this.difficulty = Difficulty.byId(Integer.parseInt(string3));
                    }
                    if ("fancyGraphics".equals(string2)) {
                        this.fancyGraphics = "true".equals(string3);
                    }
                    if ("tutorialStep".equals(string2)) {
                        this.tutorialStep = TutorialSteps.getByName(string3);
                    }
                    if ("ao".equals(string2)) {
                        if ("true".equals(string3)) {
                            this.ambientOcclusion = AmbientOcclusionStatus.MAX;
                        }
                        else if ("false".equals(string3)) {
                            this.ambientOcclusion = AmbientOcclusionStatus.OFF;
                        }
                        else {
                            this.ambientOcclusion = AmbientOcclusionStatus.byId(Integer.parseInt(string3));
                        }
                    }
                    if ("renderClouds".equals(string2)) {
                        if ("true".equals(string3)) {
                            this.renderClouds = CloudStatus.FANCY;
                        }
                        else if ("false".equals(string3)) {
                            this.renderClouds = CloudStatus.OFF;
                        }
                        else if ("fast".equals(string3)) {
                            this.renderClouds = CloudStatus.FAST;
                        }
                    }
                    if ("attackIndicator".equals(string2)) {
                        this.attackIndicator = AttackIndicatorStatus.byId(Integer.parseInt(string3));
                    }
                    if ("resourcePacks".equals(string2)) {
                        this.resourcePacks = GsonHelper.<List<String>>fromJson(Options.GSON, string3, Options.RESOURCE_PACK_TYPE);
                        if (this.resourcePacks == null) {
                            this.resourcePacks = Lists.newArrayList();
                        }
                    }
                    if ("incompatibleResourcePacks".equals(string2)) {
                        this.incompatibleResourcePacks = GsonHelper.<List<String>>fromJson(Options.GSON, string3, Options.RESOURCE_PACK_TYPE);
                        if (this.incompatibleResourcePacks == null) {
                            this.incompatibleResourcePacks = Lists.newArrayList();
                        }
                    }
                    if ("lastServer".equals(string2)) {
                        this.lastMpIp = string3;
                    }
                    if ("lang".equals(string2)) {
                        this.languageCode = string3;
                    }
                    if ("chatVisibility".equals(string2)) {
                        this.chatVisibility = ChatVisiblity.byId(Integer.parseInt(string3));
                    }
                    if ("chatOpacity".equals(string2)) {
                        this.chatOpacity = readFloat(string3);
                    }
                    if ("textBackgroundOpacity".equals(string2)) {
                        this.textBackgroundOpacity = readFloat(string3);
                    }
                    if ("backgroundForChatOnly".equals(string2)) {
                        this.backgroundForChatOnly = "true".equals(string3);
                    }
                    if ("fullscreenResolution".equals(string2)) {
                        this.fullscreenVideoModeString = string3;
                    }
                    if ("hideServerAddress".equals(string2)) {
                        this.hideServerAddress = "true".equals(string3);
                    }
                    if ("advancedItemTooltips".equals(string2)) {
                        this.advancedItemTooltips = "true".equals(string3);
                    }
                    if ("pauseOnLostFocus".equals(string2)) {
                        this.pauseOnLostFocus = "true".equals(string3);
                    }
                    if ("overrideHeight".equals(string2)) {
                        this.overrideHeight = Integer.parseInt(string3);
                    }
                    if ("overrideWidth".equals(string2)) {
                        this.overrideWidth = Integer.parseInt(string3);
                    }
                    if ("heldItemTooltips".equals(string2)) {
                        this.heldItemTooltips = "true".equals(string3);
                    }
                    if ("chatHeightFocused".equals(string2)) {
                        this.chatHeightFocused = readFloat(string3);
                    }
                    if ("chatHeightUnfocused".equals(string2)) {
                        this.chatHeightUnfocused = readFloat(string3);
                    }
                    if ("chatScale".equals(string2)) {
                        this.chatScale = readFloat(string3);
                    }
                    if ("chatWidth".equals(string2)) {
                        this.chatWidth = readFloat(string3);
                    }
                    if ("mipmapLevels".equals(string2)) {
                        this.mipmapLevels = Integer.parseInt(string3);
                    }
                    if ("useNativeTransport".equals(string2)) {
                        this.useNativeTransport = "true".equals(string3);
                    }
                    if ("mainHand".equals(string2)) {
                        this.mainHand = ("left".equals(string3) ? HumanoidArm.LEFT : HumanoidArm.RIGHT);
                    }
                    if ("narrator".equals(string2)) {
                        this.narratorStatus = NarratorStatus.byId(Integer.parseInt(string3));
                    }
                    if ("biomeBlendRadius".equals(string2)) {
                        this.biomeBlendRadius = Integer.parseInt(string3);
                    }
                    if ("mouseWheelSensitivity".equals(string2)) {
                        this.mouseWheelSensitivity = readFloat(string3);
                    }
                    if ("rawMouseInput".equals(string2)) {
                        this.rawMouseInput = "true".equals(string3);
                    }
                    if ("glDebugVerbosity".equals(string2)) {
                        this.glDebugVerbosity = Integer.parseInt(string3);
                    }
                    if ("skipMultiplayerWarning".equals(string2)) {
                        this.skipMultiplayerWarning = "true".equals(string3);
                    }
                    for (final KeyMapping dbk10 : this.keyMappings) {
                        if (string2.equals("key_" + dbk10.getName())) {
                            dbk10.setKey(InputConstants.getKey(string3));
                        }
                    }
                    for (final SoundSource aaj10 : SoundSource.values()) {
                        if (string2.equals("soundCategory_" + aaj10.getName())) {
                            this.sourceVolumes.put(aaj10, readFloat(string3));
                        }
                    }
                    for (final PlayerModelPart ayk10 : PlayerModelPart.values()) {
                        if (string2.equals("modelPart_" + ayk10.getId())) {
                            this.setModelPart(ayk10, "true".equals(string3));
                        }
                    }
                }
                catch (Exception exception4) {
                    Options.LOGGER.warn("Skipping bad option: {}:{}", string2, string3);
                }
            }
            KeyMapping.resetMapping();
        }
        catch (Exception exception2) {
            Options.LOGGER.error("Failed to load options", (Throwable)exception2);
        }
    }
    
    private CompoundTag dataFix(final CompoundTag jt) {
        int integer3 = 0;
        try {
            integer3 = Integer.parseInt(jt.getString("version"));
        }
        catch (RuntimeException ex) {}
        return NbtUtils.update(this.minecraft.getFixerUpper(), DataFixTypes.OPTIONS, jt, integer3);
    }
    
    private static float readFloat(final String string) {
        if ("true".equals(string)) {
            return 1.0f;
        }
        if ("false".equals(string)) {
            return 0.0f;
        }
        return Float.parseFloat(string);
    }
    
    public void save() {
        try (final PrintWriter printWriter2 = new PrintWriter(new OutputStreamWriter(new FileOutputStream(this.optionsFile), StandardCharsets.UTF_8))) {
            printWriter2.println("version:" + SharedConstants.getCurrentVersion().getWorldVersion());
            printWriter2.println("autoJump:" + Option.AUTO_JUMP.get(this));
            printWriter2.println("autoSuggestions:" + Option.AUTO_SUGGESTIONS.get(this));
            printWriter2.println("chatColors:" + Option.CHAT_COLOR.get(this));
            printWriter2.println("chatLinks:" + Option.CHAT_LINKS.get(this));
            printWriter2.println("chatLinksPrompt:" + Option.CHAT_LINKS_PROMPT.get(this));
            printWriter2.println("enableVsync:" + Option.ENABLE_VSYNC.get(this));
            printWriter2.println("entityShadows:" + Option.ENTITY_SHADOWS.get(this));
            printWriter2.println("forceUnicodeFont:" + Option.FORCE_UNICODE_FONT.get(this));
            printWriter2.println("discrete_mouse_scroll:" + Option.DISCRETE_MOUSE_SCROLL.get(this));
            printWriter2.println("invertYMouse:" + Option.INVERT_MOUSE.get(this));
            printWriter2.println("realmsNotifications:" + Option.REALMS_NOTIFICATIONS.get(this));
            printWriter2.println("reducedDebugInfo:" + Option.REDUCED_DEBUG_INFO.get(this));
            printWriter2.println("snooperEnabled:" + Option.SNOOPER_ENABLED.get(this));
            printWriter2.println("showSubtitles:" + Option.SHOW_SUBTITLES.get(this));
            printWriter2.println("touchscreen:" + Option.TOUCHSCREEN.get(this));
            printWriter2.println("fullscreen:" + Option.USE_FULLSCREEN.get(this));
            printWriter2.println("bobView:" + Option.VIEW_BOBBING.get(this));
            printWriter2.println("toggleCrouch:" + this.toggleCrouch);
            printWriter2.println("toggleSprint:" + this.toggleSprint);
            printWriter2.println("mouseSensitivity:" + this.sensitivity);
            printWriter2.println("fov:" + (this.fov - 70.0) / 40.0);
            printWriter2.println("gamma:" + this.gamma);
            printWriter2.println("renderDistance:" + this.renderDistance);
            printWriter2.println("guiScale:" + this.guiScale);
            printWriter2.println("particles:" + this.particles.getId());
            printWriter2.println("maxFps:" + this.framerateLimit);
            printWriter2.println("difficulty:" + this.difficulty.getId());
            printWriter2.println("fancyGraphics:" + this.fancyGraphics);
            printWriter2.println("ao:" + this.ambientOcclusion.getId());
            printWriter2.println("biomeBlendRadius:" + this.biomeBlendRadius);
            switch (this.renderClouds) {
                case FANCY: {
                    printWriter2.println("renderClouds:true");
                    break;
                }
                case FAST: {
                    printWriter2.println("renderClouds:fast");
                    break;
                }
                case OFF: {
                    printWriter2.println("renderClouds:false");
                    break;
                }
            }
            printWriter2.println("resourcePacks:" + Options.GSON.toJson(this.resourcePacks));
            printWriter2.println("incompatibleResourcePacks:" + Options.GSON.toJson(this.incompatibleResourcePacks));
            printWriter2.println("lastServer:" + this.lastMpIp);
            printWriter2.println("lang:" + this.languageCode);
            printWriter2.println("chatVisibility:" + this.chatVisibility.getId());
            printWriter2.println("chatOpacity:" + this.chatOpacity);
            printWriter2.println("textBackgroundOpacity:" + this.textBackgroundOpacity);
            printWriter2.println("backgroundForChatOnly:" + this.backgroundForChatOnly);
            if (this.minecraft.getWindow().getPreferredFullscreenVideoMode().isPresent()) {
                printWriter2.println("fullscreenResolution:" + this.minecraft.getWindow().getPreferredFullscreenVideoMode().get().write());
            }
            printWriter2.println("hideServerAddress:" + this.hideServerAddress);
            printWriter2.println("advancedItemTooltips:" + this.advancedItemTooltips);
            printWriter2.println("pauseOnLostFocus:" + this.pauseOnLostFocus);
            printWriter2.println("overrideWidth:" + this.overrideWidth);
            printWriter2.println("overrideHeight:" + this.overrideHeight);
            printWriter2.println("heldItemTooltips:" + this.heldItemTooltips);
            printWriter2.println("chatHeightFocused:" + this.chatHeightFocused);
            printWriter2.println("chatHeightUnfocused:" + this.chatHeightUnfocused);
            printWriter2.println("chatScale:" + this.chatScale);
            printWriter2.println("chatWidth:" + this.chatWidth);
            printWriter2.println("mipmapLevels:" + this.mipmapLevels);
            printWriter2.println("useNativeTransport:" + this.useNativeTransport);
            printWriter2.println("mainHand:" + ((this.mainHand == HumanoidArm.LEFT) ? "left" : "right"));
            printWriter2.println("attackIndicator:" + this.attackIndicator.getId());
            printWriter2.println("narrator:" + this.narratorStatus.getId());
            printWriter2.println("tutorialStep:" + this.tutorialStep.getName());
            printWriter2.println("mouseWheelSensitivity:" + this.mouseWheelSensitivity);
            printWriter2.println("rawMouseInput:" + Option.RAW_MOUSE_INPUT.get(this));
            printWriter2.println("glDebugVerbosity:" + this.glDebugVerbosity);
            printWriter2.println("skipMultiplayerWarning:" + this.skipMultiplayerWarning);
            for (final KeyMapping dbk7 : this.keyMappings) {
                printWriter2.println("key_" + dbk7.getName() + ":" + dbk7.saveString());
            }
            for (final SoundSource aaj7 : SoundSource.values()) {
                printWriter2.println("soundCategory_" + aaj7.getName() + ":" + this.getSoundSourceVolume(aaj7));
            }
            for (final PlayerModelPart ayk7 : PlayerModelPart.values()) {
                printWriter2.println("modelPart_" + ayk7.getId() + ":" + this.modelParts.contains(ayk7));
            }
        }
        catch (Exception exception2) {
            Options.LOGGER.error("Failed to save options", (Throwable)exception2);
        }
        this.broadcastOptions();
    }
    
    public float getSoundSourceVolume(final SoundSource aaj) {
        if (this.sourceVolumes.containsKey(aaj)) {
            return this.sourceVolumes.get(aaj);
        }
        return 1.0f;
    }
    
    public void setSoundCategoryVolume(final SoundSource aaj, final float float2) {
        this.sourceVolumes.put(aaj, float2);
        this.minecraft.getSoundManager().updateSourceVolume(aaj, float2);
    }
    
    public void broadcastOptions() {
        if (this.minecraft.player != null) {
            int integer2 = 0;
            for (final PlayerModelPart ayk4 : this.modelParts) {
                integer2 |= ayk4.getMask();
            }
            this.minecraft.player.connection.send(new ServerboundClientInformationPacket(this.languageCode, this.renderDistance, this.chatVisibility, this.chatColors, integer2, this.mainHand));
        }
    }
    
    public Set<PlayerModelPart> getModelParts() {
        return ImmutableSet.copyOf(this.modelParts);
    }
    
    public void setModelPart(final PlayerModelPart ayk, final boolean boolean2) {
        if (boolean2) {
            this.modelParts.add(ayk);
        }
        else {
            this.modelParts.remove(ayk);
        }
        this.broadcastOptions();
    }
    
    public void toggleModelPart(final PlayerModelPart ayk) {
        if (this.getModelParts().contains(ayk)) {
            this.modelParts.remove(ayk);
        }
        else {
            this.modelParts.add(ayk);
        }
        this.broadcastOptions();
    }
    
    public CloudStatus getCloudsType() {
        if (this.renderDistance >= 4) {
            return this.renderClouds;
        }
        return CloudStatus.OFF;
    }
    
    public boolean useNativeTransport() {
        return this.useNativeTransport;
    }
    
    public void loadResourcePacks(final PackRepository<UnopenedResourcePack> yq) {
        yq.reload();
        final Set<UnopenedResourcePack> set3 = Sets.newLinkedHashSet();
        final Iterator<String> iterator4 = this.resourcePacks.iterator();
        while (iterator4.hasNext()) {
            final String string5 = iterator4.next();
            UnopenedResourcePack ebc6 = yq.getPack(string5);
            if (ebc6 == null && !string5.startsWith("file/")) {
                ebc6 = yq.getPack("file/" + string5);
            }
            if (ebc6 == null) {
                Options.LOGGER.warn("Removed resource pack {} from options because it doesn't seem to exist anymore", string5);
                iterator4.remove();
            }
            else if (!ebc6.getCompatibility().isCompatible() && !this.incompatibleResourcePacks.contains(string5)) {
                Options.LOGGER.warn("Removed resource pack {} from options because it is no longer compatible", string5);
                iterator4.remove();
            }
            else if (ebc6.getCompatibility().isCompatible() && this.incompatibleResourcePacks.contains(string5)) {
                Options.LOGGER.info("Removed resource pack {} from incompatibility list because it's now compatible", string5);
                this.incompatibleResourcePacks.remove(string5);
            }
            else {
                set3.add(ebc6);
            }
        }
        yq.setSelected(set3);
    }
    
    static {
        LOGGER = LogManager.getLogger();
        GSON = new Gson();
        RESOURCE_PACK_TYPE = new ParameterizedType() {
            @Override
            public Type[] getActualTypeArguments() {
                return new Type[] { String.class };
            }
            
            @Override
            public Type getRawType() {
                return List.class;
            }
            
            @Override
            public Type getOwnerType() {
                return null;
            }
        };
        OPTION_SPLITTER = Splitter.on(':').limit(2);
    }
}
