Skip to content

Commit eabcd6e

Browse files
committed
Fix OptiFine's Connected Textures in 1.19.3+
1 parent f119d75 commit eabcd6e

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ dependencies {
3939

4040
modImplementation "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
4141
include "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
42+
43+
include(modImplementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.2.0-rc.2")))
4244
}
4345

4446
sourceSets {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package me.modmuss50.optifabric.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import me.modmuss50.optifabric.mod.OptifineResources;
6+
import net.minecraft.resource.DefaultResourcePack;
7+
import org.spongepowered.asm.mixin.Dynamic;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
14+
@Mixin(value = DefaultResourcePack.class, priority = 400)
15+
abstract class DefaultResourcePackMixin {
16+
@Dynamic
17+
@WrapOperation(method = {"findInputStream", "getResourceOF"}, at = @At(value = "INVOKE", target = "Lnet/optifine/reflect/ReflectorForge;getOptiFineResourceStream(Ljava/lang/String;)Ljava/io/InputStream;"), require = 1, allow = 1)
18+
private InputStream doFindResource(String pathStr, Operation<InputStream> original) {
19+
try {
20+
InputStream stream = OptifineResources.INSTANCE.getResource(pathStr);
21+
if (stream != null) return stream;
22+
} catch (IOException e) {
23+
//Optifine does this if it goes wrong so we will too
24+
//It doesn't in later versions (should revisit this sometime in the future)
25+
e.printStackTrace();
26+
}
27+
return original.call(pathStr);
28+
}
29+
}

src/main/java/me/modmuss50/optifabric/mixin/MixinDefaultResourcePack.java renamed to src/main/java/me/modmuss50/optifabric/mixin/DefaultResourcePackOldMixin.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package me.modmuss50.optifabric.mixin;
22

3-
import java.io.IOException;
4-
import java.io.InputStream;
5-
63
import org.spongepowered.asm.mixin.Mixin;
74
import org.spongepowered.asm.mixin.Shadow;
85
import org.spongepowered.asm.mixin.injection.At;
@@ -16,23 +13,10 @@
1613
import me.modmuss50.optifabric.mod.OptifineResources;
1714

1815
@Mixin(value = DefaultResourcePack.class, priority = 400)
19-
abstract class MixinDefaultResourcePack {
16+
abstract class DefaultResourcePackOldMixin {
2017
@Shadow
2118
private static native String getPath(ResourceType type, Identifier id);
2219

23-
@Inject(method = "findInputStream", at = @At("HEAD"), cancellable = true)
24-
protected void onFindInputStream(ResourceType type, Identifier id, CallbackInfoReturnable<InputStream> callback) {
25-
String path = getPath(type, id);
26-
27-
try {
28-
InputStream stream = OptifineResources.INSTANCE.getResource(path);
29-
if (stream != null) callback.setReturnValue(stream);
30-
} catch (IOException e) {
31-
//Optifine does this if it goes wrong so we will too
32-
e.printStackTrace();
33-
}
34-
}
35-
3620
@Inject(method = "contains", at = @At("HEAD"), cancellable = true)
3721
public void doesContain(ResourceType type, Identifier id, CallbackInfoReturnable<Boolean> callback) {
3822
String path = getPath(type, id);

src/main/resources/optifabric.optifine.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"mixins": [
55
"MixinReflectorClass",
66
"MixinOptifineConfig",
7+
"DefaultResourcePackMixin",
78
"CustomColoursMixin",
89
"ShadersMixin",
910
"VideoOptionsScreenMixin",

src/main/resources/optifabric.optifine.old-mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"parent": "optifabric.optifine.mixins.json",
33
"package": "me.modmuss50.optifabric.mixin",
44
"mixins": [
5-
"MixinDefaultResourcePack"
5+
"DefaultResourcePackOldMixin"
66
]
77
}

0 commit comments

Comments
 (0)