Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 ;)

 

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.

  • 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?

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.

  • Author

Oh sorry, I'm using 1.7.10.

 

So what exactly do I need to do to get that working?

 

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.