|
10 | 10 | import net.minecraft.server.packs.metadata.pack.PackMetadataSection; |
11 | 11 | import org.apache.commons.lang3.tuple.Pair; |
12 | 12 | import org.embeddedt.modernfix.FileWalker; |
| 13 | +import org.embeddedt.modernfix.core.config.ModernFixEarlyConfig; |
13 | 14 | import org.embeddedt.modernfix.util.FileUtil; |
14 | 15 | import org.embeddedt.modernfix.util.PackTypeHelper; |
15 | 16 | import org.spongepowered.asm.mixin.Final; |
16 | 17 | import org.spongepowered.asm.mixin.Mixin; |
17 | | -import org.spongepowered.asm.mixin.Overwrite; |
18 | 18 | import org.spongepowered.asm.mixin.Shadow; |
19 | 19 | import org.spongepowered.asm.mixin.injection.At; |
20 | 20 | import org.spongepowered.asm.mixin.injection.Inject; |
@@ -86,14 +86,16 @@ private void useCacheForExistence(PackType type, ResourceLocation location, Call |
86 | 86 | * @reason avoid going through the module class loader when we know exactly what path this resource should come |
87 | 87 | * from |
88 | 88 | */ |
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 | + } |
97 | 99 | } |
98 | 100 | } |
99 | 101 | } |
0 commit comments