Posted May 15, 20169 yr 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
May 15, 20169 yr 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.
May 15, 20169 yr Author The method is in my main class and e.g the LivingAttackEvent also works there. So it should work without the event bus registration?
May 15, 20169 yr 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.
May 15, 20169 yr Author Oh sorry, I'm using 1.7.10. So what exactly do I need to do to get that working?
May 16, 20169 yr Author Thanks a lot guys (Still don't get why the other events worked without registration^^)
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.