Jump to content

[Solved] [1.15.2] Event Handler not Detecting Events


Contomman

Recommended Posts

I have tried many different events and effects in the code below, and I have never gotten the event to fire. The project builds and the client launches without errors. Other aspects of my mod work fine, such as registering new items and blocks with the EventBusSubscriber, so I am not sure why I cant detect other events.

 

 

@Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class TestEventHandler{
    @SubscribeEvent
    public void onJumpEvent(PlayerEvent.LivingJumpEvent event) {
        ExampleMod.LOGGER.info("Event Fired");

        LivingEntity livingEntity = event.getEntityLiving();
        livingEntity.addPotionEffect(new EffectInstance(Effects.JUMP_BOOST,600,255));

    }
}

 


I tried to make a minimum working example, so I made a new mod with only the above class added. For good measure here is the main class, In case I am missing something there. It is mostly Unmodified.
 

@Mod("examplemod")
public class ExampleMod
{
    // Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "examplemod";
    public static ExampleMod instance;

    public ExampleMod() {
        instance = this;

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }
    private void setup(final FMLCommonSetupEvent event) { }
    private void doClientStuff(final FMLClientSetupEvent event) { }
    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
    }
    private void processIMC(final InterModProcessEvent event)
    {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
    }
}

 

Here is my latest log file. I didnt see anything out of the ordinary in it

https://pastebin.com/2L3gdHrE

***SOLVED EDIT***

I did not make my method static, which Is required to automatically register the class without passing the eventbus an instance of the class, as outlined in https://mcforge.readthedocs.io/en/latest/events/intro/.

Edited by Contomman
Link to comment
Share on other sites

37 minutes ago, Contomman said:

PlayerEvent.LivingJumpEvent

This even doesn't exist within Minecraft Forge 1.15.2. Did you perhaps mean LivingEvent.LivingJumpEvent?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

7 minutes ago, Animefan8888 said:

This even doesn't exist within Minecraft Forge 1.15.2. Did you perhaps mean LivingEvent.LivingJumpEvent?

Sorry about that. Unfortunately I am not getting a result using LivingEvent.LivingJumpEvent either.
I have also tried using EntityItemPickupEvent, as shown in the docs https://mcforge.readthedocs.io/en/latest/events/intro/

Link to comment
Share on other sites

8 minutes ago, Contomman said:

Sorry about that. Unfortunately I am not getting a result using LivingEvent.LivingJumpEvent either.
I have also tried using EntityItemPickupEvent, as shown in the docs https://mcforge.readthedocs.io/en/latest/events/intro/

Show the actual code you have.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

 

24 minutes ago, Animefan8888 said:

Show the actual code you have.

Sure. Here is my Event Handler

package com.example.examplemod.events;

import com.example.examplemod.ExampleMod;
import net.minecraft.entity.LivingEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;


@Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class TestEventHandler{
    @SubscribeEvent
    public void onJumpEvent(EntityItemPickupEvent event) {
        ExampleMod.LOGGER.info("Event Fired");

    }
}

And here is the main class

package com.example.examplemod;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("examplemod")
public class ExampleMod
{
    // Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "examplemod";
    public static ExampleMod instance;

    public ExampleMod() {
        instance = this;

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }
    private void setup(final FMLCommonSetupEvent event) { }
    private void doClientStuff(final FMLClientSetupEvent event) { }
    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
    }
    private void processIMC(final InterModProcessEvent event)
    {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
    }
}

Ive made a (poorly recorded,sorry) video of me building the project and trying to trigger the event, without success. I have tried several events, such as EntityItemPickupEvent and ArrowNockEvent, and I cant get any logger output, system output, potion effects triggering, etc.



This is a newly created mod for the purpose of showing this issue, so there shouldn't be any other interactions I am causing, to the best of my knowledge.

Link to comment
Share on other sites

2 minutes ago, Contomman said:

@Mod.EventBusSubscriber(modid = ExampleMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)

When registering this way your methods need to be static. And I don't know how I didn't notice that on the first post.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

11 minutes ago, Animefan8888 said:

When registering this way your methods need to be static. And I don't know how I didn't notice that on the first post.

Works Great. Thanks for your patience lol. should have read the docs more carefully

 

 

Edited by Contomman
Link to comment
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.
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.