Jump to content

[1.7] PlayerUseItemEvent help


iluvpie777

Recommended Posts

Start event fires when the player first begins using the item.

Tick event fires each tick while the item is in use.

Stop event fires when the player stops using the item.

Finish event fires after everything to do with using the item is finished.

 

Most of this is explained in the Java docs for the events, and the rest you can gather from looking at where the events are called via the Call Hierarchy in your IDE, all of which lead to the Item class eventually.

Link to comment
Share on other sites

So I'm actually still having some trouble with this event, I'm trying to make it so that when a player uses a fishing rod and it's durability goes down a counter will add 2 but it's not working does anyone know why?

 

code:

@SubscribeEvent

public void useItem(Finish event)

{

EMIEEP props = EMIEEP.get(event.entityPlayer);

if (event.entityPlayer.getHeldItem().getItem() == Items.fishing_rod && event.result.getItem().isDamaged(event.entityPlayer.getHeldItem()))

{

props.addToCounter(2.0);

System.out.println(props.getCounter());

}

}

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

#isDamaged always returns true after a stack has taken even 1 point of damage, even if it didn't take any damage recently.

 

Is the problem that the println isn't printing, or that the counter from your IEEP is not what you expected, or something else entirely?

 

Show your IEEP code for #addToCounter and #getCounter

Link to comment
Share on other sites

So basically println() isn't working which means that the if statement isn't working I know for a fact that the IEEP counter works as I have used it for alot of other events and it works just fine here is my code, isDamaged() was like the only thing I found that checked if the item has been damaged if there is a better way to check a fishing rod after using it I'm all ears anyways here is my code:

 

@SubscribeEvent

public void useItem(Finish event)

{

EMIEEP props = EMIEEP.get(event.entityPlayer);

 

if (event.entityPlayer.getHeldItem().getItem() == Items.fishing_rod && event.result.getItem().isDamaged(event.entityPlayer.getHeldItem()))

{

props.addToCounter(2.0);

System.out.println(props.getCounter());

}

}

Link to comment
Share on other sites

Did you register the event handler? Try putting a println as the very first line within the method.

 

Also, I personally prefer to use 'PlayerUseItemEvent.Finish' instead of just 'Finish' - it helps prevent any sort of ambiguity when importing, as well as making the event handling method easier to read.

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.
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.