mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 11:59:40 +00:00
Clear event phase before reusing object (#170)
This commit is contained in:
1 parent
3cde764d33
commit
97152a6ace
2 files changed
+30
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.sodium;
|
||||
|
||||
import com.gtnewhorizons.angelica.utils.EventUtils;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.event.terraingen.BiomeEvent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -19,6 +20,7 @@ public class MixinBiomeGenBase {
|
||||
@Unique
|
||||
private void prepareEvent(BiomeEvent.BiomeColor event, int defaultColor) {
|
||||
event.newColor = defaultColor;
|
||||
EventUtils.clearPhase(event);
|
||||
((AccessorBiomeColorEvent)event).setOriginalColor(defaultColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.gtnewhorizons.angelica.utils;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user