Fix KubeJS resources not being scanned for textures
This commit is contained in:
parent
a2af0cf835
commit
a6d924535e
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.embeddedt.modernfix.dynamicresources;
|
||||||
|
|
||||||
|
import dev.latvian.kubejs.script.data.KubeJSResourcePack;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.PackResources;
|
||||||
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import org.embeddedt.modernfix.util.FileUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class ResourcePackHandler {
|
||||||
|
private static final List<PackHandler> packHandlers = new ArrayList<>();
|
||||||
|
public static Collection<ResourceLocation> getExtraResources(ResourceManager manager, String path, Predicate<String> matchPredicate) {
|
||||||
|
final String normalizedPath = FileUtil.normalize(path);
|
||||||
|
return manager.listPacks().flatMap(pack -> packHandlers.stream().flatMap(handler -> {
|
||||||
|
if(handler.shouldHandle(pack)) {
|
||||||
|
return handler.getExtraResources(pack, normalizedPath, matchPredicate);
|
||||||
|
} else
|
||||||
|
return Stream.of();
|
||||||
|
})).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PackHandler {
|
||||||
|
Stream<ResourceLocation> getExtraResources(PackResources pack, String path, Predicate<String> matchPredicate);
|
||||||
|
boolean shouldHandle(PackResources pack);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class KubeJSPackHandler implements PackHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<ResourceLocation> getExtraResources(PackResources pack, String path, Predicate<String> matchPredicate) {
|
||||||
|
KubeJSResourcePack p = (KubeJSResourcePack)pack;
|
||||||
|
return p.getCachedResources().keySet().stream()
|
||||||
|
.filter(l -> l.getPath().startsWith(path))
|
||||||
|
.filter(l -> matchPredicate.test(l.getPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldHandle(PackResources pack) {
|
||||||
|
return pack instanceof KubeJSResourcePack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
if(ModList.get().isLoaded("kubejs")) {
|
||||||
|
packHandlers.add(new KubeJSPackHandler());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,7 @@ import org.apache.logging.log4j.Logger;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
import org.embeddedt.modernfix.dynamicresources.DynamicBakedModelProvider;
|
import org.embeddedt.modernfix.dynamicresources.DynamicBakedModelProvider;
|
||||||
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
|
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
|
||||||
|
import org.embeddedt.modernfix.dynamicresources.ResourcePackHandler;
|
||||||
import org.spongepowered.asm.mixin.*;
|
import org.spongepowered.asm.mixin.*;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
|
@ -159,7 +160,9 @@ public abstract class ModelBakeryMixin {
|
||||||
*/
|
*/
|
||||||
private void gatherModelMaterials(Set<Material> materialSet) {
|
private void gatherModelMaterials(Set<Material> materialSet) {
|
||||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
Collection<ResourceLocation> allModels = this.resourceManager.listResources("models", path -> path.endsWith(".json"));
|
List<ResourceLocation> allModels = new ArrayList<>(this.resourceManager.listResources("models", path -> path.endsWith(".json")));
|
||||||
|
// for KubeJS, etc.
|
||||||
|
allModels.addAll(ResourcePackHandler.getExtraResources(this.resourceManager, "models", path -> path.endsWith(".json")));
|
||||||
List<CompletableFuture<Pair<ResourceLocation, JsonElement>>> modelBytes = new ArrayList<>();
|
List<CompletableFuture<Pair<ResourceLocation, JsonElement>>> modelBytes = new ArrayList<>();
|
||||||
for(ResourceLocation fileLocation : allModels) {
|
for(ResourceLocation fileLocation : allModels) {
|
||||||
modelBytes.add(CompletableFuture.supplyAsync(() -> {
|
modelBytes.add(CompletableFuture.supplyAsync(() -> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user