Skip to content

Commit

Permalink
Setup Forge and Fabric generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Nov 6, 2023
1 parent 9ec8613 commit 63f8fd3
Show file tree
Hide file tree
Showing 61 changed files with 1,549 additions and 123 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This workflow will build a package using Gradle

name: Check Builds For Errors

on: [ pull_request, push ]

jobs:
build:
continue-on-error: true
strategy:
matrix:
# Use these Java versions
java: [ 17 ]
# and run on both Linux and Windows
os: [ ubuntu-20.04, windows-latest ]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: ${{ matrix.java }}

- name: Make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: Build Fabric
run: ./gradlew :Fabric:build
- name: Capture Fabric build artifacts
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: Fabric/build/libs/

- name: Build Forge
run: ./gradlew :Forge:build
- name: Capture Forge build artifacts
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: Forge/build/libs/

- name: Build Quilt
run: ./gradlew :Quilt:build
- name: Capture Quilt build artifacts
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: Forge/build/libs/
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
# MultiLoader Template
## AddEmAll

This project provides a Gradle project template that can compile mods for both Forge and Fabric using a common sourceset. This project does not require any third party libraries or dependencies. If you have any questions or want to discuss the project join our [Discord](https://discord.myceliummod.network).
<!-- Mod page badges. Change the project ids and hyperlinks for correct data. -->
<!--
[![](http://cf.way2muchnoise.eu/full_415747_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/crumbs)
[![](https://modrinth-utils.vercel.app/api/badge/downloads/?id=crumbs&logo=true)](https://modrinth.com/mod/crumbs)
[![](http://cf.way2muchnoise.eu/versions/415747.svg)](https://www.curseforge.com/minecraft/mc-mods/crumbs)
-->

## Getting Started
Assortment of blocks I want to use.

## What does this mod do?

This mod adds an assortment of blocks I would like to use in Minecraft. Mainly blocks inspired by the aesthetic of Half Life 2's Citadel,
as well as other things good for decorative purposes.

## Other Information:

- Report Bugs at https://github.com/Griefed/AddEmAll/issues
- You can include this mod in your modpack as long as you don't claim the mod as your own.

# Development

## IntelliJ IDEA
This guide will show how to import the MultiLoader Template into IntelliJ IDEA. The setup process is roughly equivalent to setting up Forge and Fabric independently and should be very familiar to anyone who has worked with their MDKs.

1. Clone or download this repository to your computer.
2. Configure the project by editing the `group`, `mod_name`, `mod_author`, and `mod_id` properties in the `gradle.properties` file. You will also need to change the `rootProject.name` property in `settings.gradle`, this should match the folder name of your project, or else IDEA may complain.
3. Open the template's root folder as a new project in IDEA. This is the folder that contains this README file and the gradlew executable.
4. If your default JVM/JDK is not Java 17 you will encounter an error when opening the project. This error is fixed by going to `File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JVM`and changing the value to a valid Java 17 JVM. You will also need to set the Project SDK to Java 17. This can be done by going to `File > Project Structure > Project SDK`. Once both have been set open the Gradle tab in IDEA and click the refresh button to reload the project.
5. Open the Gradle tab in IDEA if it has not already been opened. Navigate to `Your Project > Common > Tasks > vanilla gradle > decompile`. Run this task to decompile Minecraft.
6. Open the Gradle tab in IDEA if it has not already been opened. Navigate to `Your Project > Forge > Tasks > forgegradle runs > genIntellijRuns`. Run this task to set up run configurations for Forge.
7. Open your Run/Debug Configurations. Under the Application category there should now be options to run Forge and Fabric projects. Select one of the client options and try to run it.
8. Assuming you were able to run the game in step 7 your workspace should now be set up.

### Eclipse
While it is possible to use this template in Eclipse it is not recommended. During the development of this template multiple critical bugs and quirks related to Eclipse were found at nearly every level of the required build tools. While we continue to work with these tools to report and resolve issues support for projects like these are not there yet. For now Eclipse is considered unsupported by this project. The development cycle for build tools is notoriously slow so there are no ETAs available.
2. Open the template's root folder as a new project in IDEA. This is the folder that contains this README file and the gradlew executable.
3. If your default JVM/JDK is not Java 17 you will encounter an error when opening the project. This error is fixed by going to `File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JVM`and changing the value to a valid Java 17 JVM. You will also need to set the Project SDK to Java 17. This can be done by going to `File > Project Structure > Project SDK`. Once both have been set open the Gradle tab in IDEA and click the refresh button to reload the project.
4. Open the Gradle tab in IDEA if it has not already been opened. Navigate to `Your Project > Common > Tasks > vanilla gradle > decompile`. Run this task to decompile Minecraft.
5. Open the Gradle tab in IDEA if it has not already been opened. Navigate to `Your Project > Forge > Tasks > forgegradle runs > genIntellijRuns`. Run this task to set up run configurations for Forge.
6. Open your Run/Debug Configurations. Under the Application category there should now be options to run Forge and Fabric projects. Select one of the client options and try to run it.
7. Assuming you were able to run the game in step 7 your workspace should now be set up.

## Development Guide
When using this template the majority of your mod is developed in the Common project. The Common project is compiled against the vanilla game and is used to hold code that is shared between the different loader-specific versions of your mod. The Common project has no knowledge or access to ModLoader specific code, apis, or concepts. Code that requires something from a specific loader must be done through the project that is specific to that loader, such as the Forge or Fabric project.
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import de.griefed.generation.BlockAndItemCodeGenerator

plugins {
id 'fabric-loom' version '1.2-SNAPSHOT' apply(false)
id 'fabric-loom' version '1.3-SNAPSHOT' apply(false)
id 'net.minecraftforge.gradle' version '[6.0,6.2)' apply(false)
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' apply(false)
id("org.spongepowered.mixin") version "0.7-SNAPSHOT" apply(false)
}

apply plugin: BlockAndItemCodeGenerator

subprojects {
apply plugin: 'java'

Expand Down
21 changes: 21 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'java'
}

group = 'de.griefed'
version = '0.0.1'

repositories {
mavenCentral()
}

dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.3'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
useJUnitPlatform()
}

Empty file added buildSrc/settings.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package de.griefed.generation;

import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.griefed.generation.blocks.BlockDefinitionParser;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
* Generates Forge, Fabric and Quilt block-implementations from block-definitions in a JSON-file.<br>
* See <code>definitions/blocks.json</code><br>
* Take note that textures for blocks must be present in <code>definitions/blocks</code> and the name of the textures
* must match the ID of the block.
*/
public class BlockAndItemCodeGenerator implements Plugin<Project> {
private final ObjectMapper objectMapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature());

public void apply(Project project) {
project.getTasks().register("blockAndItemCodeGen", task -> task.doLast(s -> System.out.println("Hello from plugin " + this.getClass().getName())));
try {
Properties gradleProperties = new Properties();
gradleProperties.load(new FileInputStream(new File(project.getRootDir(),"gradle.properties")));
String modName = gradleProperties.getProperty("mod_name");
BlockDefinitionParser parser = new BlockDefinitionParser(project, objectMapper);

CommonGeneration common = new CommonGeneration(project.findProject("common"), modName, parser, objectMapper);
FabricGeneration fabric = new FabricGeneration(project.findProject("fabric"), modName, parser, objectMapper);
ForgeGeneration forge = new ForgeGeneration(project.findProject("forge"), modName, parser, objectMapper);

common.run();
fabric.run();
forge.run();
} catch (IOException e) {
throw new RuntimeException("Error generating block and item code.", e);
}
}
}
56 changes: 56 additions & 0 deletions buildSrc/src/main/java/de/griefed/generation/CodeGeneration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.griefed.generation;

import java.io.IOException;

public interface CodeGeneration {

void run() throws IOException;

/**
* Create the ModBlocks-class inside the <code>your.group.modid.block</code>-package.
* Depending on the modloader, the template from which this class is generated differs.
* The functionality stays the same: The generated class allows for registering all custom blocks defined in
* the <code>definitions/blocks.json</code>-file.<br>
* <b>Do not manually edit the generated file!</b>
* @throws IOException when the file could not be created or edited.
*/
void createModBlocksClass() throws IOException;

/**
* Create the ModItems-class inside the <code>your.group.modid.item</code>-package.
* Depending on the modloader, the template from which this class is generated differs.
* The functionality stays the same: The generated class allows for registering all custom items defined in
* the <code>definitions/items.json</code>-file, as well as all items for any blocks defined in the
* <code>definitions/blocks.json</code>-file.
* @throws IOException when the file could not be created or edited.
*/
void createModItemsClass() throws IOException;

/**
* Create the modloader main-class housing the registration events, making sure that all blocks and items
* actually get registered. The class gets created inside the <code>your.group.modid</code>-package.
* @throws IOException when the file could not be created or edited.
*/
void createModloaderClass() throws IOException;

/**
* Update the <code>ModBlocks</code>-class to register all defined blocks.
* @throws IOException when the file could not be created or edited.
*/
void updateModBlocksClass() throws IOException;

/**
* Update the <code>ModItems</code>-class to register all defined blocks and items.
* @throws IOException when the file could not be created or edited.
*/
void updateModItemsClass() throws IOException;

/**
* Updates the modloaders main-class, more specifically the area inside said class which is reserved for updates
* by this method. The generated code will ensure that all mods registered in the ModBlocks-class will get added
* to the game by the respective modloader.
* @throws IOException when the file could not be created or edited.
*/
void updateModloaderMain() throws IOException;

}
19 changes: 19 additions & 0 deletions buildSrc/src/main/java/de/griefed/generation/CommonGeneration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.griefed.generation;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.griefed.generation.blocks.BlockDefinitionParser;
import org.gradle.api.Project;

import java.io.IOException;

public class CommonGeneration extends ModloaderGeneration {
protected CommonGeneration(Project project, String modName, BlockDefinitionParser parser, ObjectMapper objectMapper) {
super(project, modName, parser, objectMapper);
}

public void run() throws IOException {
updateTranslations();
createBlockFiles();
createItemFiles();
}
}
Loading

0 comments on commit 63f8fd3

Please sign in to comment.