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
@Mod.EventBusSubscriber(modid = challengemod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.DEDICATED_SERVER)
public class Test {
   
    private boolean toggled = true;

    @SubscribeEvent
    public void onTick(TickEvent.WorldTickEvent event) {
        System.out.println("tickerticker");
        if(toggled){
            if (Minecraft.getInstance().player != null) {
                System.out.println("tick");
             
            
         
    }
}

Hi I watched some tutorials  but somehow it just doesn't register. Nothing happens. Any idea? From what I heard you don't need to register them in the main class but the way I do it here just outputs nothing.

Oh btw when I had the same thing in my main class it worked fine. 

Edited by TripleCF
Added information

  • Author

Ok so thanks alot for the fast reply. Thing is following: My method can't be static as far as I know because I use some variables out of the class. Then it should be running in Singleplayer but It should control the world so I thought world event tick would fit best. 

I registered the event now by doing MinecraftForge.EVENT_BUS.register(new Test()) which somehow works. But from a good qualitiy coding aspect should I instead use a non static method and change the tick event to client?

 

  • Author

Ok I get your points. Thing was I tried having my tick method static but IntelliJ showed me an error on my boolean toggled:

Non static field cannot be referenced from a static context. I probably have a bit of misunderstanding of the static constructor. I changed the boolean toggled to static as well as the method which lead to it working. I think I also understand the sides a bit better.

Thanks for the help!

  • Author
1 hour ago, diesieben07 said:

Please learn basic Java. There is no such thing as a "static constructor".

These still apply.

Im not english so I don't know the name. I think the official term for it is access modifier or so. Doesn't change anything about java knowledge

 

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.