Skip to content

Commit

Permalink
Fix up entrypoint (fixes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Jun 18, 2024
1 parent c902b2c commit 3c747fd
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 58 deletions.
62 changes: 5 additions & 57 deletions src/main/kotlin/dev/deftu/modtemplate/ModTemplate.kt
Original file line number Diff line number Diff line change
@@ -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() {
}

}
9 changes: 9 additions & 0 deletions src/main/kotlin/dev/deftu/modtemplate/ModTemplateConstants.kt
Original file line number Diff line number Diff line change
@@ -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@"

}
11 changes: 11 additions & 0 deletions src/main/kotlin/dev/deftu/modtemplate/client/ModTemplateClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.deftu.modtemplate.client

object ModTemplateClient {

/**
* Your client-only logic goes here...
*/
fun onInitializeClient() {
}

}
Original file line number Diff line number Diff line change
@@ -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

}
11 changes: 11 additions & 0 deletions src/main/kotlin/dev/deftu/modtemplate/server/ModTemplateServer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.deftu.modtemplate.server

object ModTemplateServer {

/**
* Your server-only logic goes here...
*/
fun onInitializeServer() {
}

}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"main": [
{
"adapter": "kotlin",
"value": "dev.deftu.modtemplate.ModTemplate"
"value": "dev.deftu.modtemplate.entrypoint.ModTemplateEntrypoint"
}
]
},
Expand Down

0 comments on commit 3c747fd

Please sign in to comment.