Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
1.14.3 Fixes #23 Fixes #22 Fixes #21 Fixes #10 Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jun 27, 2019
1 parent 87eb38f commit 9377b32
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 35 deletions.
58 changes: 38 additions & 20 deletions README.md
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"

modCompile 'net.fabricmc.fabric-api:fabric-api:0.3.0+build.175'
modCompile 'net.fabricmc.fabric-api:fabric-api:0.3.0+build.187'

modCompile 'com.github.Chocohead:Fabric-ASM:c4ad22d'
include 'com.github.Chocohead:Fabric-ASM:c4ad22d'
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class MixinChunkCacheOF implements AccessChunkRendererRegion {
private ChunkRendererRegion chunkCache;

//This was taken from https://github.com/FabricMC/fabric/blob/master/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/mixin/MixinChunkRenderTask.java honesly no idea what it does, but it doesnt crash the game here
@Inject(method = "<init>", at = @At("RETURN"))
@Inject(method = "<init>", at = @At("RETURN"), remap = false)
private void constructor(ChunkRendererRegion chunkCache, BlockPos posFromIn, BlockPos posToIn, int subIn, CallbackInfo info){
if(chunkCache != null) {
final TerrainRenderContext renderer = TerrainRenderContext.POOL.get();
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mixin/MixinGuiShaders.java
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 src/main/java/me/modmuss50/optifabric/mixin/MixinIndigo.java
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 src/main/java/me/modmuss50/optifabric/mixin/MixinShaders.java
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.text.Text;
import net.minecraft.util.SystemUtil;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -25,7 +25,7 @@ public abstract class MixinTitleScreen extends Screen {
@Shadow
private long backgroundFadeStart;

protected MixinTitleScreen(Component component_1) {
protected MixinTitleScreen(Text component_1) {
super(component_1);
}

Expand Down
17 changes: 13 additions & 4 deletions src/main/java/me/modmuss50/optifabric/mod/Optifabric.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package me.modmuss50.optifabric.mod;

import net.minecraft.ChatFormat;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.util.SystemUtil;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;

public class Optifabric {
public class Optifabric implements ModInitializer {

public static void checkForErrors() {
if (OptifineVersion.error != null) {
Expand All @@ -16,9 +18,16 @@ public static void checkForErrors() {
} else {
MinecraftClient.getInstance().scheduleStop();
}
}, new TextComponent(ChatFormat.RED + "There was an error finding Optifine in the mods folder!"), new TextComponent(OptifineVersion.error), ChatFormat.GREEN + "Open Help", ChatFormat.RED + "Close Game");
}, new LiteralText(Formatting.RED + "There was an error finding Optifine in the mods folder!"), new LiteralText(OptifineVersion.error), Formatting.GREEN + "Open Help", Formatting.RED + "Close Game");

MinecraftClient.getInstance().openScreen(confirmScreen);
}
}

@Override
public void onInitialize() {
if(FabricLoader.getInstance().isModLoaded("fabric-renderer-indigo")){
ShaderHelper.indigoFixSetup();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static File findOptifineJar() throws IOException {
private static JarType getJarType(File file) throws IOException {
ClassNode classNode;
try (JarFile jarFile = new JarFile(file)) {
JarEntry jarEntry = jarFile.getJarEntry("Config.class"); // I hope this is enough to detect optifine
JarEntry jarEntry = jarFile.getJarEntry("net/optifine/Config.class"); // New 1.14.3 location
if (jarEntry == null) {
return JarType.SOMETHINGELSE;
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mod/ShaderHelper.java
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);
}
}
});
}

}
5 changes: 5 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"license": "CC0-1.0",
"icon": "assets/optifabric/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"me.modmuss50.optifabric.mod.Optifabric"
]
},
"custom": {
"mm:early_risers": [
"me.modmuss50.optifabric.mod.OptifabricSetup"
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/optifabric.indigofix.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"package": "me.modmuss50.optifabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinChunkCacheOF"
"MixinChunkCacheOF",
"MixinIndigo"
],
"injectors": {
"defaultRequire": 1
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/optifabric.optifine.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"package": "me.modmuss50.optifabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinReflectorClass"
"MixinReflectorClass",
"MixinShaders",
"MixinGuiShaders"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 9377b32

Please sign in to comment.