diff --git a/src/main/kotlin/dev/deftu/modtemplate/ModTemplate.kt b/src/main/kotlin/dev/deftu/modtemplate/ModTemplate.kt index 037421d..f4fbe7c 100644 --- a/src/main/kotlin/dev/deftu/modtemplate/ModTemplate.kt +++ b/src/main/kotlin/dev/deftu/modtemplate/ModTemplate.kt @@ -1,63 +1,11 @@ package dev.deftu.modtemplate -//#if FABRIC -import net.fabricmc.api.ModInitializer -//#elseif FORGE -//#if MC >= 1.15.2 -//$$ import net.minecraftforge.fml.common.Mod -//$$ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent -//$$ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext -//#else -//$$ import net.minecraftforge.fml.common.Mod -//$$ import net.minecraftforge.fml.common.Mod.EventHandler -//$$ import net.minecraftforge.fml.common.event.FMLInitializationEvent -//#endif -//#elseif NEOFORGE -//$$ import net.neoforged.bus.api.IEventBus -//$$ import net.neoforged.fml.common.Mod -//$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent -//#endif +object ModTemplate { -//#if FORGE-LIKE -//#if MC >= 1.15.2 -//$$ @Mod(ModTemplate.ID) -//#else -//$$ @Mod(modid = ModTemplate.ID) -//#endif -//#endif -object ModTemplate - //#if FABRIC - : ModInitializer - //#endif -{ - - const val NAME = "@MOD_NAME@" - const val ID = "@MOD_ID@" - const val VERSION = "@MOD_VERSION@" - - //#if FORGE && MC >= 1.15.2 - //$$ init { - //$$ FMLJavaModLoadingContext.get().modEventBus.addListener(this::onClientSetup) - //$$ } - //#elseif NEOFORGE - //$$ constructor(modEventBus: IEventBus) { - //$$ modEventBus.addListener(this::onClientSetup) - //$$ } - //#endif - - //#if FABRIC - override - //#endif - fun onInitialize( - //#if FORGE-LIKE - //#if MC >= 1.15.2 - //$$ event: FMLClientSetupEvent - //#else - //$$ event: FMLInitializationEvent - //#endif - //#endif - ) { - // Your common (both client & server) logic goes here... + /** + * Initialize common (both client & server) logic here. + */ + fun onInitializeCommon() { } } diff --git a/src/main/kotlin/dev/deftu/modtemplate/ModTemplateConstants.kt b/src/main/kotlin/dev/deftu/modtemplate/ModTemplateConstants.kt new file mode 100644 index 0000000..27e50f0 --- /dev/null +++ b/src/main/kotlin/dev/deftu/modtemplate/ModTemplateConstants.kt @@ -0,0 +1,9 @@ +package dev.deftu.modtemplate + +object ModTemplateConstants { + + const val NAME = "@MOD_NAME@" + const val ID = "@MOD_ID@" + const val VERSION = "@MOD_VERSION@" + +} diff --git a/src/main/kotlin/dev/deftu/modtemplate/client/ModTemplateClient.kt b/src/main/kotlin/dev/deftu/modtemplate/client/ModTemplateClient.kt new file mode 100644 index 0000000..3029c75 --- /dev/null +++ b/src/main/kotlin/dev/deftu/modtemplate/client/ModTemplateClient.kt @@ -0,0 +1,11 @@ +package dev.deftu.modtemplate.client + +object ModTemplateClient { + + /** + * Your client-only logic goes here... + */ + fun onInitializeClient() { + } + +} diff --git a/src/main/kotlin/dev/deftu/modtemplate/entrypoint/ModTemplateEntrypoint.kt b/src/main/kotlin/dev/deftu/modtemplate/entrypoint/ModTemplateEntrypoint.kt new file mode 100644 index 0000000..8be66c4 --- /dev/null +++ b/src/main/kotlin/dev/deftu/modtemplate/entrypoint/ModTemplateEntrypoint.kt @@ -0,0 +1,117 @@ +package dev.deftu.modtemplate.entrypoint + +//#if FABRIC +import net.fabricmc.api.ClientModInitializer +import net.fabricmc.api.DedicatedServerModInitializer +import net.fabricmc.api.ModInitializer +//#elseif FORGE +//#if MC >= 1.15.2 +//$$ import net.minecraftforge.eventbus.api.IEventBus +//$$ import net.minecraftforge.fml.common.Mod +//$$ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent +//$$ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent +//$$ import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent +//$$ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext +//#else +//$$ import net.minecraftforge.fml.common.Mod +//$$ import net.minecraftforge.fml.common.Mod.EventHandler +//$$ import net.minecraftforge.fml.common.event.FMLInitializationEvent +//#endif +//#elseif NEOFORGE +//$$ import net.neoforged.bus.api.IEventBus +//$$ import net.neoforged.fml.common.Mod +//$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent +//$$ import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent +//$$ import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent +//#endif + +import dev.deftu.modtemplate.ModTemplate +import dev.deftu.modtemplate.client.ModTemplateClient +import dev.deftu.modtemplate.server.ModTemplateServer + +//#if FORGE-LIKE +//$$ import dev.deftu.modtemplate.ModTemplateConstants +//#if MC >= 1.15.2 +//$$ @Mod(ModTemplateConstants.ID) +//#else +//$$ @Mod(modid = ModTemplateConstants.ID) +//#endif +//#endif +object ModTemplateEntrypoint + //#if FABRIC + : ModInitializer, ClientModInitializer, DedicatedServerModInitializer + //#endif +{ + + //#if FORGE && MC >= 1.15.2 + //$$ init { + //$$ setupForgeEvents(FMLJavaModLoadingContext.get().modEventBus) + //$$ } + //#elseif NEOFORGE + //$$ constructor(modEventBus: IEventBus) { + //$$ setupForgeEvents(modEventBus) + //$$ } + //#endif + + //#if FABRIC + override + //#endif + fun onInitialize( + //#if FORGE-LIKE + //#if MC >= 1.15.2 + //$$ event: FMLCommonSetupEvent + //#else + //$$ event: FMLInitializationEvent + //#endif + //#endif + ) { + ModTemplate.onInitializeCommon() + } + + //#if FABRIC + override + //#endif + fun onInitializeClient( + //#if FORGE-LIKE + //#if MC >= 1.15.2 + //$$ event: FMLClientSetupEvent + //#else + //$$ event: FMLInitializationEvent + //#endif + //#endif + ) { + //#if MC <= 1.12.2 + //$$ if (!event.side.isClient) return + //#endif + + ModTemplateClient.onInitializeClient() + } + + //#if FABRIC + override + //#endif + fun onInitializeServer( + //#if FORGE-LIKE + //#if MC >= 1.15.2 + //$$ event: FMLDedicatedServerSetupEvent + //#else + //$$ event: FMLInitializationEvent + //#endif + //#endif + ) { + //#if MC <= 1.12.2 + //$$ if (!event.side.isServer) return + //#endif + + ModTemplateServer.onInitializeServer() + } + + //#if FORGE-LIKE && MC >= 1.15.2 + //$$ fun setupForgeEvents(modEventBus: IEventBus) { + //$$ modEventBus.addListener(this::onInitialize) + //$$ modEventBus.addListener(this::onInitializeClient) + //$$ modEventBus.addListener(this::onInitializeServer) + //$$ } + //#endif + +} diff --git a/src/main/kotlin/dev/deftu/modtemplate/server/ModTemplateServer.kt b/src/main/kotlin/dev/deftu/modtemplate/server/ModTemplateServer.kt new file mode 100644 index 0000000..a6cbeaf --- /dev/null +++ b/src/main/kotlin/dev/deftu/modtemplate/server/ModTemplateServer.kt @@ -0,0 +1,11 @@ +package dev.deftu.modtemplate.server + +object ModTemplateServer { + + /** + * Your server-only logic goes here... + */ + fun onInitializeServer() { + } + +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 58ca8e4..fa24184 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,7 +21,7 @@ "main": [ { "adapter": "kotlin", - "value": "dev.deftu.modtemplate.ModTemplate" + "value": "dev.deftu.modtemplate.entrypoint.ModTemplateEntrypoint" } ] },