PaperMC / Paperclip

Bootstrap utility and launcher for the Paper Minecraft server
MIT License
120 stars 51 forks source link

Mixin support for end users #62

Closed maestro-denery closed 1 year ago

maestro-denery commented 1 year ago

Highly Highly Highly WIP, requires PRs for Paper and Paperwight as well.

I'd like to start a discussion on a Mixin support for Paper. In this PR I made an initial draft of that using some of Fabric Loader and Paper plugins internals code. (License headers stay in places they should be) This whole PR does the following:

  1. Adds new mixins field to the paper-plugin.yml.
  2. Makes a new classloader called MixinClassLoader which loads the patched jar and makes bytecode modification possible.
  3. Reads the mixin configuration and mixins from plugins, applies them using the mentioned classloader.

This which should be made:

  1. Plugin classloaders with Mixin support. (A PR for Paper)
  2. Mixin mojmap to spigot remapping. (A PR for Paperweight)

Regarding 1: My suggestion is that we can make a part of paper plugin loading system which I briefly separated in the mixin-support submodule as an another dependency and then depend on it in the Paper-Server, and do all the functionality based on this.

Regarding 2: Mixin remapping is done using its annotation processor, a gradle plugin provides mappings and other info for it, and it generates refmap files in the output jar, which later are read by mixins. Fabric has https://github.com/FabricMC/fabric-mixin-compile-extensions which supports the tiny mapping format which uses paperweight, and it is used in their gradle plugin: https://github.com/FabricMC/fabric-loom/blob/dev/1.1/src/main/java/net/fabricmc/loom/build/mixin/AnnotationProcessorInvoker.java We can make this kind of thing in the paperweight as well so users can freely use mixins with it.

P.S. I made a test plugin with these changes using Paperweight, and ran it on the mojmap bundler jar, and it works, except there is a classloader exception in JavaPlugin's constructor, which should be fixed by a PR to Paper with the support of all of this.

JosTheDude commented 1 year ago

This would be very interesting to see and the cross compatibility would be huge

Dreamail commented 1 year ago

Have been waiting for a long time!!! There are some projects already making paper work with mixin: https://github.com/vectrix-space/ignite https://github.com/Apisium/PaperShelled

But their solutions isn't very good. I'm excited for paper officially supporting mixin.

Andre601 commented 1 year ago

Wasn't there a discussion about using Mixins internally, but not officially exposing it to devs? Like allowing access but not in an official kind of way?

electronicboy commented 1 year ago

Basically, forge treatment; they exist, you can use them, we will however not support them or environments with them

On Mon, 27 Mar 2023, 14:50 Andre_601, @.***> wrote:

Wasn't there a discussion about using Mixins internally, but not officially exposing it to devs? Like allowing access but not in an official kind of way?

— Reply to this email directly, view it on GitHub https://github.com/PaperMC/Paperclip/pull/62#issuecomment-1485135077, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJMAZHQ2KO3N4OWCXD67KTW6GLIVANCNFSM6AAAAAAWIDRYTU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

bergerkiller commented 1 year ago

I'm very excited about these changes, and such a feature might very well become reason to drop spigot support in the near future. It would also allow for people to write unique new API's and events implemented using mixins rather than forking paper.

kennytv commented 1 year ago

Sorry, we're not interested in supporting this in Paper proper. Aside from leading to headaches when it comes to user (and dev) support, mixins would break even more often than in Fabric for example, with Paper frequently changing and moving around methods. The added complexity required here, and especially paperweight, are not something we want to maintain.

You are of course still free to do this in your own fork still, there have been other forks doing this before as well. But generally, at the point where most of a mod will consist of mixins, you might as well move to a proper modding platform - Paper isn't one