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:
@@ -12,6 +12,7 @@ import com.replaymod.replay.camera.CameraEntity;
|
||||
import com.replaymod.replaystudio.io.ReplayInputStream;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
@@ -57,13 +58,6 @@ import net.minecraft.util.math.MathHelper;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
//#if FABRIC>=1
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//$$ import net.minecraftforge.event.TickEvent;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11600
|
||||
//#else
|
||||
//$$ import net.minecraft.network.packet.s2c.play.EntitySpawnGlobalS2CPacket;
|
||||
@@ -364,22 +358,9 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|
||||
}
|
||||
}
|
||||
|
||||
//#if MC>=10800
|
||||
private
|
||||
//#else
|
||||
//$$ public // All event handlers need to be public in 1.7.10
|
||||
//#endif
|
||||
class EventHandler extends EventRegistrations {
|
||||
//#if FABRIC>=1
|
||||
private class EventHandler extends EventRegistrations {
|
||||
{ on(PreTickCallback.EVENT, this::onWorldTick); }
|
||||
private void onWorldTick() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onWorldTick(TickEvent.ClientTickEvent event) {
|
||||
//$$ // Unfortunately the WorldTickEvent doesn't seem to be emitted on the CLIENT side
|
||||
//$$ if (event.phase != TickEvent.Phase.START) return;
|
||||
//#endif
|
||||
|
||||
// Spawning a player into an empty chunk (which we might do with the recording player)
|
||||
// prevents it from being moved by teleport packets (it essentially gets stuck) because
|
||||
// Entity#addedToChunk is not set and it is therefore not updated every tick.
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.replaymod.core.mixin.TimerAccessor;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.util.RandomAccessReplay;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
@@ -25,15 +26,6 @@ import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
|
||||
//#if FABRIC>=1
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//$$ import net.minecraftforge.event.TickEvent;
|
||||
//$$
|
||||
//$$ import static com.replaymod.core.versions.MCVer.FML_BUS;
|
||||
//#endif
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -285,14 +277,8 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe
|
||||
}
|
||||
|
||||
private class EventHandler extends EventRegistrations {
|
||||
//#if FABRIC>=1
|
||||
{ on(PreTickCallback.EVENT, this::onTick); }
|
||||
private void onTick() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onTick(TickEvent.ClientTickEvent event) {
|
||||
//$$ if (event.phase != TickEvent.Phase.START) return;
|
||||
//#endif
|
||||
if (!asyncMode || paused()) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
@@ -3,9 +3,13 @@ package com.replaymod.replay.camera;
|
||||
import com.replaymod.core.KeyBindingRegistry;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.SettingsRegistry;
|
||||
import com.replaymod.core.events.KeyBindingEventCallback;
|
||||
import com.replaymod.core.events.PreRenderCallback;
|
||||
import com.replaymod.core.events.PreRenderHandCallback;
|
||||
import com.replaymod.core.events.SettingsChangedCallback;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.Setting;
|
||||
@@ -24,20 +28,14 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Box;
|
||||
|
||||
//#if FABRIC>=1
|
||||
import com.replaymod.core.events.KeyBindingEventCallback;
|
||||
import com.replaymod.core.events.PreRenderCallback;
|
||||
import com.replaymod.core.events.PreRenderHandCallback;
|
||||
import com.replaymod.replay.events.RenderSpectatorCrosshairCallback;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
|
||||
//#else
|
||||
//$$ import com.replaymod.core.versions.MCVer;
|
||||
//$$ import net.minecraftforge.client.event.EntityViewRenderEvent;
|
||||
//$$ import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
//$$ import net.minecraftforge.client.event.RenderHandEvent;
|
||||
//$$ import net.minecraftforge.common.MinecraftForge;
|
||||
//$$ import net.minecraftforge.eventbus.api.EventPriority;
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//$$ import net.minecraftforge.event.TickEvent;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11400
|
||||
@@ -51,7 +49,6 @@ import net.minecraft.util.hit.HitResult;
|
||||
//$$ import net.minecraft.util.math.RayTraceResult;
|
||||
//$$ import net.minecraft.util.text.ITextComponent;
|
||||
//$$ import net.minecraft.world.World;
|
||||
//$$ import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
//$$
|
||||
//#if MC>=11400
|
||||
//$$ import net.minecraft.util.math.RayTraceFluidMode;
|
||||
@@ -671,41 +668,17 @@ public class CameraEntity
|
||||
|
||||
private EventHandler() {}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(PreTickCallback.EVENT, this::onPreClientTick); }
|
||||
private void onPreClientTick() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onPreClientTick(TickEvent.ClientTickEvent event) {
|
||||
//$$ if (event.phase != TickEvent.Phase.START) return;
|
||||
//#endif
|
||||
updateArmYawAndPitch();
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(PreRenderCallback.EVENT, this::onRenderUpdate); }
|
||||
private void onRenderUpdate() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onRenderUpdate(TickEvent.RenderTickEvent event) {
|
||||
//$$ if (event.phase != TickEvent.Phase.START) return;
|
||||
//#endif
|
||||
update();
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(KeyBindingEventCallback.EVENT, CameraEntity.this::handleInputEvents); }
|
||||
//#elseif MC<11400
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onKeyEvent(InputEvent.KeyInputEvent event) {
|
||||
//$$ handleInputEvents();
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onMouseInput(InputEvent.MouseInputEvent event) {
|
||||
//$$ handleInputEvents();
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(RenderSpectatorCrosshairCallback.EVENT, this::shouldRenderSpectatorCrosshair); }
|
||||
@@ -737,35 +710,13 @@ public class CameraEntity
|
||||
}
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(PreRenderHandCallback.EVENT, this::onRenderHand); }
|
||||
private boolean onRenderHand() {
|
||||
// Unless we are spectating another player, don't render our hand
|
||||
if (getRenderViewEntity(mc) == CameraEntity.this || !(getRenderViewEntity(mc) instanceof PlayerEntity)) {
|
||||
Entity view = getRenderViewEntity(mc);
|
||||
if (view == CameraEntity.this || !(view instanceof PlayerEntity)) {
|
||||
return true; // cancel hand rendering
|
||||
} else {
|
||||
onRenderHandMonitor();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onRenderHand(RenderHandEvent event) {
|
||||
//$$ // Unless we are spectating another player, don't render our hand
|
||||
//$$ if (getRenderViewEntity(mc) == CameraEntity.this || !(getRenderViewEntity(mc) instanceof PlayerEntity)) {
|
||||
//$$ event.setCanceled(true);
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
//#if FABRIC>=1
|
||||
private void onRenderHandMonitor() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
//$$ public void onRenderHandMonitor(RenderHandEvent event) {
|
||||
//#endif
|
||||
Entity view = getRenderViewEntity(mc);
|
||||
if (view instanceof PlayerEntity) {
|
||||
PlayerEntity player = (PlayerEntity) view;
|
||||
// When the spectated player has changed, force equip their items to prevent the equip animation
|
||||
if (lastHandRendered != player) {
|
||||
@@ -790,6 +741,7 @@ public class CameraEntity
|
||||
mc.player.renderYaw = mc.player.lastRenderYaw = player.yaw;
|
||||
mc.player.renderPitch = mc.player.lastRenderPitch = player.pitch;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,12 +170,7 @@ public class GuiReplayOverlay extends AbstractGuiOverlay<GuiReplayOverlay> {
|
||||
return this;
|
||||
}
|
||||
|
||||
//#if MC>=10800
|
||||
private
|
||||
//#else
|
||||
//$$ public // All event handlers need to be public in 1.7.10
|
||||
//#endif
|
||||
class EventHandler extends EventRegistrations {
|
||||
private class EventHandler extends EventRegistrations {
|
||||
{ on(KeyBindingEventCallback.EVENT, this::onKeyBindingEvent); }
|
||||
private void onKeyBindingEvent() {
|
||||
GameOptions gameSettings = getMinecraft().options;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.replaymod.replay.handler;
|
||||
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||
@@ -16,9 +17,7 @@ import net.minecraft.text.TranslatableText;
|
||||
//$$ import net.minecraft.client.resource.language.I18n;
|
||||
//#endif
|
||||
|
||||
//#if FABRIC>=1
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
||||
//#else
|
||||
//#if FABRIC<1
|
||||
//$$ import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#endif
|
||||
@@ -46,15 +45,8 @@ public class GuiHandler extends EventRegistrations {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(InitScreenCallback.EVENT, this::injectIntoIngameMenu); }
|
||||
private void injectIntoIngameMenu(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void injectIntoIngameMenu(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
//$$ Screen guiScreen = getGui(event);
|
||||
//$$ List<Widget> buttonList = getButtonList(event);
|
||||
//#endif
|
||||
if (!(guiScreen instanceof GameMenuScreen)) {
|
||||
return;
|
||||
}
|
||||
@@ -198,14 +190,8 @@ public class GuiHandler extends EventRegistrations {
|
||||
.forEach(button -> button.y += moveBy);
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(InitScreenCallback.EVENT, this::ensureReplayStopped); }
|
||||
private void ensureReplayStopped(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void ensureReplayStopped(GuiScreenEvent.InitGuiEvent event) {
|
||||
//$$ Screen guiScreen = getGui(event);
|
||||
//#endif
|
||||
if (!(guiScreen instanceof TitleScreen || guiScreen instanceof MultiplayerScreen)) {
|
||||
return;
|
||||
}
|
||||
@@ -225,15 +211,8 @@ public class GuiHandler extends EventRegistrations {
|
||||
}
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(InitScreenCallback.EVENT, this::injectIntoMainMenu); }
|
||||
private void injectIntoMainMenu(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void injectIntoMainMenu(GuiScreenEvent.InitGuiEvent event) {
|
||||
//$$ Screen guiScreen = getGui(event);
|
||||
//$$ List<Widget> buttonList = getButtonList(event);
|
||||
//#endif
|
||||
if (!(guiScreen instanceof TitleScreen)) {
|
||||
return;
|
||||
}
|
||||
@@ -269,7 +248,7 @@ public class GuiHandler extends EventRegistrations {
|
||||
//#if FABRIC<=0
|
||||
//$$ if (guiScreen.getClass().getName().endsWith("custommainmenu.gui.GuiFakeMain")) {
|
||||
//$$ // CustomMainMenu uses a different list in the event than in its Fake gui
|
||||
//$$ addButton(event, button);
|
||||
//$$ buttonList.add(button);
|
||||
//$$ return;
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
Reference in New Issue
Block a user