Geenium Posted August 9, 2018 Share Posted August 9, 2018 I'm rather new to forge and I'm currently doing some basic tests. I have an item that has durability and I reduce the durability when the item is used to break blocks or is right clicked whilst being held. When the item breaks I am putting a different item into the player's mainhand. The problem is I can't put a new item into the player's hand when the item breaks from right clicking but works fine if the item breaks from breaking a block with it. These methods are in my new item class. @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) { damageTrinketInHand(stack, entityLiving); return true; } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) { ItemStack stack = player.getHeldItemMainhand(); damageTrinketInHand(stack, player); return new ActionResult<>(EnumActionResult.SUCCESS, stack); } private void damageTrinketInHand(ItemStack stack, EntityLivingBase entityLiving) { stack.damageItem(1, entityLiving); if (entityLiving.getHeldItemMainhand().isEmpty()) { System.out.println("Trinket broken"); entityLiving.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(ModItems.BROKEN_TRINKET)); } } I should point out that I can place items into another slot i.e. offhand and this will work for both ways the item can break, but currently it specifically won't work when putting a new item into the slot that the intial item was in before the item broke by right clicking with it. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 9, 2018 Share Posted August 9, 2018 8 hours ago, Geenium said: I should point out that I can place items into another slot i.e. offhand and this will work for both ways the item can break, but currently it specifically won't work when putting a new item into the slot that the intial item was in before the item broke by right clicking with it. Try setting stack to the new stack instead of setting it via EntityLivingBase#setHeldItem. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Geenium Posted August 9, 2018 Author Share Posted August 9, 2018 47 minutes ago, Animefan8888 said: Try setting stack to the new stack instead of setting it via EntityLivingBase#setHeldItem. I'm sorry, but how would I do that. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 9, 2018 Share Posted August 9, 2018 1 minute ago, Geenium said: I'm sorry, but how would I do that. @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) { ItemStack stack = player.getHeldItemMainhand(); damageTrinketInHand(stack, player); if (stack.isEmpty()) { stack = new ItemStack(ModItems.BROKEN_TRINKET); } return new ActionResult<>(EnumActionResult.SUCCESS, stack); } private void damageTrinketInHand(ItemStack stack, EntityLivingBase entityLiving) { stack.damageItem(1, entityLiving); } 1 Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. 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.