Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.17] Right-click detection method


Recommended Posts

I'm trying to detect a right click on a sword.


Did ActionResult change to InteractionResult from 1.16 to 1.17?

I wrote below, but I get an error with hand in getHandSlot (hand)



public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {

attacker.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 1, 6)); 

target.setDeltaMovement(target.getDeltaMovement().add(0.0D, (double)0.2F, 1.0D));

stack.hurtAndBreak(1, attacker, (entity) -> {

entity.broadcastBreakEvent(EquipmentSlot.MAINHAND); });

return true;


public InteractionResult use (BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit)


ItemStack itemStack = player.getHandSlots(hand);  this

return InteractionResult.CONSUME;



I'm struggling to figure out how to solve this problem.

Knowledgeable people, please.

Edited by ocome
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.