mindstorm38 / portablemc

A fast, reliable and cross-platform command-line Minecraft launcher and API for developers. Including fast and easy installation of common mod loaders such as Fabric, Forge, NeoForge and Quilt.
https://pypi.org/project/portablemc/
GNU General Public License v3.0
354 stars 20 forks source link

Installing mods with events #186

Closed ZeralldMC closed 11 months ago

ZeralldMC commented 11 months ago

Good night, I'm trying to figure out eventing. I need to have several mods added to the mods folder at full load of minecraft. I have a script that allows you to do this, but it must be run after the full installation of the game itself.

My current code:

    class MyWatcher(Watcher):
        def handle(self, event) -> None:
            print(f"Event activated: {event}")
            if isinstance(event, DownloadCompleteEvent):
                print("Minecraft downloaded")
                modsCheck()

    try:
        env = version.install(watcher=MyWatcher())
        env.run()
    finally:
        eel.game_loader_end()

How can I do this and am I even moving correctly? I'm afraid I've misunderstood something.

mindstorm38 commented 11 months ago

You don't need event watcher for that use case! You can just check your mods between the .install(...) and .run(). Events are usually for debugging or printing progress to the client, not really for updating the game's state, but that's still possible if you wish!