Hi all, greetings from a newbie in MC modding
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