Skip to content

Commit

Permalink
Brightness adjustment based on in-game fog brightness (you can increa…
Browse files Browse the repository at this point in the history
…se or decrease the brightness calculated by the game)
  • Loading branch information
NaoCraftLab committed Oct 10, 2024
1 parent e036839 commit dfd392f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.21.2-2.2.0

### Added

- Brightness adjustment based on in-game fog brightness (you can increase or decrease the brightness calculated by the game)

## 1.21.2-2.1.0

### Added
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Read more about the available features in the [🛠️ Configuration](#-configur
</details>

<details>
<summary>⛔️ Disable fog based on the game mode</summary>
<summary>⛔️ Disable fog for specific game modes</summary>

![no-fog-game-modes.gif](docs/images/no-fog-game-modes.gif)

Expand Down Expand Up @@ -223,7 +223,10 @@ Preset files are located in the `config/foggypalegarden` directory. Each file co
"mode": "FIXED",

// (required for FIXED mode) fog brightness level in percent (0.0, 100.0]
"fixedBrightness": 0.0
"fixedBrightness": 0.0,

// (optional for BY_GAME_FOG mode) brightness adjustment [-1.0, 1.0]
"adjustment": 0.0
},

// (optional) fog color settings
Expand Down
14 changes: 3 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,8 @@ if (modrinthToken != null) {
versionType.set("release")
uploadFile.set(File("build/libs/${project.base.archivesName.get()}-${project.version}.jar"))
changelog.set(getChangelogForVersion("${project.property("minecraftReleaseVersion")}-${project.property("modVersion")}"))
gameVersions.set(
listOf(
project.property("minecraftFirstSnapshotVersion").toString(),
// TODO check versions
// project.property("minecraftReleaseVersion").toString()
)
)
loaders.set(project.property("fabricSupportedLoaders").toString().split(',').map { it.trim().lowercase() })
gameVersions.set(project.property("fabricModrinthGameVersions").toString().split(',').map { it.trim() })
loaders.set(project.property("fabricSupportedLoaders").toString().split(',').map { it.trim().lowercase() }.toSet())
additionalFiles.set(listOf(File("build/libs/${project.base.archivesName.get()}-${project.version}-sources.jar")))
}
}
Expand All @@ -136,9 +130,7 @@ if (curseForgeApiKey != null) {
releaseType = "release"
changelogType = "markdown"
changelog = getChangelogForVersion("${project.property("minecraftReleaseVersion")}-${project.property("modVersion")}")
gameVersionStrings.add(project.property("minecraftSnapshotVersion").toString())
// TODO check versions
// gameVersionStrings.add(project.property("minecraftReleaseVersion").toString())
gameVersionStrings.addAll(project.property("fabricCurseForgeGameVersions").toString().split(',').map { it.trim() }.toSet())
gameVersionStrings.addAll(project.property("fabricSupportedLoaders").toString().split(',').map { it.trim() })
// TODO side
// gameVersionStrings.add("Client")
Expand Down
52 changes: 52 additions & 0 deletions docs/presets/custom/SNOWY_VEIL.v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"code": "SNOWY_VEIL",
"bindings": [
{
"condition": {
"and": [
{ "weatherIn": ["RAIN"] },
{ "dimensionIn": ["minecraft:overworld"] },
{ "biomeTemperature": { "max": 0.0 } }
]
},
"startDistance": 2.0,
"skyLightStartLevel": 4,
"endDistance": 15.0,
"surfaceHeightEnd": 128.0,
"opacity": 95.0,
"encapsulationSpeed": 6.0,
"brightness": {
"mode": "BY_GAME_FOG",
"adjustment": 0.5
},
"color": {
"mode": "BY_GAME_FOG",
"fixedHex": "E9E7F8"
}
},
{
"condition": {
"and": [
{ "weatherIn": ["THUNDER"] },
{ "dimensionIn": ["minecraft:overworld"] },
{ "biomeTemperature": { "max": 0.0 } }
]
},
"startDistance": 0.0,
"skyLightStartLevel": 4,
"endDistance": 10.0,
"surfaceHeightEnd": 128.0,
"opacity": 100.0,
"encapsulationSpeed": 6.0,
"brightness": {
"mode": "BY_GAME_FOG",
"adjustment": 0.5
},
"color": {
"mode": "BY_GAME_FOG",
"fixedHex": "E9E7F8"
}
}
],
"version": 2
}
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.parallel=true
group=com.naocraftlab
modId=foggy-pale-garden
modCurseForgeId=1114471
modVersion=2.1.0
modVersion=2.2.0
modName=Foggy Pale Garden
modDescription=Adds dense fog to the Pale Garden biome.
modLicense=MIT
Expand All @@ -19,9 +19,10 @@ minecraftJavaVersion=21
minecraftFirstSnapshotVersion=24w40a
minecraftFirstSnapshotFullVersion=1.21.2-alpha.24.40.a
minecraftReleaseVersion=1.21.2
minecraftSnapshotVersion=1.21.2-Snapshot

