Jump to content

[UNRESOLVED] [1.7.2] onItemRightClick called 4 times after using setTagCompound


Recommended Posts

Posted

Hi all, greetings from a newbie in MC modding  ;D

 

I am writing a mod which adds repeating crossbow to MC. The plan is when user holds right mouse button it should shoot repeatly with a certain interval - until user releases the key.

 

As the first step I created a class which extends Item class, put it in tabCombat. I copied essential methods from ItemBow class to make it work same as a bow - till here everything works fine.

 

Then, I need a way to remember the status of a crossbow. i.e. it needs to know it is on fire. So I decided to use NBTTagCompound:

 

This is added at the beginning of onItemRightClick method. It's in Scala. What it does is if par1ItemStack doesn't have a tagCompound then create a new one for it. Then set "shooting" tag to true.

 

println("ON ITEM RIGHT CLICK")
Option(par1ItemStack.getTagCompound).getOrElse {
  par1ItemStack.setTagCompound(new NBTTagCompound)
}
par1ItemStack.getTagCompound.setBoolean("shooting", true)
....

 

And this is added at the beginning of onPlayerStoppedUsing. It just resets shooting tag.

 

println("ON PLAYER STOPPED USING")
par1ItemStack.getTagCompound.setBoolean("shooting", false)

 

Then something strange happened...

 

Before I added this tagCompound thing, while holding right mouse button on my item, both onItemRightClick and onPlayerStoppedUsing methods are called twice (one for client and one for server I guess?).

 

But after I added it, onItemRightClick is called 4 times while onPlayerStoppedUsing is still called twice. In the game UI I can also see that my item is used twice rather than once like before. And the first time happens very quickly - it's like I first click (press and release) the right mouse key then hold it again.

 

I don't understand why does this happen...

 

Thanks for reading and any help would be appreciated

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.