Jump to content

Recommended Posts

Posted

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!

Posted

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.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

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.

Posted
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));
}


}	

Posted

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.

Posted

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.
Posted

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.
Posted

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

 

If I helped please press the Thank You button.

Posted

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.

Posted

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));
}


}	

Posted

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?

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

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;

Posted

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.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

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?
Posted

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.

Posted

There's no method called getBlockName in the Block class. The getUnlocalizedName method is there, but it may not be deobfuscated.

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/

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.