Skip to content

Commit

Permalink
[#135] Compat with Nostalgia Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Jan 1, 2025
1 parent 4fbe3fa commit 4b9fb8a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
> ### DynamicSurroundings-1.21.1-0.4.2
**All Loaders**
* JAVA 21+
* Architectury 13.0.8+

**Fabric**
* Fabric Loader >= 0.16.9
* Fabric API >= 0.110.0+1.21.

**NeoForge**
* NeoForge 21.1.84+

**Fixes**
* Disabling fog effect actually works
* Compatibility with Nostalgia Tweaks world fog effect

> ### DynamicSurroundings-1.21.1-0.4.1
**All Loaders**
* JAVA 21+
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package org.orecruncher.dsurround.mixins.core;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.material.FogType;
import org.orecruncher.dsurround.eventing.ClientEventHooks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(FogRenderer.class)
public class MixinFogRenderer {

@Inject(method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void dsurround_renderFog(Camera camera, FogRenderer.FogMode fogMode, float f, boolean bl, float g, CallbackInfo ci, FogType fogType, Entity entity, FogRenderer.FogData fogData) {
@Inject(method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", at = @At("RETURN"))
private static void dsurround_renderFog(Camera camera, FogRenderer.FogMode fogMode, float f, boolean bl, float g, CallbackInfo ci, @Local FogType fogType, @Local FogRenderer.FogData fogData) {

if (fogData.mode != FogRenderer.FogMode.FOG_TERRAIN || fogType != FogType.NONE)
return;

ClientEventHooks.FOG_RENDER_EVENT.raise().onRenderFog(fogData, f, g);
// At this point, Minecraft has already configured fog. It's possible that another
// mixin fired and configured as well. We cannot trust the state of fogData, so
// we interrogate the shader directly to see what was configured. (Nostalgic Tweaks
// uses this approach.)
var data = new FogRenderer.FogData(fogData.mode);
data.start = RenderSystem.getShaderFogStart();
data.end = RenderSystem.getShaderFogEnd();
data.shape = RenderSystem.getShaderFogShape();

ClientEventHooks.FOG_RENDER_EVENT.raise().onRenderFog(data, f, g);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ private void renderFog(FogRenderer.FogData data, float renderDistance, float par

@Override
protected void gatherDiagnostics(CollectDiagnosticsEvent event) {
event.add(CollectDiagnosticsEvent.Section.Systems, "Fog: %f/%f, %s, %s".formatted(this.lastData.start, this.lastData.end, this.lastData.shape, this.lastData.mode));
if (this.fogCalculator.enabled())
event.add(CollectDiagnosticsEvent.Section.Systems, "Fog: %f/%f, %s, %s".formatted(this.lastData.start, this.lastData.end, this.lastData.shape, this.lastData.mode));
else
event.add(CollectDiagnosticsEvent.Section.Systems, "Fog: DISABLED");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public String getName() {

@Override
public boolean enabled() {
return true;
return this.fogOptions.enableFogEffects;
}

@NotNull
public FogRenderer.FogData render(@NotNull final FogRenderer.FogData data, float renderDistance, float partialTick) {

if (!this.fogOptions.enableFogEffects)
if (!this.enabled())
return data;

float start = data.start;
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ org.gradle.parallel=true

# Mod properties
mod_name = Dynamic Surroundings
mod_description = Alters the fabric of Minecraft experience by weaving a tapestry of sound and visual effects
mod_version = 0.4.1
mod_description = Alters the fabric of Minecraft experience by weaving a tapestry of sound and visual effects
mod_version = 0.4.2
mod_author = OreCruncher
mod_license = MIT
mod_issues_url = https://github.com/OreCruncher/DynamicSurroundingsFabric/issues
Expand Down

0 comments on commit 4b9fb8a

Please sign in to comment.