Posted October 19, 201311 yr 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.
October 19, 201311 yr 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.
October 19, 201311 yr 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. http://i.imgur.com/NdrFdld.png[/img]
October 19, 201311 yr 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.