Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
fix: Fix repeated config file saving on game startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Jan 10, 2024
1 parent 484ac5e commit 22f4015
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ dependencies {

// Distant Horizons
modImplementation "blank:DistantHorizons-2.0.2-a-dev-1.20.1"

// Apache Commons Math
implementation include("org.apache.commons:commons-math3:${project.apache_commons_math_version}")
}

processResources {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ fabric_version=0.86.1+1.20.1
modmenu_version=7.2.1
sodium_version=mc1.20.1-0.5.2
iris_shaders_version=1.6.8+1.20.1
apache_commons_math_version=3.6.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam;
import io.github.steveplays28.blendium.client.compat.iris.BlendiumDhShaderpackPresets;
import org.apache.commons.math3.util.Precision;

import static io.github.steveplays28.blendium.client.BlendiumClient.*;

Expand All @@ -17,6 +18,16 @@ public void afterDistantHorizonsInit(DhApiEventParam<Void> input) {

private void onBrightnessMultiplierChanged(Double brightnessMultiplier) {
DhApi.Delayed.configs.graphics().brightnessMultiplier().setValue(null);

// Check if the changed value is the same as the currently stored value, and discard the save attempt if true
// This avoids resaving the config file multiple times (e.x. during game loading)
if (Precision.equals(
brightnessMultiplier,
config.shaderpackBrightnessMultipliers.getOrDefault(BlendiumDhShaderpackPresets.getShaderpackName(), brightnessMultiplier)
)) {
return;
}

config.shaderpackBrightnessMultipliers.put(BlendiumDhShaderpackPresets.getShaderpackName(), brightnessMultiplier);
saveConfig();

Expand All @@ -27,6 +38,16 @@ private void onBrightnessMultiplierChanged(Double brightnessMultiplier) {

private void onSaturationMultiplierChanged(Double saturationMultiplier) {
DhApi.Delayed.configs.graphics().saturationMultiplier().setValue(null);

// Check if the changed value is the same as the currently stored value, and discard the save attempt if true
// This avoids resaving the config file multiple times (e.x. during game loading)
if (Precision.equals(
saturationMultiplier,
config.shaderpackSaturationMultipliers.getOrDefault(BlendiumDhShaderpackPresets.getShaderpackName(), saturationMultiplier)
)) {
return;
}

config.shaderpackSaturationMultipliers.put(BlendiumDhShaderpackPresets.getShaderpackName(), saturationMultiplier);
saveConfig();

Expand Down

0 comments on commit 22f4015

Please sign in to comment.