net.minecraftforge.fml.javafmlmod.FMLModContainer cannot access a member of class
mjm2000 opened this issue ยท 3 comments
After building a basic mod following the example in
https://github.com/Kotori316/SLP/src/main/scala/com/kotori316/scala_lib/example/ScalaModObject.scala
Starting minecraft with the complied mod causes this error
Crash Report
crash-2023-09-23_23.54.09-fml.txt
My file
import net.minecraftforge.fml.ModList
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext
import org.apache.logging.log4j.{LogManager, Logger}
//import com.mod.civcraft.registery.Register
@Mod(CivCraft.modId)
object CivCraft {
final val modId = "civcraft"
val LOGGER:Logger = LogManager.getLogger(modId)
require(Class.forName("scala.Option").getMethod("empty").invoke(null) == None)
def init( event: FMLCommonSetupEvent): Unit = {
//Register.init()
LOGGER.info("Hello from ScalaModObject#init")
LOGGER.info(s"Mod($modId) is loaded. " + event)
//LOGGER.info(ModId(modId).show)
}
FMLJavaModLoadingContext.get().getModEventBus.addListener(CivCraft.init)
case class ModId(id: String)
// Example of Cats instance.
implicit val showId: Show[ModId] = (t: ModId) => {
val name = ModList.get().getModObjectById[AnyRef](t.id).map[String](o => o.getClass.getName).orElse("None")
s"ID: ${t.id}, Class: $name"
}
object BadEventHandler {
@SubscribeEvent
def worldLogin(worldEvent: LevelEvent): Unit = {
LOGGER.fatal("NEVER HAPPENED " + worldEvent)
}
}
}
class CivCraft {
throw new java.lang.AssertionError("Mod class (not object) must not be loaded by forge. The companion object is mod instance.")
}
I think you have wrong settings in your mod, or you didn't change something required to run Mods written in Scala.
I'll update the example repo for 1.20.1, and you can compare your project (including build script and mods.toml
) and the template.
Updated: https://github.com/Kotori316/SLP-example/tree/1.20.1/src/main
If you still have problems, ask me with the whole project in zip file.