How to Access Other Mod's Items for Recipes

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
I'm just going to keep asking questions here...
So, I'm using eclipse, and I'm trying to make my own mod. I've made several items which I would LIKE to use Bedrockium Ingots from Extra Utilities for, but I'm having trouble. They don't have an OreDictionary entry for me to use, and I can't figure out how to get Extra Utilities "ModItems" sort of class and find the entry for Bedrockium Ingots. I've googled around, and it seems like I might somehow have to decompile Extra Utilities, but I don't know what that means in the context of Forge mods. I tried using 7-zip to open the deobfuscated version of Extra Utilities, but I can't import any of the classes (which makes sense)...

Help is appreciated! :)
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
You should be able to add Extra Utilities to your classpath and reference its classes this way, but there are other possibilities of getting another mod's blocks and items:
Simplest way would be Block.getBlockFromName().
If you need it more often then there's another neat way: The @ObjectHolder annotation:
Code:
@ObjectHolder("extrautilities:bedrockium")
public static final Item bedrockium = null;
FML will popluate this field with the correct item at runtime given that it exists.
 

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
You should be able to add Extra Utilities to your classpath and reference its classes this way, but there are other possibilities of getting another mod's blocks and items:
Simplest way would be Block.getBlockFromName().
If you need it more often then there's another neat way: The @ObjectHolder annotation:
Code:
@ObjectHolder("extrautilities:bedrockium")
public static final Item bedrockium = null;
FML will popluate this field with the correct item at runtime given that it exists.
Hmmm... How does the first method work, exactly? Is it only for blocks?
And for the second... I can't seem to get the ingot to register properly. Here's what I'm doing:
Code:
public class Recipes {

@ObjectHolder("ExtraUtilities:bedrockiumIngot")
public static final Item bedrockium = null;

public static void init() {
if (bedrockium == null) {
            LogHelper.info("Bedrockium is Null");
        }
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.itemBedrockiumHelmet), "bbb", "b b", "   ", 'b', new ItemStack(bedrockium)));
}
}
(is that how you use code tags?)
There's some other stuff in that class too, but I cut out all the irrelevant stuff. The phrase "Bedrockium is Null" IS logged. :/

When the game finishes loading, the recipe doesn't register; attempting to craft doesn't have anything in the output slot. Advice?

Off-Topic: Also, once I've set src/main/java as a source folder, how do I browse the Minecraft classes? I'd like to look at the weather/lightning class, but I can't find a way to browse through the classes the way I currently have set up.
EDIT: Nvm, found the way to browse MC classes. Still have issues w/ Bedrockium, though. :(
 

SatanicSanta

New Member
Jul 29, 2019
4,849
-3
0
There are a few ways to do this. Some mods have APIs just for easily getting their items as items, or usually itemstacks.
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
Ehm, there should be an equivalent one for items, like Item.getItemFromName().
I actually never used ObjectHolder myself so I can't help you there, sorry
 

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
Ehm, there should be an equivalent one for items, like Item.getItemFromName().
I actually never used ObjectHolder myself so I can't help you there, sorry
I think you can access the ItemRegistry like that
 

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
Alright, now I'm trying this:
Code:
public class Recipes {

    //Getting the Bedrockium Ingot item from XU...
    public static final Item itemBedrockium = GameRegistry.findItem("ExtraUtilities", "bedrockiumIngot");
    public static final ItemStack bedrockiumItemStack = new ItemStack(itemBedrockium);

    public static void init() {
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.itemBedrockiumHelmet), "bbb", "b b", "   ", 'b', bedrockiumItemStack));
        //Other Bedrockium Armor Recipes
    }
}
As I said before, I've cut out the irrelevant stuff. It shouldn't matter that I'm registering my Bedrockium Armor recipes in a method being called in init(), right?
Any hints as to why this doesn't work? I've used Minetweaker to find the name of the Bedrockium ingot. Typing /mt hand while holding one, this is the output: <ExtraUtilities:bedrockiumIngot> * 1
So I'm fairly certain those are the correct values. Any advice? :(

