Posted February 13, 201411 yr 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?
February 13, 201411 yr 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.
February 13, 201411 yr 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
February 13, 201411 yr 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.
February 13, 201411 yr 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
February 13, 201411 yr 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.
May 10, 20178 yr 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.