Skip to content

Rickaym/pyforge

Repository files navigation

PyForge

Static Badge

PyForge is a Python language provider crafted for Minecraft Forge. It leverages the Jython implementation of Python that runs on the JVM. The module is compatible with Python 2.7.x and is designed to support a comprehensive implementation of a Forge Mod. See an example mod using here.

I created pyforge to benchmark the capabilities of Jython and introduce Python developers to the exciting world of Minecraft modding.

- This project is in the alpha stage, use at your own discretion!

Getting Started

Creating Your Mod

The directory structure of a mod using pyforge is the same as that of a mod implemented in Java, therefore, you can start by instantiating the boilerplate code through a plugin with Java as the language. Keep note, you should set the package name to the mod id rather than your domain, i.e., com.rickaym.mod.

E.g.

  root ┓
       ┣━ ...
       ┣━ build.gradle
       ┗━ src ┓
              ┗━ pymod# - id of your mod
                       ┣━ __init__.py
                       ┣━ main.py
                       ┣━ ext.py
                       ┗━ more_ext.py

Setup

The __init__.py file inside the root.src.mod directory serves as the entrypoint to the mod. To setup the mod, you have to define a function inside the __init__.py file called get_mod_instance that returns the mod instance. This is the mod instance that used by the mod loader and it must be decorated with the @Mod decorator.

# __init__.py

from main import MyMod

get_mod_instance = lambda: MyMod()

The implementation of a mod class should look like this:

# main.py

import org.apache.logging.log4j.LogManager as LogManager

from rickaym.pyforge import Mod

from ext import ExtensionClass, SecondExtensionClass
from more_ext import MoreExt

@Mod(mod_id="abc")
class MyMod:
    ...

    def __init__(self):
        self.LOGGER = LogManager.getLogger()
        self.LOGGER.info("Pymod has been loaded in!")

    def register(self):
        ExtensionClass.register()
        SecondExtensionClass.register()
        MoreExt.register()

Contribution and Beta Testing

Contributions are open. Contact @rick.aym or join this discord server.