EDIT: Other issue, off-topic: (EDIT2: misread something in block class; this off-topic may not be an issue)
EDIT3: Yeah, got the lightning thing working. Nvm. Bedrockium still an issue, though...
EDIT4: The lightning was super easy to get working! :D Edit3 still applies. :(
EDIT5: NEEDS MOAR EDITS! Redstone behavior is confusing... Well, at least I can get right click --> lightning. :p
In the meantime, I'm trying to make a block that creates Lightning when right clicked (redstone control is the end goal). The actual spawning of lightning looks fairly simple, but when I try to add use this code as my lightning block class:
Code:
public class BlockLightningCreator extends BlockXF {
    public BlockLightningCreator(String unlocalizedName) {
        super(unlocalizedName);
    }

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player) {
        return false;
    }
}
It says I need to have that as a method in my BlockXF class (which extends Block). When I add that to BlockXF, it says that methods with the @Override annotation must implement a method from the superclass. Thing is, there IS an onBlockActivated() method in Block, with those same parameters. :(
 
Last edited:

ljfa

New Member
Jul 29, 2019
2,761
-46
0
It says I need to have that as a method in my BlockXF class (which extends Block). When I add that to BlockXF, it says that methods with the @Override annotation must implement a method from the superclass. Thing is, there IS an onBlockActivated() method in Block, with those same parameters. :(
Really? I think onBlockActivated takes a few more parameters:
World world, int x, int y, int z, EntityPlayer player, int meta, float hitX, float hitY, float hitZ
 

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
Really? I think onBlockActivated takes a few more parameters:
World world, int x, int y, int z, EntityPlayer player, int meta, float hitX, float hitY, float hitZ
Off topic Lightning stuff...
I was able to fix that issue. Now I have managed to get the lightning to happen either on a right click or on being activated with redstone. However, if the redstone method is used, the lightning happens but isn't rendered. The sound plays, but no animation appears. ;-; The difference between the Right-Click (Activated) and Redstone methods is that the Redstone one is never passed a player object; the issue is, that player object isn't used anywhere in the Click version either, so that shouldn't have an effect. :( I'm so confused...
Here's the code I'm using (I think I did good coding this, overall; even if it doesn't quite work):
Code:
public class BlockLightningCreator extends BlockXF {
    public static double lightningYOffset = 5.0D;

    public BlockLightningCreator(String unlocalizedName) {
        super(unlocalizedName);
    }

    public void spawnLightning(World world, int x, int y, int z) {
        LogHelper.info("Lightning creator created lightning");
        EntityLightningBolt lightning = new EntityLightningBolt(world, x, y + lightningYOffset, z);
        world.spawnEntityInWorld(lightning);
    }

    //Create lightning if right clicked
    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
        spawnLightning(world, x, y, z);
        return true;
    }

    //Create lightning if powered by redstone
    //TODO - works, but lightning isn't rendered. -_-
    public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
        if (!world.isRemote) {
            if (world.isBlockIndirectlyGettingPowered(x, y, z)) {        
                spawnLightning(world, x, y, z);
            }
        }
    }
}
On topic: Any advice on getting the Bedrockium to register? That's still an issue. :(
 

OreCruncher

Well-Known Member
Mod Developer
May 22, 2013
312
217
73
My Chair
Mod load order? Make sure you set up a dependency between your mod and Extra Utilities. If your mod loads before Extra Utilities you will get null like you mentioned.
 
  • Like
Reactions: Type1Ninja

gardenapple

Well-Known Member
Mod Developer
Jan 14, 2014
176
265
93
Alright, now I'm trying this:
Code:
public class Recipes {

    //Getting the Bedrockium Ingot item from XU...
    public static final Item itemBedrockium = GameRegistry.findItem("ExtraUtilities", "bedrockiumIngot");
    public static final ItemStack bedrockiumItemStack = new ItemStack(itemBedrockium);

    public static void init() {
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.itemBedrockiumHelmet), "bbb", "b b", "   ", 'b', bedrockiumItemStack));
        //Other Bedrockium Armor Recipes
    }
}
As I said before, I've cut out the irrelevant stuff. It shouldn't matter that I'm registering my Bedrockium Armor recipes in a method being called in init(), right?
Any hints as to why this doesn't work? I've used Minetweaker to find the name of the Bedrockium ingot. Typing /mt hand while holding one, this is the output: <ExtraUtilities:bedrockiumIngot> * 1
So I'm fairly certain those are the correct values. Any advice? :(

Your mod might be initializing before ExtraUtilties. One way to fix it is to register your recipe in postInit, or add ExU as a dependancy: add this to your @Mod annotation:
Code:
@Mod(/*mod id and such*/, dependencies = "after:ExtraUtilities")

Note: you can also say "required-after" instead of "after", which means that the mod won't launch without ExU.
 
  • Like
Reactions: Type1Ninja

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
Your mod might be initializing before ExtraUtilties. One way to fix it is to register your recipe in postInit, or add ExU as a dependancy: add this to your @Mod annotation:
Code:
@Mod(/*mod id and such*/, dependencies = "after:ExtraUtilities")

Note: you can also say "required-after" instead of "after", which means that the mod won't launch without ExU.
Hmm. I'll try that, but the issue is that I don't want it as a dependency; I want it as something with compatibility if it is there. In the log, XU also outputs a bunch of stuff before I output anything. I'll add some more log stuff to see if I can pinpoint which mod is going first.
 

OreCruncher

Well-Known Member
Mod Developer
May 22, 2013
312
217
73
My Chair
There are two types of dependencies. There is a hard dependency ("required-after") and soft dependency ("after"). You want the soft depdendency. Check out the source file for my mod here to see both.
 
  • Like
Reactions: Type1Ninja

ljfa

New Member
Jul 29, 2019
2,761
-46
0
I'll try that, but the issue is that I don't want it as a dependency; I want it as something with compatibility if it is there.
If you write it as "after:ExtraUtilities" then it will not be a hard dependency, unlike "required-after:ExtraUtilities". The first one just means your mod will load after Extra Utilities if it is there.
 
  • Like
Reactions: Type1Ninja

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
There are two types of dependencies. There is a hard dependency ("required-after") and soft dependency ("after"). You want the soft depdendency. Check out the source file for my mod here to see both.
If you write it as "after:ExtraUtilities" then it will not be a hard dependency, unlike "required-after:ExtraUtilities". The first one just means your mod will load after Extra Utilities if it is there.
You guys are amazing! That solved my issue right away! :D
I didn't know that there were multiple kinds of dependency. The FTB community in general just seems fantastic, and the amount of modders is great. :)
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
Seems like Extra Utilities does weird things and initializes its items in init rather than preinit like most other mods. Oh well, I'm glad to help ^^
 
  • Like
Reactions: Type1Ninja