Giter Site home page Giter Site logo

slp's Introduction

Scala language provider for Minecraft 1.20.

Branch 1.20

This mod adds Scala library to Minecraft 1.20 with Forge. NO COMPATIBILITY WITH 1.19 version of SLP.

Usage

  • For Player - Download Jar file from Curse Forge or Modrinth and move the file to your mods folder. This mod will not appear in mods list.

  • For Developer
    See this repository for example.

    In your build.gradle, add below code in the top-level.

    repositories {
        maven {
            name = "Azure-SLP"
            url = uri("https://pkgs.dev.azure.com/Kotori316/minecraft/_packaging/mods/maven/v1")
            content {
                it.includeModule("com.kotori316", "ScalableCatsForce".toLowerCase())
                it.includeModule("org.typelevel", "cats-core_3")
                it.includeModule("org.typelevel", "cats-kernel_3")
                it.includeModule("org.typelevel", "cats-free_3")
            }
        }
    }
    
    dependencies {
        // Change forge and minecraft version.
        minecraft 'net.minecraftforge:forge:1.20.1-47.1.43'
        compileOnly(group: 'org.scala-lang', name: 'scala-library', version: '3.3.0')
        // Add if you need this library. I use a modified version of Cats to avoid some module errors.
        compileOnly(group: 'org.typelevel', name: 'cats-core_3', version: '2.9.2-kotori')
    
        // The language loader. You can put the jar to the mods dir instead of declaring in `build.gradle.kts`.
        // This file is needed as the scala library will not be loaded in dev environment due to change of classpath by Forge.
        runtimeOnly(group: "com.kotori316", name: "ScalableCatsForce".toLowerCase(), version: "3.3.0-build-2", classifier: "with-library") {
            transitive(false)
        }
    }
    • If the Minecraft client doesn't launch with an exception to modules, change scala dependency from "implementation" to "compileOnly" and add slp mod in mods directory.
    • Change library version if needed.
      • See detail pages in CurseForge or Modrinth to get which library version is included in the Jar file.
    • From 1.20 version, SLP includes Scala 3
      • May not have binary compatibility with jars build with Scala2.
        • Files build with Scala2 may throw error if you use "Macthing on case classes" in your code.
        • This is due to internal change in Scala3.
        • Though SLP jar contains all classes from Scala2, this kind of error happens.
      • Compile with Scala3 will not cause these runtime errors.

Limitations

In this section, I note some points you should care.

  1. Avoid use of Mod.EventBusSubscriber in Java code. This will cause exception in "compileScala" task.
  • Use in Scala code will not throw exception.
  1. If you got compile error "ambiguous reference to overloaded definition", specify the return type.
  • For example, val offsetPos = pos.relative(direction) will cause this error because relative is declared both in BlockPos and Vec3i, and the return types aren't same. So, the compiler can't determine which method to call. To resolve this issue, specify the return type as follows. val offsetPos: BlockPos = pos.relative(direction)

API

slp's People

Contributors

bdew avatar kotori316 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slp's Issues

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

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

Crash because ModContainer.triggerMap was removed in forge 1.16.2-33.0.30

In the following commit ModContainer.triggerMap was removed: MinecraftForge/MinecraftForge@d76ee4e#diff-8e1cfb1483294fa0e650c5e32042eabfL58

- protected final Map<ModLoadingStage, Consumer<LifecycleEventProvider.LifecycleEvent>> triggerMap;
+ protected final Map<ModLoadingStage, Runnable> activityMap = new HashMap<>();

In forge 1.16.2-33.0.23 and below everything works fine but since 1.16.2-33.0.30 the game crashes.

[02Sep2020 15:59:19.350] [main/FATAL] [net.minecraft.server.Main/]: Failed to start the minecraft server
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at com.kotori316.scala_lib.ScalaLanguageTarget.loadMod(ScalaLanguageTarget.scala:19) ~[?:2.13.3-build-1]
	at net.minecraftforge.fml.ModLoader.buildModContainerFromTOML(ModLoader.java:297) ~[?:?]
	at net.minecraftforge.fml.ModLoader.lambda$buildMods$24(ModLoader.java:277) ~[?:?]
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) ~[?:1.8.0_261]
	at java.util.Iterator.forEachRemaining(Unknown Source) ~[?:1.8.0_261]
	at scala.collection.convert.JavaCollectionWrappers$MapWrapper$$anon$2$$anon$3.forEachRemaining(JavaCollectionWrappers.scala:232) ~[?:2.13.3-build-1]
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.ReferencePipeline.collect(Unknown Source) ~[?:1.8.0_261]
	at net.minecraftforge.fml.ModLoader.buildMods(ModLoader.java:279) ~[?:?]
	at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$7(ModLoader.java:183) ~[?:?]
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) ~[?:1.8.0_261]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:1.8.0_261]
	at java.util.stream.ReferencePipeline.collect(Unknown Source) ~[?:1.8.0_261]
	at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[?:?]
	at net.minecraftforge.fml.server.ServerModLoader.load(ServerModLoader.java:53) ~[?:?]
	at net.minecraft.server.Main.main(Main.java:96) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_261]
	at net.minecraftforge.fml.loading.FMLServerLaunchProvider.lambda$launchService$0(FMLServerLaunchProvider.java:51) ~[forge-1.16.2-33.0.32.jar:33.0]
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-6.1.1.jar:?]
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-6.1.1.jar:?]
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-6.1.1.jar:?]
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-6.1.1.jar:?]
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-6.1.1.jar:?]
	at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) [forge-1.16.2-33.0.32.jar:?]
	at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) [forge-1.16.2-33.0.32.jar:?]
	at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) [forge-1.16.2-33.0.32.jar:?]
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_261]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_261]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_261]
	at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_261]
	at com.kotori316.scala_lib.ScalaLanguageTarget.loadMod(ScalaLanguageTarget.scala:15) ~[?:2.13.3-build-1]
	... 37 more
