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:
Jonas Herzig
2021-02-22 23:11:34 +01:00
parent 0be2082fe7
commit 633bc19650
27 changed files with 110 additions and 378 deletions

View File

@@ -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.