Fix up some stuff with resource packs, so the guilist works properly.

This commit is contained in:
cpw committed 2019-01-05 10:19:47 -05:00
1 parent 1d1ec57909
commit 58c78560fa
5 files changed
+35 -59

No files matched your search

@@ -31,8 +31,8 @@ import java.util.Map;
public class StringSubstitutor
{
private static final Map<String,String> globals = ImmutableMap.of(
"mcVersion", FMLLoader.forgeVersion,
"forgeVersion", FMLLoader.mcVersion
"mcVersion", FMLLoader.mcVersion,
"forgeVersion", FMLLoader.forgeVersion
);
public static String replace(final String in, final ModFile file) {
@@ -52,7 +52,7 @@ public class StringSubstitutor
{
return globals.get(parts[1]);
}
else if ("file".equals(pfx))
else if ("file".equals(pfx) && file != null)
{
return String.valueOf(file.getSubstitutionMap().get().get(parts[1]));
}
@@ -60,7 +60,4 @@ public class StringSubstitutor
}
};
}
private static List<String> split(final String in) {
return Arrays.asList(in.split("."));
}
}
@@ -433,8 +433,8 @@ public class GuiModList extends GuiScreen
Pair<ResourceLocation, Dimension> logoData = selectedMod.getLogoFile().map(logoFile->
{
TextureManager tm = mc.getTextureManager();
ResourcePackInfoClient pack = ResourcePackLoader.getResourcePackInfo(selectedMod.getModId());
if (pack == null) pack = ResourcePackLoader.getResourcePackInfo("forge");
ResourcePackInfoClient pack = ResourcePackLoader.getResourcePackInfoForModId(selectedMod.getModId());
if (pack == null) pack = ResourcePackLoader.getResourcePackInfoForModId("forge");
try
{
NativeImage logo = null;
@@ -20,6 +20,7 @@
package net.minecraftforge.fml.packs;
import net.minecraft.resources.AbstractResourcePack;
import net.minecraft.resources.ResourcePackInfo;
import net.minecraft.resources.ResourcePackType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
@@ -42,6 +43,7 @@ import com.google.common.base.Joiner;
public class ModFileResourcePack extends AbstractResourcePack
{
private final ModFile modFile;
private ResourcePackInfo packInfo;
public ModFileResourcePack(final ModFile modFile)
{
@@ -135,4 +137,12 @@ public class ModFileResourcePack extends AbstractResourcePack
{
}
<T extends ResourcePackInfo> void setPackInfo(final T packInfo) {
this.packInfo = packInfo;
}
<T extends ResourcePackInfo> T getPackInfo() {
return (T)this.packInfo;
}
}
@@ -31,6 +31,7 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -39,14 +40,18 @@ public class ResourcePackLoader
private static Map<ModFile, ModFileResourcePack> modResourcePacks;
private static ResourcePackList<?> resourcePackList;
public static IResourcePack getResourcePackFor(String modId)
public static ModFileResourcePack getResourcePackFor(String modId)
{
return modResourcePacks.get(ModList.get().getModFileById(modId).getFile());
}
@SuppressWarnings("unchecked")
public static <T extends ResourcePackInfo> T getResourcePackInfo(String modId) {
return (T)resourcePackList.getPackInfo(modId);
public static <T extends ResourcePackInfo> T getResourcePackInfoForModId(String modId) {
if (Objects.equals(modId, "minecraft")) {
// Additional resources for MC are associated with forge
return getResourcePackFor("forge").getPackInfo();
}
return getResourcePackFor(modId).getPackInfo();
}
public static <T extends ResourcePackInfo> void loadResourcePacks(ResourcePackList<T> resourcePacks) {
@@ -57,50 +62,6 @@ public class ResourcePackLoader
resourcePacks.addPackFinder(new ModPackFinder());
}
private static class ForgeFolderPack extends FolderPack {
public ForgeFolderPack(final File folder) {
super(folder);
}
public InputStream getResourceStream(ResourcePackType type, ResourceLocation location) throws IOException {
if (location.getPath().startsWith("lang/")) {
return super.getResourceStream(ResourcePackType.CLIENT_RESOURCES, location);
} else {
return super.getResourceStream(type, location);
}
}
public boolean resourceExists(ResourcePackType type, ResourceLocation location) {
if (location.getPath().startsWith("lang/")) {
return super.resourceExists(ResourcePackType.CLIENT_RESOURCES, location);
} else {
return super.resourceExists(type, location);
}
}
}
private static class ForgeFilePack extends FilePack {
public ForgeFilePack(final File folder) {
super(folder);
}
public InputStream getResourceStream(ResourcePackType type, ResourceLocation location) throws IOException {
if (location.getPath().startsWith("lang/")) {
return super.getResourceStream(ResourcePackType.CLIENT_RESOURCES, location);
} else {
return super.getResourceStream(type, location);
}
}
public boolean resourceExists(ResourcePackType type, ResourceLocation location) {
if (location.getPath().startsWith("lang/")) {
return super.resourceExists(ResourcePackType.CLIENT_RESOURCES, location);
} else {
return super.resourceExists(type, location);
}
}
}
private static class ModPackFinder implements IPackFinder
{
@Override
@@ -109,7 +70,9 @@ public class ResourcePackLoader
for (Entry<ModFile, ModFileResourcePack> e : modResourcePacks.entrySet())
{
String name = "modfile/" + e.getKey().getFileName();
packList.put(name, ResourcePackInfo.func_195793_a(name, true, ()->e.getValue(), factory, ResourcePackInfo.Priority.BOTTOM));
final T packInfo = ResourcePackInfo.func_195793_a(name, true, () -> e.getValue(), factory, ResourcePackInfo.Priority.BOTTOM);
e.getValue().setPackInfo(packInfo);
packList.put(name, packInfo);
}
}
+9 -3
View File
@@ -1,11 +1,17 @@
modLoader="javafml"
loaderVersion="[2.0,]"
loaderVersion="[24,]"
updateJSONURL="https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json"
issueTrackerURL="http://www.minecraftforge.net/"
logoFile="forge_logo.png"
[[mods]]
modId="forge"
version="${jarVersion}"
# We use the global forge version
version="${global.forgeVersion}"
displayName="Forge"
description="Mod loading a compatibility API"
credits="LexManos,cpw,Mezz,fry,tterrag,gigaherz,illy"
authors="LexManos,cpw,Mezz,fry,Spacetoad,Eloraam"
description='''
Forge, a broad compatibility API.
'''