Skip to content

Commit

Permalink
Made thirst sprint prevention configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Dec 31, 2023
1 parent 193a6fd commit 479a50a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
2 changes: 2 additions & 0 deletions common/src/main/java/toughasnails/config/ThirstConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ThirstConfig extends Config
{
public boolean enableThirst;
public boolean enableHandDrinking;
public boolean thirstPreventSprint;
public double thirstExhaustionThreshold;
public int handDrinkingThirst;
public double handDrinkingHydration;
Expand All @@ -29,6 +30,7 @@ public void load()
// Toggles
enableThirst = add("toggles.enable_thirst", true, "Enable or disable thirst.");
enableHandDrinking = add("toggles.enable_hand_drinking", false, "Enable or disable hand drinking.");
thirstPreventSprint = add("toggles.thirst_prevent_sprint", true, "Prevent sprinting when thirsty.");

// General options
thirstExhaustionThreshold = addNumber("general.exhaustion_threshold", 8.0D, 0.0D, Double.MAX_VALUE, "The threshold at which exhaustion causes a reduction in hydration and the thirst bar.");
Expand Down
26 changes: 4 additions & 22 deletions common/src/main/java/toughasnails/thirst/ThirstHooksClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,10 @@
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.player.Player;
import toughasnails.api.thirst.ThirstHelper;
import toughasnails.init.ModConfig;

public class ThirstHooksClient {
public static void onAiStep(LocalPlayer player)
{
if (player.isSprinting())
{
boolean sprintingAllowable = canSprintWithThirst(player);

if (player.isSwimming())
{
if (!player.onGround() && !player.input.shiftKeyDown && !sprintingAllowable || !player.isInWater())
{
player.setSprinting(false);
}
}
else if (!sprintingAllowable)
{
player.setSprinting(false);
}
}
}

public class ThirstHooksClient
{
public static void onAiStepSetSprinting(LocalPlayer player, boolean sprinting)
{
// Don't allow sprinting if the player has insufficient thirst
Expand All @@ -40,6 +22,6 @@ public static void onAiStepSetSprinting(LocalPlayer player, boolean sprinting)

private static boolean canSprintWithThirst(LocalPlayer player)
{
return ThirstHelper.getThirst(player).getThirst() > 6 || player.getAbilities().mayfly;
return !ModConfig.thirst.thirstPreventSprint || ThirstHelper.getThirst(player).getThirst() > 6 || player.getAbilities().mayfly;
}
}

0 comments on commit 479a50a

Please sign in to comment.