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.

Featured Replies

Posted

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.

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.

  • 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

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.