Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

you can use

public int getIconIndex(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)

in your item to change it's icon.

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

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; 

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

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

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

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.

  • 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

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.

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.

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.