diff --git a/pages/advanced/addons.md b/old.md similarity index 78% rename from pages/advanced/addons.md rename to old.md index 60bda51..c34cbd5 100644 --- a/pages/advanced/addons.md +++ b/old.md @@ -15,25 +15,6 @@ Use the [Fabric Template Mod Generator](https://fabricmc.net/develop/template/) After that, just import the downloaded Project into your IDE. I recommend using IntelliJ. -### Dependency -To be able to use Cactus in your Project, you need to import it as a dependency. Currently we don't have a public maven repository for that, so you'll need to import the jarfile as a library. - -Navigate to your `build.gradle` file and look for the `dependencies` section and add Cactus as shown below. - -```gradle -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - // Add Cactus as a local library here - modImplementation fileTree(dir: 'libs', include: ['cactus-0.9.96.jar']) -} -``` ### Entrypoints Cactus uses fabric's entrypoint system to discover and load addons. To make your addon visible as one to Cactus, you need to add your main class to the entrypoint for 'cactus' in your `fabric.mod.json`. diff --git a/pages/advanced/addons/adding-content.md b/pages/advanced/addons/adding-content.md new file mode 100644 index 0000000..3078b7f --- /dev/null +++ b/pages/advanced/addons/adding-content.md @@ -0,0 +1,72 @@ +## Using the Registry Bus +Until now, the addon just exists and doesn't actually add anything. To register new (supported) content, you can use the `RegistryBus` provided in your `onInitialize` method. + + +### Creating a category +Let's register a category to keep all your addon's modules. + +Open your main class, then create a new category as shown below. You can change the icon's item and category name with whatever you want. + +```java +public static final Category CATEGORY = new Category("category_name", Items.DIAMOND); + +``` + + +Afterwards, go in the `onInitalize` methon and register your Category as shown below. + +```java +registryBus.register(Category.class, ctx -> CATEGORY); + +``` + +That's it! What did we just do? The `RegistryBus` provides a `register` method to register new content. `Category.class` specifies what kind of content you are registering - and what Cactus will use to look for your registrations. The object you pass to the function has to be an instance of this class or a child. The `ctx` you are provided is a `RegistrationContext` which can be used for retrieving instances of handlers which you might need for the construction of some objects. A good example for this is the registration of new config files: + +```java +registryBus.register(FileConfiguration.class, ctx -> new MyFileConfig(ctx.require(ConfigHandler.class))); +``` + +Calling `require` and passing `ConfigHandler.class` will prompt the context to return an instance of this class it was provided with. **Trying to retrieve instances which haven't been provided to the registration context will result in an exception.** + + +### Creating a module +Lets's register a new Module. Just create a new class which extends `Module` and give it an ID and our category (remember to change MainClass to your actual main class) . + +```java +public class MyModule extends Module { + + public MyModule() { + super("myModuleId", MainClass.CATEGORY); + } + + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + + } + + @EventHandler + public void onTick(ClientTickEvent event) { + + } + +} +``` + +You can see in the example above the `MyModule` class contains 4 methods: +- the `MyModule` method +- the `onEnable` method contains code that is ran right after you enable the module +- the `onDisable` method contains code that is ran right after you disable the module +- the `onTick` method contains code that is ran at the end of every game tick + +Now, back in your `onInitialize` method in the main class, register your Module like shown below. + +```java +registryBus.register(Module.class, ctx -> new MyModule()); +``` + +And with this you are done! Now, when opening the module gui in-game you will be able to find your category with your module inside! \ No newline at end of file diff --git a/pages/advanced/addons/informations.md b/pages/advanced/addons/informations.md new file mode 100644 index 0000000..5113b77 --- /dev/null +++ b/pages/advanced/addons/informations.md @@ -0,0 +1,8 @@ +# Addons + +This section mainly focuses on addon development. +There isn't much here now. + +## Usage + +Cactus Addons are installed the same way as normal mods. Just drag your `addon.jar` file into your `mods` directory - it's that simple! \ No newline at end of file diff --git a/pages/advanced/addons/project-setup.md b/pages/advanced/addons/project-setup.md new file mode 100644 index 0000000..c3cc8c1 --- /dev/null +++ b/pages/advanced/addons/project-setup.md @@ -0,0 +1,97 @@ +### Mod Creation + +Use the [Fabric Template Mod Generator](https://fabricmc.net/develop/template/) to create a new project. Make sure *"Split client and common sources"* is **disabled**. + +After that, just import the downloaded Project into your IDE. I recommend using IntelliJ. + + +### Dependency +To be able to use Cactus in your Project, you need to import it as a dependency. + +First, navigate your `gradle.properties` file and add a variable called `cactus_mod_version` , then, set it to your desired cactus version as shown below. + +```gradle +# Dependencies +fabric_api_version=0.155.2+26.2 + +# Add the variable here +cactus_mod_version=0.14 +``` + + +Then, go to your `build.gradle` file and look for the `repositories` section and add Modrinth as shown below so gradle can actually find cactus. + +```gradle +repositories { + + exclusiveContent { + forRepository { + maven { + name = "Modrinth" + url = "https://api.modrinth.com/maven" + } + } + filter { + includeGroup "maven.modrinth" + } + } +} +``` + + +Now, stay in your `build.gradle` file and look for the `dependencies` section and add Cactus as shown below. + +```gradle +dependencies { + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" + + // Fabric API. This is technically optional, but you probably want it anyway. + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + + // Add cactus here + implementation "maven.modrinth:cactus:${project.cactus_mod_version}" +} +``` + + +### Entrypoints +Cactus uses fabric's entrypoint system to discover and load addons. To make your addon visible as one to Cactus, you need to add your main class to the entrypoint for 'cactus' in your `fabric.mod.json`. + +Replace the `entrypoints` part in your `fabric.mod.json` with the json object below, and update the class and package name to match your main class. + +```json +"entrypoints": { + "cactus": [ + "com.yourname.MyAddon.MainClass" + ] +} +``` + + +### Main Class +Now that you've successfully imported the library and updated the required entrypoint, last but not least you'll have to update your main class. Instead of implementing `ClientModInitializer`, you have to implement `ICactusAddon` and implement the required methods. + +```java +public class MyAddon implements ICactusAddon { + + @Override + public void onInitialize(RegistryBus registryBus) { + + } + + @Override + public void onLoadComplete() { + + } + + @Override + public void onShutdown() { + + } + +} +``` + +Your mod should now work as a Cactus Addon. You can try building it and adding it to your mods directory together with Cactus, and it should be loaded as an Addon. diff --git a/pages/index.md b/pages/index.md index 9d7878e..04599ea 100644 --- a/pages/index.md +++ b/pages/index.md @@ -29,6 +29,10 @@ If you want to contribute, check out our [GitHub Repository](https://www.github. chat.md advanced/ userscripts.md + addons/ + informations.md + project-setup.md + adding-content.md addons.md experiments.md troubleshooting/