Scalable Cat's Force

Scalable Cat's Force

26M Downloads

net.minecraftforge.fml.javafmlmod.FMLModContainer cannot access a member of class

mjm2000 opened this issue ยท 3 comments

commented

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

Screenshot_2023-09-23_23-59-57

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.")
}
commented

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.

commented

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.

commented

Ok the issue was I need to change the mods.toml file's modloader to
modLoader="kotori_scala"
Thank you for your help.