Wrap AbstractFileResourcePacks in ReloadableResourceManagerImpl instead of mixing into implementations. Might cause compatibility issues though. (I should make an API for this since I use this in basically every mod :think:)
This commit is contained in:
parent
3ba6a8a3df
commit
672f8be302
|
@ -20,7 +20,9 @@ dependencies {
|
||||||
modImplementation "com.terraformersmc:modmenu:2.0.2"
|
modImplementation "com.terraformersmc:modmenu:2.0.2"
|
||||||
|
|
||||||
modApi("me.shedaniel.cloth:cloth-config-fabric:5.0.34")
|
modApi("me.shedaniel.cloth:cloth-config-fabric:5.0.34")
|
||||||
modImplementation("grondag:canvas-mc117-1.17:+") {
|
|
||||||
|
modCompileOnly "grondag:frex-mc117:+"
|
||||||
|
modRuntime("grondag:canvas-mc117-1.17:+") {
|
||||||
exclude(group: "me.shedaniel.cloth")
|
exclude(group: "me.shedaniel.cloth")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ public class GuiFactory {
|
||||||
for (Map.Entry<String, ConfigEntry<?>> in : source.getValue().entrySet()) {
|
for (Map.Entry<String, ConfigEntry<?>> in : source.getValue().entrySet()) {
|
||||||
ConfigEntry<?> entry = in.getValue();
|
ConfigEntry<?> entry = in.getValue();
|
||||||
String entryName = ("".equals(namePrefix) ? "" : namePrefix + ".") + in.getKey();
|
String entryName = ("".equals(namePrefix) ? "" : namePrefix + ".") + in.getKey();
|
||||||
Respackopts.LOGGER.info(entryName);
|
|
||||||
String translationPrefix = (source.getVersion() < 3 ? "respackopts." + entry.getEntryType() + "." : "rpo.") + screenId;
|
String translationPrefix = (source.getVersion() < 3 ? "respackopts." + entry.getEntryType() + "." : "rpo.") + screenId;
|
||||||
config.accept(entry.buildEntry(entryBuilder,
|
config.accept(entry.buildEntry(entryBuilder,
|
||||||
getText(entryName, translationPrefix),
|
getText(entryName, translationPrefix),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.function.Supplier;
|
||||||
public class ConfigBooleanEntry extends ConfigEntry<Boolean> {
|
public class ConfigBooleanEntry extends ConfigEntry<Boolean> {
|
||||||
public ConfigBooleanEntry(boolean v) {
|
public ConfigBooleanEntry(boolean v) {
|
||||||
setValue(v);
|
setValue(v);
|
||||||
|
setDefault(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package io.gitlab.jfronny.respackopts.filters;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public interface FileOpenProvider {
|
|
||||||
InputStream open(String file) throws IOException;
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package io.gitlab.jfronny.respackopts.filters;
|
|
||||||
|
|
||||||
import io.gitlab.jfronny.respackopts.filters.conditions.ResourcePackFilter;
|
|
||||||
import io.gitlab.jfronny.respackopts.filters.fallback.FallbackFilter;
|
|
||||||
import net.minecraft.resource.ResourceNotFoundException;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class FilterProvider {
|
|
||||||
ResourcePackFilter rpo;
|
|
||||||
FallbackFilter fbt;
|
|
||||||
Predicate<String> containsFileBase;
|
|
||||||
boolean containsFileWasFallback = false;
|
|
||||||
public FilterProvider(Predicate<String> containsFileBase, FileOpenProvider openFileBase) {
|
|
||||||
this.containsFileBase = containsFileBase;
|
|
||||||
rpo = new ResourcePackFilter(containsFileBase, openFileBase);
|
|
||||||
fbt = new FallbackFilter(containsFileBase, openFileBase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openFile(String name, File base, CallbackInfoReturnable<InputStream> info) throws IOException {
|
|
||||||
if (containsFileBase.test(name) && containsFileWasFallback) {
|
|
||||||
info.setReturnValue(fbt.getReplacement(name, new ResourceNotFoundException(base, name)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void containsFile(String name, CallbackInfoReturnable<Boolean> info) {
|
|
||||||
containsFileWasFallback = false;
|
|
||||||
if (info.getReturnValueZ()) {
|
|
||||||
if (rpo.fileHidden(name)) {
|
|
||||||
if (fbt.fileVisible(name)) {
|
|
||||||
containsFileWasFallback = true;
|
|
||||||
} else {
|
|
||||||
info.setReturnValue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (fbt.fileVisible(name)) {
|
|
||||||
containsFileWasFallback = true;
|
|
||||||
info.setReturnValue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void findResources(String namespace, CallbackInfoReturnable<Collection<Identifier>> info) {
|
|
||||||
Collection<Identifier> ret = info.getReturnValue();
|
|
||||||
ret.removeIf(s -> rpo.fileHidden(s.getPath()) && !fbt.fileVisible(namespace));
|
|
||||||
fbt.addFallbackResources(ret, namespace);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
package io.gitlab.jfronny.respackopts.filters;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.lambda.FileContainedProvider;
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.lambda.Tuple;
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.conditions.ResourcePackFilter;
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.fallback.FallbackFilter;
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.lambda.FileOpenProvider;
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.lambda.PathSplitter;
|
||||||
|
import net.minecraft.resource.ResourcePack;
|
||||||
|
import net.minecraft.resource.ResourceType;
|
||||||
|
import net.minecraft.resource.metadata.ResourceMetadataReader;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class WrappedPack implements ResourcePack {
|
||||||
|
public WrappedPack(ResourcePack pack) {
|
||||||
|
this.pack = pack;
|
||||||
|
PathSplitter pathGetter = s -> {
|
||||||
|
String[] s1 = s.split("/", 3);
|
||||||
|
if (s1.length != 3) {
|
||||||
|
throw new IOException("Could not split path string into resource type and ID due to insufficient length: " + s);
|
||||||
|
}
|
||||||
|
ResourceType rt = switch (s1[0]) {
|
||||||
|
case "assets" -> ResourceType.CLIENT_RESOURCES;
|
||||||
|
case "data" -> ResourceType.SERVER_DATA;
|
||||||
|
default -> throw new IllegalStateException("Unexpected value for resource type: " + s1[0] + " in: " + s);
|
||||||
|
};
|
||||||
|
return new Tuple<>(rt, new Identifier(s1[1], s1[2]));
|
||||||
|
};
|
||||||
|
FileContainedProvider contains = s -> {
|
||||||
|
Tuple<ResourceType, Identifier> p = pathGetter.split(s);
|
||||||
|
return this.pack.contains(p.left(), p.right());
|
||||||
|
};
|
||||||
|
FileOpenProvider open = s -> {
|
||||||
|
Tuple<ResourceType, Identifier> p = pathGetter.split(s);
|
||||||
|
return this.pack.open(p.left(), p.right());
|
||||||
|
};
|
||||||
|
rpo = new ResourcePackFilter(contains, open);
|
||||||
|
fbt = new FallbackFilter(contains, open);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourcePack pack;
|
||||||
|
boolean containsFileWasFallback = false;
|
||||||
|
ResourcePackFilter rpo;
|
||||||
|
FallbackFilter fbt;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public InputStream openRoot(String fileName) throws IOException {
|
||||||
|
return pack.openRoot(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream open(ResourceType type, Identifier id) throws IOException {
|
||||||
|
if (pack.contains(type, id) && containsFileWasFallback) {
|
||||||
|
return fbt.getReplacement(getFilename(type, id), new FileNotFoundException());
|
||||||
|
}
|
||||||
|
return pack.open(type, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter) {
|
||||||
|
Collection<Identifier> ret = pack.findResources(type, namespace, prefix, maxDepth, pathFilter);
|
||||||
|
ret.removeIf(s -> rpo.fileHidden(s.getPath()) && !fbt.fileVisible(namespace));
|
||||||
|
fbt.addFallbackResources(ret, namespace);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(ResourceType type, Identifier id) {
|
||||||
|
containsFileWasFallback = false;
|
||||||
|
String name = getFilename(type, id);
|
||||||
|
if (pack.contains(type, id)) {
|
||||||
|
if (rpo.fileHidden(name)) {
|
||||||
|
if (fbt.fileVisible(name)) {
|
||||||
|
containsFileWasFallback = true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (pack.contains(type, new Identifier(id.getNamespace(), id.getPath() + ".rpo")) && fbt.fileVisible(name)) { // only try to check fbt if .rpo exists
|
||||||
|
containsFileWasFallback = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getNamespaces(ResourceType type) {
|
||||||
|
return pack.getNamespaces(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public <T> T parseMetadata(ResourceMetadataReader<T> metaReader) throws IOException {
|
||||||
|
return pack.parseMetadata(metaReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return pack.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
pack.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFilename(ResourceType type, Identifier id) {
|
||||||
|
return String.format("%s/%s/%s", type.getDirectory(), id.getNamespace(), id.getPath());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,17 +2,18 @@ package io.gitlab.jfronny.respackopts.filters.conditions;
|
||||||
|
|
||||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||||
import io.gitlab.jfronny.respackopts.data.Rpo;
|
import io.gitlab.jfronny.respackopts.data.Rpo;
|
||||||
import io.gitlab.jfronny.respackopts.filters.FileOpenProvider;
|
import io.gitlab.jfronny.respackopts.filters.lambda.FileContainedProvider;
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.lambda.FileOpenProvider;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class ResourcePackFilter {
|
public class ResourcePackFilter {
|
||||||
Predicate<String> containsFileBase;
|
FileContainedProvider containsFileBase;
|
||||||
FileOpenProvider openFileBase;
|
FileOpenProvider openFileBase;
|
||||||
public ResourcePackFilter(Predicate<String> containsFileBase, FileOpenProvider openFileBase) {
|
public ResourcePackFilter(FileContainedProvider containsFileBase, FileOpenProvider openFileBase) {
|
||||||
this.containsFileBase = containsFileBase;
|
this.containsFileBase = containsFileBase;
|
||||||
this.openFileBase = openFileBase;
|
this.openFileBase = openFileBase;
|
||||||
}
|
}
|
||||||
|
@ -20,8 +21,13 @@ public class ResourcePackFilter {
|
||||||
public boolean fileHidden(String name) {
|
public boolean fileHidden(String name) {
|
||||||
if (name.endsWith(Respackopts.FILE_EXTENSION))
|
if (name.endsWith(Respackopts.FILE_EXTENSION))
|
||||||
return false;
|
return false;
|
||||||
if (!containsFileBase.test(name + Respackopts.FILE_EXTENSION))
|
try {
|
||||||
|
if (!containsFileBase.contains(name + Respackopts.FILE_EXTENSION))
|
||||||
|
return false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
Respackopts.LOGGER.error(e);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
try (InputStream stream = openFileBase.open(name + Respackopts.FILE_EXTENSION); Reader w = new InputStreamReader(stream)) {
|
try (InputStream stream = openFileBase.open(name + Respackopts.FILE_EXTENSION); Reader w = new InputStreamReader(stream)) {
|
||||||
Rpo rpo = Respackopts.GSON.fromJson(w, Rpo.class);
|
Rpo rpo = Respackopts.GSON.fromJson(w, Rpo.class);
|
||||||
if (rpo.conditions == null)
|
if (rpo.conditions == null)
|
||||||
|
|
|
@ -2,8 +2,8 @@ package io.gitlab.jfronny.respackopts.filters.fallback;
|
||||||
|
|
||||||
import io.gitlab.jfronny.respackopts.Respackopts;
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
||||||
import io.gitlab.jfronny.respackopts.data.Rpo;
|
import io.gitlab.jfronny.respackopts.data.Rpo;
|
||||||
import io.gitlab.jfronny.respackopts.filters.FileOpenProvider;
|
import io.gitlab.jfronny.respackopts.filters.lambda.FileContainedProvider;
|
||||||
import net.minecraft.resource.ResourceNotFoundException;
|
import io.gitlab.jfronny.respackopts.filters.lambda.FileOpenProvider;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -12,12 +12,11 @@ import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class FallbackFilter {
|
public class FallbackFilter {
|
||||||
Predicate<String> containsFileBase;
|
FileContainedProvider containsFileBase;
|
||||||
FileOpenProvider openFileBase;
|
FileOpenProvider openFileBase;
|
||||||
public FallbackFilter(Predicate<String> containsFileBase, FileOpenProvider openFileBase) {
|
public FallbackFilter(FileContainedProvider containsFileBase, FileOpenProvider openFileBase) {
|
||||||
this.containsFileBase = containsFileBase;
|
this.containsFileBase = containsFileBase;
|
||||||
this.openFileBase = openFileBase;
|
this.openFileBase = openFileBase;
|
||||||
}
|
}
|
||||||
|
@ -26,32 +25,32 @@ public class FallbackFilter {
|
||||||
if (name.endsWith(Respackopts.FILE_EXTENSION))
|
if (name.endsWith(Respackopts.FILE_EXTENSION))
|
||||||
return false;
|
return false;
|
||||||
String fbt = name + Respackopts.FILE_EXTENSION;
|
String fbt = name + Respackopts.FILE_EXTENSION;
|
||||||
if (containsFileBase.test(fbt)) {
|
try (InputStream stream = openFileBase.open(fbt); Reader w = new InputStreamReader(stream)) {
|
||||||
try (InputStream stream = openFileBase.open(fbt); Reader w = new InputStreamReader(stream)) {
|
if (containsFileBase.contains(fbt)) {
|
||||||
Rpo rpo = Respackopts.GSON.fromJson(w, Rpo.class);
|
Rpo rpo = Respackopts.GSON.fromJson(w, Rpo.class);
|
||||||
if (rpo.fallbacks != null) {
|
if (rpo.fallbacks != null) {
|
||||||
List<String> arr = rpo.fallbacks;
|
List<String> arr = rpo.fallbacks;
|
||||||
for (String s : arr) {
|
for (String s : arr) {
|
||||||
if (containsFileBase.test(s))
|
if (containsFileBase.contains(s))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
}
|
||||||
Respackopts.LOGGER.error("Could not determine visibility of " + name + e);
|
catch (IOException e) {
|
||||||
}
|
Respackopts.LOGGER.error("Could not determine visibility of " + name, e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getReplacement(String name, ResourceNotFoundException ex) throws ResourceNotFoundException {
|
public InputStream getReplacement(String name, IOException ex) throws IOException {
|
||||||
String fbt = name + Respackopts.FILE_EXTENSION;
|
String fbt = name + Respackopts.FILE_EXTENSION;
|
||||||
try (InputStream stream = openFileBase.open(fbt); Reader w = new InputStreamReader(stream)) {
|
try (InputStream stream = openFileBase.open(fbt); Reader w = new InputStreamReader(stream)) {
|
||||||
Rpo rpo = Respackopts.GSON.fromJson(w, Rpo.class);
|
Rpo rpo = Respackopts.GSON.fromJson(w, Rpo.class);
|
||||||
if (rpo.fallbacks != null) {
|
if (rpo.fallbacks != null) {
|
||||||
List<String> arr = rpo.fallbacks;
|
List<String> arr = rpo.fallbacks;
|
||||||
for (String s : arr) {
|
for (String s : arr) {
|
||||||
if (containsFileBase.test(s))
|
if (containsFileBase.contains(s))
|
||||||
return openFileBase.open(s);
|
return openFileBase.open(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package io.gitlab.jfronny.respackopts.filters.lambda;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface FileContainedProvider {
|
||||||
|
boolean contains(String name) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.gitlab.jfronny.respackopts.filters.lambda;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public interface FileOpenProvider {
|
||||||
|
InputStream open(String name) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package io.gitlab.jfronny.respackopts.filters.lambda;
|
||||||
|
|
||||||
|
import net.minecraft.resource.ResourceType;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface PathSplitter {
|
||||||
|
Tuple<ResourceType, Identifier> split(String name) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package io.gitlab.jfronny.respackopts.filters.lambda;
|
||||||
|
|
||||||
|
public record Tuple<T1, T2>(T1 left, T2 right) {
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package io.gitlab.jfronny.respackopts.mixin;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.respackopts.filters.WrappedPack;
|
||||||
|
import net.minecraft.resource.AbstractFileResourcePack;
|
||||||
|
import net.minecraft.resource.ReloadableResourceManagerImpl;
|
||||||
|
import net.minecraft.resource.ResourcePack;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
@Mixin(ReloadableResourceManagerImpl.class)
|
||||||
|
public class ReloadableResourceManagerImplMixin {
|
||||||
|
@ModifyVariable(method = "addPack(Lnet/minecraft/resource/ResourcePack;)V", at = @At("HEAD"), argsOnly = true, ordinal = 0)
|
||||||
|
private ResourcePack modifyPack(ResourcePack pack) {
|
||||||
|
if (pack instanceof AbstractFileResourcePack) {
|
||||||
|
return new WrappedPack(pack);
|
||||||
|
}
|
||||||
|
return pack;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,49 +0,0 @@
|
||||||
package io.gitlab.jfronny.respackopts.mixin.conditions;
|
|
||||||
|
|
||||||
import io.gitlab.jfronny.respackopts.filters.FilterProvider;
|
|
||||||
import net.minecraft.resource.AbstractFileResourcePack;
|
|
||||||
import net.minecraft.resource.DirectoryResourcePack;
|
|
||||||
import net.minecraft.resource.ResourceType;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
@Mixin(DirectoryResourcePack.class)
|
|
||||||
public abstract class DirectoryResourcePackMixin extends AbstractFileResourcePack {
|
|
||||||
public DirectoryResourcePackMixin(File base) {
|
|
||||||
super(base);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Shadow protected abstract boolean containsFile(String name);
|
|
||||||
|
|
||||||
@Shadow public abstract Set<String> getNamespaces(ResourceType type);
|
|
||||||
|
|
||||||
@Shadow protected abstract InputStream openFile(String name) throws IOException;
|
|
||||||
|
|
||||||
FilterProvider rpo$filter = new FilterProvider(this::containsFile, this::openFile);
|
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "openFile(Ljava/lang/String;)Ljava/io/InputStream;", cancellable = true)
|
|
||||||
protected void openFile(String name, CallbackInfoReturnable<InputStream> info) throws IOException {
|
|
||||||
rpo$filter.openFile(name, base, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "containsFile(Ljava/lang/String;)Z", cancellable = true)
|
|
||||||
protected void containsFile(String name, CallbackInfoReturnable<Boolean> info) {
|
|
||||||
rpo$filter.containsFile(name, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "findResources(Lnet/minecraft/resource/ResourceType;Ljava/lang/String;Ljava/lang/String;ILjava/util/function/Predicate;)Ljava/util/Collection;")
|
|
||||||
private void findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter, CallbackInfoReturnable<Collection<Identifier>> info) {
|
|
||||||
rpo$filter.findResources(namespace, info);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package io.gitlab.jfronny.respackopts.mixin.conditions;
|
|
||||||
|
|
||||||
import io.gitlab.jfronny.respackopts.filters.FilterProvider;
|
|
||||||
import net.minecraft.resource.AbstractFileResourcePack;
|
|
||||||
import net.minecraft.resource.ResourceType;
|
|
||||||
import net.minecraft.resource.ZipResourcePack;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
@Mixin(ZipResourcePack.class)
|
|
||||||
public abstract class ZipResourcePackMixin extends AbstractFileResourcePack {
|
|
||||||
public ZipResourcePackMixin(File base) {
|
|
||||||
super(base);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Shadow public abstract boolean containsFile(String name);
|
|
||||||
|
|
||||||
@Shadow public abstract Set<String> getNamespaces(ResourceType type);
|
|
||||||
|
|
||||||
@Shadow protected abstract InputStream openFile(String name) throws IOException;
|
|
||||||
|
|
||||||
FilterProvider rpo$filter = new FilterProvider(this::containsFile, this::openFile);
|
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "openFile(Ljava/lang/String;)Ljava/io/InputStream;", cancellable = true)
|
|
||||||
protected void openFile(String name, CallbackInfoReturnable<InputStream> info) throws IOException {
|
|
||||||
rpo$filter.openFile(name, base, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "containsFile(Ljava/lang/String;)Z", cancellable = true)
|
|
||||||
protected void containsFile(String name, CallbackInfoReturnable<Boolean> info) {
|
|
||||||
rpo$filter.containsFile(name, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "findResources(Lnet/minecraft/resource/ResourceType;Ljava/lang/String;Ljava/lang/String;ILjava/util/function/Predicate;)Ljava/util/Collection;")
|
|
||||||
private void findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter, CallbackInfoReturnable<Collection<Identifier>> info) {
|
|
||||||
rpo$filter.findResources(namespace, info);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,11 +4,10 @@
|
||||||
"package": "io.gitlab.jfronny.respackopts.mixin",
|
"package": "io.gitlab.jfronny.respackopts.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"conditions.DirectoryResourcePackMixin",
|
|
||||||
"conditions.ZipResourcePackMixin"
|
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"OptionsScreenMixin",
|
"OptionsScreenMixin",
|
||||||
|
"ReloadableResourceManagerImplMixin",
|
||||||
"ResourcePackEntryMixin",
|
"ResourcePackEntryMixin",
|
||||||
"ResourcePackManagerMixin"
|
"ResourcePackManagerMixin"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user