Jump to content

Recommended Posts

Posted

Since my last post in a way stalled, I decided to start a new one for the error I was now getting. 

 

Basically when I try to execute GameData.itemRegistry.getObjectByName(String) I seem to be getting an error with the itemRegistry;

Here is the error: itemRegistry cannot be resolved or is not a field

 

Any idea what could be causing this?

 

 

Posted

From my understanding, you're trying to register a item, and then get it's object for some popuse, however, what you should do is:

 

public static Item item = new  YourItem(2000);
GameRegistry.registerItem(item);

 

Where YourItem is a class that extends Item, or extends another class that extends Item, and 2000 is the id;

This way you keep the reference to your object, and can later refer to it, without using "GameData.itemRegistry.getObjectByName(String)" (Which I had never heard of).

 

Besides, this is basic Java logic, if you need a object for later use, keep it in a variable.

Posted

From my understanding, you're trying to register a item, and then get it's object for some popuse, however, what you should do is:

 

public static Item item = new  YourItem(2000);
GameRegistry.registerItem(item);

 

Where YourItem is a class that extends Item, or extends another class that extends Item, and 2000 is the id;

This way you keep the reference to your object, and can later refer to it, without using "GameData.itemRegistry.getObjectByName(String)" (Which I had never heard of).

 

Besides, this is basic Java logic, if you need a object for later use, keep it in a variable.

 

This isnt registering a single item, it is going to be used to read names from a config file (rather complicated,  see my old post).

 

The error means exactly what it says: The field you are referring to does not exist. Use GameRegistry.getItemRegistry

 

Cheers ill test it and report back :)

Posted

From my understanding, you're trying to register a item, and then get it's object for some popuse, however, what you should do is:

 

public static Item item = new  YourItem(2000);
GameRegistry.registerItem(item);

 

Where YourItem is a class that extends Item, or extends another class that extends Item, and 2000 is the id;

This way you keep the reference to your object, and can later refer to it, without using "GameData.itemRegistry.getObjectByName(String)" (Which I had never heard of).

 

Besides, this is basic Java logic, if you need a object for later use, keep it in a variable.

 

This isnt registering a single item, it is going to be used to read names from a config file (rather complicated,  see my old post).

 

Still you could, probably use a List and a for loop; And I'm not gonna search for your old post, if you want, send a link...

Posted

Named registry were introduced in 1.7.

1.6.4 only use numerical id. The preferred method was Configuration#getItem.

 

Ah rats :/ Meh ill use numerical ids for now I guess. Is the method just Configuration#getItem() or does it need any extra? Thanks.

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.