Xanderr_K Posted September 8, 2016 Posted September 8, 2016 I may be wrong, but it looks like we're supposed to write the array of strings and then feed it into the constructor. That's how we tell the class what our variants are named. So think about what you're trying to do and then write it. I'm not stupid at all. I just asking, how I can obtain list of all meta's names? If I using while cycle with names[ i ] = BlockNewStoneBricks.BrickType.byMetadata(i).getName(); throwing an excrption, so I just can't find any way to proprly obtain name of all metas as array. Of course I can register them manually, but hardcoding isn't our way, right? Also, what if I would have 10, 20 blocks with 3 to 10 metas each? Quote
Draco18s Posted September 8, 2016 Posted September 8, 2016 block.getBlockState().getValidStates(); Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Xanderr_K Posted September 8, 2016 Posted September 8, 2016 Isn't it return an array of IBlockState? Quote
Draco18s Posted September 8, 2016 Posted September 8, 2016 Yes. And you know what you can do? Block#getMetaFromState(IBlockState) Gasp. Shock. Awe. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Xanderr_K Posted September 8, 2016 Posted September 8, 2016 I'm entangled a bit. That move gives me int of every meta through loop section, but I can't find a way to convert it to meta's name. block.getStateFromMeta().toString() is deprecated and crashing Minecraft. Quote
Draco18s Posted September 8, 2016 Posted September 8, 2016 All variants will have exactly the same name unless you, personally, did something to change that. Did you? Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Xanderr_K Posted September 8, 2016 Posted September 8, 2016 That's true, but I'm in search of set-and-forget method which I can feed with any Block-extending object in future and not to hardcode an array of it's meta names, enlarging code by another 10-20 lines. Quote
Draco18s Posted September 8, 2016 Posted September 8, 2016 You're going to need to hardcode those names in some manner: the strings must exist in the code. At best you can concatenate the metadata value with the block's general name and then localize it. e.g. "minecraft.blockstone_1" and "minecraft.blockstone_2" Which would be your previous post of converting the metadata from an integer to a string (just concatenate it onto the end of the result of getUnlocalizedName). Or better yet, override getUnlocalizedName to do that for you. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Xanderr_K Posted September 8, 2016 Posted September 8, 2016 Ok, I just hardcoded all names into array and pushed it to ItemMultiTexture to register and got 4 correct ItemBlocks in creative inventory, that's better than nothing. Now I'm scratching head - how I should name correct .json for model and how to point at textures to put on? I have no such problems with single block w/out metas, it was easy, but the same way isn't working here. Quote
jeffryfisher Posted September 8, 2016 Posted September 8, 2016 The examples in vanilla code are variable blocks like stone. Each has an associated enum, and each enum has a set of arbitrary names (e.g. stone, andesite, diorite...) bound to numeric (metadata) values. That's why I said that the strings are something you write. They're usually an essential aspect of your mod's concept, so they're something that you are making up. You're the one making the mod, so only you know what your variants mean. You create the names from your own imagination. The names describe what you set out to code in the first place. It shouldn't be this hard. I'm reminded of a line from the movie Cool Hand Luke: "What we have here is a failure to communicate..." Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
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.