How to Access Other Mod's Items for Recipes

Discussion in 'Mod Development' started by Type1Ninja, Jun 14, 2015.

  1. Type1Ninja

    Type1Ninja New Member

    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! :)
     
  2. ljfa

    ljfa New Member

    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.
     
    FyberOptic and Type1Ninja like this.
  3. Type1Ninja

    Type1Ninja New Member

    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. :(
     
  4. SatanicSanta

    SatanicSanta New Member

    There are a few ways to do this. Some mods have APIs just for easily getting their items as items, or usually itemstacks.
     
  5. ljfa

    ljfa New Member

    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
     
  6. Strikingwolf

    Strikingwolf New Member

    I think you can access the ItemRegistry like that
     
  7. Type1Ninja

    Type1Ninja New Member

    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: Jun 14, 2015
  8. ljfa

    ljfa New Member

    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
     
  9. Type1Ninja

    Type1Ninja New Member

    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. :(
     
  10. OreCruncher

    OreCruncher Well-Known Member Mod Developer

    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.
     
    Type1Ninja likes this.
  11. goldenapple

    goldenapple Well-Known Member Mod Developer

    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.
     
    Type1Ninja likes this.
  12. Type1Ninja

    Type1Ninja New Member

    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.
     
  13. OreCruncher

    OreCruncher Well-Known Member Mod Developer

    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.
     
    Type1Ninja likes this.
  14. ljfa

    ljfa New Member

    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.
     
    Type1Ninja likes this.
  15. Type1Ninja

    Type1Ninja New Member

    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. :)
     
  16. ljfa

    ljfa New Member

    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 ^^
     
    Type1Ninja likes this.

Share This Page