I intend to write this post a little like a blogpost, where I will try the next step required and report back findings and tips for those interested. The mod idea is a mod update checker, yes this has been done before (once by me) however Clojure is very good at this sort of problem1.I want the main output of this to be the learnings rather than the mod itself.
I also want to be very clear, that this may not even work out. Even if that is the case then I guess we have still learned about minecraft and Clojure.
Note1: If anyone has another mod idea please suggest it, however think more data processing rather than adding blocks.
Why Clojure?
Clojure is a functional programming language that runs on the jvm (so has access to all Java libraries). The syntax of Clojure is a derivative of Lisp and in my opinion this coupled with it using a "pure functional" paradime makes it's syntax very clean. Furthermore unlike Java functions are "first class citizens" and the concept of Objects do not exist2. I find that this also makes programs both more concise and easier to understand.
I guess what it comes down to for me is that I like Clojure and I am interested to see how a minecraft mod will work.
Note2: Due to the fact that all Java code can be called in Clojure this is not strictly true, it is however not the "normal" way clojure is used.
Part 1: Set-Up & Libraries
The first hurdle I had was setting up a minecraft/clojure environment. Luckily a gradle plugin exists which will allow gradle to compile Clojure code called clojuresque.
So I had to add this as a dependancy to my build.gradle
The second problem I ran into is by default Minecraft download's its dependencies and Forge adds a few more, some of which are scala specific ones. To run Clojure at least one more library is required (core.clojure). I really had 3 options that I could think of:
Ask the Minecraft Forge developers to download clojure libraries by default as well as the ones it requires.
Package the clojure libraries I require inside my mod.
Create a "Coremod" that will download the required libraries and add them to the classpath after minecraft is started but before mods are loaded.
I doubt Minecraft Forge will agree to 1 at this early stage (with any luck down the track once we have a working prototype this might work). Option 2, although probably being the easiest will result in relatively large mods that will have to be re-downloaded each time a new version of this mod comes out. Furthermore, it doesn't scale well when (of course by when I mean if) multiple people develop Clojure mods. So I went with number 3.
Luckily I do know my way around Coremods quite well. And although Clojure is my new favourite programming language, I have tones of experience in Java. Basically these are the steps required.
Given a list of libraries with their maven details
Loop through each required library
If library has previously been downloaded do nothing
If not, download the library and put it in a known location
Load library using filename from above into classpath
For a minimum viable solution I am not worring too much about error handling or dependancies of libraries, the former of which I will do when this becomes more stable, the later I can manually do.
Because I want this to be more about my Clojure adventures and less about the boring library stuff I will skip ahead and give the TLDR version. This worked without too much trouble. This should allow any potential users to keep a cached version of the required libraries for my mod rather than having to re-download them.
For those who are interested, here is a link to the github tag with the finished library downloader.
Stay tuned for the next step of the adventure, trying to make Minecraft Forge load a Clojure mod.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThe Adventure (What is this?)
I intend to write this post a little like a blogpost, where I will try the next step required and report back findings and tips for those interested. The mod idea is a mod update checker, yes this has been done before (once by me) however Clojure is very good at this sort of problem1.I want the main output of this to be the learnings rather than the mod itself.I also want to be very clear, that this may not even work out. Even if that is the case then I guess we have still learned about minecraft and Clojure.
Note1: If anyone has another mod idea please suggest it, however think more data processing rather than adding blocks.
Why Clojure?
Clojure is a functional programming language that runs on the jvm (so has access to all Java libraries). The syntax of Clojure is a derivative of Lisp and in my opinion this coupled with it using a "pure functional" paradime makes it's syntax very clean. Furthermore unlike Java functions are "first class citizens" and the concept of Objects do not exist2. I find that this also makes programs both more concise and easier to understand. I guess what it comes down to for me is that I like Clojure and I am interested to see how a minecraft mod will work. Note2: Due to the fact that all Java code can be called in Clojure this is not strictly true, it is however not the "normal" way clojure is used.Part 1: Set-Up & Libraries
The first hurdle I had was setting up a minecraft/clojure environment. Luckily a gradle plugin exists which will allow gradle to compile Clojure code called clojuresque. So I had to add this as a dependancy to my build.gradledependencies {Add clojars as a repositoryclasspath 'clojuresque:clojuresque:1.7.0'
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
maven {As well as enable the pluginname = "clojars"
url = "https://clojars.org/repo"
}
The second problem I ran into is by default Minecraft download's its dependencies and Forge adds a few more, some of which are scala specific ones. To run Clojure at least one more library is required (core.clojure). I really had 3 options that I could think of:
- Ask the Minecraft Forge developers to download clojure libraries by default as well as the ones it requires.
- Package the clojure libraries I require inside my mod.
- Create a "Coremod" that will download the required libraries and add them to the classpath after minecraft is started but before mods are loaded.
I doubt Minecraft Forge will agree to 1 at this early stage (with any luck down the track once we have a working prototype this might work). Option 2, although probably being the easiest will result in relatively large mods that will have to be re-downloaded each time a new version of this mod comes out. Furthermore, it doesn't scale well when (of course by when I mean if) multiple people develop Clojure mods. So I went with number 3. Luckily I do know my way around Coremods quite well. And although Clojure is my new favourite programming language, I have tones of experience in Java. Basically these are the steps required.For a minimum viable solution I am not worring too much about error handling or dependancies of libraries, the former of which I will do when this becomes more stable, the later I can manually do. Because I want this to be more about my Clojure adventures and less about the boring library stuff I will skip ahead and give the TLDR version. This worked without too much trouble. This should allow any potential users to keep a cached version of the required libraries for my mod rather than having to re-download them.
For those who are interested, here is a link to the github tag with the finished library downloader.
Stay tuned for the next step of the adventure, trying to make Minecraft Forge load a Clojure mod.
Definitely an interesting idea, never heard of Clojure before. Keep going...