Jump to content

Recommended Posts

Posted

I am trying to make tools with animations, and I tried searching everywhere with no success. I have uploaded the sprite sheet below.

Drullkusitems.png

 

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?

Posted

(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)

Posted

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; 

Posted

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);
    }

Posted

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)

Posted

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.

Posted

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

Posted

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.

Posted

shiftedIndex error is now resolved! :D

 

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?)

Posted

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.

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.