Skip to content

Commit

Permalink
Fix OptiFine's Connected Textures in 1.19.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
XXMA16 committed Sep 16, 2023
1 parent f119d75 commit eabcd6e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ dependencies {

modImplementation "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
include "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"

include(modImplementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.2.0-rc.2")))
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.modmuss50.optifabric.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.modmuss50.optifabric.mod.OptifineResources;
import net.minecraft.resource.DefaultResourcePack;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import java.io.IOException;
import java.io.InputStream;

@Mixin(value = DefaultResourcePack.class, priority = 400)
abstract class DefaultResourcePackMixin {
@Dynamic
@WrapOperation(method = {"findInputStream", "getResourceOF"}, at = @At(value = "INVOKE", target = "Lnet/optifine/reflect/ReflectorForge;getOptiFineResourceStream(Ljava/lang/String;)Ljava/io/InputStream;"), require = 1, allow = 1)
private InputStream doFindResource(String pathStr, Operation<InputStream> original) {
try {
InputStream stream = OptifineResources.INSTANCE.getResource(pathStr);
if (stream != null) return stream;
} catch (IOException e) {
//Optifine does this if it goes wrong so we will too
//It doesn't in later versions (should revisit this sometime in the future)
e.printStackTrace();
}
return original.call(pathStr);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package me.modmuss50.optifabric.mixin;

import java.io.IOException;
import java.io.InputStream;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -16,23 +13,10 @@
import me.modmuss50.optifabric.mod.OptifineResources;

@Mixin(value = DefaultResourcePack.class, priority = 400)
abstract class MixinDefaultResourcePack {
abstract class DefaultResourcePackOldMixin {
@Shadow
private static native String getPath(ResourceType type, Identifier id);

@Inject(method = "findInputStream", at = @At("HEAD"), cancellable = true)
protected void onFindInputStream(ResourceType type, Identifier id, CallbackInfoReturnable<InputStream> callback) {
String path = getPath(type, id);

try {
InputStream stream = OptifineResources.INSTANCE.getResource(path);
if (stream != null) callback.setReturnValue(stream);
} catch (IOException e) {
//Optifine does this if it goes wrong so we will too
e.printStackTrace();
}
}

@Inject(method = "contains", at = @At("HEAD"), cancellable = true)
public void doesContain(ResourceType type, Identifier id, CallbackInfoReturnable<Boolean> callback) {
String path = getPath(type, id);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/optifabric.optifine.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mixins": [
"MixinReflectorClass",
"MixinOptifineConfig",
"DefaultResourcePackMixin",
"CustomColoursMixin",
"ShadersMixin",
"VideoOptionsScreenMixin",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/optifabric.optifine.old-mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"parent": "optifabric.optifine.mixins.json",
"package": "me.modmuss50.optifabric.mixin",
"mixins": [
"MixinDefaultResourcePack"
"DefaultResourcePackOldMixin"
]
}

0 comments on commit eabcd6e

Please sign in to comment.