Skip to content

Commit

Permalink
Restrict SpongeForge versions (only 7.4.8 or above is allowed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongmario committed Sep 14, 2023
1 parent 4879c13 commit 1fd9eea
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
16 changes: 13 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ minecraft {
])
extraTweakClasses.add('org.spongepowered.asm.launch.MixinTweaker')
injectedTags.put('VERSION', project.version)
injectedTags.put('MOD_ID', project.archivesBaseName)
injectedTags.put('MOD_NAME', project.mod_name)
}

tasks.injectTags.configure {
Expand Down Expand Up @@ -83,9 +85,17 @@ dependencies {
}

processResources {
// This will ensure that this task is redone when the versions change.
inputs.property 'version', project.version
inputs.property 'mcversion', project.minecraft.version
inputs.property 'mod_version', project.version
inputs.property 'mod_id', project.archivesBaseName
inputs.property 'mod_name', project.mod_name

filesMatching('mcmod.info') {
expand(
'mod_version': project.version,
'mod_id': project.archivesBaseName,
'mod_name': project.mod_name,
)
}
}

tasks.register('properJar', Jar) { jar ->
Expand Down
52 changes: 44 additions & 8 deletions src/main/java/zone/rong/mixinbooter/MixinBooterPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.google.common.eventbus.EventBus;
import com.llamalad7.mixinextras.MixinExtrasBootstrap;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.minecraftforge.fml.common.versioning.InvalidVersionSpecificationException;
import net.minecraftforge.fml.common.versioning.VersionRange;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -15,9 +17,7 @@
import zone.rong.mixinbooter.fix.MixinFixer;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.*;

@IFMLLoadingPlugin.Name("MixinBooter")
@IFMLLoadingPlugin.SortingIndex(Integer.MIN_VALUE + 1)
Expand Down Expand Up @@ -101,9 +101,10 @@ public static class Container extends DummyModContainer {

public Container() {
super(new ModMetadata());
MixinBooterPlugin.LOGGER.info("Initializing MixinBooter's Mod Container.");
ModMetadata meta = this.getMetadata();
meta.modId = "mixinbooter";
meta.name = "MixinBooter";
meta.modId = Tags.MOD_ID;
meta.name = Tags.MOD_NAME;
meta.description = "A mod that provides the Sponge Mixin library, a standard API for mods to load mixins targeting Minecraft and other mods, and associated useful utilities on 1.8 - 1.12.2";
meta.credits = "Thanks to LegacyModdingMC + Fabric for providing the initial mixin fork.";
meta.version = Tags.VERSION;
Expand All @@ -117,6 +118,41 @@ public boolean registerBus(EventBus bus, LoadController controller) {
return true;
}

@Override
public Set<ArtifactVersion> getRequirements() {
try {
return Collections.singleton(new SpongeForgeArtifactVersion());
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
}

// Thank you SpongeForge ^_^
private static class SpongeForgeArtifactVersion extends DefaultArtifactVersion {

public SpongeForgeArtifactVersion() throws InvalidVersionSpecificationException {
super("spongeforge", VersionRange.createFromVersionSpec("[7.4.8,)"));
}

@Override
public boolean containsVersion(ArtifactVersion source) {
if (source == this) {
return true;
}
String version = source.getVersionString();
String[] hyphenSplits = version.split("-");
if (hyphenSplits.length > 1) {
if (hyphenSplits[hyphenSplits.length - 1].startsWith("RC")) {
version = hyphenSplits[hyphenSplits.length - 2];
} else {
version = hyphenSplits[hyphenSplits.length - 1];
}
}
source = new DefaultArtifactVersion(source.getLabel(), version);
return super.containsVersion(source);
}
}

}

}
11 changes: 11 additions & 0 deletions src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[{
"modid": "${mod_id}",
"name": "${mod_name}",
"version": "${mod_version}",
"mcversion": "1.12.2",
"description": "A mod that provides the SpongeMixin library, a standard API for mods to load mixins targeting Minecraft and other mods, and associated useful utilities on 1.8 - 1.12.2.",
"authorList": ["Rongmario"],
"credits": "Thanks to LegacyModdingMC + Fabric for providing the initial mixin fork.",
"url": "https://github.com/CleanroomMC/MixinBooter",
"logoFile": "/icon.png"
}]

0 comments on commit 1fd9eea

Please sign in to comment.