Caused by: java.lang.NoSuchFieldError: triggerMap
	at com.kotori316.scala_lib.ScalaModContainer.<init>(ScalaModContainer.java:54) ~[?:2.13.3-build-1]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_261]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_261]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_261]
	at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_261]
	at com.kotori316.scala_lib.ScalaLanguageTarget.loadMod(ScalaLanguageTarget.scala:15) ~[?:2.13.3-build-1]
	... 37 more

intended way to add cats-free as dependency?

copied from SLP-Example because I mistakenly put this there first

To preface, I've been trying to figure out how to add cats-free as a dependency for my SLP mod for about a week.

Most of the issues have been about two things: the compile only custom cats version, and the fact that cats and all its dependencies are wrapped in scalablecatsforce at runtime. For the first issue, I've set the version of the custom cats version as strict, which seems to solve the version conflict, but that still leaves the runtime issue.

I've tried two approaches to solving this. Calling transitive(false) for cats-free removes all extraneous dependencies, but even though all its dependencies exist both at runtime and compile time, a classDefNotFoundError appears for cats.Foldable when calling foldMap on my Free dsl. I also tried to use dependency substitution, replacing cats core, kernel, etc. with ScalableCatsForce on the runtimeClasspath configuration. However, though this seems to fix gradle's reported runtimeClasspath, minecraft's runClient still contains all the unmodified typelevel dependencies. (Note: as advised by others, I'm using a custom configuration extending implementation to load cats-free and its dependencies to minecraft's classpath. I assume the dependency substitution problem has something to do with this, but I don't know why)

Is there something I can do to fix this as it is, or am I going about this all wrong?

crash on startup sever with forge 41.1.0

[27juil.2022 21:14:03.384] [main/ERROR] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: Failed to load mod file META-INF\jarjar\scala-library-2.13.8.jar from ScalableCatsForce-2.13.8-build-6-with-library.jar

that the only line i got from the latest logs (no crash reports) the client work fine

Build requires symlink in build/classes

Maybe this is from something I missed elsewhere, but in order to build or test a scala mod I must first create a symlink (or copy) from build/classes/scala to build/classes/java, otherwise Forge complains it cant find build/classes/java when trying runClient etc.

Is there some way I can either tell forge that it should look in build/classes/scala or do this automatically?

It would be great if there was a full empty example mod using this library. I tried copying the relevant parts of this mod's code but got the above problem. Having a blank slate that (ideally) could be git cloned and ready to go would be brilliant.

1.19.1 mods with @Mod annotation on object not loading anymore

Getting this on all my mods that have @mod annotation on an object. Changing them to a class works correctly.

It looks like the scan in ScalaLanguageProvider finds the annotation twice with and without the $ and when it can't get the constructor on one of them it crashes.

image

[21:36:49] [modloading-worker-0/ERROR] [co.ko.sc.ScalaModContainer/LOADING]: Failed to create/get mod instance. ModID: factorium, class net.bdew.factorium.Factorium
java.lang.NoSuchMethodException: net.bdew.factorium.Factorium.<init>()
	at java.lang.Class.getConstructor0(Class.java:3585) ~[?:?] {}
	at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}
	at com.kotori316.scala_lib.ScalaModContainer.constructMod(ScalaModContainer.java:82) ~[scalablecatsforce-2.13.8-build-6-with-library.jar%23194!/:2.13.8-build-6] {}
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.1-42.0.2.jar%23187!/:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.run$$$capture(CompletableFuture.java:1804) [?:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java) [?:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) [?:?] {}
	at java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:373) [?:?] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java) [?:?] {}
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) [?:?] {}
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) [?:?] {}
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) [?:?] {}
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) [?:?] {}

Exit code -1 only happens when slp is installed

