Jump to content

Changing item damage in onItemRightClick acting oddly


Recommended Posts

I'm probably missing something stupid or obvious.  With that said, I've created an item with different names and icons for different damage values.  I have 3 sub-items with damage values 0, 1, and 2.  I am changing the itemstack damage value in the onItemRightClick callback. 

This looks to work for damage values of 0 or 1, but when I set the damage value to 2, it resets to 0 an instant later.  The icon briefly changes to the damage value 2 icon, and then swaps back to the one for damage 0.


The item source is here in full  https://github.com/jco2641/SuperOreProcessCraft/blob/master/src/main/java/jco/mods/sopc/item/ItemuniversalMultitool.java


Here is the function:

    public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
        if(world.isRemote) {
            if (player.isSneaking()) {
                LogHelper.info("Entering routine, damage = " + this.getDamage(itemStack));
                switch (this.getDamage(itemStack)) {
                    case 0:
                        this.setDamage(itemStack, 1);
                        LogHelper.info("Setting damage from 0 to 1");
                    case 1:
                        this.setDamage(itemStack, 2);
                        LogHelper.info("Setting damage from 1 to 2");
                    case 2:
                        this.setDamage(itemStack, 0);
                        LogHelper.info("Setting damage from 2 to 0");
        return super.onItemRightClick(itemStack, world, player);





Link to comment
Share on other sites

My understanding is SetMaxDamage is set when using damage for durability.  Setting it to 2 makes there be a damage bar on the item that is half gone after the first usage, and the item disappears entirely after the second use.


Maybe this provides additional insight.  Setting the maxdamage to something big like 128, there is still a damage bar, but on the second use, the item briefly changes to the third version, and then disappears and is replaced with an undamaged item.



Link to comment
Share on other sites

Actually damage is also used like block metadata, in that you can jam alot of subitems into one single item. Spawn eggs, for instance, are all ItemMonsterPlacer, but with different damage values.


Right.  That is what I'm trying to do.  It is not working, in that every time I set the item's damage value to 2, the item appears to be immediately replaced with an item with damage value 0.

Link to comment
Share on other sites

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.

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.