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

@@ -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);
}
}