Split off highly version-dependent code from ModCompat
This commit is contained in:
@@ -1,89 +1,12 @@
|
|||||||
package com.replaymod.core.utils;
|
package com.replaymod.core.utils;
|
||||||
|
|
||||||
import com.replaymod.replaystudio.data.ModInfo;
|
import com.replaymod.replaystudio.data.ModInfo;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
//#if FABRIC>=1
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
//#else
|
|
||||||
//#if MC>=11200
|
|
||||||
//$$ import net.minecraftforge.registries.ForgeRegistry;
|
|
||||||
//$$ import net.minecraftforge.registries.RegistryManager;
|
|
||||||
//#else
|
|
||||||
//$$ import net.minecraftforge.fml.common.registry.GameData;
|
|
||||||
//$$ import java.util.stream.Stream;
|
|
||||||
//#endif
|
|
||||||
//$$
|
|
||||||
//#if MC>=11400
|
|
||||||
//$$ import net.minecraftforge.fml.ModList;
|
|
||||||
//#else
|
|
||||||
//$$ import net.minecraftforge.fml.common.Loader;
|
|
||||||
//$$ import net.minecraftforge.fml.common.ModContainer;
|
|
||||||
//#endif
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ModCompat {
|
public class ModCompat {
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static Collection<ModInfo> getInstalledNetworkMods() {
|
public static Collection<ModInfo> getInstalledNetworkMods() {
|
||||||
//#if MC>=11400
|
return ModInfoGetter.getInstalledNetworkMods();
|
||||||
//#if FABRIC>=1
|
|
||||||
Map<String, ModInfo> modInfoMap = FabricLoader.getInstance().getAllMods().stream()
|
|
||||||
.map(ModContainer::getMetadata)
|
|
||||||
.map(m -> new ModInfo(m.getId(), m.getName(), m.getVersion().toString()))
|
|
||||||
.collect(Collectors.toMap(ModInfo::getId, Function.identity()));
|
|
||||||
return Registry.REGISTRIES.stream()
|
|
||||||
.map(Registry::getIds).flatMap(Set::stream)
|
|
||||||
//#else
|
|
||||||
//$$ Map<String, ModInfo> modInfoMap = ModList.get().getMods().stream()
|
|
||||||
//$$ .map(m -> new ModInfo(m.getModId(), m.getDisplayName(), m.getVersion().toString()))
|
|
||||||
//$$ .collect(Collectors.toMap(ModInfo::getId, Function.identity()));
|
|
||||||
//$$ return RegistryManager.ACTIVE.takeSnapshot(false).keySet().stream()
|
|
||||||
//$$ .map(RegistryManager.ACTIVE::getRegistry)
|
|
||||||
//$$ .map(ForgeRegistry::getKeys).flatMap(Set::stream)
|
|
||||||
//#endif
|
|
||||||
.map(Identifier::getNamespace).filter(s -> !s.equals("minecraft")).distinct()
|
|
||||||
.map(modInfoMap::get).filter(Objects::nonNull)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
//#else
|
|
||||||
//$$ Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
|
||||||
//$$ .collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
|
||||||
//#if MC>=11200
|
|
||||||
//$$ return RegistryManager.ACTIVE.takeSnapshot(false).keySet().stream()
|
|
||||||
//$$ .map(RegistryManager.ACTIVE::getRegistry)
|
|
||||||
//$$ .map(ForgeRegistry::getKeys).flatMap(Set::stream)
|
|
||||||
//$$ .map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
|
||||||
//$$ .map(String::toLowerCase).map(ignoreCaseMap::get).filter(mod -> mod != null)
|
|
||||||
//$$ .map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
|
||||||
//$$ .collect(Collectors.toList());
|
|
||||||
//#else
|
|
||||||
//#if MC>=10800
|
|
||||||
//$$ return Stream.concat(
|
|
||||||
//$$ ((Set<ResourceLocation>) GameData.getBlockRegistry().getKeys()).stream(),
|
|
||||||
//$$ ((Set<ResourceLocation>) GameData.getItemRegistry().getKeys()).stream()
|
|
||||||
//$$ ).map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
|
||||||
//$$ .map(String::toLowerCase).map(ignoreCaseMap::get).filter(mod -> mod != null)
|
|
||||||
//$$ .map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
|
||||||
//$$ .collect(Collectors.toList());
|
|
||||||
//#else
|
|
||||||
//$$ return Stream.concat(
|
|
||||||
//$$ ((Set<String>) GameData.getBlockRegistry().getKeys()).stream(),
|
|
||||||
//$$ ((Set<String>) GameData.getItemRegistry().getKeys()).stream()
|
|
||||||
//$$ ).map(name -> {
|
|
||||||
//$$ if (!name.contains(":")) return null; // Still using old names without namespace, can't do anything, ignore
|
|
||||||
//$$ return name.split(":", 2)[0];
|
|
||||||
//$$ }).filter(s -> !s.equals("minecraft")).distinct()
|
|
||||||
//$$ .map(String::toLowerCase).map(ignoreCaseMap::get).filter(mod -> mod != null)
|
|
||||||
//$$ .map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
|
||||||
//$$ .collect(Collectors.toList());
|
|
||||||
//#endif
|
|
||||||
//#endif
|
|
||||||
//#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class ModInfoDifference {
|
public static final class ModInfoDifference {
|
||||||
|
|||||||
25
src/main/java/com/replaymod/core/utils/ModInfoGetter.java
Normal file
25
src/main/java/com/replaymod/core/utils/ModInfoGetter.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.replaymod.core.utils;
|
||||||
|
import com.replaymod.replaystudio.data.ModInfo;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
class ModInfoGetter {
|
||||||
|
static Collection<ModInfo> getInstalledNetworkMods() {
|
||||||
|
Map<String, ModInfo> modInfoMap = FabricLoader.getInstance().getAllMods().stream()
|
||||||
|
.map(ModContainer::getMetadata)
|
||||||
|
.map(m -> new ModInfo(m.getId(), m.getName(), m.getVersion().toString()))
|
||||||
|
.collect(Collectors.toMap(ModInfo::getId, Function.identity()));
|
||||||
|
return Registry.REGISTRIES.stream()
|
||||||
|
.map(Registry::getIds).flatMap(Set::stream)
|
||||||
|
.map(Identifier::getNamespace).filter(s -> !s.equals("minecraft")).distinct()
|
||||||
|
.map(modInfoMap::get).filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.replaymod.core.utils;
|
||||||
|
|
||||||
|
import com.replaymod.replaystudio.data.ModInfo;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
|
import net.minecraftforge.fml.common.registry.GameData;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
class ModInfoGetter {
|
||||||
|
static Collection<ModInfo> getInstalledNetworkMods() {
|
||||||
|
Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
||||||
|
.collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
||||||
|
return Stream.concat(
|
||||||
|
((Set<ResourceLocation>) GameData.getBlockRegistry().getKeys()).stream(),
|
||||||
|
((Set<ResourceLocation>) GameData.getItemRegistry().getKeys()).stream()
|
||||||
|
).map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
||||||
|
.map(String::toLowerCase).map(ignoreCaseMap::get).filter(Objects::nonNull)
|
||||||
|
.map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.replaymod.core.utils;
|
||||||
|
|
||||||
|
import com.replaymod.replaystudio.data.ModInfo;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistry;
|
||||||
|
import net.minecraftforge.registries.RegistryManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
class ModInfoGetter {
|
||||||
|
static Collection<ModInfo> getInstalledNetworkMods() {
|
||||||
|
Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
||||||
|
.collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
||||||
|
return RegistryManager.ACTIVE.takeSnapshot(false).keySet().stream()
|
||||||
|
.map(RegistryManager.ACTIVE::getRegistry)
|
||||||
|
.map(ForgeRegistry::getKeys).flatMap(Set::stream)
|
||||||
|
.map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
||||||
|
.map(String::toLowerCase).map(ignoreCaseMap::get).filter(Objects::nonNull)
|
||||||
|
.map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.replaymod.core.utils;
|
||||||
|
|
||||||
|
import com.replaymod.replaystudio.data.ModInfo;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
class ModInfoGetter {
|
||||||
|
static Collection<ModInfo> getInstalledNetworkMods() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.replaymod.core.utils;
|
||||||
|
|
||||||
|
import com.replaymod.replaystudio.data.ModInfo;
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
|
import cpw.mods.fml.common.ModContainer;
|
||||||
|
import cpw.mods.fml.common.registry.GameData;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
class ModInfoGetter {
|
||||||
|
static Collection<ModInfo> getInstalledNetworkMods() {
|
||||||
|
Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
||||||
|
.collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
||||||
|
return Stream.concat(
|
||||||
|
((Set<String>) GameData.getBlockRegistry().getKeys()).stream(),
|
||||||
|
((Set<String>) GameData.getItemRegistry().getKeys()).stream()
|
||||||
|
).map(name -> {
|
||||||
|
if (!name.contains(":")) return null; // Still using old names without namespace, can't do anything, ignore
|
||||||
|
return name.split(":", 2)[0];
|
||||||
|
}).filter(Objects::nonNull)
|
||||||
|
.filter(s -> !s.equals("minecraft")).distinct()
|
||||||
|
.map(String::toLowerCase).map(ignoreCaseMap::get).filter(Objects::nonNull)
|
||||||
|
.map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user