Modding in Ruby

trajing

New Member
Jul 29, 2019
3,102
0
1
As you can probably tell, I'm a bit more into Ruby than the average person. :p
So, on a whim, I decided to check if JRuby, a JVM version of Ruby, as opposed to the C-based interpreter, could compile Ruby source to Java bytecode.
It could.
It also had things that allowed me to import Java classes to use in Ruby.
The Ruby version of my main mod file isn't up on the Github repository yet, and the Java version certainly isn't, but for when I do push it to the repo, take a look here.
At the moment, I'm restricting myself to simple blocks and items, but hopefully, once I learn enough, it will actually become feasible to write fully-featured mods in Ruby.
 

ljfa

New Member
Jul 29, 2019
2,808
0
0
I'm excited so see what you come up with.
So you can use Java annotations there?
 

trajing

New Member
Jul 29, 2019
3,102
0
1
Maybe tomorrow, but I'm not familiar with Ruby.

BTW: y u no just use String rather than StringBuilder?
On the Java side? That's what JRuby compiled it to when I ran it through jrubyc. Also, make sure you install JRuby instead of the C-based interpreter.
 

ljfa

New Member
Jul 29, 2019
2,808
0
0
I got it to compile but I had to change
Code:
import Mod;
import EventHandler;
import FMLInitializationEvent;
in the java file to
Code:
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
And I had to put the jruby.jar into the libs folder so that gradle can find it there. I have no idea how to properly declare this dependency in gradle though.
I also had to put the jruby.jar in the mods folder.

But it fails on startup with this:
Code:
java.lang.ExceptionInInitializerError
.....
Caused by: org.jruby.exceptions.RaiseException: (NameError) undefined local variable or method `cpw' for main:Object
at RUBY.(root)(MCModRB.rb:5)
at net.minecraft.client.main.Main.main(SourceFile:148)
 

ljfa

New Member
Jul 29, 2019
2,808
0
0
For some reason, I can't get jrubyc to work:
Code:
NameError: missing class or uppercase package name (`org.jruby.compiler.impl.StandardASMCompiler'), caused by (NameError) cannot load Java class org.jruby.compiler.impl.StandardASMCompiler