Skip to content

Commit

Permalink
Backport for 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretOnline committed Jan 3, 2025
1 parent eea161b commit ffed582
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onEndTick(MinecraftClient client) {
}

private void setStepHeight(ClientPlayerEntity player, double height) {
EntityAttributeInstance stepHeightAttribute = player.getAttributeInstance(EntityAttributes.STEP_HEIGHT);
EntityAttributeInstance stepHeightAttribute = player.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT);
stepHeightAttribute.setBaseValue(height);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.minecraft.entity.attribute.EntityAttributes;

public class Constants {
public static final double VANILLA_STEP_HEIGHT = EntityAttributes.STEP_HEIGHT.value().getDefaultValue();
public static final double VANILLA_STEP_HEIGHT = EntityAttributes.GENERIC_STEP_HEIGHT.value().getDefaultValue();
public static final double MOD_DEFAULT_STEP_HEIGHT = 1.25;
public static final double MOD_DEFAULT_SNEAK_HEIGHT = VANILLA_STEP_HEIGHT;
public static final double MOD_DEFAULT_SPRINT_HEIGHT = MOD_DEFAULT_STEP_HEIGHT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import co.secretonline.accessiblestep.options.AccessibleStepConfig;
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.gui.screen.option.SimpleOptionsScreen;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.gui.widget.PressableWidget;
import net.minecraft.client.gui.widget.SliderWidget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.text.Text;

public class AccessibleStepOptionsScreen extends GameOptionsScreen {
public class AccessibleStepOptionsScreen extends SimpleOptionsScreen {
private static SimpleOption<?>[] getOptions() {
return new SimpleOption[] {
AccessibleStepOptions.getPerWorldOption(),
Expand All @@ -29,12 +29,13 @@ public AccessibleStepOptionsScreen(Screen parent, GameOptions gameOptions) {
super(
parent,
gameOptions,
Text.translatable("options.accessiblestep.title"));
Text.translatable("options.accessiblestep.title"),
getOptions());
}

@Override
protected void addOptions() {
this.body.addAll(getOptions());
protected void init() {
super.init();

// The values in the options may not be correct as the player might have
// switched worlds before opening the screen. As such we need to reset the
Expand All @@ -46,7 +47,7 @@ public void resetOptionsForWorld() {
// Update per world option
AccessibleStepOptions.getPerWorldOption().setValue(State.config.hasConfigForWorld());
// Also need to disable the button if no world is selected
var widget = this.body.getWidgetFor(AccessibleStepOptions.getPerWorldOption());
var widget = this.buttonList.getWidgetFor(AccessibleStepOptions.getPerWorldOption());
if (widget != null && widget instanceof PressableWidget) {

if (State.worldName == null) {
Expand Down Expand Up @@ -89,7 +90,7 @@ private void resetWidgets() {
}

private <T> void resetCyclingButtonWidget(SimpleOption<T> option) {
var widget = this.body.getWidgetFor(option);
var widget = this.buttonList.getWidgetFor(option);
if (widget != null && widget instanceof CyclingButtonWidget<?>) {
@SuppressWarnings("unchecked")
CyclingButtonWidget<T> button = (CyclingButtonWidget<T>) widget;
Expand All @@ -99,7 +100,7 @@ private <T> void resetCyclingButtonWidget(SimpleOption<T> option) {
}

private void resetSliderWidget(SimpleOption<Double> option, double maxHeight) {
var widget = this.body.getWidgetFor(option);
var widget = this.buttonList.getWidgetFor(option);

if (widget != null && widget instanceof SliderWidget) {
// Widget needs value in range of 0-1 instead of option's value
Expand Down

0 comments on commit ffed582

Please sign in to comment.