minecraftdotjarrr Posted July 28, 2014 Posted July 28, 2014 Hello! I am trying to add a block to the game, as you can tell and I had a question about this piece of code: GameRegistry.registerBlock(block, Reference.MODID + "_" + block.getUnlocalizedName() .substring(5)); in particular; the block.getUnlocalizedName() .getUnlocalizedName is underlined red and says: The method getUnlocalizedName() is undefined for the type Block. Now that confuses me because didn't we just register Block in: public void registerBlock (Block block) Anyways I have added a item using: public static void registerItem(Item item) { GameRegistry.registerItem(item, Reference.MODID + "_" + item.getUnlocalizedName().substring(5)); } and it worked fine. Another thing is that when I go into my block class and try to change the "material" it does not display the actual types it displays the functions. Sorry in advance for this very stupid question, but I don't know what to do about it. If anyone could tell me what I am doing wrong that would be wonderful, thank you! Quote
larsgerrits Posted July 28, 2014 Posted July 28, 2014 getUnloclaizedName You switched 2 characters... Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
jabelar Posted July 28, 2014 Posted July 28, 2014 You spelled it wrong: getUnloclaizedName should be getUnlocalizedName Spelling is VERY important in programming. For example, you even spelled the subject of this thread wrong -- it should be "recognizing". Anyway, to help you get spelling correct you should let Eclipse help you. If you type the "." after the instance or class and wait for a second, Eclipse should pop up with a list of all available fields or methods. You can keep typing a bit to filter the list down. If you select from that list then it will ensure that you've got a properly spelled method. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
proalt Posted July 28, 2014 Posted July 28, 2014 ANSWER: .setUnlocalizedName you have it wrong written in code. CASE CLOSED Quote
proalt Posted July 28, 2014 Posted July 28, 2014 OMG proalt YOU SOLVED IT!!!! OH THANKS YOU MY LORD. NOW THAT THIS IS SOLVER, diesieben07 you can give me a hand: http://www.minecraftforge.net/forum/index.php/topic,21792.0.html Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 You spelled it wrong: getUnloclaizedName should be getUnlocalizedName Spelling is VERY important in programming. For example, you even spelled the subject of this thread wrong -- it should be "recognizing". Anyway, to help you get spelling correct you should let Eclipse help you. If you type the "." after the instance or class and wait for a second, Eclipse should pop up with a list of all available fields or methods. You can keep typing a bit to filter the list down. If you select from that list then it will ensure that you've got a properly spelled method. As I feel very dumb spelling my title and Unlocalized wrong, I spelled it wrong when I was giving the example. So first off I am sorry for that. But for when I do spell it right: GameRegistry.registerBlock(Block, Reference.MODID + "_" + block.getUnlocalizedName().substring(5)); I still do get the same error, it says that: The method getUnlocalizedName() is undefined for the type Block. And the solution that it suggests is that I should add a cast to block. This post made me look very dumb and I could tell you that over and over again lol, but I do know that eclipse has a auto correct sort of thing that you were talking about and I do know how to use it. getUnlocalizedName() was not an option when I wrote: block. Thank you and sorry again for this horrible mistake. Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 getUnlocalizedName definitely exists, I just copied it from my workspace. So whatever you are doing, you are doing something wrong. I do know that It exists. Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 package com.somemorefood.friendlyunicorns; import net.minecraft.block.Block; import net.minecraft.item.Item; import cpw.mods.fml.common.registry.GameRegistry; public class RegisterHelper { public static void registerBlock(Block block) { GameRegistry.registerBlock(block, Reference.MODID + "_" + block.getUnlocalizedName().substring(5)); } public static void registerItem(Item item) { GameRegistry.registerItem(item, Reference.MODID + "_" + item.getUnlocalizedName().substring(5)); } } Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 I am probably stupid, but that should work. No you are not! I just can't see what is wrong with it either. The method getUnlocalizedName() is undefined for the type Block I noticed "Block" has an uppercase letter at the start (in the error message). So I was like okay ill just change: block.getUnlocalizedName() to Block.getUnlocalizedName() but that made no difference. Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 That is not right. The "Type Block" refers to the Block class, not the name of your variable. I did change it back, as I was just trying to do what ever I could think of. Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 That is not right. The "Type Block" refers to the Block class, not the name of your variable. But do you have any idea what this means or in other words why is it saying this: The method getUnlocalizedName() is undefined for the type Block. Quote
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 A theory: The method MIGHT not have been deobfuscated in 1.7.2. Look into the Block class, is the method there? I mean, there were ones that were similar but I could not find the same one. But there are 1.7.2. tutorials that do the same thing. I don't know, thank you for taking your time and trying to help me out. Quote
KeeperofMee Posted July 28, 2014 Posted July 28, 2014 May I just ask something why are you including your modid & _ before the names? I'm pretty sure that all registered names are modid specific(please correct me if I'm wrong) i.e. incl. modid & _ before makes it so if a player want to get you stuff they have to do: /give @p yourmodid:yourmodid_youritemname instead of just doing: /give @p yourmodid:youritemname Quote If I helped please press the Thank You button.
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 May I just ask something why are you including your modid & _ before the names? I'm pretty sure that all registered names are modid specific(please correct me if I'm wrong) i.e. incl. modid & _ before makes it so if a player want to get you stuff they have to do: /give @p yourmodid:yourmodid_youritemname instead of just doing: /give @p yourmodid:youritemname In this piece of code? GameRegistry.registerBlock(block, Reference.MODID + "_" + block.getUnlocalizedName().substring(5)); Because I thought it had to be like that lol, but thanks for pointing that out. Quote
jabelar Posted July 28, 2014 Posted July 28, 2014 Where do you create the block instance? Can you post the code where you recreate it? (i.e. somewhere you must have something like MyCustomBlock block = new MyCustomBlock() kind of thing). Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
minecraftdotjarrr Posted July 28, 2014 Author Posted July 28, 2014 Where do you create the block instance? Can you post the code where you recreate it? (i.e. somewhere you must have something like MyCustomBlock block = new MyCustomBlock() kind of thing). Main@Mod(modid = Reference.MODID, version = Reference.VERSION) public class SomeMoreFood { public static Block exampleBlock; public static Item grannySmith; @EventHandler public void preInit(FMLPreInitializationEvent event) { grannySmith = new ItemGrannySmith(); RegisterHelper.registerItem(grannySmith); exampleBlock = new BlockExampleBlock(); RegisterHelper.registerBlock(exampleBlock); } } Register Helper Class package com.somemorefood.friendlyunicorns; import net.minecraft.block.Block; import net.minecraft.item.Item; import cpw.mods.fml.common.registry.GameRegistry; public class RegisterHelper { public static void registerBlock(Block block) { GameRegistry.registerBlock(block, Reference.MODID + block.getUnlocalizedName().substring(5)); } public static void registerItem(Item item) { GameRegistry.registerItem(item, Reference.MODID + item.getUnlocalizedName().substring(5)); } } Quote
jabelar Posted July 29, 2014 Posted July 29, 2014 Hmmm. It seems it should be correct. Do you see any warnings or errors in Eclipse at all, other than the one about the unrecognized method? If you hover over "block" with your mouse in Eclipse, what does it say? Can you include the package and imports from your main class code? Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
minecraftdotjarrr Posted July 29, 2014 Author Posted July 29, 2014 Hmmm. It seems it should be correct. Do you see any warnings or errors in Eclipse at all, other than the one about the unrecognized method? If you hover over "block" with your mouse in Eclipse, what does it say? Can you include the package and imports from your main class code? No I don't. Block is: net.minecraft.block.Block block is: com.somemorefood.friendlyunicorns.RegisterHelper.registerBlock(Block) Main: package com.somemorefood.friendlyunicorns; import net.minecraft.block.Block; import net.minecraft.item.Item; import cpw.mods.fml.common.registry.GameRegistry; Quote
jabelar Posted July 29, 2014 Posted July 29, 2014 Do all your Block instances have this problem? What about if you create a vanilla block instance? Since you said Eclipse isn't complaining, I assume your custom block is a proper extension of Block (or one of its sub-classes). but it would be interesting to see if your custom block behaves differently than vanilla. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
minecraftdotjarrr Posted July 29, 2014 Author Posted July 29, 2014 Hmmm. It seems it should be correct. Do you see any warnings or errors in Eclipse at all, other than the one about the unrecognized method? If you hover over "block" with your mouse in Eclipse, what does it say? Can you include the package and imports from your main class code? What exactly do you mean by warnings in Eclipse? Quote
imadnsn Posted July 29, 2014 Posted July 29, 2014 Probably dumb question, but are you sure your BlockExampleBlock extends the Block class in net.minecraft.block.Block? Because there are multiple Block classes you can extend and maybe you've imported the wrong one in BlockExampleBlock.java file or whatever file you hold the class in. Quote
knokko Posted July 29, 2014 Posted July 29, 2014 setUnlocalizedName is for items and setBlockName is for blocks. Maybe this is the big problem? Quote
imadnsn Posted July 29, 2014 Posted July 29, 2014 setUnlocalizedName is for items and setBlockName is for blocks. Maybe this is the big problem? It is getUnlocalizedName() we have problem with Quote
knokko Posted July 29, 2014 Posted July 29, 2014 Than I think this must be getBlockName instead of getUnlocalizedName. Quote
larsgerrits Posted July 29, 2014 Posted July 29, 2014 There's no method called getBlockName in the Block class. The getUnlocalizedName method is there, but it may not be deobfuscated. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
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.