简体   繁体   中英

How to use class declarations using jruby

I'm trying to make a mod for Minecraft using Forge and JRuby. I want to use Ruby to write mods, but I need use class declarations for Forge to accept it as a mod.

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)

I tried write this like a function, but it doesn't work. I see no errors, but Forge doesn't recognize then.

Mod(modid = MyMod.modid, version = MyMod.version)

How do I write this in Ruby? If i write this part in Java and the rest in Ruby, it works, but I would prefer for it to all be in Ruby.

Edited: This is the correct way to create a mod using java:

package com.example.examplemod;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
    public static final String MODID = "examplemod";
    public static final String VERSION = "1.0";

    @EventHandler
    public void init(FMLInitializationEvent event)
    {

    }
}

My code in ruby:

require 'java'

import 'cpw.mods.fml.common.Mod'
import 'cpw.mods.fml.common.registry.GameRegistry'
import 'net.minecraft.init.Blocks'
import 'net.minecraft.creativetab.CreativeTabs'
import 'net.minecraft.block.material.Material'

class MyMod
    modid = "examplemod2";
    version = "1.0";

    def init(event)

    end
end

It looks like these are annotations, so take a look at JRuby's reference on them .

It might end up looking something like:

java_annotation('Mod(modid="MyModID", name="MyModName")')
class MyMod
  # ... mod stuff
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM