-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for editing Sodium core shaders in resource packs
- Loading branch information
Showing
5 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
fabric/src/main/java/com/noxcrew/noxesium/mixin/sodium/SodiumShaderLoaderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.noxcrew.noxesium.mixin.sodium; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.noxcrew.noxesium.NoxesiumMod; | ||
import me.jellysquid.mods.sodium.client.gl.shader.ShaderLoader; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.apache.commons.io.IOUtils; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* Based on <a href="https://github.com/lni-dev/SodiumCoreShaderSupport/blob/1.20.6/src/main/java/de/linusdev/mixin/MixinShaderLoader.java">Sodium Core Shader Support</a>. | ||
* <p> | ||
* Sodium has indicated they do not want to add core shader support natively, the discussion of why is best left to other places. | ||
* But in practice this leaves server developers that want to use core shaders with half their players being unable to see them. So, Noxesium | ||
* lets you edit the shaders but acknowledges that it is entirely the responsibility of the server developer to fix any issues that occur. | ||
* <p> | ||
* Using Sodium's core shaders on a public server is irresponsible and entirely your problem if it causes issues. This system is meant for | ||
* private servers where you can guarantee the version clients are using. But I'm a code comment, not a cop, I can't stop you. | ||
*/ | ||
@Mixin(value = ShaderLoader.class, remap = false) | ||
public class SodiumShaderLoaderMixin { | ||
|
||
@WrapMethod(method = "getShaderSource") | ||
private static String noxesium$getShaderSource(ResourceLocation name, Operation<String> original) { | ||
// Determine if this shader is being provided by some resource pack, we fall back to Sodium | ||
// if anything goes wrong while doing so! | ||
var cache = NoxesiumMod.getInstance().getCachedShaders(); | ||
var resource = cache != null ? cache.cache().get(name) : null; | ||
if (resource != null) { | ||
try { | ||
return IOUtils.toString(resource.open(), StandardCharsets.UTF_8); | ||
} catch (Exception x) { | ||
NoxesiumMod.getInstance().getLogger().error("Exception while reading shader for source {} from resource pack", name); | ||
} | ||
} | ||
return original.call(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters