Posted October 28, 201410 yr I have an event handler which handles the LivingDeathEvent, but it either fires twice or not at all. Why is that? I'm using Forge 1230 for Minecraft 1.7.10 The event handler: public class MobKillHandler { @SubscribeEvent public void onMobDeath(LivingDeathEvent event) { if(!event.entityLiving.worldObj.isRemote) // Removing this line will cause the event to be fired twice, not removing it causes it to not be fired at all { return; } try { Entity killer = event.source.getSourceOfDamage(); Entity killedMob = event.entityLiving; if(killer instanceof EntityPlayer) { int soulsAward = getSoulAward(killedMob); SoulMemoryHandler.addSoulAmount(((EntityPlayer) killer).getDisplayName(), soulsAward); } } // Probably died of fall damage, or a cactus catch(NullPointerException ex) { // NOOP } } private int getSoulAward(Entity mob) { if(mob instanceof EntityZombie) { return Config.soulsPerZombie; } if(mob instanceof EntitySkeleton) { return Config.soulsPerSkeleton; } if(mob instanceof EntityCreeper) { return Config.soulsPerCreeper; } if(mob instanceof EntitySpider) { return Config.soulsPerSpider; } return 0; } } The registry: public class EventHandlers { public static void register() { // Entity death event MinecraftForge.EVENT_BUS.register(new MobKillHandler()); } } The registry is called here: @Mod.EventHandler public void init(FMLInitializationEvent evt) { // Initialize recipes Recipes.init(); // Register event handlers EventHandlers.register(); Logger.info("Init completed!"); } I tried using event.entity.worldObj.isRemote in the same sense, but that gave the same result. EDIT: I tried making the event sided using @SideOnly(Side.CLIENT), same result. Pretty sure that would be a wrong approach anyway.
October 28, 201410 yr You need to have the event only on the clientside? If yes, then you have to use packets, since the event is fired serverside only. Why it's fired twice? I don't know. Why do you need to have it on the clientside anyway? Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
October 28, 201410 yr Author I assume I don't need it on the clientside. Is it clientside? I'm not very familiar with events like that. This is my first attempt to make an actual mod. Edit: Looking at the debugger, it seems my event listener is registered twice
October 28, 201410 yr Author I feel like an idiot. The EventHander was indeed registered twice. Once in preinit, once in init...
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.