# fabric
fabricSupportedLoaders=Fabric, Quilt
fabricYarnMappingsVersion=24w40a+build.11
fabricLoaderMinVersion=0.16.4
fabricModrinthGameVersions=24w40a,1.21.2-pre1
fabricCurseForgeGameVersions=1.21.2-Snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ public Predicate<Environment> toPredicate() {
@Builder
public record Brightness(
BrightnessMode mode,
Float fixedBrightness
Float fixedBrightness,
Float adjustment
) {

public enum BrightnessMode {
Expand All @@ -230,9 +231,13 @@ public enum BrightnessMode {
public void validate() {
if (mode == BrightnessMode.FIXED && (fixedBrightness == null || fixedBrightness < 0.0f || fixedBrightness > 100.0f)) {
throw new FoggyPaleGardenConfigurationException(
"Binding fixedBrightness is not defined or out of range [0.0, 1.0]"
"Binding brightness fixedBrightness is not defined or out of range [0.0, 1.0]"
);
}
if (mode == BrightnessMode.BY_GAME_FOG && adjustment != null
&& (adjustment < -1.0f || adjustment > 1.0f)) {
throw new FoggyPaleGardenConfigurationException("Binding brightness adjustment is out of range [-1.0, 1.0]");
}
}
}

Expand Down Expand Up @@ -278,7 +283,7 @@ public Float encapsulationSpeed() {

@Override
public Brightness brightness() {
return brightness == null ? new Brightness(BrightnessMode.BY_GAME_FOG, null) : brightness;
return brightness == null ? new Brightness(BrightnessMode.BY_GAME_FOG, null, null) : brightness;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ private static Color calculateColor(Color gameFogColor, FogPresetV2.Binding bind
red = Math.min(hexToRed(binding.color().fixedHex()) * brightness, 1.0f);
green = Math.min(hexToGreen(binding.color().fixedHex()) * brightness, 1.0f);
blue = Math.min(hexToBlue(binding.color().fixedHex()) * brightness, 1.0f);
if (binding.brightness().adjustment() != null) {
float adjustment = binding.brightness().adjustment();

if (adjustment >= 0) {
red = red + adjustment * (1.0f - red);
} else {
red = red + adjustment * red;
}
red = Math.max(0.0f, Math.min(red, 1.0f));

if (adjustment >= 0) {
green = green + adjustment * (1.0f - green);
} else {
green = green + adjustment * green;
}
green = Math.max(0.0f, Math.min(green, 1.0f));

if (adjustment >= 0) {
blue = blue + adjustment * (1.0f - blue);
} else {
blue = blue + adjustment * blue;
}
blue = Math.max(0.0f, Math.min(blue, 1.0f));
}
} else if (brightnessMode == BrightnessMode.FIXED && colorMode == ColorMode.BY_GAME_FOG) {
val targetBrightness = binding.brightness().fixedBrightness() / 100.0f;
val currentBrightness = calculateBrightness(gameFogColor);
Expand All @@ -86,6 +110,30 @@ private static Color calculateColor(Color gameFogColor, FogPresetV2.Binding bind
red = gameFogColor.red();
green = gameFogColor.green();
blue = gameFogColor.blue();
if (binding.brightness().adjustment() != null) {
float adjustment = binding.brightness().adjustment();

if (adjustment >= 0) {
red = red + adjustment * (1.0f - red);
} else {
red = red + adjustment * red;
}
red = Math.max(0.0f, Math.min(red, 1.0f));

if (adjustment >= 0) {
green = green + adjustment * (1.0f - green);
} else {
green = green + adjustment * green;
}
green = Math.max(0.0f, Math.min(green, 1.0f));

if (adjustment >= 0) {
blue = blue + adjustment * (1.0f - blue);
} else {
blue = blue + adjustment * blue;
}
blue = Math.max(0.0f, Math.min(blue, 1.0f));
}
}
val alpha = (binding.opacity() > 0f) ? fogDensity * (binding.opacity() / 100f - 0.001f) : 0f;
return Color.builder()
Expand Down

0 comments on commit dfd392f

Please sign in to comment.