I've tried different forge versions, different slp versions all come back with exit code -1. I really want to play with advanced generators so I would really like this to work. I tried using the exact same mod setup for these files (AG, bdlib and slp) that another modpack uses (that works fine) and still no success. I know slp is the problem because I tried loading the modpack without it and it loaded fine, apart from the message saying Advanced Generators and Bdlib needing kotori_scala.

Latest log here:
https://paste-bin.xyz/42111

2.13.8-build-1 on curseforge?

I've started porting my scala mods to 1.18 and used 2.13.8-build-1
but i noticed CF only has 2.13.7
could you upload the new version please?

Could you please upload ScalableCatsForce-2.13.1-build-6-dev to curseforge?

Hi there!
I was trying to backport a mod to 1.15.2 but noticed that the dev artifact on the curseforge maven is missing for ScalableCatsForce-2.13.1-build-6.
I don't know if this is an oversight and maybe you don't support <1.16 versions anymore but it would be very convenient if I could consume the library via the curseforge maven registry.

Forge Not Loading If The Library Is In Mod Folder

if the library is out of the folder Minecraft will load but if it is in the mods folder it will not load

the crash occurred in the FML early progress window whilst doing the deep scan on all the mods

error:

The game crashed whilst initializing game
Error: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

Crash Log: https://pastebin.com/2zP7CF0h

thank you

Upload to Modrinth

Modrinth seems to be getting some traction with the modding community as an alternative to curseforge.

Could you please upload Scalable Cat's Force so it's available for mods depending on it?

can't make the tanks

there is no recipe for the tanks in rei so i don't know how im supposed to make the tank when there is no recipe im running fabric on 1.20.1 i see the tanks in the rei just no recipe for the tanks

Crash while loading

When I start Minecraft with this mod (version: 2.13.3-build-6) I will get a crash (circa 2 seconds after starting). There is no crash report or anything. I just get the message "Exit Code: 0"

1.20.4 The Mod File *\build\sourcesSets\main has mods that were not found

In 1.20.4 game verstion it can't find main class file(any class file to be exact). The implementation of the class:

cpw.mods.jarhandling.impl.Jar

differs in 1.20.1 and 1.20.4. As a result it returns different paths and the loader searches for location where are no classes. In case I manualy copy classes to \build\sourcesSets\main it works.

Not loading in 1.17.1

When putting ScalableCatsForce-2.13.6-build-4-with-library on minecraft 1.17.1 into mods folder

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "net.minecraftforge.forgespi.language.IModFileInfo.moduleName()" because the return value of "net.minecraftforge.forgespi.locating.IModFile.getModFileInfo()" is null
at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.moddiscovery.ModJarMetadata.name(ModJarMetadata.java:53)
at [email protected]/cpw.mods.jarhandling.impl.Jar.name(Jar.java:202)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:550)
at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.ModuleLayerHandler.buildLayer(ModuleLayerHandler.java:69)
at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.ModuleLayerHandler.buildLayer(ModuleLayerHandler.java:82)
at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:93)
at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)
at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)
at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)
at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90)

Support for Minecraft 1.17.1

I'm working to support 1.17, but I have encountered some problems due to the change of mod loading system of Forge and bugs(?).
In this issue, I share the critical points, solutions and progress.

  • Launch Minecraft with SLP(kotori_scala)

    • Currently I get crashes due to NPE, which means forge has bugs or there is more good way to load language provider.
  • Develop with SLP

  • Search why NPE occurred.

    • Because of lack of IModFileInfo. The instance should be created in loading mods, but the creation doesn't work for language providers.
    • I have to implement custom ModLocator to load my scala provider.
    • I have created some classes but another problem related to module system occurred.

NoClassDefFoundError for 3rd party scala dependencies

Hi,

I'm porting my mod to 1.18 with Forge 40.1.0, but have problem of NoClassDefFoundError for 3rd party scala library.

Reproduce steps:

  1. Use your SLP-example repository.
  2. Add random scala dependencies to gradle. For example,
    • implementation(group: "org.json4s", name: "json4s-native_2.13", version: "4.1.0-M1")
  3. Use this library in ExampleMod.scala as below.
package com.example.examplemod

import net.minecraftforge.fml.common.Mod
import org.apache.logging.log4j.LogManager
import org.json4s.native.JsonMethods._

@Mod(ExampleMod.MOD_ID)
object ExampleMod {
  final val MOD_ID = "examplemod"
  private val LOGGER = LogManager.getLogger
  LOGGER.info(parse(""" { "numbers" : [1, 2, 3, 4] } """))
}
  1. Run gradle runClient, and it will throw Suppressed: java.lang.NoClassDefFoundError: org/json4s/native/JsonMethods$

I tested with multiple external scala libraries and did some experiments to solve it.

  1. Copy-paste the source code of external libraries to the local project. It will be load successfully.
  2. Build Jar shadowing the external libraries, and it will be OK.

But these solutions aren't good to use in development. Do you have any better idea to deal with it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.