Jump to content

Recommended Posts

Posted

Hello guys, I hope somebody can help me with this:

 

I am creating a new crafting / brewing system with my own block and gui. The system requires a registry, where I can register vanilla Items / Blocks with some values related to my system. In my solution I use a HashTabe. The key in the HashTable I use, is the String which ItemStack.getUnlocalizedName() gives.

This system works, but I have a few issues with it, and in my opinion it is very inefficient.

 

First issue: I do not think ItemStack.getUnlocalizedName() was made for that kind of tasks.

Second issue: As example, when I register "new ItemStack(Blocks.sapling)", only the default sapling gets registered, but the other ones(birch, oak...) are not registered. Same for coal/charcoal etc...

 

By inefficient I mean, that if I am registering only one single ItemStack, it causes a lot of lag (only server side). If I do not register anything, it performs well.

try {

...

}catch(Throwable t) {

    MagicAppErrorSolver.solveProblem(t, this);

}

//Programmers will lose work

Posted

ItemStack.getItem()

 

Also, new ItemStack(Blocks.sapling, 1, 1) for metadata.

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.

Posted

Well thanks for the answer, but I do not understand it at all. So should I use the Item as key in my Map? I do not think so, because Item is not implementing equals() and hashCode(). Or are the standard implementations in Object enough, because each Item does only exist one time in memory?

 

BTW I am pretty new to forge at all and I am really confused, because I started modding minecraft right at the time, when the 1.7 forge update came out.

try {

...

}catch(Throwable t) {

    MagicAppErrorSolver.solveProblem(t, this);

}

//Programmers will lose work

Posted

It does work with Item as key itself! It is because the hashCode() method implementation in java.lang.Object returns the address of the object mapped to an integer. equals() standard implementation uses the == operator. There is no need to reference items or blocks by old id numbers.

try {

...

}catch(Throwable t) {

    MagicAppErrorSolver.solveProblem(t, this);

}

//Programmers will lose work

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.

×
×
  • Create New...

Important Information

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