diff --git a/src/client/java/co/secretonline/accessiblestep/AccessibleStepEndTick.java b/src/client/java/co/secretonline/accessiblestep/AccessibleStepEndTick.java index f853985..215506d 100644 --- a/src/client/java/co/secretonline/accessiblestep/AccessibleStepEndTick.java +++ b/src/client/java/co/secretonline/accessiblestep/AccessibleStepEndTick.java @@ -1,9 +1,9 @@ package co.secretonline.accessiblestep; -import co.secretonline.accessiblestep.AccessibleStepOptions.AccessibleStepOptionMode; +import co.secretonline.accessiblestep.options.AccessibleStepOptions; +import co.secretonline.accessiblestep.options.StepMode; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents.EndTick; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.SimpleOption; import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeInstance; import net.minecraft.entity.attribute.EntityAttributeModifier; @@ -30,7 +30,7 @@ public class AccessibleStepEndTick implements EndTick { * Modifier to add an amount to the step height. * * This mod uses modifiers to avoid conflicts where the server might update the - * base value to be different from the normal value. This mod will stull affect + * base value to be different from the normal value. This mod will still affect * the step height, but hopefully not as much. */ private static final EntityAttributeModifier STEP_HEIGHT_MODIFIER = new EntityAttributeModifier( @@ -44,11 +44,11 @@ public void onEndTick(MinecraftClient client) { return; } - SimpleOption accessibleStepOption = AccessibleStepOptions.getStepOption(); + StepMode stepMode = AccessibleStepOptions.getStepModeOption().getValue(); EntityAttributeInstance stepHeightAttribute = client.player.getAttributeInstance(STEP_HEIGHT_ATTRIBUTE); - if (accessibleStepOption.getValue().equals(AccessibleStepOptionMode.STEP)) { + if (stepMode.equals(StepMode.STEP)) { if (client.player.isSneaking()) { removeModifier(stepHeightAttribute); } else { diff --git a/src/client/java/co/secretonline/accessiblestep/AccessibleStepOptions.java b/src/client/java/co/secretonline/accessiblestep/AccessibleStepOptions.java deleted file mode 100644 index 0d4a5ef..0000000 --- a/src/client/java/co/secretonline/accessiblestep/AccessibleStepOptions.java +++ /dev/null @@ -1,81 +0,0 @@ -package co.secretonline.accessiblestep; - -import java.util.Arrays; - -import com.mojang.serialization.Codec; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.option.SimpleOption; -import net.minecraft.text.Text; -import net.minecraft.util.StringIdentifiable; -import net.minecraft.util.TranslatableOption; - -public class AccessibleStepOptions { - private static final Text OFF_TOOLTIP = Text.translatable("options.accessiblestep.off.tooltip"); - private static final Text STEP_TOOLTIP = Text.translatable("options.accessiblestep.step.tooltip"); - private static final Text AUTO_JUMP_TOOLTIP = Text.translatable("options.accessiblestep.autojump.tooltip"); - - private static final SimpleOption stepOption = new SimpleOption( - "options.accessiblestep.option", - (value) -> switch (value) { - case AccessibleStepOptionMode.OFF -> Tooltip.of(OFF_TOOLTIP); - case AccessibleStepOptionMode.STEP -> Tooltip.of(STEP_TOOLTIP); - case AccessibleStepOptionMode.AUTO_JUMP -> Tooltip.of(AUTO_JUMP_TOOLTIP); - default -> throw new MatchException(null, null); - }, - SimpleOption.enumValueText(), - new SimpleOption.PotentialValuesBasedCallbacks( - Arrays.asList(AccessibleStepOptionMode.values()), - AccessibleStepOptionMode.CODEC), - AccessibleStepOptionMode.OFF, - AccessibleStepOptions::onStepOptionChange); - - private static void onStepOptionChange(AccessibleStepOptionMode value) { - MinecraftClient client = MinecraftClient.getInstance(); - - // Also update auto-jump option behind the scenes - if (value == AccessibleStepOptionMode.AUTO_JUMP) { - client.options.getAutoJump().setValue(true); - } else { - client.options.getAutoJump().setValue(false); - } - } - - public static SimpleOption getStepOption() { - return stepOption; - } - - public enum AccessibleStepOptionMode implements TranslatableOption, StringIdentifiable { - OFF(0, "false", "options.off"), - STEP(1, "step", "options.accessiblestep.step"), - AUTO_JUMP(2, "autojump", "options.autoJump"); - - public static final Codec CODEC; - private final int id; - private final String serializedId; - private final String translationKey; - - private AccessibleStepOptionMode(int id, String serializedId, String translationKey) { - this.id = id; - this.serializedId = serializedId; - this.translationKey = translationKey; - } - - public String asString() { - return this.serializedId; - } - - public int getId() { - return this.id; - } - - public String getTranslationKey() { - return this.translationKey; - } - - static { - CODEC = StringIdentifiable.createCodec(AccessibleStepOptionMode::values); - } - } -} diff --git a/src/client/java/co/secretonline/accessiblestep/mixin/client/AccessibilityOptionsScreenMixin.java b/src/client/java/co/secretonline/accessiblestep/mixin/client/AccessibilityOptionsScreenMixin.java index 48b0943..1d522ed 100644 --- a/src/client/java/co/secretonline/accessiblestep/mixin/client/AccessibilityOptionsScreenMixin.java +++ b/src/client/java/co/secretonline/accessiblestep/mixin/client/AccessibilityOptionsScreenMixin.java @@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import co.secretonline.accessiblestep.AccessibleStepOptions; +import co.secretonline.accessiblestep.options.AccessibleStepOptions; import net.minecraft.client.gui.screen.option.AccessibilityOptionsScreen; import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.SimpleOption; @@ -13,6 +13,6 @@ public class AccessibilityOptionsScreenMixin { @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;getAutoJump()Lnet/minecraft/client/option/SimpleOption;"), method = "getOptions") private static SimpleOption replaceAutoJump(GameOptions gameOptions) { - return AccessibleStepOptions.getStepOption(); + return AccessibleStepOptions.getStepModeOption(); } } diff --git a/src/client/java/co/secretonline/accessiblestep/mixin/client/ControlsOptionsScreenMixin.java b/src/client/java/co/secretonline/accessiblestep/mixin/client/ControlsOptionsScreenMixin.java index ca23c68..48f0803 100644 --- a/src/client/java/co/secretonline/accessiblestep/mixin/client/ControlsOptionsScreenMixin.java +++ b/src/client/java/co/secretonline/accessiblestep/mixin/client/ControlsOptionsScreenMixin.java @@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import co.secretonline.accessiblestep.AccessibleStepOptions; +import co.secretonline.accessiblestep.options.AccessibleStepOptions; import net.minecraft.client.gui.screen.option.ControlsOptionsScreen; import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.SimpleOption; @@ -13,6 +13,6 @@ public class ControlsOptionsScreenMixin { @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;getAutoJump()Lnet/minecraft/client/option/SimpleOption;"), method = "getOptions") private static SimpleOption replaceAutoJump(GameOptions gameOptions) { - return AccessibleStepOptions.getStepOption(); + return AccessibleStepOptions.getStepModeOption(); } } diff --git a/src/client/java/co/secretonline/accessiblestep/mixin/client/GameOptionsMixin.java b/src/client/java/co/secretonline/accessiblestep/mixin/client/GameOptionsMixin.java index 25cd3a8..03c651f 100644 --- a/src/client/java/co/secretonline/accessiblestep/mixin/client/GameOptionsMixin.java +++ b/src/client/java/co/secretonline/accessiblestep/mixin/client/GameOptionsMixin.java @@ -5,15 +5,13 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import co.secretonline.accessiblestep.AccessibleStepOptions; +import co.secretonline.accessiblestep.options.AccessibleStepOptions; import net.minecraft.client.option.GameOptions; @Mixin(GameOptions.class) public class GameOptionsMixin { - private static final String OPTIONS_KEY = "accessibleStep"; - @Inject(at = @At("HEAD"), method = "accept(Lnet/minecraft/client/option/GameOptions$Visitor;)V") private void injectStepOption(GameOptions.Visitor visitor, CallbackInfo info) { - visitor.accept(OPTIONS_KEY, AccessibleStepOptions.getStepOption()); + visitor.accept(AccessibleStepOptions.STEP_MODE_OPTIONS_KEY, AccessibleStepOptions.getStepModeOption()); } } diff --git a/src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepOptionsScreen.java b/src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepOptionsScreen.java index a7d5e3f..8ee3f2f 100644 --- a/src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepOptionsScreen.java +++ b/src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepOptionsScreen.java @@ -1,6 +1,6 @@ package co.secretonline.accessiblestep.modmenu; -import co.secretonline.accessiblestep.AccessibleStepOptions; +import co.secretonline.accessiblestep.options.AccessibleStepOptions; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.GameOptionsScreen; import net.minecraft.client.option.GameOptions; @@ -9,7 +9,7 @@ public class AccessibleStepOptionsScreen extends GameOptionsScreen { private static SimpleOption[] getOptions(GameOptions gameOptions) { - return new SimpleOption[] { AccessibleStepOptions.getStepOption() }; + return new SimpleOption[] { AccessibleStepOptions.getStepModeOption() }; } public AccessibleStepOptionsScreen(Screen parent, GameOptions gameOptions) { @@ -21,6 +21,6 @@ public AccessibleStepOptionsScreen(Screen parent, GameOptions gameOptions) { @Override protected void addOptions() { - this.body.addAll(AccessibleStepOptionsScreen.getOptions(this.gameOptions)); + this.body.addAll(getOptions(this.gameOptions)); } } diff --git a/src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepModMenu.java b/src/client/java/co/secretonline/accessiblestep/modmenu/ModMenuFactory.java similarity index 88% rename from src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepModMenu.java rename to src/client/java/co/secretonline/accessiblestep/modmenu/ModMenuFactory.java index c7d5be4..eb664ce 100644 --- a/src/client/java/co/secretonline/accessiblestep/modmenu/AccessibleStepModMenu.java +++ b/src/client/java/co/secretonline/accessiblestep/modmenu/ModMenuFactory.java @@ -5,7 +5,7 @@ import net.minecraft.client.MinecraftClient; -public class AccessibleStepModMenu implements ModMenuApi { +public class ModMenuFactory implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { diff --git a/src/client/java/co/secretonline/accessiblestep/options/AccessibleStepOptions.java b/src/client/java/co/secretonline/accessiblestep/options/AccessibleStepOptions.java new file mode 100644 index 0000000..69358bb --- /dev/null +++ b/src/client/java/co/secretonline/accessiblestep/options/AccessibleStepOptions.java @@ -0,0 +1,50 @@ +package co.secretonline.accessiblestep.options; + +import java.util.Arrays; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.option.SimpleOption; +import net.minecraft.text.Text; + +public class AccessibleStepOptions { + public static final String STEP_MODE_OPTIONS_KEY = "accessibleStep"; + + private static final Text STEP_MODE_OFF_TOOLTIP = Text.translatable("options.accessiblestep.off.tooltip"); + private static final Text STEP_MODE_STEP_TOOLTIP = Text.translatable("options.accessiblestep.step.tooltip"); + private static final Text STEP_MODE_AUTO_JUMP_TOOLTIP = Text.translatable("options.accessiblestep.autojump.tooltip"); + + private static final SimpleOption stepModeOption = new SimpleOption( + "options.accessiblestep.option", + AccessibleStepOptions::getStepModeTooltip, + SimpleOption.enumValueText(), + new SimpleOption.PotentialValuesBasedCallbacks( + Arrays.asList(StepMode.values()), + StepMode.CODEC), + StepMode.OFF, + AccessibleStepOptions::onStepModeChange); + + private static Tooltip getStepModeTooltip(StepMode value) { + return switch (value) { + case StepMode.OFF -> Tooltip.of(STEP_MODE_OFF_TOOLTIP); + case StepMode.STEP -> Tooltip.of(STEP_MODE_STEP_TOOLTIP); + case StepMode.AUTO_JUMP -> Tooltip.of(STEP_MODE_AUTO_JUMP_TOOLTIP); + default -> throw new MatchException(null, null); + }; + } + + private static void onStepModeChange(StepMode value) { + MinecraftClient client = MinecraftClient.getInstance(); + + // Also update auto-jump option behind the scenes + if (value == StepMode.AUTO_JUMP) { + client.options.getAutoJump().setValue(true); + } else { + client.options.getAutoJump().setValue(false); + } + } + + public static SimpleOption getStepModeOption() { + return stepModeOption; + } +} diff --git a/src/client/java/co/secretonline/accessiblestep/options/StepMode.java b/src/client/java/co/secretonline/accessiblestep/options/StepMode.java new file mode 100644 index 0000000..a8ee347 --- /dev/null +++ b/src/client/java/co/secretonline/accessiblestep/options/StepMode.java @@ -0,0 +1,39 @@ +package co.secretonline.accessiblestep.options; + +import com.mojang.serialization.Codec; + +import net.minecraft.util.StringIdentifiable; +import net.minecraft.util.TranslatableOption; + +public enum StepMode implements TranslatableOption, StringIdentifiable { + OFF(0, "false", "options.off"), + STEP(1, "step", "options.accessiblestep.step"), + AUTO_JUMP(2, "autojump", "options.autoJump"); + + public static final Codec CODEC; + private final int id; + private final String serializedId; + private final String translationKey; + + private StepMode(int id, String serializedId, String translationKey) { + this.id = id; + this.serializedId = serializedId; + this.translationKey = translationKey; + } + + public String asString() { + return this.serializedId; + } + + public int getId() { + return this.id; + } + + public String getTranslationKey() { + return this.translationKey; + } + + static { + CODEC = StringIdentifiable.createCodec(StepMode::values); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6b54541..1bc2612 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,7 +18,7 @@ "co.secretonline.accessiblestep.AccessibleStepClient" ], "modmenu": [ - "co.secretonline.accessiblestep.modmenu.AccessibleStepModMenu" + "co.secretonline.accessiblestep.modmenu.ModMenuFactory" ] }, "mixins": [