Jump to content

[1.7.10] [SOLVED] Call onItemRightClick of another Item.class


Recommended Posts

Posted

I am trying to make an item that contains tools and copies the texture and attributes of a selected contained tool. Everything works perfectly so far, except when a sword is selected, right clicking doesn't block. Here is the relevant method in my class:

 

 

    @Override

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

if(!world.isRemote){

if (player.isSneaking()){

                    if(itemStack.stackTagCompound==null){

                          this.onCreated(itemStack, world, player);

                    }

                    int active=itemStack.stackTagCompound.getInteger("active");

                    active=(active+1)%contained.length;

                    itemStack.stackTagCompound.setInteger("active",active);

                  } else {

                        getActiveItem(itemStack).onItemRightClick(getActiveStack(itemStack), world, player);

                  }

              }

        return itemStack;

    }

 

 

getActiveItem returns the Item of the active contained ItemStack.

 

Using print statements, I have determined that "getActiveItem(itemStack).onItemRightClick(getActiveStack(itemStack), world, player);" is called but the active items onItemRightClick is not. Does anyone know why this is?

Posted

I do know that the blocking animation is determined by Item.getUseAction(), and doesn't have anything to do with Item.onItemRightClick(). Perhaps it has something to do with that?

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

Posted

I think you are right, but I think that onUseItem is called after onItemRightClick is. I used a modified ItemSword class with print statements. Blocking is supposed to call onItemRightClick, onUseItem, and itemMaxUseDuration, but only calls itemMaxUseDuration of the contained Item.

 

Right clicking with a hoe selected tills dirt with the proper animation, but that is because right clicking a block calls onItemUse.

Posted

Never mind, found a solution. I moved "getActiveItem(itemStack).onItemRightClick(itemStack, world, player);" outside of "if(!world.isRemote)". I didn't do enough testing to figure out why this works, just that it does.

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.