Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

LivingDeathEvent Listener code problem


Recommended Posts

After some debugging I still can't figure out why this code (code below) don't print expected - when print line was outside if, it also didn't work

@Subscribe
public void onLivingDeathEvent (LivingDeathEvent deadEntity){

    if ( deadEntity.getSource() == DamageSource.DROWN) {
        System.out.println("Entity died: drown");
    }
    else{
        System.out.println("Entity died: other reasons");
    }

}

 

This code is in main class, class is registered to MinecraftForge.EVENT_BUS 

Thanks for your time :) 

Link to post
Share on other sites

Ohh sorry :/, now I reread it, and I tried with same, but static method:

@Subscribe
public static void onLivingDeathEvent (LivingDeathEvent deadEntity){

    if ( deadEntity.getSource() == DamageSource.DROWN) {
        System.out.println("Entity died: drown");
    }
    else{
        System.out.println("Entity died: other reasons");
    }

}

And it still doesn't work - I am confused, why should it be static?

 

 

Link to post
Share on other sites
package com.saltbeard.potc;

import com.google.common.eventbus.Subscribe;
import com.saltbeard.potc.util.RegistryBlocksHandler;
import com.saltbeard.potc.util.RegistryItemsHandler;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod("potc")
public class PotC
{
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "potc";

    public PotC() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);

        RegistryItemsHandler.init();
        RegistryBlocksHandler.init();

    }



    private void setup(final FMLCommonSetupEvent event){
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
    }

    public static final ItemGroup MISC_TAB = new ItemGroup("miscTab"){

        @Override
        public ItemStack createIcon(){

            return new ItemStack(RegistryItemsHandler.JADE.get());

        }

    };

    @Subscribe
    public static void onLivingDeathEvent (LivingDeathEvent deadEntity){

        if ( deadEntity.getSource() == DamageSource.DROWN) {
            System.out.println("Entity died: drown");
        }
        else{
            System.out.println("Entity died: other reasons");
        }

    }
}
Link to post
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.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.