Check OptiFine Shader at real time #2871
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
At the moment the
Mods#Optifinechecks whether shaderpack is active by reflection, the result is cached and never changed afterward.GregTech/src/main/java/gregtech/api/util/Mods.java
Lines 82 to 99 in 3fc7f42
This results in issues when players turn shaders on/off after the cache is created. In the case where players disabled shaders, the bloom effect won't come back (since they still think the shader is on from the cached value); and in the other case where the shader is turned off afterward, the game will come to a crash.
This PR make it so the shaderpack load state is checked at real-time, which should potentially fix the issues mentioned above.
Implementation Details
This PR moves the shaderpack checker to a separate enum constant, named
ShadersMod(Where the OptiFine shader code originally come from), and@Overrides theisModLoadedmethod with a reference toShaders#shaderPackLoadedWhere the class
net.optifine.shaders.Shaderscreated inapipackage is adapted and minimized from OptiFine itself. TheOptiFine.isModLoaded()method call serves as a guard to avoidClassNotFoundExceptions.And the original enum constant is renamed from
OptifinetoOptiFine, under the consideration of both fixing the spelling mistake and preventing unexpected compatibility issues. The OptiFine checker is now delegating the forge-provided method for checking OptiFine's existence.Outcome
Mods#Optifinewill break.