Patch VanillaPackResources.getResource since it's still an issue

This commit is contained in:
embeddedt 2023-02-26 20:13:28 -05:00
parent f36074376b
commit c269cbedac
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 38 additions and 1 deletions

View File

@ -17,7 +17,7 @@ public class ModernFixEarlyConfig {
// Defines the default rules which can be configured by the user or other mods.
// You must manually add a rule for any new mixins not covered by an existing package rule.
this.addMixinRule("core", true); // TODO: Don't actually allow the user to disable this
this.addMixinRule("perf.modern_resourcepacks", false);
this.addMixinRule("perf.modern_resourcepacks", true);
this.addMixinRule("feature.branding", true);
this.addMixinRule("feature.measure_time", true);
this.addMixinRule("feature.reduce_loading_screen_freezes", false);

View File

@ -0,0 +1,36 @@
package org.embeddedt.modernfix.mixin.perf.modern_resourcepacks;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.VanillaPackResources;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
@Mixin(VanillaPackResources.class)
public class VanillaPackResourcesMixin {
@Shadow @Final private static Map<PackType, Path> ROOT_DIR_BY_TYPE;
/**
* @author embeddedt
* @reason avoid going through the module class loader when we know exactly what path this resource should come
* from
*/
@Overwrite
protected InputStream getResourceAsStream(PackType type, ResourceLocation location) {
Path rootPath = ROOT_DIR_BY_TYPE.get(type);
Path targetPath = rootPath.resolve(location.getNamespace() + "/" + location.getPath());
try {
return Files.newInputStream(targetPath);
} catch(IOException e) {
return null;
}
}
}

View File

@ -7,6 +7,7 @@
"refmap": "modernfix.refmap.json",
"mixins": [
"bugfix.edge_chunk_not_saved.ChunkManagerMixin",
"perf.modern_resourcepacks.VanillaPackResourcesMixin",
"perf.remove_biome_temperature_cache.BiomeMixin",
"perf.reduce_blockstate_cache_rebuilds.GameDataMixin",
"perf.reduce_blockstate_cache_rebuilds.BlockCallbacksMixin",