Merge remote-tracking branch 'origin/1.18' into 1.19.2

This commit is contained in:
embeddedt 2023-04-21 13:41:54 -04:00
commit f3fd986512
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 18 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import net.minecraftforge.resource.PathPackResources;
import org.embeddedt.modernfix.util.CachedResourcePath; import org.embeddedt.modernfix.util.CachedResourcePath;
import org.embeddedt.modernfix.util.FileUtil; import org.embeddedt.modernfix.util.FileUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.embeddedt.modernfix.util.PackTypeHelper;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -87,7 +88,8 @@ public abstract class PathPackResourcesMixin {
rootListingForNamespaces.put(namespace, Collections.emptyList()); rootListingForNamespaces.put(namespace, Collections.emptyList());
} }
} }
rootListingByNamespaceAndType.put(type, rootListingForNamespaces); if(PackTypeHelper.isVanillaPackType(type))
rootListingByNamespaceAndType.put(type, rootListingForNamespaces);
} }
this.rootListingByNamespaceAndType = rootListingByNamespaceAndType; this.rootListingByNamespaceAndType = rootListingByNamespaceAndType;
this.containedPaths = containedPaths; this.containedPaths = containedPaths;
@ -111,6 +113,8 @@ public abstract class PathPackResourcesMixin {
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true) @Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) { private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
if(!PackTypeHelper.isVanillaPackType(type))
return;
Set<String> cachedNamespaces; Set<String> cachedNamespaces;
synchronized (this.namespacesByType) { synchronized (this.namespacesByType) {
cachedNamespaces = this.namespacesByType.get(type); cachedNamespaces = this.namespacesByType.get(type);
@ -122,6 +126,8 @@ public abstract class PathPackResourcesMixin {
@Inject(method = "getNamespaces", at = @At("TAIL")) @Inject(method = "getNamespaces", at = @At("TAIL"))
private void storeCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) { private void storeCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
if(!PackTypeHelper.isVanillaPackType(type))
return;
synchronized (this.namespacesByType) { synchronized (this.namespacesByType) {
this.namespacesByType.put(type, cir.getReturnValue()); this.namespacesByType.put(type, cir.getReturnValue());
} }
@ -140,6 +146,8 @@ public abstract class PathPackResourcesMixin {
@Inject(method = "getResources", at = @At("HEAD"), cancellable = true) @Inject(method = "getResources", at = @At("HEAD"), cancellable = true)
public void getResources(PackType type, String resourceNamespace, String pathIn, Predicate<ResourceLocation> filter, CallbackInfoReturnable<Collection<ResourceLocation>> cir) public void getResources(PackType type, String resourceNamespace, String pathIn, Predicate<ResourceLocation> filter, CallbackInfoReturnable<Collection<ResourceLocation>> cir)
{ {
if(!PackTypeHelper.isVanillaPackType(type))
return;
this.generateResourceCache(); this.generateResourceCache();
if(!pathIn.endsWith("/")) if(!pathIn.endsWith("/"))
pathIn = pathIn + "/"; pathIn = pathIn + "/";

View File

@ -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;
}
}