Implement a simple feature system for Forge (#8670)

* Implement a simple feature system for Forge. Allows mods to demand certain features are available in the loading system. An example for java_version is provided, but not expected to be used widely. This is more targeted to properties of the display, such as GL version and glsl profile.

Requires https://github.com/MinecraftForge/ForgeSPI/pull/13 to be merged first in ForgeSPI, and the SPI to be updated appropriately in build.gradle files.

* rebase onto 1.19 and add in SPI update
This commit is contained in:
cpw authored and GitHub committed 2022-06-09 17:00:39 -04:00
1 parent 27480c15fa
commit e16f54eebe
4 files changed
+37 -9

No files matched your search

@@ -11,12 +11,11 @@ import net.minecraftforge.fml.loading.StringUtils;
import net.minecraftforge.forgespi.language.IConfigurable;
import net.minecraftforge.forgespi.language.IModInfo;
import net.minecraftforge.forgespi.language.MavenVersionAdapter;
import net.minecraftforge.forgespi.locating.ForgeFeature;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import java.net.URL;
import java.util.Collections;
@@ -43,6 +42,8 @@ public class ModInfo implements IModInfo, IConfigurable
private final boolean logoBlur;
private final Optional<URL> updateJSONURL;
private final List<? extends IModInfo.ModVersion> dependencies;
private final List<ForgeFeature.Bound> features;
private final Map<String,Object> properties;
private final IConfigurable config;
private final Optional<URL> modUrl;
@@ -84,6 +85,12 @@ public class ModInfo implements IModInfo, IConfigurable
.collect(Collectors.toList()))
.orElse(Collections.emptyList());
this.features = ownFile.map(mfi -> mfi.<Map<String, String>>getConfigElement("features", this.modId)
.stream()
.flatMap(m->m.entrySet().stream())
.map(e->new ForgeFeature.Bound(e.getKey(), e.getValue(), this))
.collect(Collectors.toList())).orElse(Collections.emptyList());
this.properties = ownFile.map(mfi -> mfi.<Map<String, Object>>getConfigElement("modproperties", this.modId)
.orElse(Collections.emptyMap()))
.orElse(Collections.emptyMap());
@@ -156,6 +163,11 @@ public class ModInfo implements IModInfo, IConfigurable
return this;
}
@Override
public List<? extends ForgeFeature.Bound> getForgeFeatures() {
return this.features;
}
@Override
public <T> Optional<T> getConfigElement(final String... key) {
return this.config.getConfigElement(key);