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

How can I make it so that when the user holds right click, onItemRightClick doesn't get called multiple times? Is there any built in function or would I have to program a lock manually? If I need to program it manually, how would I go about doing so?

  • Author

Hmm, It still repeats if I hold down on the right mouse button. I'm not sure if this has anything to do with it, but I'm in creative mode.

Hi

 

Unfortunately it is pretty difficult to override some of the minecraft default behaviour for user inputs.  You could perhaps stop multiple clicking by overrwriting the repeat counter every tick using your own TickEvent.

 

            if (this.gameSettings.keyBindUseItem.pressed && this.rightClickDelayTimer == 0 && !this.thePlayer.isUsingItem())
            {
                this.clickMouse(1);
            }

 

Unfortunately rightClickDelayTimer is private so you would need to use reflection (AccessTransformer) to access it.

 

This link talks a bit more about user input and where the clicks are detected (and the "repeat click every x ticks" code)

 

http://greyminecraftcoder.blogspot.com.au/2013/10/user-input.html

 

If you dig through the vanilla code you might be able to find a place to intercept it, for example the PlayerInteractEvent (with RIGHT_CLICK_AIR)

 

Some items (eg) the bow do this by overriding getMaxItemUseDuration, that might also be of help.

 

-TGG

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,	EntityPlayer par3EntityPlayer) {
   if(par1ItemStack.stackTagCompound.getIteger("onItemRightClickDelay") == 0) {
      par1ItemStack.stackTagCompound.setInteger("onItemRightClickDelay", 5);
      //do stuff
   }
}

 

Then you can either tick that value down in onUpdate or you can wait for the onItemStoppedUsing (sp?) and set it back to zero

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Use Draco's, I'm dumb.

 

package tlhpoe.fs.item;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemTest extends ItemBow {
private boolean fired;

@Override
public ItemStack onItemRightClick(ItemStack is, World w, EntityPlayer player) {
	if(!w.isRemote) {
		if(!fired) {
			fired = true;
		}
	}
	return is;
}

@Override
public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) {
	fired = false;
}
}

Kain

The noest of nos.  There's a reason I referenced the item stack NBT data.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • 3 years later...
On 2014-2-13 at 4:14 PM, Draco18s said:

 


public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,	EntityPlayer par3EntityPlayer) {
   if(par1ItemStack.stackTagCompound.getIteger("onItemRightClickDelay") == 0) {
      par1ItemStack.stackTagCompound.setInteger("onItemRightClickDelay", 5);
      //do stuff
   }
}
 

 

 

Then you can either tick that value down in onUpdate or you can wait for the onItemStoppedUsing (sp?) and set it back to zero

This inplementation worked thanks. 

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.