This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
14 changed files
with
229 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,58 @@ | ||
# A message to Optifine users and developers | ||
# OptiFabric | ||
|
||
#### TL;DR: **OptiFabric is no longer supported.** | ||
![](https://ss.modmuss50.me/javaw_2019-05-22_20-33-34.jpg) | ||
|
||
__Note:__ This project is not related or supported by either Fabric or Optifine. | ||
|
||
Please do not send messages to me, or the Optifine developers demanding fabric support. | ||
__Note:__ This project does not contain Optifine, you must download it separately! | ||
|
||
## The Issue | ||
A little over a week ago I released OptiFabric and it quickly came to my attention that there were some incompatibilities, especially with the shaders mod. I had a large amount of DM/pings letting me know of this. | ||
## Installing | ||
|
||
The issue was tracked down to be an incompatibly with Fabric API's new Rendering API and the implementation called Indigo. To fix the issue correctly knowledge of how Optifine works is required, this is not possible without good knowledge of the fabric rendering API and details on how Optifine works. | ||
After installing fabric for 1.14.3, you will need to place the OptiFabric mod jar as well as the optifine installer in the mods folder. | ||
|
||
I see a few solutions to this issue, | ||
Fabric Loader should be the latest version from the [Fabric Website](https://fabricmc.net/use/) | ||
|
||
• Official built in support for Fabric in Optifine. I think this is the best solution to the issue and the Optifine Developers should explore the idea further. (More on this later) | ||
|
||
• A fix from a developer outside of Fabric or Optifine could create a PR to OptiFabric, I would not mind looking into giving them access over the project if required. | ||
## Links | ||
|
||
• Don’t use the features that don’t work, not great but it seems to work ok as-is currently. | ||
### [OptiFabric Downloads](https://minecraft.curseforge.com/projects/optifabric) | ||
|
||
## The best solution | ||
### [Optifine Download](https://optifine.net/downloads) | ||
|
||
The ideal solution to this whole issue is official support for Fabric from Optifine. OptiFabric has proved that is possible and that users want the feature (5000+ downloads in week!). | ||
## Issues | ||
|
||
I see a few ways this could be made possible: | ||
If you happen to find an issue and you believe it is to do with OptiFabric and not Optifine or a mod please open an issue [here](https://github.com/modmuss50/OptiFabric/issues) | ||
|
||
|
||
• Optifine could include parts or the whole of OptiFabric, I see this being the easiest solution as the code already exists and has been proven to mostly work. | ||
## For Mod Devs | ||
|
||
• Optifine could become a normal fabric mod that uses mixins. This would require a lot of time and effort from the Optifine Developers but it would allow faster updates to newer Minecraft versions. | ||
(Needs testing please report issues) | ||
|
||
If you want to explore this option or just need to ask a few questions feel free to contact me. | ||
Optifabric 0.2 and up will work in a mod dev environment. Just install OptiFabric and Optifine in the mods folder. | ||
|
||
## The current Situation | ||
As for now I can no longer maintain OptiFabric to the standard that I had intended to, and there will be no updates for the foreseeable future (Unless someone else can take on the challenge). Do not expect any support from Optifine or the Fabric developers if you continue to use this mod. | ||
Class export can be enabled using the following VM Option, this will extract the overwritten classes to the .optifine folder, useful for debugging. | ||
|
||
Thanks for reading this and understanding, | ||
`-Doptifabric.extract=true` | ||
|
||
Modmuss50 | ||
## Screenshots | ||
|
||
Feel free to open a PR with more screenshots. | ||
|
||
![](https://ss.modmuss50.me/javaw_2019-05-22_20-36-25.jpg) | ||
|
||
![](https://ss.modmuss50.me/javaw_2019-05-22_19-49-41.jpg) | ||
|
||
## How it works | ||
|
||
This would not have been possible without Chocohead's [Fabric-ASM](https://github.com/Chocohead/Fabric-ASM). | ||
|
||
1. The mod looks for an optifine installer or mod jar in the current mods folder | ||
2. If it finds an installer jar it runs the extract task in its own throwaway classloader. | ||
3. The optifine mod jar is a set of classes that need to replace the ones that minecraft provides. | ||
4. Optifine's replacement classes change the name of some lambada methods, so I take a good guess at the old name (using the original minecraft jar). | ||
5. Remap optifine to intermediary (or yarn in development) | ||
6. Move the patched classes out as they wont do much good on the classpath twice | ||
7. Add optifine to the classpath | ||
8. Register the patching tweaker for every class that needs replacing | ||
9. Replace the target class with the class that was extracted, also do some more fixes to it, and make it public (due to access issues). | ||
10. Hope it works |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# Done to increase the memory available to gradle. | ||
org.gradle.jvmargs=-Xmx1G | ||
|
||
minecraft_version=1.14.2 | ||
yarn_mappings=1.14.2+build.2 | ||
loader_version=0.4.8+build.154 | ||
minecraft_version=1.14.3 | ||
yarn_mappings=1.14.3+build.1 | ||
loader_version=0.4.8+build.155 | ||
|
||
mod_version = 0.2.1 | ||
mod_version = 0.3.0 | ||
maven_group = me.modmuss50 | ||
archives_base_name = optifabric |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/me/modmuss50/optifabric/mixin/MixinGuiShaders.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,32 @@ | ||
package me.modmuss50.optifabric.mixin; | ||
|
||
import me.modmuss50.optifabric.mod.ShaderHelper; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.awt.*; | ||
|
||
//Shows a warning when shaders are enabled | ||
@Pseudo | ||
@Mixin(targets = "net.optifine.shaders.gui.GuiShaders") | ||
public abstract class MixinGuiShaders extends Screen { | ||
|
||
protected MixinGuiShaders(Text text_1) { | ||
super(text_1); | ||
} | ||
|
||
@Inject(method = "render", at = @At("RETURN"), remap = false) | ||
private void render(int int_1, int int_2, float float_1, CallbackInfo ci){ | ||
if(ShaderHelper.isShadersEnabled()){ | ||
drawString(font, "The indigo rendering pipeline has been disabled", 10, 5, Color.RED.getRGB()); | ||
drawString(font, "Disable shaders before reporting issues.", 10, 15, Color.RED.getRGB()); | ||
} | ||
} | ||
|
||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/me/modmuss50/optifabric/mixin/MixinIndigo.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,56 @@ | ||
package me.modmuss50.optifabric.mixin; | ||
|
||
import net.fabricmc.indigo.Indigo; | ||
import net.fabricmc.indigo.renderer.aocalc.AoConfig; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Indigo.class) | ||
public class MixinIndigo { | ||
|
||
@Shadow @Final @Mutable | ||
public static AoConfig AMBIENT_OCCLUSION_MODE; | ||
private static AoConfig optifabric_backupAOM; | ||
|
||
@Shadow @Final @Mutable | ||
public static boolean ALWAYS_TESSELATE_INDIGO; | ||
private static boolean optifabric_backupATI; | ||
|
||
private static boolean wasEnabled; | ||
|
||
@Inject(method = "<clinit>", at = @At("RETURN")) | ||
private static void staticInit(CallbackInfo ci){ | ||
|
||
//Saves the configs from disk in-case shaders are disabled | ||
optifabric_backupAOM = AMBIENT_OCCLUSION_MODE; | ||
optifabric_backupATI = ALWAYS_TESSELATE_INDIGO; | ||
} | ||
|
||
//Called via reflection | ||
@SuppressWarnings("unused") | ||
private static void optifabric_ShaderChange(boolean enabled){ | ||
if(enabled){ | ||
System.out.println("Enabling optifabric shader support in Indigo"); | ||
|
||
//Force these config options to make shaders work, sorta | ||
AMBIENT_OCCLUSION_MODE = AoConfig.VANILLA; | ||
ALWAYS_TESSELATE_INDIGO = false; | ||
|
||
|
||
wasEnabled = true; | ||
} else if (wasEnabled) { | ||
System.out.println("Disabling optifabric shader support in Indigo"); | ||
wasEnabled = false; | ||
|
||
//Go back to the backup values | ||
AMBIENT_OCCLUSION_MODE = optifabric_backupAOM; | ||
ALWAYS_TESSELATE_INDIGO = optifabric_backupATI; | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/modmuss50/optifabric/mixin/MixinShaders.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,23 @@ | ||
package me.modmuss50.optifabric.mixin; | ||
|
||
import me.modmuss50.optifabric.mod.ShaderHelper; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Pseudo | ||
@Mixin(targets = "net.optifine.shaders.Shaders") | ||
public class MixinShaders { | ||
|
||
@Shadow | ||
private static boolean shaderPackLoaded; | ||
|
||
@Inject(method = "loadShaderPack", at = @At("RETURN"), remap = false) | ||
private static void loadShaderPack(CallbackInfo ci) { | ||
ShaderHelper.changeShaderState(shaderPackLoaded); | ||
} | ||
|
||
} |
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/me/modmuss50/optifabric/mod/ShaderHelper.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,48 @@ | ||
package me.modmuss50.optifabric.mod; | ||
|
||
import net.fabricmc.indigo.Indigo; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class ShaderHelper { | ||
|
||
private static boolean shadersEnabled; | ||
|
||
private static List<Consumer<Boolean>> changeConsumers = new ArrayList<>(); | ||
|
||
public static boolean isShadersEnabled(){ | ||
return shadersEnabled; | ||
} | ||
|
||
public static void toggleHandler(Consumer<Boolean> consumer){ | ||
changeConsumers.add(consumer); | ||
} | ||
|
||
public static void changeShaderState(boolean enabled){ | ||
shadersEnabled = enabled; | ||
changeConsumers.forEach(booleanConsumer -> booleanConsumer.accept(shadersEnabled)); | ||
} | ||
|
||
public static void indigoFixSetup(){ | ||
ShaderHelper.toggleHandler(new Consumer<Boolean>() { | ||
Method method = null; | ||
|
||
@Override | ||
public void accept(Boolean aBoolean) { | ||
try { | ||
if (method == null){ | ||
method = Indigo.class.getDeclaredMethod("optifabric_ShaderChange", boolean.class); | ||
method.setAccessible(true); | ||
} | ||
method.invoke(null, aBoolean); | ||
} catch (Exception e){ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
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
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