From d2f9ca787ca3fcfac234b68b4972416c65302666 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Sat, 25 Nov 2023 01:44:12 -0500 Subject: [PATCH] Example mod --- exampleMod/build.gradle | 55 +++++++++++++++++++ .../examplemod/ExampleMod.java | 15 +++++ .../examplemod/mixin/MainMixin.java | 15 +++++ .../src/main/resources/examplemod.mixins.json | 13 +++++ exampleMod/src/main/resources/fabric.mod.json | 27 +++++++++ 5 files changed, 125 insertions(+) create mode 100644 exampleMod/build.gradle create mode 100644 exampleMod/src/main/java/com/elitemastereric/examplemod/ExampleMod.java create mode 100644 exampleMod/src/main/java/com/elitemastereric/examplemod/mixin/MainMixin.java create mode 100644 exampleMod/src/main/resources/examplemod.mixins.json create mode 100644 exampleMod/src/main/resources/fabric.mod.json diff --git a/exampleMod/build.gradle b/exampleMod/build.gradle new file mode 100644 index 0000000..de069c5 --- /dev/null +++ b/exampleMod/build.gradle @@ -0,0 +1,55 @@ +plugins { + id 'java' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 + +version = "1.2.0" +group = "com.elitemastereric" +archivesBaseName = "examplemod" + +repositories { + mavenCentral() + maven { + url 'https://jitpack.io' + } + maven { + url "https://repo.spongepowered.org/maven/" + } + maven { + url "https://maven.fabricmc.net/" + } +} + +dependencies { + // Dependency on the Hello World app + implementation project(':app') + implementation project(':modLoader') +} + +processResources { + inputs.property "version", project.version + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + it.options.release = 16 +} + +task buildAndCopy(type: Copy) { + group 'build' + dependsOn 'assemble' + from "build/libs/" + into "../run/mods" +} \ No newline at end of file diff --git a/exampleMod/src/main/java/com/elitemastereric/examplemod/ExampleMod.java b/exampleMod/src/main/java/com/elitemastereric/examplemod/ExampleMod.java new file mode 100644 index 0000000..229babd --- /dev/null +++ b/exampleMod/src/main/java/com/elitemastereric/examplemod/ExampleMod.java @@ -0,0 +1,15 @@ +package com.elitemastereric.examplemod; + +import net.fabricmc.api.ModInitializer; + +import java.util.logging.Logger; + +public class ExampleMod implements ModInitializer { + public static final String MOD_ID = "examplemod"; + public static final Logger LOGGER = Logger.getLogger(MOD_ID); + + @Override + public void onInitialize() { + // System.out.println("Hello Fabric world!"); + } +} diff --git a/exampleMod/src/main/java/com/elitemastereric/examplemod/mixin/MainMixin.java b/exampleMod/src/main/java/com/elitemastereric/examplemod/mixin/MainMixin.java new file mode 100644 index 0000000..99bd487 --- /dev/null +++ b/exampleMod/src/main/java/com/elitemastereric/examplemod/mixin/MainMixin.java @@ -0,0 +1,15 @@ +package com.elitemastereric.examplemod.mixin; + +import com.elitemastereric.helloworld.Main; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Main.class) +public class MainMixin { + @Inject(method = "getGreeting*", at = @At("RETURN"), cancellable = true) + public void injectGetGreeting(CallbackInfoReturnable callbackInfo) { + callbackInfo.setReturnValue("Goodbye World!"); + } +} diff --git a/exampleMod/src/main/resources/examplemod.mixins.json b/exampleMod/src/main/resources/examplemod.mixins.json new file mode 100644 index 0000000..a9e0405 --- /dev/null +++ b/exampleMod/src/main/resources/examplemod.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.elitemastereric.examplemod.mixin", + "mixins": [ + "MainMixin" + ], + "client": [], + "server": [], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/exampleMod/src/main/resources/fabric.mod.json b/exampleMod/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..a246517 --- /dev/null +++ b/exampleMod/src/main/resources/fabric.mod.json @@ -0,0 +1,27 @@ +{ + "schemaVersion": 1, + "id": "examplemod", + "version": "${version}", + "name": "Hello World Example Mod", + "description": "An example mod for Hello World app", + "authors": [ + "EliteMasterEric" + ], + "contact": { + "homepage": "https://elitemastereric.com" + }, + "license": "MIT", + "environment": "*", + "entrypoints": { + "main": [ + "com.elitemastereric.examplemod.ExampleMod" + ] + }, + "mixins": [ + "examplemod.mixins.json" + ], + "depends": { + "fabricloader": ">=0.13.3", + "helloworld": "1.0.*" + } + } \ No newline at end of file