Posted July 4, 20169 yr I have a question, about something I have noticed and not sure how this works. Is the method onUpdate called more times in comparison with the onItemUse? have an item that does one thing with the player right clicks it, and it also has a "lock" to do the same thing without needing to right click the item, and for that I'm using the onUpdate. However, when "locked" (meaning, its using the onUpdate to do it's things) it works much faster. Is this intended? And if so, how can I slow down the onUpdate so it matches the speed that it would have when onItemUse?
July 4, 20169 yr Author onItemUse is subject to the right-click delay timer, which ensures you can only click every 4 ticks. onUpdate is called every tick. Can I delay the onUpdate using an if statement that works only when X is equal to 4, and update that value from 1 to 4 on each update?
July 4, 20169 yr Author You would have to put that either in the ItemStack (in which case you need to override shouldCauseReequipAnimation as well) or put it into the player using a capability. On the ItemStack? Not sure how to do that I did it on the item, and I see the problems already, it messes when the player has more than 1 of my item on inventory, even when the max stack size is 1, they conflict eachother. Having 1 item, it works perfectly, but when having 2 the problems start... Can you elaborate on how should I do it? Thanks a lot.
July 4, 20169 yr Author Well, yes, items are sortof singletons. Item is more like "type of item". Every ItemStack has an NBTTagCompound attached to it ( ItemStack#getTagCompoun d). You can use ItemStack#getSubCompound(<modID>, true) to get an NBTTagCompound named after your ModID to avoid conflicts. You can now put whatever the heck you want into that NBTTagCompound and it will persist with that ItemStack . Ohhh ok, I have to work with NBTTagCompounds :'( let the headhaches begin, I'm so confused about those... I guess I will have to learn someday. As a general idea, what I should do is check if the player is holding my item when he presses the trigger key, and if it's true write to nbt something that says he is holding my item and then I check holding and that value I write in the NBT? That will ensure that another item of the same in inventory, but not holding by player will turn it off again right? Sorry if it gets confuse, I'm not even sure the steps I should go thru
July 4, 20169 yr Author Ok, what? I think we are talking besides each other here. Please specify exactly how you want your item to behave (no code talk, say it how an end user would describe the functionality). It's a Warering Dongle (My version of a watering can, you may be familiar with those) When use (Right click) it waters the area in a 3x3x3 around the block you pointing at. The new feature I want to add is that when you press Control (Any key can be configured for it already) the can "Locks" (If the player is holding it) and I check with the onUpdate method if the can is locked, if so, it gets a glowing effect, like enchanted (It really it that) and it waters the 3x3x3 area around the block the player is looking at without the need of the player holding right click. All that works the way I described, problem is that the way I coded it, a 2nd watering dongle on inventory will return that the player isn't holding it, so it never locks.
July 4, 20169 yr Author Thanks you, I will do some experimentation This turned out to be more complicate of what I thought.
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.