Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
- Fix enum options not respecting Sodium's allowed values
- Improve MoreCulling integration by adding reset cache button
- Fix mixin warning logs when some compat mods aren't loaded
  • Loading branch information
isXander committed Sep 23, 2022
1 parent 36d2e8a commit e72b7af
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 14 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = "dev.isxander"
version = "1.0.0"
version = "1.0.1"

repositories {
mavenCentral()
Expand All @@ -38,7 +38,7 @@ dependencies {
mappings("net.fabricmc:yarn:$minecraftVersion+build.+:v2")
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")

modImplementation("dev.isxander:yet-another-config-lib:1.4.0")
modImplementation("dev.isxander:yet-another-config-lib:1.5.0")
modImplementation("maven.modrinth:sodium:mc1.19.2-0.4.4")

// sodium extra compat
Expand Down
3 changes: 3 additions & 0 deletions changelogs/1.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fix enum options not respecting Sodium's allowed values
- Improve MoreCulling integration by adding reset cache button
- Fix mixin warning logs when some compat mods aren't loaded
13 changes: 8 additions & 5 deletions src/main/java/dev/isxander/xso/XandersSodiumOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.isxander.xso.compat.IrisCompat;
import dev.isxander.xso.compat.MoreCullingCompat;
import dev.isxander.xso.compat.SodiumExtraCompat;
import dev.isxander.xso.mixins.CyclingControlAccessor;
import dev.isxander.xso.mixins.SliderControlAccessor;
import dev.isxander.xso.utils.ClassCapture;
import dev.isxander.yacl.api.*;
Expand Down Expand Up @@ -41,7 +42,6 @@ public static Screen wrapSodiumScreen(SodiumOptionsGUI sodiumOptionsGUI, List<Op
}
}


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

Expand All @@ -55,6 +55,9 @@ public static Screen wrapSodiumScreen(SodiumOptionsGUI sodiumOptionsGUI, List<Op
categoryBuilder.group(groupBuilder.build());
}

if (Compat.MORE_CULLING)
MoreCullingCompat.extendMoreCullingPage(sodiumOptionsGUI, page, categoryBuilder);

builder.category(categoryBuilder.build());
}

Expand All @@ -80,7 +83,7 @@ private static <T> Option<T> convertOption(me.jellysquid.mods.sodium.client.gui.
builder.tooltip(Text.translatable("sodium.options.performance_impact_string", sodiumOption.getImpact().getLocalizedName()).formatted(Formatting.GRAY));
}

genericBuilder(builder, sodiumOption);
addController(builder, sodiumOption);

