American2050 Posted December 13, 2017 Posted December 13, 2017 As for now I tried a "not so nice way" and by subscribing to onBlockRegister I just called event.getRegistry().getEntries() and made a list that way. My "problem" is that I only get the block, and I don't think I can get the variants for each block from there. Where can I get those like for planks get {minecraft:planks:0},{minecraft:planks:1},{minecraft:planks:2},{minecraft:planks:3},{minecraft:planks:4},{minecraft:planks:5} And same for all the blocks. PS: Is ok to get them that way, or should I get the variants and not the meta? For example in the case I later need to call it from my code. Quote
JaredBGreat Posted December 13, 2017 Posted December 13, 2017 Well, this is how I did it in order to print them out: /** * This will list all mobs, using there unlocalized names, writing * the data to the file lists/mobs.txt. */ public static void listMobs() { Set<ResourceLocation> mobrl = EntityList.getEntityNameList(); ArrayList<String> mobs = new ArrayList<String>(); for(ResourceLocation mob : mobrl) { mobs.add(mob.toString()); } Collections.sort(mobs); BufferedWriter outstream = null; File moblist = new File(listsDir.toString() + File.separator + "entities.txt"); if(moblist.exists()) moblist.delete(); try { outstream = new BufferedWriter(new FileWriter(moblist.toString())); for(String mob : mobs){ outstream.write(mob.toString()); outstream.newLine(); } if(outstream != null) outstream.close(); } catch (IOException e) { e.printStackTrace(); } } /** * This will list all items, using their complete unlocalized names * with mod id's, and write them the file lists/items.txt. This * is useful for writing theme files. */ public static void listItems() { BufferedWriter outstream = null; File itemlist = new File(listsDir.toString() + File.separator + "items.txt"); if(itemlist.exists()) itemlist.delete(); try { outstream = new BufferedWriter(new FileWriter(itemlist.toString())); for(Object item : Item.REGISTRY){ String name = Item.REGISTRY.getNameForObject((Item) item).toString(); if(true) { outstream.write(name); outstream.newLine(); } } if(outstream != null) outstream.close(); } catch (IOException e) { System.err.println("[DLDUNGEONS] Error: Could not write file items.txt"); e.printStackTrace(); } } /** * This will list all blocks using their correct, unlocalized names, complete with * mod id's, and write them to the file lists/blocks.txt. This is useful for editing * theme files. */ public static void listBlocks() { BufferedWriter outstream = null; File itemlist = new File(listsDir.toString() + File.separator + "blocks.txt"); if(itemlist.exists()) itemlist.delete(); try { outstream = new BufferedWriter(new FileWriter(itemlist.toString())); for(Object block : Block.REGISTRY){ String name = Block.REGISTRY.getNameForObject((Block)block).toString(); if(true) {; outstream.write(name); outstream.newLine(); } } if(outstream != null) outstream.close(); } catch (IOException e) { System.err.println("[DLDUNGEONS] Error: Could not write file blocks.txt"); e.printStackTrace(); } } I hope it helps. 1 Quote Developer of Doomlike Dungeons.
American2050 Posted December 13, 2017 Author Posted December 13, 2017 (edited) 43 minutes ago, JaredBGreat said: Well, this is how I did it in order to print them out: /** * This will list all mobs, using there unlocalized names, writing * the data to the file lists/mobs.txt. */ public static void listMobs() { Set<ResourceLocation> mobrl = EntityList.getEntityNameList(); ArrayList<String> mobs = new ArrayList<String>(); for(ResourceLocation mob : mobrl) { mobs.add(mob.toString()); } Collections.sort(mobs); BufferedWriter outstream = null; File moblist = new File(listsDir.toString() + File.separator + "entities.txt"); if(moblist.exists()) moblist.delete(); try { outstream = new BufferedWriter(new FileWriter(moblist.toString())); for(String mob : mobs){ outstream.write(mob.toString()); outstream.newLine(); } if(outstream != null) outstream.close(); } catch (IOException e) { e.printStackTrace(); } } /** * This will list all items, using their complete unlocalized names * with mod id's, and write them the file lists/items.txt. This * is useful for writing theme files. */ public static void listItems() { BufferedWriter outstream = null; File itemlist = new File(listsDir.toString() + File.separator + "items.txt"); if(itemlist.exists()) itemlist.delete(); try { outstream = new BufferedWriter(new FileWriter(itemlist.toString())); for(Object item : Item.REGISTRY){ String name = Item.REGISTRY.getNameForObject((Item) item).toString(); if(true) { outstream.write(name); outstream.newLine(); } } if(outstream != null) outstream.close(); } catch (IOException e) { System.err.println("[DLDUNGEONS] Error: Could not write file items.txt"); e.printStackTrace(); } } /** * This will list all blocks using their correct, unlocalized names, complete with * mod id's, and write them to the file lists/blocks.txt. This is useful for editing * theme files. */ public static void listBlocks() { BufferedWriter outstream = null; File itemlist = new File(listsDir.toString() + File.separator + "blocks.txt"); if(itemlist.exists()) itemlist.delete(); try { outstream = new BufferedWriter(new FileWriter(itemlist.toString())); for(Object block : Block.REGISTRY){ String name = Block.REGISTRY.getNameForObject((Block)block).toString(); if(true) {; outstream.write(name); outstream.newLine(); } } if(outstream != null) outstream.close(); } catch (IOException e) { System.err.println("[DLDUNGEONS] Error: Could not write file blocks.txt"); e.printStackTrace(); } } I hope it helps. Thanks a lot! Sure it helps Problem is getting the different variants for each block found, but I gonna take a look around and see what I can find there that can provide me that information. Edited December 13, 2017 by American2050 Quote
American2050 Posted December 13, 2017 Author Posted December 13, 2017 10 minutes ago, diesieben07 said: If you want all possible block states of a Block use Block::getBlockState().getValidStates(), which will give you a List<IBlockState>. If you want all valid states of all blocks you can use flatMap: ForgeRegistries.BLOCKS.getValues().stream().flatMap(block -> block.getBlockState().getValidStates()).collect(Collectors.toList()) Thanks, I knew there was something like the getValidStates, just wasn't sure where and the actual name of it That should do it. Thanks once again. Quote
JaredBGreat Posted December 13, 2017 Posted December 13, 2017 18 minutes ago, diesieben07 said: If you want all possible block states of a Block use Block::getBlockState().getValidStates(), which will give you a List<IBlockState>. If you want all valid states of all blocks you can use flatMap: ForgeRegistries.BLOCKS.getValues().stream().flatMap(block -> block.getBlockState().getValidStates()).collect(Collectors.toList()) And that could be helpful for me -- perhaps I don't have to use meta-data in my configs if users can get all the correct state labels. 1 Quote Developer of Doomlike Dungeons.
Recommended Posts
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.