Skip to content

Commit debfbdc

Browse files
committed
Fix OptiFine resources not being loaded with mixin.perf.resourcepacks
This will impact launch performance, but that is unavoidable if we want the OF patch to apply. Using a Sodium port is recommended instead. Related: #41, #45
1 parent ecf3417 commit debfbdc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/resourcepacks/VanillaPackMixin.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
1111
import org.apache.commons.lang3.tuple.Pair;
1212
import org.embeddedt.modernfix.FileWalker;
13+
import org.embeddedt.modernfix.core.config.ModernFixEarlyConfig;
1314
import org.embeddedt.modernfix.util.FileUtil;
1415
import org.embeddedt.modernfix.util.PackTypeHelper;
1516
import org.spongepowered.asm.mixin.Final;
1617
import org.spongepowered.asm.mixin.Mixin;
17-
import org.spongepowered.asm.mixin.Overwrite;
1818
import org.spongepowered.asm.mixin.Shadow;
1919
import org.spongepowered.asm.mixin.injection.At;
2020
import org.spongepowered.asm.mixin.injection.Inject;
@@ -86,14 +86,16 @@ private void useCacheForExistence(PackType type, ResourceLocation location, Call
8686
* @reason avoid going through the module class loader when we know exactly what path this resource should come
8787
* from
8888
*/
89-
@Overwrite
90-
protected InputStream getResourceAsStream(PackType type, ResourceLocation location) {
91-
Path rootPath = ROOT_DIR_BY_TYPE.get(type);
92-
Path targetPath = rootPath.resolve(location.getNamespace() + "/" + location.getPath());
93-
try {
94-
return Files.newInputStream(targetPath);
95-
} catch(IOException e) {
96-
return null;
89+
@Inject(method = "getResourceAsStream(Lnet/minecraft/server/packs/PackType;Lnet/minecraft/resources/ResourceLocation;)Ljava/io/InputStream;", at = @At("HEAD"), cancellable = true)
90+
private void getResourceAsStreamFast(PackType type, ResourceLocation location, CallbackInfoReturnable<InputStream> cir) {
91+
if(!ModernFixEarlyConfig.OPTIFINE_PRESENT) {
92+
Path rootPath = ROOT_DIR_BY_TYPE.get(type);
93+
Path targetPath = rootPath.resolve(location.getNamespace() + "/" + location.getPath());
94+
try {
95+
cir.setReturnValue(Files.newInputStream(targetPath));
96+
} catch(IOException e) {
97+
cir.setReturnValue(null);
98+
}
9799
}
98100
}
99101
}

0 commit comments

Comments
 (0)