Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] Forge scheduler/timer


bloodi
 Share

Recommended Posts

Hey,

I want to run a method every second and use something like the bukkit scheduler for this.

I tried it with the ServerTickEvent but nothing happens with it:

int tick = 0;
@SubscribeEvent
public void scheduler(ServerTickEvent e){
	if(tick != 20){
		tick++;
		return;
	}
	tick = 0;
	//do stuff

Also tried with @EventHandler (idk the difference^^)

 

Hope for a good reply ;)

 

Link to comment
Share on other sites

Did you register an instance of your event handler class with the appropriate event bus? I suggest reading a tutorial on Forge event handlers, e.g. this one.

 

@SubscribeEvent

is for subscribing to events that extend

net.minecraftforge.fml.common.eventhandler.Event

(e.g.

ServerTickEvent

,

LivingUpdateEvent

) and are posted to an

EventBus

.

 

@Mod.EventHandler

is for handling FML lifecycle events that extend

net.minecraftforge.fml.common.event.FMLEvent

(e.g.

FMLPreInitializationEvent

,

FMLServerStartingEvent

), this only works in your

@Mod

class (hence it being a nested type of

@Mod

). See the doc comment of the annotation for more details.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Which version of Minecraft are you using? In future, include that in your title.

 

In 1.8 and earlier,

ServerTickEvent

is fired on the FML bus (

FMLCommonHandler#bus

) rather than the Forge bus (

MinecraftForge.EVENT_BUS

). In 1.8.9 and later, the Forge and FML buses have been merged.

 

Your event handler will only be called if you register it with the right event bus.

 

Every

TickEvent

subclass (including

ServerTickEvent

) is fired twice per tick of its system (server, world, player, etc.): Once at the start with

Phase.START

and once at the end with

Phase.END

. Make sure you check the event's

Phase

so your code only runs once per tick.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

 Share



×
×
  • Create New...

Important Information

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