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

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

  • Author

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.

  • Author

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

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.