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

Hello,

 

I'm trying to make a config file for my block and item id's. But unfortunately then i would need to make a var for each of my blocks containing the config id. And then i had to make this line of this code for each block:

 

config.get(Configuration.CATEGORY_BLOCKS, "test", 0);

 

And i thought: Why can't i just get all the blocks and items of my mod and iterate through all of them?

I found out that all blocks are added to a private Multimap in GameRegistry and i could access that map with reflection.

But i don't think that's a good way of doing this.

 

Do you guys have ideas how to do this?

 

Thanks in advance!

 

ss7

You sir are a god damn hero.

  • Author

Hello,

 

OK, i think i can't do that because i can't change the block id after i registered the block.

But anyways: Here is the code to get only blocks of a mod:

 

 

Field blocks;

	Multimap<ModContainer, BlockProxy> blockregistry = null;

	try
	{
		blocks = GameRegistry.class.getDeclaredField("blockRegistry");

		blocks.setAccessible(true);

		blockregistry = (Multimap<ModContainer, BlockProxy>)blocks.get(new GameRegistry());
	}

	catch (Exception ex)
	{
		ex.printStackTrace();
	}

	if (blockregistry.size() > 0)
	{
		for (ModContainer modcontainer : Loader.instance().getModList())
		{				
			if (modcontainer.getModId().equals("modid"))
			{					
				for (BlockProxy block : blockregistry.get(modcontainer))
				{
					System.out.println(block.getClass().getSimpleName());
				}
			}
		}
	}

 

 

ss7

You sir are a god damn hero.

That's pretty cool - I was trying to figure out how to get the loaded mods :)

 

I know this isn't quite what you're looking for, but the way I get around creating variables for every single block is to create a single int modBlockIndex and increment it each time I initialize a Block:

private static int modBlockIndex;

public static Block yourBlock1, yourBlock2, etc;

// pre-init: get modBlockIndex start from config

// init:
yourBlock1 = new Block(modBlockIndex++);
yourBlock2 = new Block(modBlockIndex++);
etc.

This way your ids are still configurable as a group, but saves the hassle of all those extra variables. I do the same for items.

Don't declare each Item and Block as separate variable ?

Group them in a structure.

Like Item[], Block[]; List<Item>, List<Block>...

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.