Jump to content

[Minecraft 1.8] Help needed with Event Handlers


ThexXTURBOXx

Recommended Posts

Hello guys,

I tried to make a class, which registers my EventHandlers (there is only one yet). But I can't get it working. Here is, what I coded until now:

 

Main Class:

package de.Femtopedia.titantoolbox;

import de.Femtopedia.titantoolbox.Constants.Constants;
import de.Femtopedia.titantoolbox.Skype.skypemethods;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid=Constants.MODID, version=Constants.VERSION, name=Constants.NAME)
public class titantoolbox {

@Instance
public static titantoolbox instance = new titantoolbox();

@EventHandler
public void preInit(FMLPreInitializationEvent e)
{		

}

@EventHandler
public void init(FMLInitializationEvent e)
{
	FMLCommonHandler.instance().bus().register(new titantoolboxDCHandler());
}

@EventHandler
public void postInit(FMLPostInitializationEvent e)
{

}

}

 

EventHandler-Class:

package de.Femtopedia.titantoolbox;

import de.Femtopedia.titantoolbox.Constants.Constants;
import de.Femtopedia.titantoolbox.Skype.skypemethods;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;

public class titantoolboxDCHandler {

@SubscribeEvent
    public void clientConnection(ClientConnectedToServerEvent e)
    {
	System.out.println("Message");
    }

}

Bringing the best mod back alive! Our mod REFORGED!

Balkon's Weapons for 1.8: https://github.com/TheOnlySilverClaw/Reforged/releases

Link to comment
Share on other sites

You need to check if the connection is local when running a singleplayer world. To do this, do something like this:

 

@SubscribeEvent
public void onJoin(ClientConnectedToServerEvent event) {
	if(event.isLocal) {
		System.out.println("Local Connection");
	}else {
		System.out.println("Server Connection");
	}
}

 

As you can see, I check if the client is on a local server, and print in the console accordingly. When you do not check if it is local, you need to run a server within forge, and join it from the client. When you do, it will print out whatever you'd like in the server console. :)

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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.

Announcements



×
×
  • Create New...

Important Information

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