Jump to content

Recommended Posts

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?

Posted

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

 

Posted

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

  • Like 1

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.

Posted

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

Posted

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

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