Skip to content

Commit

Permalink
Refactor and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretOnline committed Jun 15, 2024
1 parent 9d4ad79 commit 485550f
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand All @@ -44,11 +44,11 @@ public void onEndTick(MinecraftClient client) {
return;
}

SimpleOption<AccessibleStepOptionMode> 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 {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import net.minecraft.client.MinecraftClient;

public class AccessibleStepModMenu implements ModMenuApi {
public class ModMenuFactory implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StepMode> stepModeOption = new SimpleOption<StepMode>(
"options.accessiblestep.option",
AccessibleStepOptions::getStepModeTooltip,
SimpleOption.enumValueText(),
new SimpleOption.PotentialValuesBasedCallbacks<StepMode>(
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<StepMode> getStepModeOption() {
return stepModeOption;
}
}
Original file line number Diff line number Diff line change
@@ -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<StepMode> 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);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"co.secretonline.accessiblestep.AccessibleStepClient"
],
"modmenu": [
"co.secretonline.accessiblestep.modmenu.AccessibleStepModMenu"
"co.secretonline.accessiblestep.modmenu.ModMenuFactory"
]
},
"mixins": [
Expand Down

0 comments on commit 485550f

Please sign in to comment.