Skip to content

Commit

Permalink
fix: Fix disableStepAssist not working correctly with Forge's step_he…
Browse files Browse the repository at this point in the history
…ight_addition attribute #71
  • Loading branch information
BlayTheNinth committed Sep 13, 2023
1 parent 2d228d6 commit 70df4fd
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}
Expand Down

0 comments on commit 70df4fd

Please sign in to comment.