58 lines
2.0 KiB
Java
58 lines
2.0 KiB
Java
package io.gitlab.jfronny.resclone;
|
|
|
|
import net.fabricmc.fabric.api.resource.ModResourcePack;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
|
import net.minecraft.resource.*;
|
|
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class RescloneResourcePack extends ZipResourcePack implements ModResourcePack {
|
|
private static final ModMetadata METADATA = FabricLoader.getInstance().getModContainer(Resclone.MOD_ID).orElseThrow().getMetadata();
|
|
private final String name;
|
|
|
|
RescloneResourcePack(ZipFileWrapper file, String name, String overlay) {
|
|
super(name, file, true, overlay);
|
|
this.name = name;
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
@Override
|
|
public ModMetadata getFabricModMetadata() {
|
|
return METADATA;
|
|
}
|
|
|
|
public static class Factory implements ResourcePackProfile.PackFactory {
|
|
private final File file;
|
|
private final String name;
|
|
|
|
public Factory(File file, String name) {
|
|
this.file = file;
|
|
this.name = name;
|
|
}
|
|
|
|
@Override
|
|
public ResourcePack open(String name) {
|
|
ZipFileWrapper zipFileWrapper = new ZipFileWrapper(this.file);
|
|
return new RescloneResourcePack(zipFileWrapper, this.name, "");
|
|
}
|
|
|
|
@Override
|
|
public ResourcePack openWithOverlays(String name, ResourcePackProfile.Metadata metadata) {
|
|
ZipFileWrapper zipFileWrapper = new ZipFileWrapper(this.file);
|
|
ZipResourcePack resourcePack = new RescloneResourcePack(zipFileWrapper, this.name, "");
|
|
List<String> overlays = metadata.overlays();
|
|
if (overlays.isEmpty()) return resourcePack;
|
|
List<ResourcePack> overlayPacks = new ArrayList<>(overlays.size());
|
|
for (String string : overlays) overlayPacks.add(new RescloneResourcePack(zipFileWrapper, this.name, string));
|
|
return new OverlayResourcePack(resourcePack, overlayPacks);
|
|
}
|
|
}
|
|
}
|