-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear event phase when reusing event object
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/org/embeddedt/vintagefix/util/EventUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.embeddedt.vintagefix.util; | ||
|
||
import net.minecraftforge.fml.common.eventhandler.Event; | ||
import net.minecraftforge.fml.common.eventhandler.EventPriority; | ||
import net.minecraftforge.fml.relauncher.ReflectionHelper; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
|
||
public class EventUtils { | ||
private static final MethodHandle EVENT_PHASE; | ||
|
||
static { | ||
try { | ||
EVENT_PHASE = MethodHandles.publicLookup().unreflectSetter(ReflectionHelper.findField(Event.class, "phase")); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static void clearPhase(Event e) { | ||
try { | ||
EVENT_PHASE.invokeExact(e, (EventPriority)null); | ||
} catch(Throwable ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} |