Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for FG2-era Forge #70

Open
wants to merge 18 commits into
base: dev/0.10.0
Choose a base branch
from

Conversation

Johni0702
Copy link

Adds support for Forge versions which previously required ForgeGradle 2.
Should be fully functional for building production-ready jars as well as running in a development environment (I only tested IntelliJ but there's no IDE-specific code).

This was developed mostly late November completely independently from #63. Afaict notable differences are:

  • Significantly smaller diff; as few changes to FG3 code paths as possible (within reason)
  • No FG code; instead of implementing the old patch algorithm, the old patches are converted to the modern format (which is surprisingly similar) when they are extracted (similarly, old srg files are converted to tsrg when extracted)
  • Supports the TerminalConsoleAppender (by bumping the log4j version and merging the old "helper" classes, which forge depends on, into the forge jar), this may cause issues if mods depend on other parts of log4j that were changed between 2.0-beta9 and release (seems unlikely), but makes for MUCH better console output
  • Access transformers are applied directly to the official-mapped jar (remapping the transformer on the fly) instead of converting the whole thing to srg and back
  • The intermediary mappings are generated by stitch instead of manually traversing all classes
  • Passes the forge/simple integration test case for 1.8.9 and 1.12.2

I had originally bundled pack200 directly into loom but later switched that out for the external plugin as in #63. I was unable to figure out a nice way to get it into the integration test though (classloader shenanigans where the plugin couldn't see our interface; and just adding it to the test classpath doesn't add it to the nested gradle jvm). The best I could come up with is adding a "runtimeOnly" dependency to the main project but is not ideal if the goal was to not have a dependency on that pack200 implementation (though the java classpath exception applies to it, so this shouldn't be an issue license-wise).

There's two extra commits before the main one, each of which fixes a bug I ran into (see their commit messages for details).

Somewhat complex example project: https://github.com/Sk1erLLC/Patcher/tree/tmp/archloom
(needs archloom published to mavenLocal; features a coremod, tweakers, mixins, 1.8.9 and 1.12.2)

Way easier to read than the previous array-copy implementation and trivial to
extend when more file are optional (see next commit).
This jar used to always be included in the cache file list even though it is
only used/generated with official mappings. Therefore it would always be missing
from the cache when not using official mappings, unnecessarily re-running the
patching code.
A fallback SrgProvider is instantiated and initialized here but never added to
the provider list, resulting in a NPE right below in `getRawSrgFile`.
}
}

private static class FabricSideStripper extends ClassVisitor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be an issue for the Forge 1.13+ setups as well (Noticed it in some classes), I will just keep a comment here so I can go back here in the future

@@ -57,6 +57,13 @@ jar {
}
}

loom {
forge {
// FIXME should eventually be handled by architectury-pack200 gradle plugin?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping a comment here, yes, this will be handled there once a PR is merged.

We never use the v1 file, so there isn't really any reason to keep it around.
Cause modern versions of Forge do not need them.
@shedaniel shedaniel added enhancement New feature or request new feature This pull request introduces a (major) new feature priority: low This does not immediately need to be resolved labels Jan 10, 2022
loom {
forge {
// FIXME should eventually be handled by architectury-pack200 gradle plugin?
pack200Provider = new dev.architectury.pack200.java.Pack200Adapter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff should be in its own test since pack200 isn't used in the Forge code for current MC versions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only temporary. It'll be moved into the pack200 plugin once this PR is merged (so the pack200 plugin can compile against it).

src/main/java/net/fabricmc/loom/LoomRepositoryPlugin.java Outdated Show resolved Hide resolved
src/main/java/net/fabricmc/loom/LoomGradleExtension.java Outdated Show resolved Hide resolved
build.gradle Outdated
@@ -119,13 +119,17 @@ dependencies {
implementation ('de.oceanlabs.mcp:mcinjector:3.8.0')
implementation ('com.opencsv:opencsv:5.4')

// Legacy Forge access transformers
implementation ('net.md-5:SpecialSource:1.10.0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the current AT tool not work for old MC versions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would require remapping the entire minecraft jar (and presumably also forge? I guess ATs can apply to it as well?) from official to srg and back, only to run the AT tool. Much slower than this implementation which basically just converts the names as it looks them up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see. You could also remap the AT since we have tools (CadixDev's library) for that.

@Juuxel Juuxel self-requested a review January 11, 2022 17:24
addDependency(Constants.Dependencies.DEV_LAUNCH_INJECTOR + Constants.Dependencies.Versions.DEV_LAUNCH_INJECTOR, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES);
addDependency(Constants.Dependencies.TERMINAL_CONSOLE_APPENDER + Constants.Dependencies.Versions.TERMINAL_CONSOLE_APPENDER, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES);
addDependency(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS, JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME);

if (getExtension().isForge()) {
if (getExtension().isForge() && !getExtension().isLegacyForge()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (getExtension().isForge() && !getExtension().isLegacyForge()) {
if (getExtension().isModernForge()) {

@Johni0702 Johni0702 requested a review from Juuxel January 17, 2022 11:29
We've assumed that Forge adds its annotation everywhere via its patches but it
actually only adds them if a given file needs to have a patch applied for
reasons other than just the SideOnly annotation.
This would leave some classes/fields/methods without annotation which resulted
in an exception when deserializing horses on 1.12.2 (because it references a
class which in turn has methods referencing the dedicated server class which is
server-only).

Instead, we now convert all Fabric annotations (added during merging) to the
Forge ones and remove duplicates (where patches also added them).
@Juuxel
Copy link
Member

Juuxel commented May 4, 2022

This should probably be updated to target dev/0.11.0, as that's where the development is happening, but it might be a bit too much work with the refactors done to both Loom's core/upstream code as well as the Forge-specific parts...

Forge has not published regular source artifacts for old versions, instead the
sources zip is bundled within the userdev jar.

Co-authored-by: DJtheRedstoner <[email protected]>
@wagyourtail
Copy link

wagyourtail commented Jun 8, 2022

as well as the Forge-specific parts...

exactly the reason I split fg3+ and fg2 classes in mine, makes it so changes to one don't cascade into the other
(also why am I struggling to get jitpack to build this one... oh. missing yml to bump java?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new feature This pull request introduces a (major) new feature priority: low This does not immediately need to be resolved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants