Skip to content

Commit

Permalink
1.1.0 (read changelog for deets)
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed Dec 28, 2022
1 parent b62ddba commit bb6d541
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 133 deletions.
27 changes: 14 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ plugins {
java

id("fabric-loom") version "1.0.+"
id("io.github.juuxel.loom-quiltflower") version "1.7.+"
id("io.github.juuxel.loom-quiltflower") version "1.8.+"

id("com.modrinth.minotaur") version "2.4.+"
id("com.modrinth.minotaur") version "2.5.+"
id("me.hypherionmc.cursegradle") version "2.+"
id("com.github.breadmoirai.github-release") version "2.+"
id("io.github.p03w.machete") version "1.+"
`maven-publish`
}

group = "dev.isxander"
version = "1.0.2"
version = "1.1.0"

repositories {
mavenCentral()
Expand All @@ -23,6 +23,7 @@ repositories {
maven("https://maven.shedaniel.me")
maven("https://maven.terraformersmc.com")
maven("https://jitpack.io")
maven("https://maven.gegy.dev")
maven("https://api.modrinth.com/maven") {
content {
includeGroup("maven.modrinth")
Expand All @@ -38,23 +39,23 @@ dependencies {
mappings("net.fabricmc:yarn:$minecraftVersion+build.+:v2")
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")

modImplementation("dev.isxander:yet-another-config-lib:1.5.0")
modImplementation("maven.modrinth:sodium:mc1.19.2-0.4.4")
modImplementation("dev.isxander:yet-another-config-lib:2.2.0")
modImplementation("maven.modrinth:sodium:mc1.19.3-0.4.6")
modImplementation("com.terraformersmc:modmenu:5.0.2")

// sodium extra better options compat
modImplementation("me.flashyreese.mods:sodium-extra-fabric:0.4.10+mc1.19.2-build.64") {
exclude(module = "reeses-sodium-options")
}
modImplementation("maven.modrinth:sodium-extra:mc1.19.3-0.4.15")
// moreculling category placement
modImplementation("maven.modrinth:moreculling:v0.10.0")
modImplementation("maven.modrinth:moreculling:v0.12.3")
// iris category placement
modImplementation("maven.modrinth:iris:1.19.x-v1.3.1")
modImplementation("maven.modrinth:iris:1.19.3-v1.4.6")
// entityviewdistance button option compat
modImplementation("maven.modrinth:entity-view-distance:1.0.2+1.19")
modImplementation("maven.modrinth:entity-view-distance:1.1.0+1.19.3")

modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:8.2.88")
modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:9.0.+")
modRuntimeOnly("dev.lambdaurora:spruceui:4.1.0+1.19.3")

modImplementation(include("com.github.llamalad7:mixinextras:0.0.12")!!)
implementation(include(annotationProcessor("com.github.llamalad7:mixinextras:0.1.1")!!)!!)
}

tasks {
Expand Down
7 changes: 7 additions & 0 deletions changelogs/1.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Update to 1.19.3
- Add options category to sodium options & new modmenu config.
- New option: Lenient options: (previously default behaviour) replaces broken options with placeholder option
- New option: Hard crash: (previously default on) Crashes the game to generate crash report instead of a nice warning and the ability to just display actual Sodium
- Add warning screen to proceed to default sodium gui upon failure
- Fix moreculling 0.12+ compatibility
- Handle errors a lot nicer in stacktrace
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx3G

minecraftVersion=1.19.2
fabricLoaderVersion=0.14.9
minecraftVersion=1.19.3
fabricLoaderVersion=0.14.12

modId=xanders-sodium-options
modName=Xander's Sodium Options
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/isxander/xso/ModEntrypoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.isxander.xso;

import dev.isxander.xso.config.XsoConfig;
import net.fabricmc.api.ClientModInitializer;

public class ModEntrypoint implements ClientModInitializer {
@Override
public void onInitializeClient() {
XsoConfig.INSTANCE.load();
}
}
140 changes: 91 additions & 49 deletions src/main/java/dev/isxander/xso/XandersSodiumOptions.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.isxander.xso;

import dev.isxander.xso.compat.*;
import dev.isxander.xso.config.XsoConfig;
import dev.isxander.xso.mixins.CyclingControlAccessor;
import dev.isxander.xso.mixins.SliderControlAccessor;
import dev.isxander.xso.utils.ClassCapture;
import dev.isxander.yacl.api.*;
import dev.isxander.yacl.gui.controllers.ActionController;
import dev.isxander.yacl.gui.controllers.EnumController;
import dev.isxander.yacl.gui.controllers.TickBoxController;
import dev.isxander.yacl.gui.controllers.cycling.EnumController;
import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController;
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
Expand All @@ -16,37 +17,72 @@
import me.jellysquid.mods.sodium.client.gui.options.control.SliderControl;
import me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.NoticeScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.TranslatableOption;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

public class XandersSodiumOptions {
private static boolean errorOccured = false;

public static Screen wrapSodiumScreen(SodiumOptionsGUI sodiumOptionsGUI, List<OptionPage> pages, Screen prevScreen) {
YetAnotherConfigLib.Builder builder = YetAnotherConfigLib.createBuilder()
.title(Text.translatable("Sodium Options"));
try {
YetAnotherConfigLib.Builder builder = YetAnotherConfigLib.createBuilder()
.title(Text.translatable("Sodium Options"));

for (OptionPage page : pages) {
builder.category(convertCategory(page, sodiumOptionsGUI));
}

builder.category(XsoConfig.getConfigCategory());

builder.save(() -> {
Set<OptionStorage<?>> storages = new HashSet<>();
pages.stream().flatMap(s -> s.getOptions().stream()).forEach(opt -> storages.add(opt.getStorage()));
storages.forEach(OptionStorage::save);

XsoConfig.INSTANCE.save();
});

return builder.build().generateScreen(prevScreen);
} catch (Exception e) {
var exception = new IllegalStateException("Failed to convert Sodium option screen to YACL with XSO!", e);

for (OptionPage page : pages) {
if (XsoConfig.INSTANCE.getConfig().hardCrash) {
throw exception;
} else {
exception.printStackTrace();

return new NoticeScreen(() -> {
errorOccured = true;
MinecraftClient.getInstance().setScreen(sodiumOptionsGUI);
errorOccured = false;
}, Text.literal("Xander's Sodium Options failed"), Text.literal("Whilst trying to convert Sodium's GUI to YACL with XSO mod, an error occured which prevented the conversion. This is most likely due to a third-party mod adding its own settings to Sodium's screen. XSO will now display the original GUI.\n\nThe error has been logged to latest.log file."), ScreenTexts.PROCEED, true);
}
}
}

private static ConfigCategory convertCategory(OptionPage page, SodiumOptionsGUI sodiumOptionsGUI) {
try {
if (Compat.IRIS) {
ConfigCategory shaderPackPage = IrisCompat.replaceShaderPackPage(sodiumOptionsGUI, page);
if (shaderPackPage != null) {
builder.category(shaderPackPage);
continue;
Optional<ConfigCategory> shaderPackPage = IrisCompat.replaceShaderPackPage(sodiumOptionsGUI, page);
if (shaderPackPage.isPresent()) {
return shaderPackPage.get();
}
}

ConfigCategory.Builder categoryBuilder = ConfigCategory.createBuilder()
.name(page.getName());

for (me.jellysquid.mods.sodium.client.gui.options.OptionGroup group : page.getGroups()) {
for (var group : page.getGroups()) {
OptionGroup.Builder groupBuilder = OptionGroup.createBuilder();

for (me.jellysquid.mods.sodium.client.gui.options.Option<?> option : group.getOptions()) {
for (var option : group.getOptions()) {
groupBuilder.option(convertOption(option));
}

Expand All @@ -56,50 +92,52 @@ public static Screen wrapSodiumScreen(SodiumOptionsGUI sodiumOptionsGUI, List<Op
if (Compat.MORE_CULLING)
MoreCullingCompat.extendMoreCullingPage(sodiumOptionsGUI, page, categoryBuilder);

builder.category(categoryBuilder.build());
return categoryBuilder.build();
} catch (Exception e) {
throw new IllegalStateException("Failed to convert Sodium option page named '" + page.getName().getString() + "' to YACL config category.", e);
}

builder.save(() -> {
Set<OptionStorage<?>> storages = new HashSet<>();
pages.stream().flatMap(s -> s.getOptions().stream()).forEach(opt -> storages.add(opt.getStorage()));
storages.forEach(OptionStorage::save);
});

return builder.build().generateScreen(prevScreen);
}

private static <T> Option<?> convertOption(me.jellysquid.mods.sodium.client.gui.options.Option<T> sodiumOption) {
if (Compat.ENTITY_VIEW_DIST && EntityViewDistanceCompat.isFakeOption(sodiumOption)) {
return EntityViewDistanceCompat.convertFakeOption(sodiumOption);
}
try {
if (Compat.ENTITY_VIEW_DIST) {
Optional<Option<?>> fakeOption = EntityViewDistanceCompat.convertFakeOption(sodiumOption);
if (fakeOption.isPresent()) return fakeOption.get();
}

if (!(sodiumOption instanceof ClassCapture<?>)) {
// incompatible - some custom option impl
return ButtonOption.createBuilder()
if (!(sodiumOption instanceof ClassCapture<?>)) {
throw new IllegalStateException("Failed to capture class of sodium option! Likely due to custom Option implementation.");
}

Option.Builder<T> builder = Option.createBuilder(((ClassCapture<T>) sodiumOption).getCapturedClass())
.name(sodiumOption.getName())
.tooltip(sodiumOption.getTooltip(), Text.translatable("xso.incompatible.tooltip").formatted(Formatting.RED))
.available(false)
.controller(opt -> new ActionController(opt, Text.translatable("xso.incompatible.button").formatted(Formatting.RED)))
.action((screen, opt) -> {})
.build();
}
.tooltip(sodiumOption.getTooltip())
.flags(convertFlags(sodiumOption))
.binding(Compat.MORE_CULLING ? MoreCullingCompat.getBinding(sodiumOption) : new SodiumBinding<>(sodiumOption))
.available(sodiumOption.isAvailable());

Option.Builder<T> builder = Option.createBuilder(((ClassCapture<T>) sodiumOption).getCapturedClass())
.name(sodiumOption.getName())
.tooltip(sodiumOption.getTooltip())
.flags(convertFlags(sodiumOption))
.binding(Compat.MORE_CULLING ? MoreCullingCompat.getBinding(sodiumOption) : new SodiumBinding<>(sodiumOption))
.available(sodiumOption.isAvailable());
if (sodiumOption.getImpact() != null) {
builder.tooltip(Text.translatable("sodium.options.performance_impact_string", sodiumOption.getImpact().getLocalizedName()).formatted(Formatting.GRAY));
}

if (sodiumOption.getImpact() != null) {
builder.tooltip(Text.translatable("sodium.options.performance_impact_string", sodiumOption.getImpact().getLocalizedName()).formatted(Formatting.GRAY));
addController(builder, sodiumOption);

Option<T> built = builder.build();
if (Compat.MORE_CULLING) MoreCullingCompat.addAvailableCheck(built, sodiumOption);
return built;
} catch (Exception e) {
if (XsoConfig.INSTANCE.getConfig().lenientOptions) {
return ButtonOption.createBuilder()
.name(sodiumOption.getName())
.tooltip(sodiumOption.getTooltip(), Text.translatable("xso.incompatible.tooltip").formatted(Formatting.RED))
.available(false)
.controller(opt -> new ActionController(opt, Text.translatable("xso.incompatible.button").formatted(Formatting.RED)))
.action((screen, opt) -> {})
.build();
} else {
throw new IllegalStateException("Failed to convert Sodium option named '" + sodiumOption.getName().getString() + "' to a YACL option!", e);
}
}

addController(builder, sodiumOption);

Option<T> built = builder.build();
if (Compat.MORE_CULLING) MoreCullingCompat.addAvailableCheck(built, sodiumOption);
return built;
}

// nasty, nasty raw types to make the compiler not commit die
Expand Down Expand Up @@ -156,4 +194,8 @@ private static List<OptionFlag> convertFlags(me.jellysquid.mods.sodium.client.gu

return flags;
}

public static boolean shouldConvertGui() {
return XsoConfig.INSTANCE.getConfig().enabled && !errorOccured;
}
}
23 changes: 12 additions & 11 deletions src/main/java/dev/isxander/xso/compat/EntityViewDistanceCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
import eu.pb4.entityviewdistance.modcompat.SodiumCompat;
import me.jellysquid.mods.sodium.client.gui.options.Option;

import java.util.Optional;

public class EntityViewDistanceCompat {
public static boolean isFakeOption(Option<?> sodiumOption) {
return sodiumOption instanceof SodiumCompat.FakeOptionImpl;
}
public static Optional<dev.isxander.yacl.api.Option<?>> convertFakeOption(Option<?> sodiumOption) {
if (sodiumOption instanceof SodiumCompat.FakeOptionImpl fakeOption) {
return Optional.of(ButtonOption.createBuilder()
.name(sodiumOption.getName())
.tooltip(sodiumOption.getTooltip())
.controller(ActionController::new)
.action(((yaclScreen, buttonOption) -> fakeOption.setValue(SodiumCompat.Void.VOID)))
.build());
}

public static ButtonOption convertFakeOption(Option<?> sodiumOption) {
SodiumCompat.FakeOptionImpl fakeOption = (SodiumCompat.FakeOptionImpl) sodiumOption;
return ButtonOption.createBuilder()
.name(sodiumOption.getName())
.tooltip(sodiumOption.getTooltip())
.controller(ActionController::new)
.action(((yaclScreen, buttonOption) -> fakeOption.setValue(SodiumCompat.Void.VOID)))
.build();
return Optional.empty();
}
}
10 changes: 6 additions & 4 deletions src/main/java/dev/isxander/xso/compat/IrisCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
import net.coderbot.iris.gui.screen.ShaderPackScreen;

import java.util.Optional;

public class IrisCompat {
public static ConfigCategory replaceShaderPackPage(SodiumOptionsGUI optionsGUI, OptionPage page) {
public static Optional<ConfigCategory> replaceShaderPackPage(SodiumOptionsGUI optionsGUI, OptionPage page) {
ShaderPageHolder shaderPageHolder = (ShaderPageHolder) optionsGUI;
if (shaderPageHolder.getShaderPage() == page) {
return PlaceholderCategory.createBuilder()
return Optional.of(PlaceholderCategory.createBuilder()
.name(page.getName())
.screen((client, parent) -> new ShaderPackScreen(parent))
.build();
.build());
}

return null;
return Optional.empty();
}

public interface ShaderPageHolder {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/isxander/xso/compat/MoreCullingCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import ca.fxco.moreculling.config.sodium.FloatSliderControl;
import ca.fxco.moreculling.config.sodium.IntSliderControl;
import ca.fxco.moreculling.config.sodium.MoreCullingOptionImpl;
import ca.fxco.moreculling.config.sodium.MoreCullingSodiumOptionImpl;
import ca.fxco.moreculling.utils.CacheUtils;
import dev.isxander.xso.SodiumBinding;
import dev.isxander.xso.mixins.compat.moreculling.FloatSliderControlAccessor;
import dev.isxander.xso.mixins.compat.moreculling.IntSliderControlAccessor;
import dev.isxander.xso.mixins.compat.moreculling.MoreCullingOptionImplAccessor;
import dev.isxander.xso.mixins.compat.moreculling.MoreCullingSodiumOptionImplAccessor;
import dev.isxander.yacl.api.ButtonOption;
import dev.isxander.yacl.api.ConfigCategory;
import dev.isxander.yacl.gui.controllers.ActionController;
Expand All @@ -21,16 +21,16 @@

public class MoreCullingCompat {
public static <S, T> SodiumBinding<S, T> getBinding(Option<T> option) {
if (option instanceof MoreCullingOptionImpl<?, ?> moreCullingOption) {
return new SodiumBinding<>(((MoreCullingOptionImplAccessor<S, T>) moreCullingOption).getBinding(), (OptionStorage<S>) moreCullingOption.getStorage());
if (option instanceof MoreCullingSodiumOptionImpl<?, ?> moreCullingOption) {
return new SodiumBinding<>(((MoreCullingSodiumOptionImplAccessor<S, T>) moreCullingOption).getBinding(), (OptionStorage<S>) moreCullingOption.getStorage());
} else {
return new SodiumBinding<>(option);
}
}

@SuppressWarnings({"unchecked"})
public static <T> void addAvailableCheck(dev.isxander.yacl.api.Option<T> yaclOption, Option<T> sodiumOption) {
if (!(sodiumOption instanceof MoreCullingOptionImpl<?, ?>))
if (!(sodiumOption instanceof MoreCullingSodiumOptionImpl<?,?>))
return;

((OptionHolder<T>) sodiumOption).holdOption(yaclOption);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/dev/isxander/xso/config/ModMenuEntrypoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.isxander.xso.config;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import dev.isxander.yacl.api.YetAnotherConfigLib;
import net.minecraft.text.Text;

public class ModMenuEntrypoint implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> YetAnotherConfigLib.createBuilder()
.title(Text.translatable("xso.title"))
.category(XsoConfig.getConfigCategory())
.save(XsoConfig.INSTANCE::save)
.build().generateScreen(parent);
}
}
Loading

0 comments on commit bb6d541

Please sign in to comment.