Jump to content

[1.13.2] Certain subscribed events not firing


edma0

Recommended Posts

Thanks in advance for pointing me in the right direction here!

 

What is happening?

I'm updating my mod from 1.10.2 to 1.13.2 and everything is working as expected except for the events.

Some are working perfectly and others are never fired.

I have commented the resulting behaviour in the below code.

I've likely missed something pretty obvious and would really appreciate any help.

 

How are you checking if the event is firing?

I'm running the debug configuration for both client only and server + client, placing breakpoints and stepping through the code.

 

What version of Forge are you working with?

forge-1.13.2-25.0.107-mdk

 

The code I am using to reproduce the issue:

 

First, in the main mod class, I register the EventsCommon class instance and call the proxy to register the others.

In the main mod class:

Spoiler

private void init(FMLCommonSetupEvent event)
{
    MinecraftForge.EVENT_BUS.register(EventsCommon.instance);
    proxy.hookEvents();
}

 

 

EventsCommon:

Spoiler

 


public class EventsCommon
{
    public static EventsCommon instance = new EventsCommon();

    @SubscribeEvent
    public void eventBlockDestroyed(BlockEvent.BreakEvent event)
    {
        // Works perfectly
    }

    @SubscribeEvent
    public void eventBlockPlaced(BlockEvent.PlaceEvent event)
    {
        // Never fired
    }
}

 

 

Then in the ClientProxy and ServerProxy hookEvents method, I register the EventsClient and EventsServer respectively.

CommonProxy:

Spoiler

public class CommonProxy
{
    public void hookEvents() { }
}

 

 

ClientProxy:

Spoiler

public class ClientProxy extends CommonProxy
{
    @Override
    public void hookEvents()
    {
        super.hookEvents();
        MinecraftForge.EVENT_BUS.register(EventsClient.instance);
    }
}

 

 

ServerProxy:

Spoiler

public class ServerProxy extends CommonProxy
{
    @Override
    public void hookEvents()
    {
        super.hookEvents();
        MinecraftForge.EVENT_BUS.register(EventsServer.instance);
    }
}

 

 

 

Finally, the EventsClient and EventsServer classes. The EventsCommon class is posted above:

EventsClient:

Spoiler

public class EventsClient
{
    public static EventsClient instance = new EventsClient();
	
    @SubscribeEvent
    public void eventrenderWorldLast(RenderWorldLastEvent event)
    {
        // Works perfectly
    }
}

 

 

EventsServer:

Spoiler

public class EventsServer
{
    public static EventsServer instance = new EventsServer();
    
    @SubscribeEvent
    public void eventEntityJoining(EntityJoinWorldEvent event)
    {
        // Never fired
    }
}

 

 

Edited by edma0
Enclosed code blocks in spoiler tags to clean up post
  • Like 1
Link to comment
Share on other sites

This is a lovely, comprehensive and well laid out post, regardless of code style. Personally I think you should just use the static event subscribing system as you can specify sides and not worry about registering the subscribers conditionally yourself (you can specify a Side in the annotation).

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Thank you for your suggestion, I took your advice looked into the @Mod.EventBusSubscriber annotation.

That will make things very neat, I am glad I looked into it further, awesome tip.

 

I have implemented the change but I am still having no luck with BlockEvent.PlaceEvent.

It just isn't firing, but is registered in an identical fashion to BlockEvent.BreakEvent.

However BlockEvent.BreakEvent is working perfectly.

 

So I am singling out these two events as they are registered in the same way, but one works and the other does not.

Here is the code, in the Main mod class I have explicitly assigned the value and bus fields of the annotation to be on the safe side (rather than leaving them as default):

Spoiler

@Mod.EventBusSubscriber(value={Dist.CLIENT, Dist.DEDICATED_SERVER}, bus=Mod.EventBusSubscriber.Bus.FORGE)
public static class CommonEvents
{
    @SubscribeEvent
    public static void onBlockBreak(final BlockEvent.BreakEvent event)
    {
        // Working perfectly
    }

    @SubscribeEvent
    public static void onBlockPlace(final BlockEvent.PlaceEvent event)
    {
        // Never fired
    }
}

 

 

Link to comment
Share on other sites

I can't find where BlockEvent.PlaceEvent is used in forge code. 

 

rg BlockEvent.PlaceEvent
minecraftforge/event/ForgeEventFactory.java
125:import net.minecraftforge.event.world.BlockEvent.PlaceEvent;

minecraftforge/common/ForgeHooks.java
635:            BlockEvent.PlaceEvent placeEvent = null;

 

Only two places in forge code that this shows up. That may be why its not firing.

 

Link to comment
Share on other sites

In my forge version (#100) it’s used in a method in ForgeEventFactory. For me method is called from vanilla code. I’ll see if I can reproduce this issue when I get home

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Just updated to 25.0.108 to ensure the issue had not already been resolved.

Ah, yeah if the logic is similar to BlockEvent.BreakEvent then I think I see the issue.

 

There is a function with the following signature commented out with the task:

/* TODO: Talk to Sponge folk about World rollbacks.

@line 602 of net.minecraftforge.common.ForgeHooks.class

public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemUseContext context)

 

In this function (that is now commented out) it seems the BlockEvent.PlaceEvent was generated and a call to ForgeEventFactory.onPlayerBlockPlaced event was made.

 

Edit:
Yeah it seems to be an open issue on the issue tracker, kicking myself for missing it.

https://github.com/MinecraftForge/MinecraftForge/issues/5476

Edited by edma0
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.