Modding in Ruby

Discussion in 'Mod Development' started by trajing, Feb 17, 2015.

  1. trajing

    trajing New Member

    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.
     
    xbony2, CoolSquid and InfinityRaider like this.
  2. CoolSquid

    CoolSquid New Member

    That's interesting... I still love Java though <3

    Oh, @Strikingwolf
     
  3. Strikingwolf

    Strikingwolf New Member

    Yes I like this...if only it was in Clojure :p

    I need to see if I can do that...
     
  4. trajing

    trajing New Member

    The main class should be up tomorrow.
     
  5. Strikingwolf

    Strikingwolf New Member

    Awesome \o/
     
  6. ljfa

    ljfa New Member

    I'm excited so see what you come up with.
    So you can use Java annotations there?
     
  7. trajing

    trajing New Member

    Yes, with the java_annotation function.
     
  8. trajing

    trajing New Member

    Okay, first commit done. It may or may not fail horribly, I'm about to test.
     
  9. trajing

    trajing New Member

    ..and too many errors to count.
    Let's call try one a failure. Anyone want to try and help?
    *pokes @Strikingwolf*
     
  10. Strikingwolf

    Strikingwolf New Member

    /me is not touching this
     
  11. trajing

    trajing New Member

    Yes, the Java part does indeed look ugly.
     
  12. ljfa

    ljfa New Member

    Maybe tomorrow, but I'm not familiar with Ruby.

    BTW: y u no just use String rather than StringBuilder?
     
  13. trajing

    trajing New Member

    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.
     
  14. ljfa

    ljfa New Member

    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)
     
  15. ljfa

    ljfa New Member

    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
     

Share This Page