Search in sources :

Example 1 with IrisConfig

use of net.coderbot.iris.config.IrisConfig in project Iris by IrisShaders.

the class Iris method onInitializeClient.

@Override
public void onInitializeClient() {
    FabricLoader.getInstance().getModContainer("sodium").ifPresent(modContainer -> {
        sodiumInstalled = true;
        String versionString = modContainer.getMetadata().getVersion().getFriendlyString();
        // nice warning, and prevent them from playing the game with a wrong version of Sodium.
        if (!SodiumVersionCheck.isAllowedVersion(versionString)) {
            sodiumInvalid = true;
        }
    });
    ModContainer iris = FabricLoader.getInstance().getModContainer(MODID).orElseThrow(() -> new IllegalStateException("Couldn't find the mod container for Iris"));
    IRIS_VERSION = iris.getMetadata().getVersion().getFriendlyString();
    try {
        if (!Files.exists(getShaderpacksDirectory())) {
            Files.createDirectories(getShaderpacksDirectory());
        }
    } catch (IOException e) {
        logger.warn("Failed to create the shaderpacks directory!");
        logger.warn("", e);
    }
    irisConfig = new IrisConfig(FabricLoader.getInstance().getConfigDir().resolve("iris.properties"));
    try {
        irisConfig.initialize();
    } catch (IOException e) {
        logger.error("Failed to initialize Iris configuration, default values will be used instead");
        logger.error("", e);
    }
    reloadKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds"));
    toggleShadersKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds"));
    shaderpackScreenKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds"));
    initialized = true;
}
Also used : IrisConfig(net.coderbot.iris.config.IrisConfig) ModContainer(net.fabricmc.loader.api.ModContainer) KeyMapping(net.minecraft.client.KeyMapping) IOException(java.io.IOException)

Example 2 with IrisConfig

use of net.coderbot.iris.config.IrisConfig in project Iris by IrisShaders.

the class IrisApiV0ConfigImpl method setShadersEnabledAndApply.

@Override
public void setShadersEnabledAndApply(boolean enabled) {
    IrisConfig config = Iris.getIrisConfig();
    config.setShadersEnabled(enabled);
    try {
        config.save();
    } catch (IOException e) {
        Iris.logger.error("Error saving configuration file!", e);
    }
    try {
        Iris.reload();
    } catch (IOException e) {
        Iris.logger.error("Error reloading shader pack while applying changes!", e);
    }
}
Also used : IrisConfig(net.coderbot.iris.config.IrisConfig) IOException(java.io.IOException)

Example 3 with IrisConfig

use of net.coderbot.iris.config.IrisConfig in project Iris by IrisShaders.

the class Iris method handleKeybinds.

public static void handleKeybinds(Minecraft minecraft) {
    if (reloadKeybind.consumeClick()) {
        try {
            reload();
            if (minecraft.player != null) {
                minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.reloaded"), false);
            }
        } catch (Exception e) {
            logger.error("Error while reloading Shaders for Iris!", e);
            if (minecraft.player != null) {
                minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.reloaded.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false);
            }
        }
    } else if (toggleShadersKeybind.consumeClick()) {
        IrisConfig config = getIrisConfig();
        try {
            config.setShadersEnabled(!config.areShadersEnabled());
            config.save();
            reload();
            if (minecraft.player != null) {
                minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.toggled", config.areShadersEnabled() ? currentPackName : "off"), false);
            }
        } catch (Exception e) {
            logger.error("Error while toggling shaders!", e);
            if (minecraft.player != null) {
                minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.toggled.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false);
            }
            setShadersDisabled();
            currentPackName = "(off) [fallback, check your logs for errors]";
        }
    } else if (shaderpackScreenKeybind.consumeClick()) {
        minecraft.setScreen(new ShaderPackScreen(null));
    }
}
Also used : IrisConfig(net.coderbot.iris.config.IrisConfig) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ShaderPackScreen(net.coderbot.iris.gui.screen.ShaderPackScreen) NoSuchFileException(java.nio.file.NoSuchFileException) InvalidPathException(java.nio.file.InvalidPathException) ZipException(java.util.zip.ZipException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 IrisConfig (net.coderbot.iris.config.IrisConfig)3 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)1 InvalidPathException (java.nio.file.InvalidPathException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ZipException (java.util.zip.ZipException)1 ShaderPackScreen (net.coderbot.iris.gui.screen.ShaderPackScreen)1 ModContainer (net.fabricmc.loader.api.ModContainer)1 KeyMapping (net.minecraft.client.KeyMapping)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1