Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
dffb89390e
|
|
@ -0,0 +1,27 @@
|
|||
package org.embeddedt.modernfix.common.mixin.perf.resourcepacks;
|
||||
|
||||
import net.minecraft.server.packs.PackResources;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.util.Unit;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(ReloadableResourceManager.class)
|
||||
public class ReloadableResourceManagerMixin {
|
||||
@Inject(method = "createReload", at = @At("HEAD"))
|
||||
private void invalidateResourceCaches(Executor backgroundExecutor, Executor gameExecutor, CompletableFuture<Unit> waitingFor, List<PackResources> resourcePacks, CallbackInfoReturnable<?> cir) {
|
||||
ModernFix.LOGGER.info("Invalidating pack caches");
|
||||
for(PackResources pack : resourcePacks) {
|
||||
if(pack instanceof ICachingResourcePack)
|
||||
((ICachingResourcePack)pack).invalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.embeddedt.modernfix.resources;
|
||||
|
||||
public interface ICachingResourcePack {
|
||||
void invalidateCache();
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package org.embeddedt.modernfix.fabric.mixin.perf.fabric_resourcepacks;
|
||||
package org.embeddedt.modernfix.fabric.mixin.perf.resourcepacks;
|
||||
|
||||
import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack;
|
||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.annotation.RequiresMod;
|
||||
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
||||
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
|
@ -21,7 +22,7 @@ import java.util.Set;
|
|||
|
||||
@Mixin(ModNioResourcePack.class)
|
||||
@RequiresMod("fabric-resource-loader-v0")
|
||||
public abstract class ModNioResourcePackMixin {
|
||||
public abstract class ModNioResourcePackMixin implements ICachingResourcePack {
|
||||
@Shadow public abstract Set<String> getNamespaces(PackType type);
|
||||
|
||||
@Shadow @Final private List<Path> basePaths;
|
||||
|
|
@ -30,6 +31,12 @@ public abstract class ModNioResourcePackMixin {
|
|||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void cacheResources(CallbackInfo ci) {
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache() {
|
||||
this.cacheEngine = null;
|
||||
if(this.basePaths.size() == 1) {
|
||||
Path basePath = this.basePaths.get(0);
|
||||
this.cacheEngine = new PackResourcesCacheEngine(this::getNamespaces, (type, namespace) -> {
|
||||
|
|
@ -3,6 +3,7 @@ package org.embeddedt.modernfix.forge.mixin.perf.resourcepacks;
|
|||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.resource.PathResourcePack;
|
||||
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
||||
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
|
@ -17,7 +18,7 @@ import java.util.*;
|
|||
import java.util.function.Predicate;
|
||||
|
||||
@Mixin(PathResourcePack.class)
|
||||
public abstract class ModFileResourcePackMixin {
|
||||
public abstract class ModFileResourcePackMixin implements ICachingResourcePack {
|
||||
@Shadow public abstract Set<String> getNamespaces(PackType type);
|
||||
|
||||
@Shadow protected abstract Path resolve(String... paths);
|
||||
|
|
@ -29,18 +30,26 @@ public abstract class ModFileResourcePackMixin {
|
|||
this.cacheEngine = null;
|
||||
}
|
||||
|
||||
private void generateResourceCache() {
|
||||
private PackResourcesCacheEngine generateResourceCache() {
|
||||
synchronized (this) {
|
||||
if(this.cacheEngine != null)
|
||||
return;
|
||||
this.cacheEngine = new PackResourcesCacheEngine(this::getNamespaces, (type, namespace) -> this.resolve(type.getDirectory(), namespace));
|
||||
PackResourcesCacheEngine engine = this.cacheEngine;
|
||||
if(engine != null)
|
||||
return engine;
|
||||
this.cacheEngine = engine = new PackResourcesCacheEngine(this::getNamespaces, (type, namespace) -> this.resolve(type.getDirectory(), namespace));
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache() {
|
||||
this.cacheEngine = null;
|
||||
}
|
||||
|
||||
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
|
||||
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
||||
if(cacheEngine != null) {
|
||||
Set<String> namespaces = cacheEngine.getNamespaces(type);
|
||||
PackResourcesCacheEngine engine = cacheEngine;
|
||||
if(engine != null) {
|
||||
Set<String> namespaces = engine.getNamespaces(type);
|
||||
if(namespaces != null)
|
||||
cir.setReturnValue(namespaces);
|
||||
}
|
||||
|
|
@ -48,9 +57,9 @@ public abstract class ModFileResourcePackMixin {
|
|||
|
||||
@Inject(method = "hasResource(Ljava/lang/String;)Z", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void useCacheForExistence(String path, CallbackInfoReturnable<Boolean> cir) {
|
||||
this.generateResourceCache();
|
||||
if(cacheEngine != null)
|
||||
cir.setReturnValue(this.cacheEngine.hasResource(path));
|
||||
PackResourcesCacheEngine engine = this.generateResourceCache();
|
||||
if(engine != null)
|
||||
cir.setReturnValue(engine.hasResource(path));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +71,6 @@ public abstract class ModFileResourcePackMixin {
|
|||
{
|
||||
if(!PackTypeHelper.isVanillaPackType(type) || this.cacheEngine == null)
|
||||
return;
|
||||
this.generateResourceCache();
|
||||
cir.setReturnValue(this.cacheEngine.getResources(type, resourceNamespace, pathIn, maxDepth, filter));
|
||||
cir.setReturnValue(this.generateResourceCache().getResources(type, resourceNamespace, pathIn, maxDepth, filter));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user