Fix getName for builtin packs not returning an internal name (#3047)

This commit is contained in:
Technici4n 2023-05-14 15:57:09 +02:00 committed by GitHub
parent 80d07a0ab1
commit 5ade3c3853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 25 deletions

View file

@ -40,7 +40,6 @@ import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourcePackProfile;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack;
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator;
@ -71,7 +70,7 @@ public class GameOptionsMixin {
}
File trackerFile = new File(dataDir, "fabricDefaultResourcePacks.dat");
Set<Identifier> trackedPacks = new HashSet<>();
Set<String> trackedPacks = new HashSet<>();
if (trackerFile.exists()) {
try {
@ -79,14 +78,14 @@ public class GameOptionsMixin {
NbtList values = data.getList("values", NbtElement.STRING_TYPE);
for (int i = 0; i < values.size(); i++) {
trackedPacks.add(new Identifier(values.getString(i)));
trackedPacks.add(values.getString(i));
}
} catch (IOException e) {
LOGGER.warn("[Fabric Resource Loader] Could not read " + trackerFile.getAbsolutePath(), e);
}
}
Set<Identifier> removedPacks = new HashSet<>(trackedPacks);
Set<String> removedPacks = new HashSet<>(trackedPacks);
Set<String> resourcePacks = new LinkedHashSet<>(this.resourcePacks);
List<ResourcePackProfile> profiles = new ArrayList<>();
@ -101,10 +100,10 @@ public class GameOptionsMixin {
try (ResourcePack pack = profile.createResourcePack()) {
if (pack instanceof ModNioResourcePack builtinPack && builtinPack.getActivationType().isEnabledByDefault()) {
if (trackedPacks.add(builtinPack.getId())) {
if (trackedPacks.add(builtinPack.getName())) {
resourcePacks.add(profile.getName());
} else {
removedPacks.remove(builtinPack.getId());
removedPacks.remove(builtinPack.getName());
}
}
}
@ -113,9 +112,9 @@ public class GameOptionsMixin {
try {
NbtList values = new NbtList();
for (Identifier id : trackedPacks) {
for (String id : trackedPacks) {
if (!removedPacks.contains(id)) {
values.add(NbtString.of(id.toString()));
values.add(NbtString.of(id));
}
}

View file

@ -76,7 +76,7 @@ public class FabricModResourcePack extends GroupResourcePack {
@Override
public String getName() {
return "Fabric Mods";
return "fabric";
}
@Override

View file

@ -45,7 +45,6 @@ import net.minecraft.resource.InputSupplier;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.resource.metadata.ResourceMetadataReader;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.PathUtil;
@ -59,8 +58,7 @@ public class ModNioResourcePack implements ResourcePack, ModResourcePack {
private static final Pattern RESOURCE_PACK_PATH = Pattern.compile("[a-z0-9-_.]+");
private static final FileSystem DEFAULT_FS = FileSystems.getDefault();
private final Identifier id;
private final Text name;
private final String id;
private final ModMetadata modInfo;
private final List<Path> basePaths;
private final ResourceType type;
@ -68,7 +66,7 @@ public class ModNioResourcePack implements ResourcePack, ModResourcePack {
private final ResourcePackActivationType activationType;
private final Map<ResourceType, Set<String>> namespaces;
public static ModNioResourcePack create(Identifier id, Text name, ModContainer mod, String subPath, ResourceType type, ResourcePackActivationType activationType) {
public static ModNioResourcePack create(String id, ModContainer mod, String subPath, ResourceType type, ResourcePackActivationType activationType) {
List<Path> rootPaths = mod.getRootPaths();
List<Path> paths;
@ -91,14 +89,13 @@ public class ModNioResourcePack implements ResourcePack, ModResourcePack {
if (paths.isEmpty()) return null;
ModNioResourcePack ret = new ModNioResourcePack(id, name, mod.getMetadata(), paths, type, null, activationType);
ModNioResourcePack ret = new ModNioResourcePack(id, mod.getMetadata(), paths, type, null, activationType);
return ret.getNamespaces(type).isEmpty() ? null : ret;
}
private ModNioResourcePack(Identifier id, Text name, ModMetadata modInfo, List<Path> paths, ResourceType type, AutoCloseable closer, ResourcePackActivationType activationType) {
private ModNioResourcePack(String id, ModMetadata modInfo, List<Path> paths, ResourceType type, AutoCloseable closer, ResourcePackActivationType activationType) {
this.id = id;
this.name = name;
this.modInfo = modInfo;
this.basePaths = paths;
this.type = type;
@ -281,10 +278,6 @@ public class ModNioResourcePack implements ResourcePack, ModResourcePack {
@Override
public String getName() {
return name.getString();
}
public Identifier getId() {
return id;
}

View file

@ -38,7 +38,6 @@ import net.minecraft.resource.ResourcePackProfile;
import net.minecraft.resource.ResourceType;
import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.resource.ModResourcePack;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
@ -68,7 +67,7 @@ public final class ModResourcePackUtil {
continue;
}
ModResourcePack pack = ModNioResourcePack.create(new Identifier("fabric", container.getMetadata().getId()), getName(container.getMetadata()), container, subPath, type, ResourcePackActivationType.ALWAYS_ENABLED);
ModResourcePack pack = ModNioResourcePack.create(container.getMetadata().getId(), container, subPath, type, ResourcePackActivationType.ALWAYS_ENABLED);
if (pack != null) {
packs.add(pack);

View file

@ -73,8 +73,8 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
List<Path> paths = container.getRootPaths();
String separator = paths.get(0).getFileSystem().getSeparator();
subPath = subPath.replace("/", separator);
ModNioResourcePack resourcePack = ModNioResourcePack.create(id, displayName, container, subPath, ResourceType.CLIENT_RESOURCES, activationType);
ModNioResourcePack dataPack = ModNioResourcePack.create(id, displayName, container, subPath, ResourceType.SERVER_DATA, activationType);
ModNioResourcePack resourcePack = ModNioResourcePack.create(id.toString(), container, subPath, ResourceType.CLIENT_RESOURCES, activationType);
ModNioResourcePack dataPack = ModNioResourcePack.create(id.toString(), container, subPath, ResourceType.SERVER_DATA, activationType);
if (resourcePack == null && dataPack == null) return false;
if (resourcePack != null) {
@ -112,7 +112,7 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
if (!pack.getNamespaces(resourceType).isEmpty()) {
// Make the resource pack profile for built-in pack, should never be always enabled.
ResourcePackProfile profile = ResourcePackProfile.create(
entry.getRight().getId().toString(),
entry.getRight().getName(),
entry.getLeft(),
pack.getActivationType() == ResourcePackActivationType.ALWAYS_ENABLED,
ignored -> entry.getRight(),