Jump to content

Recommended Posts

Posted

I have made an event handling class, and have registered it using the following:

 

public class EventManager 
{
@EventHandler
public void load(FMLInitializationEvent event)
{
	FMLCommonHandler.instance().bus().register(new EventManager());
}


 @SubscribeEvent
 public void onEntitySpawn(EntityJoinWorldEvent event)
 {
	 MineAILog.log.info("Entity Has Spawned");
	 if (event.entity instanceof EntityMob) 
	 {
		 MineAILog.log.info("Entity is a mob");
		 assignAI((EntityMob) event.entity, event);
	 }
 }

 private void assignAI(EntityMob e, Event ev)
 {
		e.tasks.addTask(4, new EntityAIAttackOnCollide(e, EntityAI.class, 1.0D, false));
		e.targetTasks.addTask(4, new EntityAINearestAttackableTarget(e, EntityAI.class, 0, true));

 }
}

 

And yet the event does not fire at all, and the log functions do not run. I have also tried registering the EventManager class in the main mod class, but this has not worked either. I honestly do not know why it is not firing.

Posted

your "load" method can't be annotated with @EventHandler because that's not your mod class. you can invoke it from inside the actual load method from your mod class, or move the register code there and delete this method from EventManager. the other thing wrong is that you're registering to the wrong bus. EntityJoinWorld event is fired in MinecraftForge.EVENT_BUS.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

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.