Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
91d7e0f1f9
|
|
@ -10,6 +10,7 @@ import org.apache.commons.lang3.tuple.Triple;
|
|||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.util.CachedResourcePath;
|
||||
import org.embeddedt.modernfix.util.FileUtil;
|
||||
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
|
@ -83,7 +84,8 @@ public abstract class PathResourcePackMixin {
|
|||
rootListingForNamespaces.put(namespace, Collections.emptyList());
|
||||
}
|
||||
}
|
||||
rootListingByNamespaceAndType.put(type, rootListingForNamespaces);
|
||||
if(PackTypeHelper.isVanillaPackType(type))
|
||||
rootListingByNamespaceAndType.put(type, rootListingForNamespaces);
|
||||
}
|
||||
this.rootListingByNamespaceAndType = rootListingByNamespaceAndType;
|
||||
this.containedPaths = containedPaths;
|
||||
|
|
@ -107,6 +109,8 @@ public abstract class PathResourcePackMixin {
|
|||
|
||||
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
|
||||
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
||||
if(!PackTypeHelper.isVanillaPackType(type))
|
||||
return;
|
||||
Set<String> cachedNamespaces;
|
||||
synchronized (this.namespacesByType) {
|
||||
cachedNamespaces = this.namespacesByType.get(type);
|
||||
|
|
@ -118,6 +122,8 @@ public abstract class PathResourcePackMixin {
|
|||
|
||||
@Inject(method = "getNamespaces", at = @At("TAIL"))
|
||||
private void storeCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
||||
if(!PackTypeHelper.isVanillaPackType(type))
|
||||
return;
|
||||
synchronized (this.namespacesByType) {
|
||||
this.namespacesByType.put(type, cir.getReturnValue());
|
||||
}
|
||||
|
|
@ -136,6 +142,8 @@ public abstract class PathResourcePackMixin {
|
|||
@Inject(method = "getResources", at = @At("HEAD"), cancellable = true)
|
||||
public void getResources(PackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<String> filter, CallbackInfoReturnable<Collection<ResourceLocation>> cir)
|
||||
{
|
||||
if(!PackTypeHelper.isVanillaPackType(type))
|
||||
return;
|
||||
this.generateResourceCache();
|
||||
if(!pathIn.endsWith("/"))
|
||||
pathIn = pathIn + "/";
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
|||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.embeddedt.modernfix.FileWalker;
|
||||
import org.embeddedt.modernfix.util.FileUtil;
|
||||
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
|
@ -43,6 +44,8 @@ public class VanillaPackResourcesMixin {
|
|||
containedPaths = new HashSet<>();
|
||||
Joiner slashJoiner = Joiner.on('/');
|
||||
for(PackType type : PackType.values()) {
|
||||
if(!PackTypeHelper.isVanillaPackType(type))
|
||||
continue;
|
||||
Path root = ROOT_DIR_BY_TYPE.get(type);
|
||||
if(root == null)
|
||||
throw new IllegalStateException("No filesystem for vanilla " + type.name() + " assets");
|
||||
|
|
@ -72,6 +75,8 @@ public class VanillaPackResourcesMixin {
|
|||
|
||||
@Inject(method = "hasResource", at = @At(value = "INVOKE", target = "Ljava/lang/Class;getResource(Ljava/lang/String;)Ljava/net/URL;"), cancellable = true)
|
||||
private void useCacheForExistence(PackType type, ResourceLocation location, CallbackInfoReturnable<Boolean> cir) {
|
||||
if(!PackTypeHelper.isVanillaPackType(type))
|
||||
return;
|
||||
cir.setReturnValue(containedPaths.contains(type.getDirectory() + "/" + location.getNamespace() + "/" + FileUtil.normalize(location.getPath())));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package org.embeddedt.modernfix.util;
|
||||
|
||||
import net.minecraft.server.packs.PackType;
|
||||
|
||||
public class PackTypeHelper {
|
||||
public static boolean isVanillaPackType(PackType type) {
|
||||
return type == PackType.CLIENT_RESOURCES || type == PackType.SERVER_DATA;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user