Merge remote-tracking branch 'origin/1.19.2' into 1.19.4
This commit is contained in:
commit
ec2f6e8490
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.embeddedt.modernfix.forge.load;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import net.minecraftforge.forgespi.language.IModFileInfo;
|
||||||
|
import net.minecraftforge.forgespi.locating.IModFile;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
|
||||||
|
public class ModResourcePackPathFixer {
|
||||||
|
private static final IdentityHashMap<Path, IModFile> modFileByPath = new IdentityHashMap<>();
|
||||||
|
|
||||||
|
public static synchronized IModFile getModFileByRootPath(Path path) {
|
||||||
|
if(modFileByPath.size() == 0) {
|
||||||
|
for(IModFileInfo info : ModList.get().getModFiles()) {
|
||||||
|
modFileByPath.put(info.getFile().getFilePath(), info.getFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modFileByPath.get(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,10 @@ package org.embeddedt.modernfix.forge.mixin.perf.resourcepacks;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.packs.PackResources;
|
import net.minecraft.server.packs.PackResources;
|
||||||
import net.minecraft.server.packs.PackType;
|
import net.minecraft.server.packs.PackType;
|
||||||
|
import net.minecraftforge.forgespi.locating.IModFile;
|
||||||
import net.minecraftforge.resource.PathPackResources;
|
import net.minecraftforge.resource.PathPackResources;
|
||||||
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
|
import org.embeddedt.modernfix.forge.load.ModResourcePackPathFixer;
|
||||||
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
||||||
import org.embeddedt.modernfix.resources.NewResourcePackAdapter;
|
import org.embeddedt.modernfix.resources.NewResourcePackAdapter;
|
||||||
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||||
|
|
@ -36,12 +39,26 @@ public abstract class ForgePathPackResourcesMixin implements ICachingResourcePac
|
||||||
|
|
||||||
private PackResourcesCacheEngine cacheEngine;
|
private PackResourcesCacheEngine cacheEngine;
|
||||||
|
|
||||||
|
private IModFile mfix$resolveFileOverride;
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void cacheResources(CallbackInfo ci) {
|
private void cacheResources(String packId, boolean isBuiltin, final Path source, CallbackInfo ci) {
|
||||||
|
// handle buggy mods instantiating at the root path, but only if they didn't override at all
|
||||||
|
// (otherwise they may have handled resolve() already)
|
||||||
|
if(((Object)this).getClass() == PathPackResources.class)
|
||||||
|
this.mfix$resolveFileOverride = ModResourcePackPathFixer.getModFileByRootPath(source);
|
||||||
|
if(this.mfix$resolveFileOverride != null)
|
||||||
|
ModernFix.LOGGER.warn("PathResourcePack base class instantiated with root path of mod file {}. This probably means a mod should be calling ResourcePackLoader.createPackForMod instead. Applying workaround.", mfix$resolveFileOverride.getFileName());
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
PackResourcesCacheEngine.track(this);
|
PackResourcesCacheEngine.track(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "resolve", at = @At("HEAD"), cancellable = true, remap = false)
|
||||||
|
private void resolveViaModFile(String[] paths, CallbackInfoReturnable<Path> cir) {
|
||||||
|
if(this.mfix$resolveFileOverride != null)
|
||||||
|
cir.setReturnValue(this.mfix$resolveFileOverride.findResource(paths));
|
||||||
|
}
|
||||||
|
|
||||||
private PackResourcesCacheEngine generateResourceCache() {
|
private PackResourcesCacheEngine generateResourceCache() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
PackResourcesCacheEngine engine = this.cacheEngine;
|
PackResourcesCacheEngine engine = this.cacheEngine;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user