mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Resource loader for 20w45a. (#1)
* Resource loader for 20w45a. * You have seen nothing.
This commit is contained in:
parent
27eec61ee2
commit
151ba21b21
6 changed files with 26 additions and 10 deletions
fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric
impl/resource/loader
ModNioResourcePack.javaModResourcePackCreator.javaModResourcePackUtil.javaResourceManagerHelperImpl.java
mixin/resource/loader
|
@ -47,16 +47,18 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR
|
|||
private static final Pattern RESOURCE_PACK_PATH = Pattern.compile("[a-z0-9-_]+");
|
||||
private final ModMetadata modInfo;
|
||||
private final Path basePath;
|
||||
private final ResourceType type;
|
||||
private final boolean cacheable;
|
||||
private final AutoCloseable closer;
|
||||
private final String separator;
|
||||
private final String name;
|
||||
private final boolean defaultEnabled;
|
||||
|
||||
public ModNioResourcePack(ModMetadata modInfo, Path path, AutoCloseable closer, String name, boolean defaultEnabled) {
|
||||
public ModNioResourcePack(ModMetadata modInfo, Path path, ResourceType type, AutoCloseable closer, String name, boolean defaultEnabled) {
|
||||
super(null);
|
||||
this.modInfo = modInfo;
|
||||
this.basePath = path.toAbsolutePath().normalize();
|
||||
this.type = type;
|
||||
this.cacheable = false; /* TODO */
|
||||
this.closer = closer;
|
||||
this.separator = basePath.getFileSystem().getSeparator();
|
||||
|
@ -101,7 +103,7 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR
|
|||
}
|
||||
}
|
||||
|
||||
stream = ModResourcePackUtil.openDefault(modInfo, filename);
|
||||
stream = ModResourcePackUtil.openDefault(this.modInfo, this.type, filename);
|
||||
|
||||
if (stream != null) {
|
||||
return stream;
|
||||
|
|
|
@ -19,12 +19,15 @@ package net.fabricmc.fabric.impl.resource.loader;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import net.minecraft.resource.ResourcePackProvider;
|
||||
import net.minecraft.resource.ResourcePackSource;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.resource.metadata.PackResourceMetadata;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
import net.fabricmc.fabric.api.resource.ModResourcePack;
|
||||
|
@ -35,10 +38,22 @@ import net.fabricmc.fabric.api.resource.ModResourcePack;
|
|||
public class ModResourcePackCreator implements ResourcePackProvider {
|
||||
public static final ResourcePackSource RESOURCE_PACK_SOURCE = text -> new TranslatableText("pack.nameAndSource", text, new TranslatableText("pack.source.fabricmod"));
|
||||
public static final ModResourcePackCreator CLIENT_RESOURCE_PACK_PROVIDER = new ModResourcePackCreator(ResourceType.CLIENT_RESOURCES);
|
||||
private final ResourcePackProfile.Factory factory;
|
||||
private final ResourceType type;
|
||||
|
||||
public ModResourcePackCreator(ResourceType type) {
|
||||
this.type = type;
|
||||
this.factory = (name, text, bl, supplier, metadata, initialPosition, source) ->
|
||||
new ResourcePackProfile(name, text, bl, supplier, metadata, type, initialPosition, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the resource packs.
|
||||
*
|
||||
* @param consumer The resource pack profile consumer.
|
||||
*/
|
||||
public void register(Consumer<ResourcePackProfile> consumer) {
|
||||
this.register(consumer, this.factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,8 +35,6 @@ import net.fabricmc.loader.api.metadata.ModMetadata;
|
|||
* Internal utilities for managing resource packs.
|
||||
*/
|
||||
public final class ModResourcePackUtil {
|
||||
public static final int PACK_FORMAT_VERSION = SharedConstants.getGameVersion().getPackVersion();
|
||||
|
||||
private ModResourcePackUtil() { }
|
||||
|
||||
public static void appendModResourcePacks(List<ResourcePack> packList, ResourceType type) {
|
||||
|
@ -46,7 +44,7 @@ public final class ModResourcePackUtil {
|
|||
}
|
||||
|
||||
Path path = container.getRootPath();
|
||||
ResourcePack pack = new ModNioResourcePack(container.getMetadata(), path, null, null, true);
|
||||
ResourcePack pack = new ModNioResourcePack(container.getMetadata(), path, type, null, null, true);
|
||||
|
||||
if (!pack.getNamespaces(type).isEmpty()) {
|
||||
packList.add(pack);
|
||||
|
@ -58,7 +56,7 @@ public final class ModResourcePackUtil {
|
|||
return "pack.mcmeta".equals(filename);
|
||||
}
|
||||
|
||||
public static InputStream openDefault(ModMetadata info, String filename) {
|
||||
public static InputStream openDefault(ModMetadata info, ResourceType type, String filename) {
|
||||
switch (filename) {
|
||||
case "pack.mcmeta":
|
||||
String description = info.getName();
|
||||
|
@ -69,7 +67,7 @@ public final class ModResourcePackUtil {
|
|||
description = description.replaceAll("\"", "\\\"");
|
||||
}
|
||||
|
||||
String pack = String.format("{\"pack\":{\"pack_format\":" + PACK_FORMAT_VERSION + ",\"description\":\"%s\"}}", description);
|
||||
String pack = String.format("{\"pack\":{\"pack_format\":" + type.method_31438(SharedConstants.getGameVersion()) + ",\"description\":\"%s\"}}", description);
|
||||
return IOUtils.toInputStream(pack, Charsets.UTF_8);
|
||||
default:
|
||||
return null;
|
||||
|
|
|
@ -76,7 +76,8 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
|
|||
}
|
||||
|
||||
String name = id.getNamespace() + "/" + id.getPath();
|
||||
builtinResourcePacks.add(new Pair<>(name, new ModNioResourcePack(container.getMetadata(), resourcePackPath, null, name, enabledByDefault)));
|
||||
builtinResourcePacks.add(new Pair<>(name, new ModNioResourcePack(container.getMetadata(), resourcePackPath, ResourceType.CLIENT_RESOURCES, null, name, enabledByDefault)));
|
||||
builtinResourcePacks.add(new Pair<>(name, new ModNioResourcePack(container.getMetadata(), resourcePackPath, ResourceType.SERVER_DATA, null, name, enabledByDefault)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class MixinCreateWorldScreen {
|
|||
private static DataPackSettings onNew(DataPackSettings settings) {
|
||||
ModResourcePackCreator modResourcePackCreator = new ModResourcePackCreator(ResourceType.SERVER_DATA);
|
||||
List<ResourcePackProfile> moddedResourcePacks = new ArrayList<>();
|
||||
modResourcePackCreator.register(moddedResourcePacks::add, ResourcePackProfile::new);
|
||||
modResourcePackCreator.register(moddedResourcePacks::add);
|
||||
|
||||
List<String> enabled = new ArrayList<>(settings.getEnabled());
|
||||
List<String> disabled = new ArrayList<>(settings.getDisabled());
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MixinGameOptions {
|
|||
// Add built-in resource packs if they are enabled by default only if the options file is blank.
|
||||
if (this.resourcePacks.isEmpty()) {
|
||||
List<ResourcePackProfile> profiles = new ArrayList<>();
|
||||
ModResourcePackCreator.CLIENT_RESOURCE_PACK_PROVIDER.register(profiles::add, ResourcePackProfile::new);
|
||||
ModResourcePackCreator.CLIENT_RESOURCE_PACK_PROVIDER.register(profiles::add);
|
||||
this.resourcePacks = new ArrayList<>();
|
||||
|
||||
for (ResourcePackProfile profile : profiles) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue