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,8 @@
|
||||
package com.replaymod.extras;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.events.PostRenderCallback;
|
||||
import com.replaymod.core.events.PreRenderCallback;
|
||||
import com.replaymod.core.versions.MCVer.Keyboard;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
@@ -14,14 +16,6 @@ import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
|
||||
//#if FABRIC>=1
|
||||
import com.replaymod.core.events.PreRenderCallback;
|
||||
import com.replaymod.core.events.PostRenderCallback;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//$$ import net.minecraftforge.event.TickEvent;
|
||||
//#endif
|
||||
|
||||
public class FullBrightness extends EventRegistrations implements Extra {
|
||||
private ReplayMod core;
|
||||
private ReplayModReplay module;
|
||||
@@ -72,14 +66,8 @@ public class FullBrightness extends EventRegistrations implements Extra {
|
||||
return Type.Gamma;
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(PreRenderCallback.EVENT, this::preRender); }
|
||||
private void preRender() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void preRender(TickEvent.RenderTickEvent event) {
|
||||
//$$ if (event.phase != TickEvent.Phase.START) return;
|
||||
//#endif
|
||||
if (active && module.getReplayHandler() != null) {
|
||||
Type type = getType();
|
||||
if (type == Type.Gamma || type == Type.Both) {
|
||||
@@ -98,14 +86,8 @@ public class FullBrightness extends EventRegistrations implements Extra {
|
||||
}
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(PostRenderCallback.EVENT, this::postRender); }
|
||||
private void postRender() {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void postRender(TickEvent.RenderTickEvent event) {
|
||||
//$$ if (event.phase != TickEvent.Phase.END) return;
|
||||
//#endif
|
||||
if (active && module.getReplayHandler() != null) {
|
||||
Type type = getType();
|
||||
if (type == Type.Gamma || type == Type.Both) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.extras.playeroverview;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.events.PreRenderHandCallback;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.extras.Extra;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
@@ -14,23 +15,11 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
//#if MC>=11400
|
||||
import com.replaymod.core.events.PreRenderHandCallback;
|
||||
import java.util.stream.Collectors;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.client.event.RenderHandEvent;
|
||||
//$$
|
||||
//#if MC>=11400
|
||||
//#else
|
||||
//$$ import org.lwjgl.input.Keyboard;
|
||||
//#endif
|
||||
//$$
|
||||
//#if MC>=10800
|
||||
//$$ import com.google.common.base.Predicate;
|
||||
//#if MC>=11400
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -126,16 +115,7 @@ public class PlayerOverview extends EventRegistrations implements Extra {
|
||||
hiddenPlayers.clear();
|
||||
}
|
||||
|
||||
//#if MC>=11400
|
||||
{ on(PreRenderHandCallback.EVENT, this::shouldHideHand); }
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void oRenderHand(RenderHandEvent event) {
|
||||
//$$ if (shouldHideHand()) {
|
||||
//$$ event.setCanceled(true);
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#endif
|
||||
private boolean shouldHideHand() {
|
||||
Entity view = getRenderViewEntity(module.getCore().getMinecraft());
|
||||
return view != null && isHidden(view.getUuid());
|
||||
|
||||
@@ -3,19 +3,11 @@ package com.replaymod.extras.youtube;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.extras.Extra;
|
||||
import com.replaymod.render.gui.GuiRenderingDone;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
|
||||
//#if FABRIC>=1
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.OpenGuiScreenCallback;
|
||||
import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
//$$ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
public class YoutubeUpload extends EventRegistrations implements Extra {
|
||||
@Override
|
||||
@@ -23,16 +15,11 @@ public class YoutubeUpload extends EventRegistrations implements Extra {
|
||||
register();
|
||||
}
|
||||
|
||||
//#if FABRIC>=1
|
||||
{ on(OpenGuiScreenCallback.EVENT, this::onGuiOpen); }
|
||||
{ on(InitScreenCallback.EVENT, ((screen, buttons) -> onGuiOpen(screen))); }
|
||||
private void onGuiOpen(Screen vanillaGui) {
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onGuiOpen(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
//$$ net.minecraft.client.gui.screen.Screen vanillaGui = getGui(event);
|
||||
//#endif
|
||||
if (GuiScreen.from(vanillaGui) instanceof GuiRenderingDone) {
|
||||
GuiRenderingDone gui = (GuiRenderingDone) GuiScreen.from(vanillaGui);
|
||||
AbstractGuiScreen<?> abstractScreen = de.johni0702.minecraft.gui.container.GuiScreen.from(vanillaGui);
|
||||
if (abstractScreen instanceof GuiRenderingDone) {
|
||||
GuiRenderingDone gui = (GuiRenderingDone) abstractScreen;
|
||||
// Check if there already is a youtube button
|
||||
if (gui.actionsPanel.getChildren().stream().anyMatch(it -> it instanceof YoutubeButton)) {
|
||||
return; // Button already added
|
||||
|
||||
Reference in New Issue
Block a user