From 8737dd4d2c4f9dc375a278a5aef30e42518b78d2 Mon Sep 17 00:00:00 2001 From: Crystal Spider Date: Thu, 7 Mar 2024 16:54:34 +0100 Subject: [PATCH] Update and fix mixins with examples. --- .../cobweb_mod_template/Constants.java | 7 ++++ .../cobweb_mod_template/mixin/.gitkeep | 1 - .../mixin/TitleScreenMixin.java | 27 +++++++++++++ .../platform/Services.java | 6 --- .../resources/cobweb_mod_template.mixins.json | 4 +- .../cobweb_mod_template/mixin/.gitkeep | 1 - .../mixin/MinecraftServerMixin.java | 40 +++++++++++++++++++ .../cobweb_mod_template.fabric.mixins.json | 6 ++- .../cobweb_mod_template/mixin/.gitkeep | 1 - .../mixin/MinecraftServerMixin.java | 40 +++++++++++++++++++ .../cobweb_mod_template.forge.mixins.json | 6 ++- .../cobweb_mod_template/mixin/.gitkeep | 1 - .../mixin/MinecraftServerMixin.java | 40 +++++++++++++++++++ .../cobweb_mod_template.neoforge.mixins.json | 6 ++- 14 files changed, 169 insertions(+), 17 deletions(-) delete mode 100644 common/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep create mode 100644 common/src/main/java/crystalnest/cobweb_mod_template/mixin/TitleScreenMixin.java delete mode 100644 fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep create mode 100644 fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java delete mode 100644 forge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep create mode 100644 forge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java delete mode 100644 neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep create mode 100644 neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java diff --git a/common/src/main/java/crystalnest/cobweb_mod_template/Constants.java b/common/src/main/java/crystalnest/cobweb_mod_template/Constants.java index d78ccca..be2551c 100644 --- a/common/src/main/java/crystalnest/cobweb_mod_template/Constants.java +++ b/common/src/main/java/crystalnest/cobweb_mod_template/Constants.java @@ -1,5 +1,7 @@ package crystalnest.cobweb_mod_template; +import crystalnest.cobweb_mod_template.platform.Services; +import crystalnest.cobweb_mod_template.platform.services.PlatformHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,4 +20,9 @@ private Constants() {} * Mod logger. */ public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + /** + * Provides information about what platform the mod is running on. + */ + public static final PlatformHelper PLATFORM = Services.load(PlatformHelper.class); } diff --git a/common/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep b/common/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/common/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/common/src/main/java/crystalnest/cobweb_mod_template/mixin/TitleScreenMixin.java b/common/src/main/java/crystalnest/cobweb_mod_template/mixin/TitleScreenMixin.java new file mode 100644 index 0000000..696d8f0 --- /dev/null +++ b/common/src/main/java/crystalnest/cobweb_mod_template/mixin/TitleScreenMixin.java @@ -0,0 +1,27 @@ +package crystalnest.cobweb_mod_template.mixin; + +import crystalnest.cobweb_mod_template.Constants; +import net.minecraft.client.gui.components.LogoRenderer; +import net.minecraft.client.gui.screens.TitleScreen; +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.CallbackInfo; + +/** + * Example mixin class. + */ +@Mixin(TitleScreen.class) +public class TitleScreenMixin { + /** + * Injects at the end of the base constructor to print an example message. + * + * @param fading + * @param logoRenderer + * @param ci + */ + @Inject(method = "(ZLnet/minecraft/client/gui/components/LogoRenderer;)V", at = @At(value = "TAIL")) + private void onInit(boolean fading, LogoRenderer logoRenderer, CallbackInfo ci) { + Constants.LOGGER.info("Example mixin from " + Constants.PLATFORM.getPlatformName()); + } +} diff --git a/common/src/main/java/crystalnest/cobweb_mod_template/platform/Services.java b/common/src/main/java/crystalnest/cobweb_mod_template/platform/Services.java index 4e98475..1b94d4c 100644 --- a/common/src/main/java/crystalnest/cobweb_mod_template/platform/Services.java +++ b/common/src/main/java/crystalnest/cobweb_mod_template/platform/Services.java @@ -1,7 +1,6 @@ package crystalnest.cobweb_mod_template.platform; import crystalnest.cobweb_mod_template.Constants; -import crystalnest.cobweb_mod_template.platform.services.PlatformHelper; import java.util.ServiceLoader; @@ -10,11 +9,6 @@ * In the context of MultiLoader we use this feature to access a mock API in the common code that is swapped out for the platform specific implementation at runtime. */ public final class Services { - /** - * Provides information about what platform the mod is running on. - */ - public static final PlatformHelper PLATFORM = load(PlatformHelper.class); - private Services() {} /** diff --git a/common/src/main/resources/cobweb_mod_template.mixins.json b/common/src/main/resources/cobweb_mod_template.mixins.json index 65644f7..3631a8d 100644 --- a/common/src/main/resources/cobweb_mod_template.mixins.json +++ b/common/src/main/resources/cobweb_mod_template.mixins.json @@ -4,7 +4,9 @@ "package": "${group}.${mod_id}.mixin", "refmap": "${mod_id}.refmap.json", "compatibilityLevel": "JAVA_17", - "mixins": [], + "mixins": [ + "TitleScreenMixin" + ], "client": [], "server": [], "injectors": { diff --git a/fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep b/fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java b/fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java new file mode 100644 index 0000000..8707c54 --- /dev/null +++ b/fabric/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java @@ -0,0 +1,40 @@ +package crystalnest.cobweb_mod_template.mixin; + +import com.mojang.datafixers.DataFixer; +import crystalnest.cobweb_mod_template.Constants; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.Services; +import net.minecraft.server.WorldStem; +import net.minecraft.server.level.progress.ChunkProgressListenerFactory; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.world.level.storage.LevelStorageSource; +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.CallbackInfo; + +import java.net.Proxy; + +/** + * Example mixin class. + */ +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + /** + * Injects at the end of the base constructor to print an example message. + * + * @param thread + * @param levelStorageAccess + * @param packRepository + * @param worldStem + * @param proxy + * @param dataFixer + * @param services + * @param chunkProgressListenerFactory + * @param ci + */ + @Inject(method = "", at = @At(value = "TAIL")) + private void onInit(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) { + Constants.LOGGER.info("Example mixin from Fabric"); + } +} diff --git a/fabric/src/main/resources/cobweb_mod_template.fabric.mixins.json b/fabric/src/main/resources/cobweb_mod_template.fabric.mixins.json index 2d9e800..82cc272 100644 --- a/fabric/src/main/resources/cobweb_mod_template.fabric.mixins.json +++ b/fabric/src/main/resources/cobweb_mod_template.fabric.mixins.json @@ -1,10 +1,12 @@ { "required": true, "minVersion": "0.8", - "package": "${group}.mixin", + "package": "${group}.${mod_id}.mixin", "refmap": "${mod_id}.refmap.json", "compatibilityLevel": "JAVA_17", - "mixins": [], + "mixins": [ + "MinecraftServerMixin" + ], "client": [], "server": [], "injectors": { diff --git a/forge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep b/forge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/forge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/forge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java b/forge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java new file mode 100644 index 0000000..60ef605 --- /dev/null +++ b/forge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java @@ -0,0 +1,40 @@ +package crystalnest.cobweb_mod_template.mixin; + +import com.mojang.datafixers.DataFixer; +import crystalnest.cobweb_mod_template.Constants; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.Services; +import net.minecraft.server.WorldStem; +import net.minecraft.server.level.progress.ChunkProgressListenerFactory; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.world.level.storage.LevelStorageSource; +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.CallbackInfo; + +import java.net.Proxy; + +/** + * Example mixin class. + */ +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + /** + * Injects at the end of the base constructor to print an example message. + * + * @param thread + * @param levelStorageAccess + * @param packRepository + * @param worldStem + * @param proxy + * @param dataFixer + * @param services + * @param chunkProgressListenerFactory + * @param ci + */ + @Inject(method = "", at = @At(value = "TAIL")) + private void onInit(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) { + Constants.LOGGER.info("Example mixin from Forge"); + } +} diff --git a/forge/src/main/resources/cobweb_mod_template.forge.mixins.json b/forge/src/main/resources/cobweb_mod_template.forge.mixins.json index 2d9e800..82cc272 100644 --- a/forge/src/main/resources/cobweb_mod_template.forge.mixins.json +++ b/forge/src/main/resources/cobweb_mod_template.forge.mixins.json @@ -1,10 +1,12 @@ { "required": true, "minVersion": "0.8", - "package": "${group}.mixin", + "package": "${group}.${mod_id}.mixin", "refmap": "${mod_id}.refmap.json", "compatibilityLevel": "JAVA_17", - "mixins": [], + "mixins": [ + "MinecraftServerMixin" + ], "client": [], "server": [], "injectors": { diff --git a/neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep b/neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java b/neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java new file mode 100644 index 0000000..6b6dbf5 --- /dev/null +++ b/neoforge/src/main/java/crystalnest/cobweb_mod_template/mixin/MinecraftServerMixin.java @@ -0,0 +1,40 @@ +package crystalnest.cobweb_mod_template.mixin; + +import com.mojang.datafixers.DataFixer; +import crystalnest.cobweb_mod_template.Constants; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.Services; +import net.minecraft.server.WorldStem; +import net.minecraft.server.level.progress.ChunkProgressListenerFactory; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.world.level.storage.LevelStorageSource; +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.CallbackInfo; + +import java.net.Proxy; + +/** + * Example mixin class. + */ +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + /** + * Injects at the end of the base constructor to print an example message. + * + * @param thread + * @param levelStorageAccess + * @param packRepository + * @param worldStem + * @param proxy + * @param dataFixer + * @param services + * @param chunkProgressListenerFactory + * @param ci + */ + @Inject(method = "", at = @At(value = "TAIL")) + private void onInit(Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) { + Constants.LOGGER.info("Example mixin from NeoForge"); + } +} diff --git a/neoforge/src/main/resources/cobweb_mod_template.neoforge.mixins.json b/neoforge/src/main/resources/cobweb_mod_template.neoforge.mixins.json index 117f3fa..23cd3ac 100644 --- a/neoforge/src/main/resources/cobweb_mod_template.neoforge.mixins.json +++ b/neoforge/src/main/resources/cobweb_mod_template.neoforge.mixins.json @@ -1,9 +1,11 @@ { "required": true, "minVersion": "0.8", - "package": "${group}.mixin", + "package": "${group}.${mod_id}.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [], + "mixins": [ + "MinecraftServerMixin" + ], "client": [], "server": [], "injectors": {