Giter Site home page Giter Site logo

Comments (6)

falkreon avatar falkreon commented on August 16, 2024

Implementing ClientModInitializer/DedicatedServerModInitializer may have unexpected effects if implemented in a class that also implements another initializer interface.

How did you expect to implement both ClientModInitializer and DedicatedServerModInitializer without loading classes from the client?

There is also currently no way to declare dependently loaded interfaces for add-on resolution. I imagine initializers used by a mod like JEI might contain environment specific parts.

Oh. Okay. So:

Interfaces are only loaded if you try to make a class that extends from them. (including when you try to make an instance of a class that extends from them, or when you try to Class.forName any of the above). Forge had a heavy ASM system to conditionally strip an interface from a class, but... that's ASM. I am not aware of a way to do that which is not ASM.

So you're going to have to make do with simply not referencing or instantiating classes if they implement an interface, and storing them bare/type-unsafe as Object if you must refer to them, unless you want to get into the mess which even forge is actively moving away from

TehNut has already gotten us 90% of the way there by taking the JEI-style loader and making it generic- plugin-loader. The rest - such as adjudicating between many mods' copies of classes for a given power API - can be solved by jar-in-jar, which is on its way.

from fabric-loader.

JamiesWhiteShirt avatar JamiesWhiteShirt commented on August 16, 2024

How did you expect to implement both ClientModInitializer and DedicatedServerModInitializer without loading classes from the client?

It could actually be done, it's just very prone to breakage. No one should, but someone could. However, at the time of writing this issue, environment stripping was not implemented. ClientModInitializer and DedicatedServerModInitializer are now stripped which makes it impossible even if the initializer is loaded.

If we decide implementing multiple interfaces on an initializer is invalid, fabric-loader should make it so and throw an exception. That makes us more dependent on ASM and doesn't validate well with Java.

We know Forge's Optional is not coming to Fabric, so that is not an option.

TehNut has already gotten us 90% of the way there by taking the JEI-style loader and making it generic- plugin-loader. The rest - such as adjudicating between many mods' copies of classes for a given power API - can be solved by jar-in-jar, which is on its way.

Add-on resolution is one of the use cases of the initializer system but the loading behavior leaves a little to be desired. I learned that initializers are not loaded if they implement an interface which is not on the classpath. It's definitely better than trying to load the class. It is similar to the client/server initializer loading. It uses ASM, has the same bug mentioned, and is unintuitive.

If there is a need for a plugin-loader then Fabric needs to improve its initializers or not do add-on resolution at all. IMO we shouldn't have to depend on a separate mod for this.

from fabric-loader.

asiekierka avatar asiekierka commented on August 16, 2024

I was considering using annotations on the class for this, but I'm not sure how liked that idea would be.

from fabric-loader.

asiekierka avatar asiekierka commented on August 16, 2024

So, here's an odd proposal:

  • Deprecate all initializers and just make initializers required to implement either Runnable or Consumer,
  • Ensure that all initializers get loaded in order,
  • Find a compact way to define initializers with siding requirements.

So we have "scala:[class]" now, as a way to define classes to be loaded explicitly by the Scala language adapter. What if, instead of keying initializers by interfaces, we keyed them by strings?

"client/scala:mypackage.MyClass", say. Now, instead of .getInitializers, you would have .initialize(String key) + .initialize(String key, Object argument) in Loader. (It would also prevent re-entrant calling of initializers, which should NEVER BE DONE anyway)

This is rough and off-the-top-of-my-head, so please discuss!

from fabric-loader.

asiekierka avatar asiekierka commented on August 16, 2024

After mild discussion:

"mypackage.MyClass::myMethod" <- keyed to "main", calls static myMethod (must return void, but can have any number of arguments)

"scala/mypackage.MyClass::myMethod" <- same, but for Scala language adapter

"client:mypackage.MyClass::myMethod" <- keyed to "client", yadda yadda

"client:scala/mypackage.MyClass::myMethod" <- etc

Initializers are no longer instantiated per se. If you want instances, you handle them yourself. If you want an API instance, you can either define an initializer key for a kind of proto-dependency injection (any number of arguments, remember?) or a static get()

from fabric-loader.

JamiesWhiteShirt avatar JamiesWhiteShirt commented on August 16, 2024

The initializer system has been reworked into entry points in loader 0.4, so this issue is no longer relevant.

from fabric-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.