Search code examples
javarubyjrubyminecraft-forge

Create java chars using jruby


Hi i need a char using jruby but all i have is this error:

org.jruby.embed.InvokeFailedException: java.lang.ClassCastException: net.minecraft.item.ItemFood cannot be cast to java.lang.Character

i'm making a mod for minecraft using jruby, i am trying make new recipes, this is the way to make this in java:

GameRegistry.addRecipe(new ItemStack(Items.apple), new Object[]{
        "XXX",
        "XYX",
        "XXX",
        'X', //required char
        Items.arrow,
        'Y', //required char
        Items.bone
 });

this is my ruby code:

xx = 'XY'
blockStack = ItemStack.new(newBlock)
GameRegistry.addRecipe(blockStack, ["XYX", xx[0], Items.apple, xx[1], Items.redstone].to_java)

how to create java chars using ruby? i tried use .charAt() but this return a number and .toCharArray() but dont work too.


Solution

  • integers might be converted to chars (42.to_java(:char)) thus try passing that in (unfortunately you'll need to know the char's ordinal representation, this is a bit annoying)