Posted February 15, 201411 yr 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
February 15, 201411 yr 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.
February 16, 201411 yr Author 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
February 16, 201411 yr There are still IDs used internally, which you can access as follows for your Map: // getting the ID to put in your Map as a key: Item.getIdFromItem(stack.getItem()) // and getting an Item from an ID, if needed Item.getItemById(int) You can do the same thing with Blocks. http://i.imgur.com/NdrFdld.png[/img]
February 16, 201411 yr Author 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.