Use callback-style events throughout all versions
Removes the need for //#if statements on each and every event handler. Instead we now always use the equivalent Callback and have one central 1.12.2 class which forwards Forge events to the callbacks.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.replaymod.core.mixin.MinecraftAccessor;
|
||||
import com.replaymod.core.versions.forge.EventsAdapter;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
@@ -36,6 +37,7 @@ import static com.replaymod.core.versions.MCVer.getMinecraft;
|
||||
guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||
public class ReplayModBackend {
|
||||
private final ReplayMod mod = new ReplayMod(this);
|
||||
private final EventsAdapter eventsAdapter = new EventsAdapter();
|
||||
|
||||
@Deprecated
|
||||
public static Configuration config;
|
||||
@@ -52,6 +54,7 @@ public class ReplayModBackend {
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
mod.initModules();
|
||||
eventsAdapter.register();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.replaymod.core.versions.forge;
|
||||
|
||||
import com.replaymod.core.events.KeyBindingEventCallback;
|
||||
import com.replaymod.core.events.PostRenderCallback;
|
||||
import com.replaymod.core.events.PostRenderWorldCallback;
|
||||
import com.replaymod.core.events.PreRenderCallback;
|
||||
import com.replaymod.core.events.PreRenderHandCallback;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import de.johni0702.minecraft.gui.versions.MatrixStack;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
public class EventsAdapter extends EventRegistrations {
|
||||
@SubscribeEvent
|
||||
public void onKeyEvent(InputEvent.KeyInputEvent event) {
|
||||
KeyBindingEventCallback.EVENT.invoker().onKeybindingEvent();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouseInput(InputEvent.MouseInputEvent event) {
|
||||
KeyBindingEventCallback.EVENT.invoker().onKeybindingEvent();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void preRender(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
PreRenderCallback.EVENT.invoker().preRender();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void postRender(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END) return;
|
||||
PostRenderCallback.EVENT.invoker().postRender();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void renderCameraPath(RenderWorldLastEvent event) {
|
||||
PostRenderWorldCallback.EVENT.invoker().postRenderWorld(new MatrixStack());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void oRenderHand(RenderHandEvent event) {
|
||||
if (PreRenderHandCallback.EVENT.invoker().preRenderHand()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user