Search in sources :

Example 1 with KeyModifier

use of net.minecraftforge.client.settings.KeyModifier in project DynamicSurroundings by OreCruncher.

the class MinecraftConfigHandler method onConfigLoad.

@SubscribeEvent
public static void onConfigLoad(@Nonnull final PresetEvent.Load event) {
    final PresetData data = event.getModData(MINECRAFT);
    if (data != null) {
        final GameSettings settings = Minecraft.getMinecraft().gameSettings;
        boolean refreshChat = false;
        boolean refreshMipmaps = false;
        boolean refreshRenderDistance = false;
        boolean refreshRenderers = false;
        boolean refreshUnicodeFlag = false;
        boolean refreshResources = false;
        boolean refreshVsync = false;
        for (final Entry<String, String> e : data.getEntries()) {
            if (e.getKey().startsWith(SOUND_PREFIX)) {
                final String catName = e.getKey().replace(SOUND_PREFIX, "");
                final SoundCategory sc = SoundCategory.getByName(catName);
                if (sc != null) {
                    settings.setSoundLevel(sc, (float) Double.parseDouble(e.getValue()));
                } else {
                    Presets.log().warn("Unknown sound category: %s", catName);
                }
            } else if (e.getKey().startsWith(KEYBIND_PREFIX)) {
                boolean found = false;
                final String keyName = e.getKey().replace(KEYBIND_PREFIX, "");
                for (final KeyBinding binding : settings.keyBindings) {
                    if (keyName.equals(binding.getKeyDescription())) {
                        final String[] parts = StringUtils.split(e.getValue(), ':');
                        final int keyCode = Integer.parseInt(parts[0]);
                        final KeyModifier modifier = parts.length == 1 ? KeyModifier.NONE : KeyModifier.valueFromString(parts[1]);
                        binding.setKeyModifierAndCode(modifier, keyCode);
                        found = true;
                        break;
                    }
                }
                if (!found)
                    Presets.log().warn("Unknown keybinding found: %s", keyName);
            } else {
                final String theName = e.getKey();
                final Options option = getOptionByName(theName);
                if (option != null) {
                    switch(option) {
                        case INVERT_MOUSE:
                            settings.invertMouse = data.getBoolean(theName, settings.invertMouse);
                            break;
                        case SENSITIVITY:
                            settings.mouseSensitivity = (float) data.getDouble(theName, settings.mouseSensitivity);
                            break;
                        case FOV:
                            settings.fovSetting = (float) data.getDouble(theName, settings.fovSetting);
                            break;
                        case GAMMA:
                            settings.gammaSetting = (float) data.getDouble(theName, settings.gammaSetting);
                            break;
                        case SATURATION:
                            settings.saturation = (float) data.getDouble(theName, settings.saturation);
                            break;
                        case RENDER_DISTANCE:
                            final int rd = data.getInt(theName, settings.renderDistanceChunks);
                            if (settings.renderDistanceChunks != rd) {
                                settings.renderDistanceChunks = rd;
                                refreshRenderDistance = true;
                            }
                            break;
                        case VIEW_BOBBING:
                            settings.viewBobbing = data.getBoolean(theName, settings.viewBobbing);
                            break;
                        case ANAGLYPH:
                            final boolean anal = data.getBoolean(theName, settings.anaglyph);
                            if (settings.anaglyph != anal) {
                                settings.anaglyph = anal;
                                refreshResources = true;
                            }
                            break;
                        case FRAMERATE_LIMIT:
                            settings.limitFramerate = data.getInt(theName, settings.limitFramerate);
                            break;
                        case FBO_ENABLE:
                            settings.fboEnable = data.getBoolean(theName, settings.fboEnable);
                            break;
                        case CHAT_COLOR:
                            settings.chatColours = data.getBoolean(theName, settings.chatColours);
                            refreshChat = true;
                            break;
                        case CHAT_LINKS:
                            settings.chatLinks = data.getBoolean(theName, settings.chatLinks);
                            refreshChat = true;
                            break;
                        case CHAT_OPACITY:
                            settings.chatOpacity = (float) data.getDouble(theName, settings.chatOpacity);
                            refreshChat = true;
                            break;
                        case CHAT_LINKS_PROMPT:
                            settings.chatLinksPrompt = data.getBoolean(theName, settings.chatLinksPrompt);
                            refreshChat = true;
                            break;
                        case SNOOPER_ENABLED:
                            settings.snooperEnabled = data.getBoolean(theName, settings.snooperEnabled);
                            break;
                        case USE_FULLSCREEN:
                            settings.fullScreen = data.getBoolean(theName, settings.fullScreen);
                            break;
                        case ENABLE_VSYNC:
                            final boolean vsync = data.getBoolean(theName, settings.enableVsync);
                            if (settings.enableVsync != vsync) {
                                settings.enableVsync = vsync;
                                refreshVsync = true;
                            }
                            break;
                        case USE_VBO:
                            final boolean vbo = data.getBoolean(theName, settings.useVbo);
                            if (settings.useVbo != vbo) {
                                settings.useVbo = vbo;
                                refreshRenderers = true;
                            }
                            break;
                        case TOUCHSCREEN:
                            settings.touchscreen = data.getBoolean(theName, settings.touchscreen);
                            break;
                        case CHAT_SCALE:
                            settings.chatScale = (float) data.getDouble(theName, settings.chatScale);
                            refreshChat = true;
                            break;
                        case CHAT_WIDTH:
                            settings.chatWidth = (float) data.getDouble(theName, settings.chatWidth);
                            refreshChat = true;
                            break;
                        case CHAT_HEIGHT_FOCUSED:
                            settings.chatHeightFocused = (float) data.getDouble(theName, settings.chatHeightFocused);
                            refreshChat = true;
                            break;
                        case CHAT_HEIGHT_UNFOCUSED:
                            settings.chatHeightUnfocused = (float) data.getDouble(theName, settings.chatHeightUnfocused);
                            refreshChat = true;
                            break;
                        case MIPMAP_LEVELS:
                            final int mips = data.getInt(theName, settings.mipmapLevels);
                            if (settings.mipmapLevels != mips) {
                                settings.mipmapLevels = mips;
                                refreshMipmaps = true;
                            }
                            break;
                        case FORCE_UNICODE_FONT:
                            final boolean force = data.getBoolean(theName, settings.forceUnicodeFont);
                            if (settings.forceUnicodeFont != force) {
                                settings.forceUnicodeFont = force;
                                refreshUnicodeFlag = true;
                            }
                            break;
                        case REDUCED_DEBUG_INFO:
                            settings.reducedDebugInfo = data.getBoolean(theName, settings.reducedDebugInfo);
                            break;
                        case ENTITY_SHADOWS:
                            settings.entityShadows = data.getBoolean(theName, settings.entityShadows);
                            break;
                        case ENABLE_WEAK_ATTACKS:
                            settings.enableWeakAttacks = data.getBoolean(theName, settings.enableWeakAttacks);
                            break;
                        case SHOW_SUBTITLES:
                            settings.showSubtitles = data.getBoolean(theName, settings.showSubtitles);
                            break;
                        case REALMS_NOTIFICATIONS:
                            settings.realmsNotifications = data.getBoolean(theName, settings.realmsNotifications);
                            break;
                        case AUTO_JUMP:
                            settings.autoJump = data.getBoolean(theName, settings.autoJump);
                            break;
                        case RENDER_CLOUDS:
                            settings.clouds = data.getInt(theName, settings.clouds);
                            break;
                        case GRAPHICS:
                            final boolean fancy = data.getBoolean(theName, settings.fancyGraphics);
                            if (settings.fancyGraphics != fancy) {
                                settings.fancyGraphics = fancy;
                                refreshRenderers = true;
                            }
                            break;
                        case AMBIENT_OCCLUSION:
                            final int occlusion = data.getInt(theName, settings.ambientOcclusion);
                            if (settings.ambientOcclusion != occlusion) {
                                settings.ambientOcclusion = occlusion;
                                refreshRenderers = true;
                            }
                            break;
                        case GUI_SCALE:
                            settings.guiScale = data.getInt(theName, settings.guiScale);
                            break;
                        case PARTICLES:
                            settings.particleSetting = data.getInt(theName, settings.particleSetting);
                            break;
                        case CHAT_VISIBILITY:
                            settings.chatVisibility = EnumChatVisibility.getEnumChatVisibility(data.getInt(theName, settings.chatVisibility.ordinal()));
                            break;
                        case MAIN_HAND:
                            settings.mainHand = EnumHandSide.valueOf(data.getString(theName, settings.mainHand.name()));
                            break;
                        case ATTACK_INDICATOR:
                            settings.attackIndicator = data.getInt(theName, settings.attackIndicator);
                            break;
                        default:
                    }
                } else {
                    Presets.log().warn("Unknown option value: %s", theName);
                }
            }
        }
        settings.saveOptions();
        // Tickle the various modules of Minecraft to get the update
        // settings since we bypassed the get/set of GameSettings.
        final Minecraft mc = Minecraft.getMinecraft();
        if (refreshChat)
            mc.ingameGUI.getChatGUI().refreshChat();
        if (refreshMipmaps) {
            mc.getTextureMapBlocks().setMipmapLevels(settings.mipmapLevels);
            mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
            mc.getTextureMapBlocks().setBlurMipmapDirect(false, settings.mipmapLevels > 0);
            refreshResources = true;
        }
        if (refreshRenderDistance)
            mc.renderGlobal.setDisplayListEntitiesDirty();
        if (refreshRenderers)
            mc.renderGlobal.loadRenderers();
        if (refreshUnicodeFlag)
            mc.fontRenderer.setUnicodeFlag(mc.getLanguageManager().isCurrentLocaleUnicode() || settings.forceUnicodeFont);
        if (refreshResources)
            mc.refreshResources();
        if (refreshVsync)
            Display.setVSyncEnabled(settings.enableVsync);
        if (settings.fullScreen != mc.isFullScreen())
            mc.toggleFullscreen();
    }
}
Also used : KeyBinding(net.minecraft.client.settings.KeyBinding) Options(net.minecraft.client.settings.GameSettings.Options) SoundCategory(net.minecraft.util.SoundCategory) PresetData(org.blockartistry.Presets.api.PresetData) KeyModifier(net.minecraftforge.client.settings.KeyModifier) GameSettings(net.minecraft.client.settings.GameSettings) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Minecraft (net.minecraft.client.Minecraft)1 GameSettings (net.minecraft.client.settings.GameSettings)1 Options (net.minecraft.client.settings.GameSettings.Options)1 KeyBinding (net.minecraft.client.settings.KeyBinding)1 SoundCategory (net.minecraft.util.SoundCategory)1 KeyModifier (net.minecraftforge.client.settings.KeyModifier)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 PresetData (org.blockartistry.Presets.api.PresetData)1