Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

If I wanted to lets say get the block ID and meta of ic2's machine block or rp2's screwdriver.

 

How could I achieve this?

 

Also how would I detect if its installed?

You can either use Reflections or IndustrialCraft API.

 

RedPower has some rules about decompiling, so you should ask Eloraam before doing anything with it.

imho items and blocks can be aquired by normal means: looking for an item with specific name in an array

Item.itemsList

or for a block in

Block.blocksList

. if a mod is present you can find out either using the mod's api, using reflection or

Loader.isModLoaded

method (there will be even more ways I guess).

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

  • Author

imho items and blocks can be aquired by normal means: looking for an item with specific name in an array

Item.itemsList

or for a block in

Block.blocksList

. if a mod is present you can find out either using the mod's api, using reflection or

Loader.isModLoaded

method (there will be even more ways I guess).

how would i figure out from the blockList what the block is?

You can either use Reflections or IndustrialCraft API.

 

RedPower has some rules about decompiling, so you should ask Eloraam before doing anything with it.

 

Reflecting would be de-obfuscating the mod with something like BON (beared octo nemesis) getting rid of everything except the item/block definitions then on post init check to see if the class exists if it doesn't it skips those blocks/items?

or is there an easier way?

how would i figure out from the blockList what the block is?

by its name or class. lets say you're looking for a block named "stone", you'd just iterate over all blocks and look if it's the one you want.

for(int i=0; i<Block.blocksList.length; i++){
  Block current = Block.blocksList[i];
  if(current != null && "stone".equals(current.getBlockName())){
      // found block
  }
}

 

Reflecting would be de-obfuscating the mod with something like BON (beared octo nemesis) getting rid of everything except the item/block definitions then on post init check to see if the class exists if it doesn't it skips those blocks/items?

or is there an easier way?

I wrote you the easy way, use Loader.isModLoaded to check if the mod is present. If you need just IDs I don't see any reason why use reflection, also it might be illegal without consent of mod developer.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

  • Author
]

 

Ok I tried this and it works perfectly for most mods (major mods) but some of the other major mods (not naming any names) are registering their block names as Null how would I work past this? is there any other name I can grab from somewhere

but some of the other major mods (not naming any names) are registering their block names as Null how would I work past this? is there any other name I can grab from somewhere

if the block can be uniquely identified by its class name, you can get and compare it like this:

String className = testedBlock.getClass().getCanonicalName();
if (className.equals("net.minecraft.block.BlockGrass")) {
  //found grass!
}

 

it is possible that the mod's block is not setting its name, because there's ItemBlock handling this block (block name is mainly used for getting title for user). you probably could look at all items searching for ones named after block you're looking for. after getting this item you'd simply cast it to

ItemBlock

and use

getBlockID

.

 

remarks:

  • cache your findings, do NOT search IDs more than once (probably in/from your @init method) after MC started
  • mark your mod to load after mods which blocks you're using

 

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

  • Author

so if i wanted to bind grass i would use String className = Blockgrass.getClass().getCanonicalName();

 

but I cannot access it because of the static modifier

not this way, in a same loop (the for) you'd test a block to figure out if its class is what you want. similar code to this one should do the trick:

for(int i=0; i<Block.blocksList.length; i++){
  Block current = Block.blocksList[i];
  if(current != null){
    if("stone".equals(current.getBlockName())){
      // found block by its name (stone)
    }else{
      String className = current.getClass().getCanonicalName();
      if (className.equals("net.minecraft.block.BlockGrass")) {
        //found a block by its class name (grass)
      }  
    }
  }
}

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.