rc1, work around a known bug with fabulous shaders

This commit is contained in:
JFronny 2021-11-25 19:15:50 +01:00
parent 61306eef50
commit b985879809
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
6 changed files with 48 additions and 31 deletions

View File

@ -2,16 +2,15 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.18-pre4
yarn_mappings=build.9
minecraft_version=1.18-rc1
yarn_mappings=build.1
loader_version=0.12.5
# Mod Properties
mod_version=2.8.3
maven_group=io.gitlab.jfronny
archives_base_name=respackopts
# Dependencies
fabric_version=0.42.7+1.18
jfapi_version=2.1.4-412595557
fabric_version=0.43.1+1.18
jfapi_version=2.1.3-416552327
modrinth_id=TiF5QWZY
modrinth_required_dependencies=3CD6YUw1

View File

@ -2,10 +2,10 @@ package io.gitlab.jfronny.respackopts.filters;
import io.gitlab.jfronny.libjf.ResourcePath;
import io.gitlab.jfronny.libjf.data.manipulation.api.UserResourceEvents;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import io.gitlab.jfronny.respackopts.Respackopts;
import io.gitlab.jfronny.respackopts.model.DirRpo;
import io.gitlab.jfronny.respackopts.model.enums.PackCapability;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import io.gitlab.jfronny.respackopts.util.RpoFormatException;
import net.minecraft.resource.ResourcePack;
import net.minecraft.util.Identifier;
@ -19,7 +19,7 @@ public class DirFilterEventImpl {
public static void init() {
UserResourceEvents.OPEN.register((type, id, previous, pack) -> {
if (!MetaCache.hasCapability(pack, PackCapability.DirFilter))
return previous;
return previous.get();
String path = new ResourcePath(type, id).getName();
DirRpo rpo = findDirRpo(pack, path);
if (rpo != null && dirHidden(rpo, MetaCache.getId(pack))) {
@ -28,16 +28,17 @@ public class DirFilterEventImpl {
ResourcePath rp = new ResourcePath(path);
return pack.open(rp.getType(), rp.getId());
}
return previous;
return previous.get();
});
UserResourceEvents.FIND_RESOURCE.register((type, namespace, prefix, maxDepth, pathFilter, previous, pack) -> {
// Warning: the Identifiers here DON'T CONTAIN THE TYPE!
// Therefore, it needs to be added when calling a method that generates a ResourcePath!
Collection<Identifier> prevVals = previous.get();
if (!MetaCache.hasCapability(pack, PackCapability.DirFilter))
return previous;
Collection<Identifier> nextRes = new LinkedHashSet<>(previous);
return prevVals;
Collection<Identifier> nextRes = new LinkedHashSet<>(prevVals);
boolean dirFilterAdditive = MetaCache.hasCapability(pack, PackCapability.DirFilterAdditive);
for (Identifier identifier : previous) {
for (Identifier identifier : prevVals) {
String path = type.getDirectory() + "/" + identifier.getNamespace() + "/" + identifier.getPath();
DirRpo rpo = findDirRpo(pack, path);
if (rpo != null) {
@ -66,7 +67,7 @@ public class DirFilterEventImpl {
});
UserResourceEvents.CONTAINS.register((type, id, previous, pack) -> {
if (!MetaCache.hasCapability(pack, PackCapability.DirFilter))
return previous;
return previous.get();
String path = new ResourcePath(type, id).getName();
DirRpo rpo = findDirRpo(pack, path);
if (rpo != null && dirHidden(rpo, MetaCache.getId(pack))) {
@ -76,7 +77,7 @@ public class DirFilterEventImpl {
ResourcePath rp = new ResourcePath(path);
return pack.contains(rp.getType(), rp.getId());
}
return previous;
return previous.get();
});
}

View File

@ -11,6 +11,7 @@ import net.minecraft.resource.AbstractFileResourcePack;
import net.minecraft.resource.ResourcePack;
import net.minecraft.util.Identifier;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -28,32 +29,33 @@ public class FileFilterEventImpl {
public static void init() {
UserResourceEvents.OPEN.register((type, id, previous, pack) -> {
if (skip(pack)) return previous;
if (skip(pack)) return previous.get();
String name = new ResourcePath(type, id).getName();
if (pack.contains(type, id)) {
return containsFileWasFallback()
? FileFallbackProvider.getReplacement(pack, name)
: FileExpansionProvider.replace(previous, pack, name);
: FileExpansionProvider.replace(previous.get(), pack, name);
}
else return null;
});
UserResourceEvents.FIND_RESOURCE.register((type, namespace, prefix, maxDepth, pathFilter, previous, pack) -> {
// Warning: the Identifiers here DON'T CONTAIN THE TYPE!
// Therefore, it needs to be added when calling a method that generates a ResourcePath!
if (skip(pack)) return previous;
previous.removeIf(s -> {
Collection<Identifier> prevVals = previous.get();
if (skip(pack)) return prevVals;
prevVals.removeIf(s -> {
String fileName = type.getDirectory() + "/" + s.getNamespace() + "/" + s.getPath();
return FileExclusionProvider.fileHidden(pack, fileName) && !FileFallbackProvider.fileHasFallback(pack, fileName);
});
// Completion of the path is handled separately here
FileFallbackProvider.addFallbackResources(pack, previous, namespace, type);
return previous;
FileFallbackProvider.addFallbackResources(pack, prevVals, namespace, type);
return prevVals;
});
UserResourceEvents.CONTAINS.register((type, id, previous, pack) -> {
if (skip(pack)) return previous;
if (skip(pack)) return previous.get();
containsFileWasFallback(false);
String name = new ResourcePath(type, id).getName();
if (previous) {
if (previous.get()) {
if (FileExclusionProvider.fileHidden(pack, name)) {
if (FileFallbackProvider.fileHasFallback(pack, name)) {
containsFileWasFallback(true);

View File

@ -8,8 +8,9 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(GLImportProcessor.class)
public class GLImportProcessorMixin {
private static final String respackopts$prefix = "\n//include " + Respackopts.RPO_SHADER_ID;
@ModifyArg(method = "readSource(Ljava/lang/String;)Ljava/util/List;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gl/GLImportProcessor;parseImports(Ljava/lang/String;Lnet/minecraft/client/gl/GLImportProcessor$Context;Ljava/lang/String;)Ljava/util/List;"), index = 0)
private String modify(String value) {
return value.replace("\n//include " + Respackopts.RPO_SHADER_ID, "\n" + Respackopts.getShaderImportSource());
return value.replace(respackopts$prefix, "\n" + Respackopts.getShaderImportSource());
}
}

View File

@ -6,6 +6,7 @@ import io.gitlab.jfronny.respackopts.model.PackMeta;
import net.minecraft.resource.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -13,15 +14,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Mixin(ResourcePackManager.class)
public class ResourcePackManagerMixin {
@Shadow private Map<String, ResourcePackProfile> profiles;
@Unique private final Set<String> packIds = new HashSet<>();
@Inject(at = @At("TAIL"), method = "scanPacks()V")
private void scanPacks(CallbackInfo info) {
MetaCache.clear();
Set<String> toRemove = new HashSet<>(packIds);
packIds.clear();
profiles.forEach((s, v) -> {
ResourcePack rpi = v.createResourcePack();
ResourceType packConfType = null;
@ -49,11 +54,16 @@ public class ResourcePackManagerMixin {
else {
MetaCache.addFromScan(displayName, packName, conf, Respackopts.FALLBACK_CONF_DIR.resolve(conf.id + ".json"));
}
packIds.add(conf.id);
toRemove.remove(conf.id);
} catch (Throwable e) {
Respackopts.LOGGER.error("Could not initialize pack meta for " + s, e);
}
}
});
for (String s : toRemove) {
MetaCache.remove(s);
}
MetaCache.save();
}
}

View File

@ -28,14 +28,14 @@ public class MetaCache {
private static final Map<String, String> PACK_NAME_LOOKUP = new HashMap<>(); // pack name -> pack id
public static final Map<String, Map<String, DirRpo>> DIR_RPOS = new HashMap<>(); // pack id -> .rpo path -> parsed .rpo
public static final Map<String, Map<String, FileRpo>> FILE_RPOS = new HashMap<>(); // pack id -> .rpo path -> parsed .rpo
public static void clear() {
CONFIG_BRANCH.clear();
PACK_METAS.clear();
DATA_LOCATIONS.clear();
DISPLAY_NAME_LOOKUP.clear();
PACK_NAME_LOOKUP.clear();
DIR_RPOS.clear();
FILE_RPOS.clear();
public static void remove(String packId) {
CONFIG_BRANCH.remove(packId);
PACK_METAS.remove(packId);
DATA_LOCATIONS.remove(packId);
DISPLAY_NAME_LOOKUP.remove(packId);
//PACK_NAME_LOOKUP
DIR_RPOS.remove(packId);
FILE_RPOS.remove(packId);
}
public static void addFromScan(String displayName, String packName, PackMeta meta, Path dataLocation) {
@ -44,6 +44,7 @@ public class MetaCache {
}
meta.conf.setVersion(meta.version);
if (meta.version < 5) meta.capabilities.add(PackCapability.DirFilter);
remove(meta.id);
if (CONFIG_BRANCH.containsKey(meta.id))
CONFIG_BRANCH.get(meta.id).sync(meta.conf, ConfigSyncMode.RESPACK_LOAD);
else
@ -128,6 +129,9 @@ public class MetaCache {
public static boolean hasCapability(ResourcePack pack, PackCapability capability) {
String id = getId(pack);
if (id == null) return false;
if (!PACK_METAS.containsKey(id)) {
throw new NullPointerException("Could not get pack \"" + id + "\" (available: " + String.join(", ", PACK_METAS.keySet()) + ")");
}
return PACK_METAS.get(id).capabilities.contains(capability);
}