Posted December 31, 201212 yr I am trying to make tools with animations, and I tried searching everywhere with no success. I have uploaded the sprite sheet below. EDIT: I am trying to create a single animation with item slots 1, 2, 3 and another animation with 5, 6, 7, 8. (0 and 4 are something else). Does anyone have ideas on how to animate tools?
December 31, 201212 yr you can use public int getIconIndex(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) in your item to change it's icon.
December 31, 201212 yr Author (I'm not entirely fluent in java) I have no idea what the parameters are? public int getIconIndex(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
December 31, 201212 yr According to the Javadoc, these are the parameters. stack - The item stack to get the icon for. (Usually this, and usingItem will be the same if usingItem is not null) renderPass - The pass to get the icon for, 0 is default. player - The player holding the item usingItem - The item the player is actively using. Can be null if not using anything. useRemaining - The ticks remaining for the active item. You'll probably want to have the icon change depending on how long the item has been in use for. You can get that number like this int usageTicks = usingItem.getMaxItemUseDuration() - useRemaining;
December 31, 201212 yr Author I find it disturbing that I'm putting this piece of code into wrong places, is there any example code on this? (I'm learning modding, with 1.4.6)
December 31, 201212 yr Alright. You just need to put this method into your <YourItem>.java. It'll override getIconIndex() in Item. You need to return the index that the new texture is at. From Item.java, here's an example on how this would be used for the Vanilla Bow. public int getIconIndex(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { Here is an example usage for Vanilla bows. if (usingItem != null && usingItem.getItem().shiftedIndex == Item.bow.shiftedIndex) { int k = usingItem.getMaxItemUseDuration() - useRemaining; if (k >= 18) return 133; if (k > 13) return 117; if (k > 0) return 101; } return getIconIndex(stack); }
December 31, 201212 yr Author I have no idea if that helped, because when I loaded the world with the item in my inventory, minecraft suddenly crashed when I switched to the item in my itembar. ('Entity Render' crash)
December 31, 201212 yr Was the error caused by the line "Here is an example usage for Vanilla bows." by any chance. Accidentally forgot to remove that, and I wouldn't be surprised if you accidentally copied that along with you. If not, crash report and Item file? I'll see if I can find out what's wrong.
December 31, 201212 yr Author Was the error caused by the line "Here is an example usage for Vanilla bows." by any chance. Accidentally forgot to remove that, and I wouldn't be surprised if you accidentally copied that along with you. If not, crash report and Item file? I'll see if I can find out what's wrong. Haha, I did remove the little text that came with the piece of code. Mediafire
December 31, 201212 yr Okay, I'm pretty sure that your crashing is caused by usingItem being null. Check to make sure usingItem != null before running the rest of your code.
December 31, 201212 yr Author http://images.wikia.com/drullkus-industries/images/8/89/Screen_Shot_2012-12-31_at_12.46.15_AM.png[/img] Apparently there's an error here. (Just to say: The way I wanted it to animate was to have animate at least in the player's hand, no right/left clicking. It doesn't have to animate in the item bar.)
December 31, 201212 yr Instead of ItemDIDDrill.shiftedIndex, you need to use ~PlaceYouRegisteredYourItem~.~ItemName~.shiftedIndex. And this won't animate the item in the item bar, just in your hand, and as for having it render all the time, I'm entirely sure about how you'd do that. You could set an integer somewhere in your Item class, have the icon index change depending on the integer, and change the integer each time this method is run.
December 31, 201212 yr Author shiftedIndex error is now resolved! As for the anim loop, should there be an int 'anim' and the number attached to it should be in a loop? Say it is now 1, and then waits one tick before changing to 2. Then it waits another tick and goes to 3. Another tick, and it sees the four so it goes 1 again. Also how do I get it to wait for a tick (or multiple ticks?)
December 31, 201212 yr There's an onUpdate() method in Item.java. public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) Called every tick as long as the item is in a player's inventory. You could check to see if the item is being held, and if it is, change anim. And then inside getIconIndex, look at what anim is, and set your item's texture dependant on that.
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.