Backport to 1.7.10
This commit is contained in:
@@ -3,6 +3,9 @@ package com.replaymod.core;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiOverlay;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
@@ -16,9 +19,6 @@ import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -84,10 +84,21 @@ public abstract class AbstractTask implements Task {
|
||||
|
||||
private void expectGuiClosed0(int timeout, Runnable onClosed) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
class EventHandler {
|
||||
FMLCommonHandler.instance().bus().register(new GuiEventHandler(timeout, stackTrace, onClosed));
|
||||
}
|
||||
public class GuiEventHandler {
|
||||
final net.minecraft.client.gui.GuiScreen currentScreen = mc.currentScreen;
|
||||
private final int timeout;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
private final Runnable onClosed;
|
||||
int framesPassed;
|
||||
|
||||
public GuiEventHandler(int timeout, StackTraceElement[] stackTrace, Runnable onClosed) {
|
||||
this.timeout = timeout;
|
||||
this.stackTrace = stackTrace;
|
||||
this.onClosed = onClosed;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
@@ -106,8 +117,6 @@ public abstract class AbstractTask implements Task {
|
||||
}
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new EventHandler());
|
||||
}
|
||||
|
||||
public void expectPopupClosed(Runnable onClosed) {
|
||||
expectPopupClosed0(10, onClosed);
|
||||
@@ -119,13 +128,25 @@ public abstract class AbstractTask implements Task {
|
||||
|
||||
private void expectPopupClosed0(int timeout, Runnable onClosed) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
AbstractGuiPopup popup = getPopup(mc.currentScreen);
|
||||
if (popup == null) {
|
||||
throw new IllegalStateException("No popup found.");
|
||||
}
|
||||
class EventHandler {
|
||||
FMLCommonHandler.instance().bus().register(new PopupEventHandler(timeout, stackTrace, onClosed));
|
||||
}
|
||||
public class PopupEventHandler {
|
||||
private final int timeout;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
private final Runnable onClosed;
|
||||
private final AbstractGuiPopup popup;
|
||||
int framesPassed;
|
||||
|
||||
public PopupEventHandler(int timeout, StackTraceElement[] stackTrace, Runnable onClosed) {
|
||||
this.timeout = timeout;
|
||||
this.stackTrace = stackTrace;
|
||||
this.onClosed = onClosed;
|
||||
this.popup = getPopup(mc.currentScreen);
|
||||
if (this.popup == null) {
|
||||
throw new IllegalStateException("No popup found.");
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
@@ -143,8 +164,6 @@ public abstract class AbstractTask implements Task {
|
||||
}
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new EventHandler());
|
||||
}
|
||||
|
||||
private AbstractGuiPopup getPopup(net.minecraft.client.gui.GuiScreen minecraft) {
|
||||
GuiContainer<?> container = GuiOverlay.from(minecraft);
|
||||
@@ -165,10 +184,21 @@ public abstract class AbstractTask implements Task {
|
||||
|
||||
public <T> void expectGui(Class<T> guiClass, Consumer<T> onOpen) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
class EventHandler {
|
||||
FMLCommonHandler.instance().bus().register(new ExpectGuiEventHandler<T>(guiClass, stackTrace, onOpen));
|
||||
}
|
||||
public class ExpectGuiEventHandler<T> {
|
||||
private final Class<T> guiClass;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
private final Consumer<T> onOpen;
|
||||
net.minecraft.client.gui.GuiScreen currentScreen;
|
||||
int framesPassed;
|
||||
|
||||
public ExpectGuiEventHandler(Class<T> guiClass, StackTraceElement[] stackTrace, Consumer<T> onOpen) {
|
||||
this.guiClass = guiClass;
|
||||
this.stackTrace = stackTrace;
|
||||
this.onOpen = onOpen;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
@@ -210,16 +240,15 @@ public abstract class AbstractTask implements Task {
|
||||
return;
|
||||
}
|
||||
}
|
||||
class UnexpectedGuiException extends Exception {
|
||||
UnexpectedGuiException(Object foundGui) {
|
||||
super("Expected instance of " + guiClass + " but found " + foundGui);
|
||||
setStackTrace(Arrays.copyOfRange(stackTrace, 2, stackTrace.length));
|
||||
}
|
||||
}
|
||||
future.setException(new UnexpectedGuiException(foundGui == null ? currentScreen : foundGui));
|
||||
future.setException(new UnexpectedGuiException(guiClass, stackTrace,
|
||||
foundGui == null ? currentScreen : foundGui));
|
||||
}
|
||||
}
|
||||
FMLCommonHandler.instance().bus().register(new EventHandler());
|
||||
class UnexpectedGuiException extends Exception {
|
||||
UnexpectedGuiException(Class<?> guiClass, StackTraceElement[] stackTrace, Object foundGui) {
|
||||
super("Expected instance of " + guiClass + " but found " + foundGui);
|
||||
setStackTrace(Arrays.copyOfRange(stackTrace, 2, stackTrace.length));
|
||||
}
|
||||
}
|
||||
|
||||
private void clickNow(int x, int y) {
|
||||
|
||||
@@ -10,10 +10,10 @@ import com.replaymod.recording.ExitSPWorld;
|
||||
import com.replaymod.replay.ExitReplay;
|
||||
import com.replaymod.replay.LoadReplay;
|
||||
import com.replaymod.replay.OpenReplayViewer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.replaymod.core.AbstractTask.mc;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.replaymod.extra;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.extras.OpenEyeExtra;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.gui.GuiCreateWorld;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiSelectWorld;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class CreateSPWorld extends AbstractTask {
|
||||
@Override
|
||||
@@ -17,16 +17,17 @@ public class CreateSPWorld extends AbstractTask {
|
||||
click("Create New World");
|
||||
expectGui(GuiCreateWorld.class, createWorld -> {
|
||||
click("Create New World");
|
||||
class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.function.Clickable;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.util.Point;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
@@ -19,14 +19,15 @@ public class LoadReplay extends AbstractTask {
|
||||
// Load first replay
|
||||
click(replayViewer.loadButton);
|
||||
|
||||
class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
}));
|
||||
}
|
||||
|
||||
public class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.extras.playeroverview.PlayerOverviewGui;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -34,7 +34,7 @@ public class SpectatePlayer extends AbstractTask {
|
||||
future.setException(new TimeoutException("Camera hasn't stopped spectating."));
|
||||
return;
|
||||
}
|
||||
if (mc.getRenderViewEntity() == mc.thePlayer) {
|
||||
if (mc.renderViewEntity == mc.thePlayer) {
|
||||
future.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user