Jump to content

onItemUse() ineficent on CPU cycles


jordan30001

Recommended Posts

When the onItemUse() is called from my item I have noticed that it runs twice within the same tick.

 

so if my method is taking 1/20th of a tick to run its actually taking 2-20th of a tick now this may seem redundant as its only 2/20th of a tick but if its running on a server that has 50 people on it and they all use the item at once then it takes 100/20th of a tick to run the method where as if its only running the method once its running 50/20th of a tick which is better because obviously its not needlessly doing things it doesn't need to do twice.

 

How can I detect if the current item has run this method the previous tick or current tick and then not do it without setting the global itemstacks of the same item to do the same

 

I am not 100% sure about this but the onItemRightClick() method sounds like it would do what I want it to do but its missing most of the params that I need to use.

Link to comment
Share on other sites

The problem propably is that your onItemUse() is getting called client and serversided. Just use if(!world.isRemote) and it will only be run server sided. Often running certain functions on the client results in problems, f.e. ghost items. Server functions (f.e. world changes, entity spawns,...) will get sent to the client anyway so it shouldnt cause any problems.

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.