Jump to content

Help on registering events.


TripleCF

Recommended Posts

@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
Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

 

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