Jump to content

[1.10.2] [Solved] Search for items from other mods via ID?


ZTagre

Recommended Posts

I have recently ran into a situation that I would like to find a way of rectifying (if indeed it is possible!).

 

   I have / am developing  a mod that has a copper ore and ingot as items. I use these blocks / items for various purposes within my mod (duh), and this is all working out - no problems in this regard. I have added my copper ingot to the ore dictionary as is the "norm", and I know that my copper ingot is usable by other mods which utilize copper ingots in their recipes, so that's working (yeah!).

 

   The problem is that I also like using a mod that I have NOT developed myself, but that works fine nevertheless. However, this particular mod ALSO has a copper ore and copper ingot; the KICKER is - that mod's author did NOT add his copper to the ore dictionary. That mod's copper ingot will NOT work in mods whose recipes call for "ingotCopper", etc. Thus, his copper is not compatible with my mod, either :-{

 

   Which leads me to my question: Is there a way to "search" through all the registered items in the RUNNING GAME, "looking" for specific items by their registered ID's? And, then, should a specific item be found, is it then possible to add that item to the ore dictionary "on the fly" so to speak? This would allow my mod (and others I use in my game play) to utilize that particular mod's copper ingot (as an example) in all ore-dictionary-aware  recipes.

 

   The alternative is to not be able to use that mod's copper for any other purposes but in which that modder intended (ie. recipes within that particular mod only.). That would be a shame!

 

   Now, I am aware that there are mods out there that work to "merge" all items of a certain type into one "global" type (that is, take all "ingotCopper" entries in the ore dictionary, and merge them all into a single "ingotCopper", compatible with all mods utilizing the ore dictionary (at least, I think that's what those mods do?). But this particular idea is different, because the item does not yet have an ore dictionary entry (otherwise, I would not be asking this question!).

 

   Is what I'm describing at all possible? If so, a small snippet of example code would be most helpful! I would of course provide full credit in my mod's code for the example code I wind up using (or, even, simply giving credit to anyone providing me with a "leg up" on how I might do this).

 

   I really hate having that mod's copper going to waste, but I just can't use it for what I need!!!

 

   But, even if what I have described (finding an item from an "outside" mod, via its registered ID, and then adding it to the ore dictionary "on the fly" ) is NOT possible, is it still possible merely to find out if a SPECIFIC ITEM is present in the running game? That is, if I wanted to know whether a specific mod's copper ingot was indeed "registered" in my running game, could I do so, and how would I accomplish this?

 

   Thanks in advance,

   ZTagre.

Edited by ZTagre
solved
Link to comment
Share on other sites

Get the Item registry from the ForgeRegistries class, then use IForgeRegistry#getValue to get the Item with the specified registry name. You can then register this Item with the Ore Dictionary.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Thanks for the advice, Choonster!

 

Here's what I did (in postInit() )

 

        // Here, we are using the method Choonster provided to
        // acquire an Item ID for the zeiyocraft:copperIngot"
        // item, which we will then use to add this ingot to the
        // Ore Dictionary...
        ResourceLocation rloc;
        final IForgeRegistry item_registry = GameRegistry.findRegistry(Item.class);
        rloc = new ResourceLocation("zeiyocraft","copperIngot");
        final IForgeRegistryEntry<Item> zeiyocraft_copper_ingot = item_registry.getValue(rloc);
        OreDictionary.registerOre("ingotCopper", (Item)zeiyocraft_copper_ingot);

 

   It works splendidly :-}

 

   Thanks a bunch...

   ZTagre.

Link to comment
Share on other sites

You should try contacting the author of the mod so he can register the ores to the OreDictionary himself. The mod is open-source, so you can also try to make an issue or PR to add it to the mod.

Edited by larsgerrits
  • Like 1

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

 

Thanks for that advice,  larsgerrits!

 

   I plan on doing just that; however, I felt that KNOWING how to do this would assist in any situation I might encounter, including those where the author(s) no longer maintain the mod(s)...

  

   I can't INSIST that those author(s) who haven't already USED Ore Dictionary registration begin doing so, and since the process of ore registration is so straightforward, it's really surprising to me that they didn't do this in the first place :-}

 

   I'm relatively new to Minecraft modding, and I realized very quickly just how important ore dictionary registration was for overall mod resource cooperation.

 

PS.- Yeah, it's OreDictionary (one word) I know, I just find that WHAT IT IS looks more understandable when discussed as two separate words...my bad...

   Again, thanks!

 

   ZTagre.

Edited by ZTagre
addendum
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.