mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 06:53:20 +00:00
Split server and client side pack locators apart and move them to their
respective behavioural components. This should facilitate fixing the server pack data pack ordering, as well as other new features of mod resource packs. Signed-off-by: cpw <[email protected]>
This commit is contained in:
3 files changed
+85
-30
No files matched your search
@@ -19,12 +19,12 @@
|
||||
|
||||
package net.minecraftforge.fml.packs;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -35,16 +35,11 @@ import net.minecraft.resources.IPackFinder;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraft.resources.ResourcePackList;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
import net.minecraftforge.fml.ModLoadingWarning;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
|
||||
public class ResourcePackLoader
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static Map<ModFile, ModFileResourcePack> modResourcePacks;
|
||||
private static ResourcePackList<?> resourcePackList;
|
||||
|
||||
@@ -54,36 +49,32 @@ public class ResourcePackLoader
|
||||
map(ModFileInfo::getFile).map(mf->modResourcePacks.get(mf));
|
||||
}
|
||||
|
||||
public static <T extends ResourcePackInfo> void loadResourcePacks(ResourcePackList<T> resourcePacks) {
|
||||
public static <T extends ResourcePackInfo> void loadResourcePacks(ResourcePackList<T> resourcePacks, BiFunction<Map<ModFile, ModFileResourcePack>, BiConsumer<ModFileResourcePack, T>, IPackInfoFinder> packFinder) {
|
||||
resourcePackList = resourcePacks;
|
||||
modResourcePacks = ModList.get().getModFiles().stream().
|
||||
filter(mf->!Objects.equals(mf.getModLoader(),"minecraft")).
|
||||
map(mf -> new ModFileResourcePack(mf.getFile())).
|
||||
collect(Collectors.toMap(ModFileResourcePack::getModFile, Function.identity()));
|
||||
resourcePacks.addPackFinder(new ModPackFinder());
|
||||
resourcePacks.addPackFinder(new LambdaFriendlyPackFinder(packFinder.apply(modResourcePacks, ModFileResourcePack::setPackInfo)));
|
||||
}
|
||||
|
||||
private static class ModPackFinder implements IPackFinder
|
||||
{
|
||||
public interface IPackInfoFinder<T extends ResourcePackInfo> {
|
||||
void addPackInfosToMap(Map<String, T> packList, ResourcePackInfo.IFactory<T> factory);
|
||||
}
|
||||
|
||||
// SO GROSS - DON'T @ me bro
|
||||
@SuppressWarnings("unchecked")
|
||||
private static class LambdaFriendlyPackFinder implements IPackFinder {
|
||||
private IPackInfoFinder wrapped;
|
||||
|
||||
private LambdaFriendlyPackFinder(final IPackInfoFinder wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> packList, ResourcePackInfo.IFactory<T> factory)
|
||||
{
|
||||
for (Entry<ModFile, ModFileResourcePack> e : modResourcePacks.entrySet())
|
||||
{
|
||||
IModInfo mod = e.getKey().getModInfos().get(0);
|
||||
if (Objects.equals(mod.getModId(), "minecraft")) continue; // skip the minecraft "mod"
|
||||
final String name = "mod:" + mod.getModId();
|
||||
final T packInfo = ResourcePackInfo.createResourcePack(name, true, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM);
|
||||
if (packInfo == null) {
|
||||
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
|
||||
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
|
||||
continue;
|
||||
}
|
||||
e.getValue().setPackInfo(packInfo);
|
||||
LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
|
||||
packList.put(name, packInfo);
|
||||
}
|
||||
wrapped.addPackInfosToMap(packList, factory);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user