2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-09-21 09:15:03 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2018-10-06 01:42:15 +00:00
|
|
|
package net.minecraftforge.fml.packs;
|
2013-12-16 16:48:09 +00:00
|
|
|
|
2018-10-06 01:42:15 +00:00
|
|
|
import net.minecraft.resources.*;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-06-23 02:45:01 +00:00
|
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
import net.minecraftforge.fml.loading.FMLLoader;
|
|
|
|
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
2019-01-26 21:55:57 +00:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2018-06-23 02:45:01 +00:00
|
|
|
|
2018-10-06 01:42:15 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2018-06-23 02:45:01 +00:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.util.Map;
|
2018-10-11 21:50:42 +00:00
|
|
|
import java.util.Map.Entry;
|
2019-01-05 15:19:47 +00:00
|
|
|
import java.util.Objects;
|
2018-06-23 02:45:01 +00:00
|
|
|
import java.util.function.Function;
|
|
|
|
import java.util.stream.Collectors;
|
2018-06-11 13:56:44 +00:00
|
|
|
|
2019-01-26 21:55:57 +00:00
|
|
|
import static net.minecraftforge.fml.Logging.CORE;
|
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
public class ResourcePackLoader
|
2013-12-16 16:48:09 +00:00
|
|
|
{
|
2019-01-26 21:55:57 +00:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
2018-06-23 02:45:01 +00:00
|
|
|
private static Map<ModFile, ModFileResourcePack> modResourcePacks;
|
2018-09-05 00:23:45 +00:00
|
|
|
private static ResourcePackList<?> resourcePackList;
|
2018-06-23 02:45:01 +00:00
|
|
|
|
2019-01-05 15:19:47 +00:00
|
|
|
public static ModFileResourcePack getResourcePackFor(String modId)
|
2018-06-11 13:56:44 +00:00
|
|
|
{
|
2018-12-31 21:33:54 +00:00
|
|
|
return modResourcePacks.get(ModList.get().getModFileById(modId).getFile());
|
2018-06-23 02:45:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 00:23:45 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2019-01-05 15:19:47 +00:00
|
|
|
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();
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static <T extends ResourcePackInfo> void loadResourcePacks(ResourcePackList<T> resourcePacks) {
|
|
|
|
resourcePackList = resourcePacks;
|
2018-06-23 02:45:01 +00:00
|
|
|
modResourcePacks = ModList.get().getModFiles().stream().
|
|
|
|
map(mf -> new ModFileResourcePack(mf.getFile())).
|
|
|
|
collect(Collectors.toMap(ModFileResourcePack::getModFile, Function.identity()));
|
2018-09-22 10:40:22 +00:00
|
|
|
resourcePacks.addPackFinder(new ModPackFinder());
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 01:42:15 +00:00
|
|
|
private static class ModPackFinder implements IPackFinder
|
2018-09-05 00:23:45 +00:00
|
|
|
{
|
|
|
|
@Override
|
2018-09-22 10:40:22 +00:00
|
|
|
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> packList, ResourcePackInfo.IFactory<T> factory)
|
2018-09-05 00:23:45 +00:00
|
|
|
{
|
2018-12-31 21:33:54 +00:00
|
|
|
for (Entry<ModFile, ModFileResourcePack> e : modResourcePacks.entrySet())
|
2018-10-11 21:50:42 +00:00
|
|
|
{
|
2019-01-26 21:55:57 +00:00
|
|
|
final String name = "mod:" + e.getKey().getModInfos().get(0).getModId();
|
|
|
|
final T packInfo = ResourcePackInfo.func_195793_a(name, true, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM);
|
2019-01-05 15:19:47 +00:00
|
|
|
e.getValue().setPackInfo(packInfo);
|
2019-01-26 21:55:57 +00:00
|
|
|
LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
|
2019-01-05 15:19:47 +00:00
|
|
|
packList.put(name, packInfo);
|
2018-10-11 21:50:42 +00:00
|
|
|
}
|
2018-09-05 00:23:45 +00:00
|
|
|
}
|
2018-10-11 21:50:42 +00:00
|
|
|
|
2018-06-11 13:56:44 +00:00
|
|
|
}
|
2013-12-16 16:48:09 +00:00
|
|
|
}
|