Jump to content

[1.8] Item (and maybe Block) name and getName


jeffryfisher

Recommended Posts

One tutorial (Wuppy Upgrading from 1.7 to 1.8) says that mc 1.8 items and blocks need to contain a static final variable called "name" and a public method called "getName". It doesn't say why, and it doesn't point to the part of Forge that needs these things (and reflection is really tricky to trace), so I'm somewhat unclear on what's really necessary. I've looked in the Forge docs, but I can't find answers to these questions. If someone knows (or could point me to the Forge class that uses name / getName() on items and/or blocks), I'd appreciate it.

 

I'm trying to generalize some abstract classes for a whole series of mods, so I'd like to know what constraints I face. In particular:

 

Is it enough to provide a getName method, or is the data member "name" also referenced via reflection?

 

If so, does the class member need to be called exactly "name", all lowercase?

 

Does "name" absolutely need to be final and/or static? I especially want to remove the "static" qualifier so my constructor can assign a value.

 

How early does name need to get its value? Can I set it during construction?

 

Do both items and blocks need these, or just one not the other?

 

What are the consequences / symptoms of doing this wrong or not at all? I left out name and getName() from some of my ItemBlock classes, but I don't see any error messages. I tried setting a breakpoint on the getName() method and then debugging. I was able to load a world, place my blocks and save the world all without triggering on a call. Maybe reflection doesn't trigger breakpoints.

 

Where does Forge call getName() or use name? If I could walk the source, I might answer my own questions.  Maybe the name member and getName method are merely Wuppy's modding style needed to fit with his own private framework. If so, then I'd like to know so I can discard these apparently unused elements (and constraints).

 

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.

Link to comment
Share on other sites

This is just Wuppy's style, it's not required (or used at all) by Forge. He just uses it to store the name passed to

GameRegistry.registerBlock

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

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.