Option<T> built = builder.build();
if (Compat.MORE_CULLING) MoreCullingCompat.addAvailableCheck(built, sodiumOption);
Expand All @@ -89,20 +92,20 @@ private static <T> Option<T> convertOption(me.jellysquid.mods.sodium.client.gui.

// nasty, nasty raw types to make the compiler not commit die
@SuppressWarnings({"rawtypes", "unchecked"})
private static <T> void genericBuilder(Option.Builder yaclOption, me.jellysquid.mods.sodium.client.gui.options.Option<T> sodiumOption) {
private static <T> void addController(Option.Builder yaclOption, me.jellysquid.mods.sodium.client.gui.options.Option<T> sodiumOption) {
if (sodiumOption.getControl() instanceof TickBoxControl) {
yaclOption.controller(opt -> new TickBoxController((Option<Boolean>) opt));
return;
}

if (sodiumOption.getControl() instanceof CyclingControl) {
if (sodiumOption.getControl() instanceof CyclingControl cyclingControl) {
yaclOption.controller(opt -> new EnumController((Option) opt, value -> {
if (value instanceof TextProvider textProvider)
return textProvider.getLocalizedName();
if (value instanceof TranslatableOption translatableOption)
return translatableOption.getText();
return Text.of(((Enum<?>) value).name());
}));
}, ((CyclingControlAccessor<?>) cyclingControl).getAllowedValues()));
return;
}

Expand Down
24 changes: 23 additions & 1 deletion src/main/java/dev/isxander/xso/compat/MoreCullingCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
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.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.yacl.api.ButtonOption;
import dev.isxander.yacl.api.ConfigCategory;
import dev.isxander.yacl.gui.controllers.ActionController;
import dev.isxander.yacl.gui.controllers.slider.FloatSliderController;
import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController;
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import net.minecraft.text.Text;

public class MoreCullingCompat {
public static <S, T> SodiumBinding<S, T> getBinding(Option<T> option) {
Expand All @@ -29,7 +36,7 @@ public static <T> void addAvailableCheck(dev.isxander.yacl.api.Option<T> yaclOpt
((OptionHolder<T>) sodiumOption).holdOption(yaclOption);
}

@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({"rawtypes", "unchecked"})
public static <T> boolean convertControl(dev.isxander.yacl.api.Option.Builder yaclOption, Option<T> sodiumOption) {
if (sodiumOption.getControl() instanceof IntSliderControl sliderControl) {
IntSliderControlAccessor accessor = (IntSliderControlAccessor) sliderControl;
Expand All @@ -46,7 +53,22 @@ public static <T> boolean convertControl(dev.isxander.yacl.api.Option.Builder ya
return false;
}

public static void extendMoreCullingPage(SodiumOptionsGUI optionsGUI, OptionPage page, ConfigCategory.Builder builder) {
MoreCullingPageHolder shaderPageHolder = (MoreCullingPageHolder) optionsGUI;
if (shaderPageHolder.getMoreCullingPage() == page) {
builder.option(ButtonOption.createBuilder()
.name(Text.translatable("moreculling.config.resetCache"))
.action((screen, button) -> CacheUtils.resetAllCache())
.controller(ActionController::new)
.build());
}
}

public interface OptionHolder<T> {
void holdOption(dev.isxander.yacl.api.Option<T> option);
}

public interface MoreCullingPageHolder {
OptionPage getMoreCullingPage();
}
}
11 changes: 11 additions & 0 deletions src/main/java/dev/isxander/xso/mixins/CyclingControlAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.isxander.xso.mixins;

import me.jellysquid.mods.sodium.client.gui.options.control.CyclingControl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(CyclingControl.class)
public interface CyclingControlAccessor<T extends Enum<T>> {
@Accessor
T[] getAllowedValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;

@Pseudo
@Mixin(value = SodiumOptionsGUI.class, priority = 2000)
public class SodiumOptionsGUIMixin_iris implements IrisCompat.ShaderPageHolder {
public class SodiumOptionsGUIMixin implements IrisCompat.ShaderPageHolder {
private OptionPage shaderPacks;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import ca.fxco.moreculling.config.sodium.FloatSliderControl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.gen.Accessor;

@Pseudo
@Mixin(FloatSliderControl.class)
public interface FloatSliderControlAccessor {
@Accessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import ca.fxco.moreculling.config.sodium.IntSliderControl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.gen.Accessor;

@Pseudo
@Mixin(IntSliderControl.class)
public interface IntSliderControlAccessor {
@Accessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import ca.fxco.moreculling.config.sodium.MoreCullingOptionImpl;
import me.jellysquid.mods.sodium.client.gui.options.binding.OptionBinding;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.gen.Accessor;

@Pseudo
@Mixin(MoreCullingOptionImpl.class)
public interface MoreCullingOptionImplAccessor<S, T> {
@Accessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.isxander.xso.utils.ClassCapture;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

@Pseudo
@Mixin(MoreCullingOptionImpl.Builder.class)
public class MoreCullingOptionImplBuilderMixin<S, T> implements ClassCapture<T> {
@Unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import dev.isxander.yacl.api.Option;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(value = MoreCullingOptionImpl.class, remap = false)
public abstract class MoreCullingOptionImplMixin<S, T> implements ClassCapture<T>, MoreCullingCompat.OptionHolder<T> {
@Unique
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.isxander.xso.mixins.compat.moreculling;

import dev.isxander.xso.compat.MoreCullingCompat;
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;

@Pseudo
@Mixin(value = SodiumOptionsGUI.class, priority = 2000)
public class SodiumOptionsGUIMixin implements MoreCullingCompat.MoreCullingPageHolder {
private OptionPage moreCullingPage;

@Override
public OptionPage getMoreCullingPage() {
return moreCullingPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import me.flashyreese.mods.sodiumextra.client.gui.options.control.SliderControlExtended;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlValueFormatter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.gen.Accessor;

@Pseudo
@Mixin(SliderControlExtended.class)
public interface SliderControlExtAccessor {
@Accessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;

@Pseudo
@Mixin(SodiumExtraGameOptions.class)
public class SodiumExtraGameOptionsMixins {
@ModifyReturnValue(method = "hasSuggestedRSO", at = @At("RETURN"))
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"minecraft": "1.19.x",
"java": ">=17",
"sodium": "<0.5.0",
"yet-another-config-lib": ">=1.2.0"
"yet-another-config-lib": ">=1.5.0"
},
"breaks": {
"reeses-sodium-options": "*"
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/xanders-sodium-options.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_17",
"client": [
"SodiumOptionsGUIAccessor",
"SodiumOptionsGUIMixin",
"OptionImplAccessor",
"OptionImplBuilderMixin",
"OptionImplMixin",
"SliderControlAccessor",
"SodiumOptionsGUIAccessor",
"SodiumOptionsGUIMixin",
"CyclingControlAccessor",
"compat.iris.SodiumOptionsGUIMixin",
"compat.moreculling.FloatSliderControlAccessor",
"compat.moreculling.IntSliderControlAccessor",
"compat.moreculling.MoreCullingOptionImplAccessor",
"compat.moreculling.MoreCullingOptionImplBuilderMixin",
"compat.moreculling.MoreCullingOptionImplMixin",
"compat.moreculling.SodiumOptionsGUIMixin",
"compat.sodiumextra.SliderControlExtAccessor",
"compat.sodiumextra.SodiumExtraGameOptionsMixins",
"compat.iris.SodiumOptionsGUIMixin_iris"
"compat.sodiumextra.SodiumExtraGameOptionsMixins"
]
}

0 comments on commit e72b7af

Please sign in to comment.