简体   繁体   English

如何使用jruby使用类声明

[英]How to use class declarations using jruby

I'm trying to make a mod for Minecraft using Forge and JRuby. 我正在尝试使用Forge和JRuby为Minecraft制作一个mod。 I want to use Ruby to write mods, but I need use class declarations for Forge to accept it as a mod. 我想使用Ruby编写mod,但是我需要使用类声明来让Forge接受它作为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. 我没有看到任何错误,但是Forge无法识别。

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

How do I write this in Ruby? 如何用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. 如果我用Java和Ruby编写其余部分,那么它可以工作,但我希望所有这些都使用Ruby。

Edited: This is the correct way to create a mod using java: 编辑:这是使用java创建mod的正确方法:

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 . 看起来这些是注解,因此请看一下JRuby对其的引用

It might end up looking something like: 它最终可能看起来像:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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