Skip to content

Commit d699187

Browse files
committed
Fix AttachCapabilitiesEvent dispatch being very slow
EventBus strikes again...
1 parent cff2914 commit d699187

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.forge_cap_retrieval;
2+
3+
import net.minecraftforge.event.AttachCapabilitiesEvent;
4+
import net.minecraftforge.eventbus.api.Event;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
7+
@Mixin(AttachCapabilitiesEvent.class)
8+
public abstract class AttachCapabilitiesEventMixin extends Event {
9+
/**
10+
* @author embeddedt
11+
* @reason EventSubclassTransformer is supposed to inject an override returning a constant on the class to avoid the
12+
* {@link net.minecraftforge.eventbus.api.EventListenerHelper#isCancelable(Class)} slow path.
13+
* However, the false case is only done for direct subclasses of Event (the true case is done for
14+
* any cancelable event). This works for normal events because they must subclass Event directly, or be a subclass
15+
* of an event that does. However, AttachCapabilitiesEvent subclasses GenericEvent, which does not pass through
16+
* the EventSubclassTransformer as it comes from the EventBus library (where transformers are not run) rather than
17+
* Forge which is on the GAME layer. The transformer on AttachCapabilitiesEvent then does not add the override as
18+
* it expects it to be present on GenericEvent already.
19+
* <p>
20+
* The simplest workaround to that whole mess is to just inject the override ourselves.
21+
*/
22+
@Override
23+
public boolean isCancelable() {
24+
return false;
25+
}
26+
}

0 commit comments

Comments
 (0)