Skip to content

Commit

Permalink
Fix crashes when using indigo renderer, still needs work
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed May 22, 2019
1 parent aacacdd commit f12ad7b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __Note:__ This project does not contain Optifine, you must download it separatel

After installing fabric for 1.14, you will need to place the OptiFabric mod jar as well as the optifine installer in the mods folder.

Note currently only fabric api 0.2.7 is supported, you can download it from [here](https://minecraft.curseforge.com/projects/fabric/files/2702281). This will be fixed soon.
Fabric API 0.2.7 is recommended, you can download it from [here](https://minecraft.curseforge.com/projects/fabric/files/2702281). Newer (0.3.0+) versions may have issues with shaders, if you know how to fix this please get in contact, thanks.

## Links

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repositories {
}

dependencies {
modCompile 'net.fabricmc:fabric:0.2.7+build.127'
modCompile 'net.fabricmc.fabric-api:fabric-api:0.3.0-pre+build.165'

modCompile 'com.github.Chocohead:Fabric-ASM:c4ad22d'
include 'com.github.Chocohead:Fabric-ASM:c4ad22d'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ minecraft_version=1.14
yarn_mappings=1.14+build.21
loader_version=0.4.7+build.147

mod_version = 0.1.0
mod_version = 0.1.1
maven_group = me.modmuss50
archives_base_name = optifabric
43 changes: 43 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mixin/MixinChunkCacheOF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.modmuss50.optifabric.mixin;

import net.fabricmc.indigo.renderer.accessor.AccessChunkRendererRegion;
import net.fabricmc.indigo.renderer.render.TerrainRenderContext;
import net.minecraft.client.render.chunk.ChunkRendererRegion;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Final;
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;

//Fabric API's indigo renderer support for optifine. This stops it from crashing, I dont really know whats going on here
@Pseudo
@Mixin(targets = "net.optifine.override.ChunkCacheOF")
public abstract class MixinChunkCacheOF implements AccessChunkRendererRegion {
private TerrainRenderContext fabric_renderer;

@Shadow @Final
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"))
private void constructor(ChunkRendererRegion chunkCache, BlockPos posFromIn, BlockPos posToIn, int subIn, CallbackInfo info){
if(chunkCache != null) {
final TerrainRenderContext renderer = TerrainRenderContext.POOL.get();
renderer.setBlockView(chunkCache);
fabric_setRenderer(renderer);
}
}

@Override
public TerrainRenderContext fabric_getRenderer() {
return fabric_renderer;
}

@Override
public void fabric_setRenderer(TerrainRenderContext renderer) {
fabric_renderer = renderer;
}
}
18 changes: 18 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package me.modmuss50.optifabric.mod;

import com.chocohead.mm.api.ClassTinkerers;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.launch.common.FabricMixinBootstrap;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class OptifabricSetup implements Runnable {

Expand All @@ -19,7 +23,21 @@ public void run() {
OptifineInjector injector = new OptifineInjector(optifineSetup.getClassesDir());
injector.setup();
} catch (Throwable e) {
if(OptifineVersion.error == null || OptifineVersion.error.isEmpty()){
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
OptifineVersion.error = "Failed to load optifine, check the log for more info \n\n " + e.getMessage();
}
throw new RuntimeException("Failed to setup optifine", e);
}

if(FabricLoader.getInstance().isModLoaded("fabric-renderer-indigo")){
try {
Method method = FabricMixinBootstrap.class.getDeclaredMethod("addConfiguration", String.class);
method.setAccessible(true);
method.invoke(null, "optifabric.indigofix.mixins.json");
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to inject indigo render fixes", e);
}
}
}
}
11 changes: 11 additions & 0 deletions src/main/resources/optifabric.indigofix.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "me.modmuss50.optifabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinChunkCacheOF"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit f12ad7b

Please sign in to comment.