Jump to content

Timer for mod - PLZ HELP


Recommended Posts

so um I need some help with my mod...

wut I'm trying to do is that after every 10 min (20x10=200 ticks) it makes the player say something in chat.

this will run forever. this is wut I have so far but it not working. I recently got into java so IDK wut I'm doing so plz help.

I think that the code is accurate and should work but it don't.


public class Timer {

    private int timer = 0;

    public void onPlayerTick(PlayerTickEvent evt)
      if (timer == 200)
          <MOD NAME>.getInstance().getMinecraft().thePlayer.sendChatMessage("10min passed bud");
          timer =0;
      else {
          tickCounter =0;


Link to comment
Share on other sites

10 minutes is not 200 ticks, its 12000.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.


Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.


DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The general idea is correct. However there are a couple Java things plus a couple Minecraft things that probably need to be fixed.


Java Stuff:


First of all, you have a private field called timer but you're incrementing something called tickCounter. Actually I'm not sure why Eclipse isn't warning about the fact that tickCounter isn't even declared, and also I'm not sure why it even would run for you at all. I think everywhere you have tickCounter you should replace with timer.


Minecraft Stuff:


How did you register the class as an event handler? Just annotating the method isn't enough. You need to register the whole class to the event bus. 


Also, as mentioned you only want the event to fire on the client. So you should use the client tick event. Since you reference the Minecraft class, you should also technically make sure that bit of code is client side only. There are a couple approaches to this:

  1. Put the code with Minecraft into a method that runs through your proxy system. The concept of the proxy is very important in Minecraft modding. Basically it means you create a method with same name/parameters that has different code on client versus server. In this case, your client-side version would have the code you used, and the server side would just do nothing.
  2. Alternatively you could make your whole event handling class client-side only (by annotating it as sided) and only register it on the client side. For the registration you could that again using the proxy, or you could switch to the annotation style of event handler registration and indicate that it is sided in the annotation.

If you haven't modded before, all the points about client versus server might be confusing, but it is worthwhile taking time to fully understand it as it is critical to bug-free modding.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

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.


  • Create New...

Important Information

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