Jump to content

EventHandler won't register


sep87x

Recommended Posts

Hello there,

 

I'm very close to finishing a new mod, but MinecraftForge won't let me finish my job :c I want to register an event handler - no big deal, but MinecraftForge won't let me. I've set up anything that I need, but it won't call the events. There must be something I can't see.

OverlayMod.java

 

package net.sep87x.steamol;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import net.minecraftforge.common.MinecraftForge;
import net.sep87x.steamol.network.JobPlanetMinecraft;
import net.sep87x.steamol.network.PMCTag;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = OverlayMod.MOD_MODID, name = OverlayMod.MOD_NAME, version = OverlayMod.MOD_VERSION)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class OverlayMod {

/* a lot of uninteresting, secret fields. please ignore */

public GamingSession session;

@EventHandler
public void onInit(FMLInitializationEvent event) {
	// secret code ... unnecessary

	session = new GamingSession();
	MinecraftForge.EVENT_BUS.register(session);
}

}

 

GamingSession.java

 

package net.sep87x.steamol;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;

import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;

public class GamingSession {

private Date startDate;

private float statTossedItems, statPlayerDamageTaken = 0;

public GamingSession() {
	this.startDate = new Date();
}

/**
 * @return A integer array with the time listed as follows. { SECONDS, MINUTES, HOURS }
 */
public ArrayList<Integer> getDuration() {
	ArrayList<Integer> timeDecoded = new ArrayList<Integer>();

	Date now = new Date();
	long timeInMilliseconds = now.getTime() - startDate.getTime();
	long timeInSeconds = timeInMilliseconds / 1000;
	long timeInMinutes = timeInSeconds / 60;
	long timeInHours = timeInMinutes / 60;

	timeInSeconds = timeInSeconds % 60;
	timeInMinutes = timeInMinutes % 60;
	timeInHours = timeInHours % 60;

	timeDecoded.add(new Double(Math.floor(timeInSeconds)).intValue());
	timeDecoded.add(new Double(Math.floor(timeInMinutes)).intValue());
	timeDecoded.add(new Double(Math.floor(timeInHours)).intValue());

	return timeDecoded;
}

@ForgeSubscribe
public void onItemToss(ItemTossEvent event) {
	++statTossedItems;
	System.out.println(statTossedItems);
}

@ForgeSubscribe
public void onLivingAttack(LivingAttackEvent event) {
	if (event.entity instanceof EntityClientPlayerMP) {
		statPlayerDamageTaken += event.ammount;
	}
}

}

 

There's no output on the console, which means that the methods won't be called. Any help?

 

Greets from Germany

~sep87x

Link to comment
Share on other sites

Try adding a debug println right after you register the EventHandler class. It might not get printed if anything before it in the method throws any exception. Guava's EventBus (which is what FML uses for the @EventHandler) is a bit funky if an event handler method throws an exception: it get's silently ignored.

 

Tried it, but it prints the debug message in the console, so it should work.

 

	@EventHandler
public void onInit(FMLInitializationEvent event) {		
	session = new GamingSession();
	MinecraftForge.EVENT_BUS.register(session);

	System.out.println("DEBUG :3");
}

 

2013-09-15 12:53:12 [information] [sTDOUT] DEBUG :3

Link to comment
Share on other sites

Try using FMLPreInitializationEvent

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.