diff --git a/shared/src/main/java/net/blay09/mods/clienttweaks/tweak/StepAssistIsAnnoying.java b/shared/src/main/java/net/blay09/mods/clienttweaks/tweak/StepAssistIsAnnoying.java index fbe2671..a48abcb 100644 --- a/shared/src/main/java/net/blay09/mods/clienttweaks/tweak/StepAssistIsAnnoying.java +++ b/shared/src/main/java/net/blay09/mods/clienttweaks/tweak/StepAssistIsAnnoying.java @@ -3,27 +3,51 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.event.TickPhase; import net.blay09.mods.balm.api.event.TickType; +import net.blay09.mods.balm.api.event.client.ClientStartedEvent; import net.blay09.mods.clienttweaks.ClientTweaksConfig; import net.blay09.mods.clienttweaks.ClientTweaksConfigData; import net.minecraft.client.Minecraft; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; public class StepAssistIsAnnoying extends AbstractClientTweak { private static final float DEFAULT_STEP_HEIGHT = 0.6f; + private final AttributeModifier disableStepAssistModifier = new AttributeModifier("Disable step assist", -1, AttributeModifier.Operation.MULTIPLY_TOTAL); + private Attribute stepHeightAttribute; public StepAssistIsAnnoying() { super("disableStepAssist"); + Balm.getEvents() + .onEvent(ClientStartedEvent.class, + event -> stepHeightAttribute = Balm.getRegistries().getAttribute(new ResourceLocation("forge", "step_height_addition"))); + // TODO might have to add prio to tick event handlers since this used to run on Lowest Balm.getEvents().onTickEvent(TickType.Client, TickPhase.Start, this::onPlayerTick); } public void onPlayerTick(Minecraft client) { - if (isEnabled()) { - Player player = client.player; - if (player != null) { + Player player = client.player; + if (player != null) { + if (isEnabled()) { player.setMaxUpStep(DEFAULT_STEP_HEIGHT); + if (stepHeightAttribute != null) { + AttributeInstance attributeInstance = player.getAttribute(stepHeightAttribute); + if (attributeInstance != null && !attributeInstance.hasModifier(disableStepAssistModifier)) { + attributeInstance.addTransientModifier(disableStepAssistModifier); + } + } + } else { + if (stepHeightAttribute != null) { + AttributeInstance attributeInstance = player.getAttribute(stepHeightAttribute); + if (attributeInstance != null) { + attributeInstance.removeModifier(disableStepAssistModifier); + } + } } } }