Jump to content

[Solved] Can't access variables inside of java.util.Timer


Recommended Posts

Posted

So in an item class, I'm overriding the onItemUse like so

 

  Reveal hidden contents

 

 

The issue is, I have a java.util.timer declaration inside of it, and it refuses to allow me to edit the ItemStack itemStack variable since it is not final. However, if it is final, it doesn't let me edit it anyway.

 

The java.util.Timer

 

  Reveal hidden contents

 

 

This is the error I get in the little lightbulb on the left:

Cannot refer to the non-final local variable itemStack defined in an enclosing scope.

 

I found a java forum that had the same issue, however their solution was of no use to me.

http://stackoverflow.com/questions/21485590/the-final-local-variable-cannot-be-assigned-since-it-is-defined-in-an-enclosing

 

There were several solutions to this problem at that page, however none that seemed to allow me to edit the itemStack variable as itself. I have been working on this for a few hours now, decided to ask you guys to see if there's a simple solution I'm missing. Thanks for reading.

[/code]

Posted

Trying to make it so, if the conditions are set up, the itemStack.stackTagCompound has some values changed every second. If Minecraft does things in ticks, how would I do it using ticks? I thought that Minecraft could essentially use any ordinary Java method?

Posted

So it says 20 ticks is equivalent to one second, unless the computer is slower, then ticks happen at a slower rate. Is there a way to guarantee one second will pass? When twenty ticks isn't guaranteed to be one second.

Posted

It works perfectly, many thanks my friend.

 

Solved timer:

 

  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.