Posted December 4, 20195 yr Hello there, I am trying to replicate the functionality of sword items in that left clicks while holding the item don't destroy blocks in creative. I dug around a bit in the Item.Sword class but don't see anything that would cause this functionality. (My guess is it's handled somewhere else, but I don't know where.) If anyone knows how to implement this for a new item type (or where the code that does this for swords is located), please respond. Thank you!
December 4, 20195 yr Author Thanks for the quick reply! I'll check out that method as soon as possible.
December 4, 20195 yr Another thing you can do is Subscribe to the BlockEvent.BreakEvent and check if the player is holding your item and cancel that event. It doesn't have quite the same effect as the sword in creative, but it won't allow the player to break that block if he is holding the item. @SubscribeEvent public static void onBlockBreak(BlockEvent.BreakEvent event){ PlayerEntity player = event.getPlayer(); if(player != null){ Item item = player.getHeldItemMainhand().getItem(); if(item instanceof *youritemhere*){ event.setCanceled(true); } } }
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.