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.

Inconsistent Event-subsciption in eclipse vs built mod

Featured Replies

Posted

I have the following classes:

 

package mhfc.net.common.eventhandler.quests;

import cpw.mods.fml.common.eventhandler.Event;

public abstract class QuestGoalEventHandler<EventType extends Event> {
NotifyableQuestGoal<EventType> questGoal;
boolean stillActive;
protected Class<EventType> eventType;

public QuestGoalEventHandler(NotifyableQuestGoal<EventType> g,
		Class<EventType> t) {
	this.questGoal = g;
	stillActive = false;
	this.eventType = t;
}

public abstract <E extends EventType> void onEventCaught(E event);

public void setActive(boolean active) {
	stillActive = active;
}
}

 

package mhfc.net.common.eventhandler.quests;

import net.minecraftforge.event.entity.living.LivingDeathEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class LivingDeathEventHandler
	extends
		QuestGoalEventHandler<LivingDeathEvent> {

public LivingDeathEventHandler(NotifyableQuestGoal<LivingDeathEvent> g) {
	super(g, LivingDeathEvent.class);
}

@Override
@SubscribeEvent
public void onEventCaught(LivingDeathEvent event) {
	if (stillActive)
		questGoal.notifyOfEvent(event);
}

}

 

At some point I call this piece of code:

MinecraftForge.EVENT_BUS.register(new LivingDeathEventHandler(this));

. Now the following is inconsistent.

When I execute and test the Mod in eclipse nothing special happens and everything runs smooth, the problem occurs after I built the mod and try it "in the wild":

 

java.lang.ClassCastException: net.minecraftforge.client.event.RenderLivingEvent$Specials$Pre cannot be cast to net.minecraftforge.event.entity.living.LivingDeathEvent
        at mhfc.net.common.eventhandler.quests.LivingDeathEventHandler.onEventCaught(LivingDeathEventHandler.java:6)

Full crash report can be found here: http://pastebin.com/8mBh7h9K

 

I can fully understand WHY this happens in the wild, if you can't refrain to this: http://stackoverflow.com/questions/28388034/

Why does forge think it has to call LivingDeathEventHandler.onEventCaught() for net.minecraftforge.client.event.RenderLivingEvent$Specials$Pre? When I analyze the produced classes I see the @SubscribeEvent annotation only on the method "onEventCaught(LivingDeathEvent)", so I don't see why the method should be registered for any other event at all.

 

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.