Jump to content

Recommended Posts

Posted

Im trying to detect when a player clicks with my item

 

if (player.getHeldItemMainhand().getItem() == RegistryHandler.BACKPACK.get())
        player.setHealth(0);
}
Posted (edited)

New Code:

 

if (player.getHeldItemMainhand().getItem() == RegistryHandler.BACKPACK.get()) {
    player.setHealth(0);
}

 

 

P.S Still doesn't work

Edited by Turnrp
Posted
  On 12/23/2020 at 8:04 AM, Saksham4106 said:

that's way too less info... where are you writing this if statement?

 

Expand  
@SubscribeEvent
public void OnRightClick(PlayerInteractEvent.RightClickItem RightClick) {
    LivingEntity player = RightClick.getEntityLiving();
    if (player.getHeldItemMainhand().getItem() == RegistryHandler.BACKPACK.get()) {
        player.setHealth(0);
    }
}
Posted
   @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        playerIn.setHealth(0);
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

 

Posted
  On 12/23/2020 at 8:20 AM, Saksham4106 said:
   @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        playerIn.setHealth(0);
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

 

Expand  

gave me a bunch of errors

Posted

1. That method triggers on both the client and the server side. You will need to check the side with World#isRemote.

2. Your overriding method does not have the correct signatures (please learn Java before attempting to write a mod).

Some tips:

  Reveal hidden contents

 

Posted
  On 12/23/2020 at 8:45 AM, DavidM said:

1. That method triggers on both the client and the server side. You will need to check the side with World#isRemote.

2. Your overriding method does not have the correct signatures (please learn Java before attempting to write a mod).

Expand  

I jsut wanna know why its broken

Posted
  On 12/23/2020 at 7:48 PM, Turnrp said:

I jsut wanna know why its broken

Expand  

Learning java is the best way of knowing why your code is broken

Learn Java

 

"keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here." - this is literally right below the forum title

Posted
  On 12/23/2020 at 7:48 PM, Turnrp said:

I jsut wanna know why its broken

Expand  

I just told you.

  On 12/23/2020 at 8:45 AM, DavidM said:

Your overriding method does not have the correct signatures

Expand  

and

  On 12/23/2020 at 8:45 AM, DavidM said:

That method triggers on both the client and the server side. You will need to check the side with World#isRemote.

Expand  

 

Some tips:

  Reveal hidden contents

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.