Posted April 28, 20169 yr I have an item and block that interact with each other just fine. I want to add a little bit more functionality by giving the item another 'mode' aka change behavior if the player is sneaking. So I added an if else block into my code to see if player is sneaking, and then do stuff. However in game my debug code will not fire if I'm sneaking and clicking on the block with the item. When I switch to an empty hand, the debug code fires and then it crashes (because the clause with the logic for sneaking is supposed to be using a certain item, not an empty hand). So this is making me wonder if it is possible to right click a block, while sneaking, with a specific item? All code is done within the block's onBlockActivated() method.
April 28, 20169 yr When you hold an item in your hand right clicking on a block effectively overrides the items onActivated with the blocks onActivated when you are sneaking the items onActivated effectively overrides the blocks onActivated. So you want a sneak right click interaction you have to put that code in your items onActivated. BTW the method probably isn't actually call onActivated but I don't recall the actual name right now. Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
April 28, 20169 yr Author Method is onItemUse(), and it works perfectly, thanks! As a side query, is there any benefit of having the original code in the blocks use method and the sneaking code in the items use method, compared to having all the code in the items use method? Besides for having cleaner looking code?
April 28, 20169 yr If you already have the code in two places and it is working there is no reason to change it. It's really up to personal preference where you put the code. Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
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.