dev909 Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Link to comment Share on other sites More sharing options...
UberAffe Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures Link to comment Share on other sites More sharing options...
dev909 Posted April 28, 2016 Author Share Posted April 28, 2016 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? Quote Link to comment Share on other sites More sharing options...
UberAffe Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures Link to comment Share on other sites More sharing options...
Recommended Posts
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.