Cleaned up Gui overriding and replaced it with Forge Event Handlers
This commit is contained in:
@@ -1,31 +1,33 @@
|
|||||||
package eu.crushedpixel.replaymod.events;
|
package eu.crushedpixel.replaymod.events;
|
||||||
|
|
||||||
import eu.crushedpixel.replaymod.gui.GuiCustomMainMenu;
|
import java.util.List;
|
||||||
import eu.crushedpixel.replaymod.gui.GuiCustomOptions;
|
|
||||||
import eu.crushedpixel.replaymod.gui.GuiExitReplay;
|
import net.minecraft.client.Minecraft;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiChat;
|
import net.minecraft.client.gui.GuiChat;
|
||||||
import net.minecraft.client.gui.GuiDisconnected;
|
import net.minecraft.client.gui.GuiDisconnected;
|
||||||
import net.minecraft.client.gui.GuiIngameMenu;
|
import net.minecraft.client.gui.GuiIngameMenu;
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
import net.minecraft.client.gui.GuiOptions;
|
import net.minecraft.client.gui.GuiOptions;
|
||||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||||
|
import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
|
||||||
|
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import eu.crushedpixel.replaymod.gui.GuiCustomOptions;
|
||||||
|
import eu.crushedpixel.replaymod.gui.GuiExitReplay;
|
||||||
|
import eu.crushedpixel.replaymod.gui.GuiReplayManager;
|
||||||
|
import eu.crushedpixel.replaymod.gui.GuiReplaySaving;
|
||||||
|
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
|
||||||
|
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||||
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
|
|
||||||
public class GuiEventHandler {
|
public class GuiEventHandler {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onGui(GuiOpenEvent event) {
|
public void onGui(GuiOpenEvent event) {
|
||||||
if(event.gui instanceof GuiMainMenu) {
|
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
||||||
event.gui = new GuiCustomMainMenu();
|
|
||||||
} else if(event.gui instanceof GuiOptions) {
|
|
||||||
GuiOptions go = (GuiOptions)event.gui;
|
|
||||||
GuiCustomOptions gco = new GuiCustomOptions(GuiCustomOptions.getGuiScreen(go), GuiCustomOptions.getGameSettings(go));
|
|
||||||
event.gui = gco;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
|
||||||
if(ReplayHandler.replayActive()) {
|
if(ReplayHandler.replayActive()) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
@@ -42,7 +44,39 @@ public class GuiEventHandler {
|
|||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int REPLAY_MANAGER_ID = 9001;
|
||||||
|
private static final int REPLAY_OPTIONS_ID = 9001;
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onInit(InitGuiEvent event) {
|
||||||
|
if(event.gui instanceof GuiMainMenu) {
|
||||||
|
int i1 = event.gui.height / 4 + 48;
|
||||||
|
|
||||||
|
for(GuiButton b : (List<GuiButton>)event.buttonList) {
|
||||||
|
if(b.id != 0 && b.id != 4 && b.id != 5) {
|
||||||
|
b.yPosition = b.yPosition - 24;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.buttonList.add(new GuiButton(REPLAY_MANAGER_ID, event.gui.width / 2 - 100, i1 + 2*24, I18n.format("Replay Manager", new Object[0])));
|
||||||
|
} else if(event.gui instanceof GuiOptions) {
|
||||||
|
event.buttonList.add(new GuiButton(9001, event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onButton(ActionPerformedEvent event) {
|
||||||
|
if(event.gui instanceof GuiMainMenu && event.button.id == REPLAY_MANAGER_ID) {
|
||||||
|
if(ConnectionEventHandler.saving) {
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(new GuiReplaySaving());
|
||||||
|
} else {
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(new GuiReplayManager());
|
||||||
|
}
|
||||||
|
} else if(event.gui instanceof GuiOptions && event.button.id == REPLAY_OPTIONS_ID) {
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(new GuiReplaySettings(event.gui));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ public class RecordingHandler {
|
|||||||
playerItems = new ItemStack[5];
|
playerItems = new ItemStack[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int ticksSinceLastCorrection = 0;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onPlayerTick(PlayerTickEvent e) {
|
public void onPlayerTick(PlayerTickEvent e) {
|
||||||
try {
|
try {
|
||||||
@@ -135,6 +137,12 @@ public class RecordingHandler {
|
|||||||
lastZ = e.player.posZ;
|
lastZ = e.player.posZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ticksSinceLastCorrection++;
|
||||||
|
if(ticksSinceLastCorrection >= 100) {
|
||||||
|
ticksSinceLastCorrection = 0;
|
||||||
|
force = true;
|
||||||
|
}
|
||||||
|
|
||||||
double dx = e.player.posX - lastX;
|
double dx = e.player.posX - lastX;
|
||||||
double dy = e.player.posY - lastY;
|
double dy = e.player.posY - lastY;
|
||||||
double dz = e.player.posZ - lastZ;
|
double dz = e.player.posZ - lastZ;
|
||||||
@@ -151,7 +159,6 @@ public class RecordingHandler {
|
|||||||
byte yaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
|
byte yaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
|
||||||
byte pitch = (byte)((int)(e.player.rotationPitch * 256.0F / 360.0F));
|
byte pitch = (byte)((int)(e.player.rotationPitch * 256.0F / 360.0F));
|
||||||
packet = new S18PacketEntityTeleport(entityID, x, y, z, yaw, pitch, e.player.onGround);
|
packet = new S18PacketEntityTeleport(entityID, x, y, z, yaw, pitch, e.player.onGround);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
byte oldYaw = (byte)((int)(e.player.prevRotationYaw * 256.0F / 360.0F));
|
byte oldYaw = (byte)((int)(e.player.prevRotationYaw * 256.0F / 360.0F));
|
||||||
byte newYaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
|
byte newYaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
|
||||||
@@ -274,6 +281,23 @@ public class RecordingHandler {
|
|||||||
ConnectionEventHandler.insertPacket(pea);
|
ConnectionEventHandler.insertPacket(pea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Sleeping
|
||||||
|
if(!mc.thePlayer.isPlayerSleeping() && wasSleeping) {
|
||||||
|
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||||
|
|
||||||
|
ByteBuf bb = Unpooled.buffer();
|
||||||
|
PacketBuffer pb = new PacketBuffer(bb);
|
||||||
|
|
||||||
|
pb.writeVarIntToBuffer(entityID);
|
||||||
|
pb.writeByte(2);
|
||||||
|
|
||||||
|
pac.readPacketData(pb);
|
||||||
|
|
||||||
|
ConnectionEventHandler.insertPacket(pac);
|
||||||
|
|
||||||
|
wasSleeping = false;
|
||||||
|
}
|
||||||
|
|
||||||
} catch(Exception e1) {
|
} catch(Exception e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -378,14 +402,17 @@ public class RecordingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean wasSleeping = false;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onSleep(PlayerSleepInBedEvent event) {
|
public void onSleep(PlayerSleepInBedEvent event) {
|
||||||
try {
|
try {
|
||||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
|
||||||
|
if(event.entityPlayer != mc.thePlayer) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(event.result == EnumStatus.OK) {
|
System.out.println(event.getResult());
|
||||||
S0APacketUseBed pub = new S0APacketUseBed();
|
S0APacketUseBed pub = new S0APacketUseBed();
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.buffer();
|
ByteBuf buf = Unpooled.buffer();
|
||||||
@@ -398,8 +425,8 @@ public class RecordingHandler {
|
|||||||
|
|
||||||
ConnectionEventHandler.insertPacket(pub);
|
ConnectionEventHandler.insertPacket(pub);
|
||||||
|
|
||||||
System.out.println("SLEEP PACKET SENT");
|
wasSleeping = true;
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
package eu.crushedpixel.replaymod.gui;
|
|
||||||
|
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
|
||||||
import net.minecraft.client.gui.GuiButtonLanguage;
|
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
|
||||||
import net.minecraft.client.gui.GuiSelectWorld;
|
|
||||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.network.Packet;
|
|
||||||
|
|
||||||
public class GuiCustomMainMenu extends GuiMainMenu {
|
|
||||||
|
|
||||||
private static final int REPLAY_MANAGER_ID = 9001;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initGui() {
|
|
||||||
Class<? extends GuiMainMenu> clazz = GuiMainMenu.class;
|
|
||||||
|
|
||||||
int i1 = this.height / 4 + 48;
|
|
||||||
this.buttonList.add(new GuiButton(REPLAY_MANAGER_ID, this.width / 2 - 100, i1 + 2*24, I18n.format("Replay Manager", new Object[0])));
|
|
||||||
|
|
||||||
try {
|
|
||||||
Field viewportTexture = clazz.getDeclaredField(MCPNames.field("field_73977_n"));
|
|
||||||
viewportTexture.setAccessible(true);
|
|
||||||
viewportTexture.set(this, new DynamicTexture(256, 256));
|
|
||||||
|
|
||||||
Field field_110351_G = clazz.getDeclaredField(MCPNames.field("field_110351_G"));
|
|
||||||
field_110351_G.setAccessible(true);
|
|
||||||
field_110351_G.set(this, this.mc.getTextureManager().getDynamicTextureLocation("background", (DynamicTexture)viewportTexture.get(this)));
|
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(new Date());
|
|
||||||
|
|
||||||
Field splashText = clazz.getDeclaredField(MCPNames.field("field_73975_c"));
|
|
||||||
splashText.setAccessible(true);
|
|
||||||
|
|
||||||
if (calendar.get(2) + 1 == 11 && calendar.get(5) == 9)
|
|
||||||
{
|
|
||||||
splashText.set(this, "Happy birthday, ez!");
|
|
||||||
}
|
|
||||||
else if (calendar.get(2) + 1 == 6 && calendar.get(5) == 1)
|
|
||||||
{
|
|
||||||
splashText.set(this, "Happy birthday, Notch!");
|
|
||||||
}
|
|
||||||
else if (calendar.get(2) + 1 == 12 && calendar.get(5) == 24)
|
|
||||||
{
|
|
||||||
splashText.set(this, "Merry X-Mas!");
|
|
||||||
}
|
|
||||||
else if (calendar.get(2) + 1 == 1 && calendar.get(5) == 1)
|
|
||||||
{
|
|
||||||
splashText.set(this, "Happy new year!");
|
|
||||||
}
|
|
||||||
else if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31)
|
|
||||||
{
|
|
||||||
splashText.set(this, "OOoooOOOoooo! Spooky!");
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean flag = true;
|
|
||||||
int i = this.height / 4 + 48;
|
|
||||||
|
|
||||||
if (this.mc.isDemo())
|
|
||||||
{
|
|
||||||
Method addDemoButtons = clazz.getDeclaredMethod(MCPNames.method("func_73972_b"), int.class, int.class);
|
|
||||||
addDemoButtons.setAccessible(true);
|
|
||||||
addDemoButtons.invoke(this, i, 24);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Method addSingleplayerMultiplayerButtons = clazz.getDeclaredMethod(MCPNames.method("func_73969_a"), int.class, int.class);
|
|
||||||
addSingleplayerMultiplayerButtons.setAccessible(true);
|
|
||||||
addSingleplayerMultiplayerButtons.invoke(this, i - 24, 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, i + 72 + 12, 98, 20, I18n.format("menu.options", new Object[0])));
|
|
||||||
this.buttonList.add(new GuiButton(4, this.width / 2 + 2, i + 72 + 12, 98, 20, I18n.format("menu.quit", new Object[0])));
|
|
||||||
this.buttonList.add(new GuiButtonLanguage(5, this.width / 2 - 124, i + 72 + 12));
|
|
||||||
|
|
||||||
Field threadLock = clazz.getDeclaredField(MCPNames.field("field_104025_t"));
|
|
||||||
threadLock.setAccessible(true);
|
|
||||||
Object object = threadLock.get(this);
|
|
||||||
|
|
||||||
Field field_92023_s = clazz.getDeclaredField(MCPNames.field("field_92023_s"));
|
|
||||||
field_92023_s.setAccessible(true);
|
|
||||||
|
|
||||||
Field openGLWarning1 = clazz.getDeclaredField(MCPNames.field("openGLWarning1"));
|
|
||||||
openGLWarning1.setAccessible(true);
|
|
||||||
|
|
||||||
Field openGLWarning2 = clazz.getDeclaredField(MCPNames.field("openGLWarning2"));
|
|
||||||
openGLWarning2.setAccessible(true);
|
|
||||||
|
|
||||||
Field field_92024_r = clazz.getDeclaredField(MCPNames.field("field_92024_r"));
|
|
||||||
field_92024_r.setAccessible(true);
|
|
||||||
|
|
||||||
Field field_92022_t = clazz.getDeclaredField(MCPNames.field("field_92022_t"));
|
|
||||||
field_92022_t.setAccessible(true);
|
|
||||||
|
|
||||||
Field field_92021_u = clazz.getDeclaredField(MCPNames.field("field_92021_u"));
|
|
||||||
field_92021_u.setAccessible(true);
|
|
||||||
|
|
||||||
Field field_92020_v = clazz.getDeclaredField(MCPNames.field("field_92020_v"));
|
|
||||||
field_92020_v.setAccessible(true);
|
|
||||||
|
|
||||||
Field field_92019_w = clazz.getDeclaredField(MCPNames.field("field_92019_w"));
|
|
||||||
field_92019_w.setAccessible(true);
|
|
||||||
|
|
||||||
synchronized (object)
|
|
||||||
{
|
|
||||||
field_92023_s.set(this, this.fontRendererObj.getStringWidth((String)openGLWarning1.get(this)));
|
|
||||||
field_92024_r.set(this, this.fontRendererObj.getStringWidth((String)openGLWarning2.get(this)));
|
|
||||||
int j = Math.max((Integer)(field_92023_s.get(this)), (Integer)(field_92024_r.get(this)));
|
|
||||||
field_92022_t.set(this, (this.width - j) / 2);
|
|
||||||
field_92021_u.set(this, ((GuiButton)this.buttonList.get(0)).yPosition - 24);
|
|
||||||
field_92020_v.set(this, (Integer)field_92022_t.get(this) + j);
|
|
||||||
field_92019_w.set(this, (Integer)field_92021_u.get(this) + 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void actionPerformed(GuiButton button) throws IOException {
|
|
||||||
if(button.id == REPLAY_MANAGER_ID) {
|
|
||||||
this.mc.displayGuiScreen(new GuiReplayManager());
|
|
||||||
}
|
|
||||||
super.actionPerformed(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package eu.crushedpixel.replaymod.gui;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import com.mojang.realmsclient.util.Pair;
|
|
||||||
|
|
||||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
|
||||||
import net.minecraft.client.gui.GuiCustomizeSkin;
|
|
||||||
import net.minecraft.client.gui.GuiOptionButton;
|
|
||||||
import net.minecraft.client.gui.GuiOptions;
|
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
|
||||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
|
||||||
import net.minecraft.client.settings.GameSettings;
|
|
||||||
|
|
||||||
public class GuiCustomOptions extends GuiOptions {
|
|
||||||
|
|
||||||
public static GuiScreen getGuiScreen(GuiOptions go) {
|
|
||||||
try {
|
|
||||||
Class<GuiOptions> clazz = GuiOptions.class;
|
|
||||||
Field guiScreen = clazz.getDeclaredField(MCPNames.field(MCPNames.field("field_146441_g")));
|
|
||||||
guiScreen.setAccessible(true);
|
|
||||||
Object obj = guiScreen.get(go);
|
|
||||||
return (GuiScreen)obj;
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameSettings getGameSettings(GuiOptions go) {
|
|
||||||
try {
|
|
||||||
Class<GuiOptions> clazz = GuiOptions.class;
|
|
||||||
Field gameSettings = clazz.getDeclaredField(MCPNames.field(MCPNames.field("field_146443_h")));
|
|
||||||
gameSettings.setAccessible(true);
|
|
||||||
Object obj = gameSettings.get(go);
|
|
||||||
return (GameSettings)obj;
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiCustomOptions(GuiScreen guiScreen, GameSettings gameSettings) {
|
|
||||||
super(guiScreen, gameSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initGui() {
|
|
||||||
super.initGui();
|
|
||||||
buttonList.add(new GuiButton(9001, this.width / 2 - 155, this.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(GuiButton button) throws IOException {
|
|
||||||
super.actionPerformed(button);
|
|
||||||
if (button.enabled && button.id == 9001) { //Replay Mod Settings...
|
|
||||||
this.mc.displayGuiScreen(new GuiReplaySettings(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -45,19 +45,17 @@ public class GuiExitReplay extends GuiIngameMenu {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
mc.displayGuiScreen(new GuiReplaySaving());
|
||||||
ReplayHandler.endReplay();
|
ReplayHandler.endReplay();
|
||||||
ReplayHandler.setSpeed(1f);
|
ReplayHandler.setSpeed(1f);
|
||||||
|
|
||||||
ReplayHandler.lastExit = System.currentTimeMillis();
|
ReplayHandler.lastExit = System.currentTimeMillis();
|
||||||
mc.theWorld.sendQuittingDisconnectingPacket();
|
mc.theWorld.sendQuittingDisconnectingPacket();
|
||||||
mc.displayGuiScreen(new GuiMainMenu());
|
|
||||||
//mc.loadWorld((WorldClient)null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
t.run();
|
t.run();
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
super.actionPerformed(button);
|
super.actionPerformed(button);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,23 +5,18 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.gui.GuiYesNo;
|
import net.minecraft.client.gui.GuiYesNo;
|
||||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||||
import net.minecraft.client.network.NetHandlerLoginClient;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.network.EnumConnectionState;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.handshake.client.C00Handshake;
|
|
||||||
import net.minecraft.network.login.client.C00PacketLoginStart;
|
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
|
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||||
@@ -36,7 +31,6 @@ import com.mojang.realmsclient.util.Pair;
|
|||||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplaySender;
|
|
||||||
|
|
||||||
public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||||
|
|
||||||
@@ -103,7 +97,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Pair<File, ReplayMetaData> o1, Pair<File, ReplayMetaData> o2) {
|
public int compare(Pair<File, ReplayMetaData> o1, Pair<File, ReplayMetaData> o2) {
|
||||||
return (int) (o2.second().getDate() - o1.second().getDate());
|
return (int)(new Date(o2.second().getDate()).compareTo(new Date(o1.second().getDate())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package eu.crushedpixel.replaymod.gui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiIngameMenu;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
|
|
||||||
|
public class GuiReplaySaving extends GuiScreen {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
this.drawDefaultBackground();
|
||||||
|
this.drawCenteredString(this.fontRendererObj, "Saving Replay File...", this.width / 2, 20, 16777215);
|
||||||
|
this.drawCenteredString(this.fontRendererObj, "Please wait while your recent Replay is being saved.", this.width / 2, 40, 16777215);
|
||||||
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
|
if(!ConnectionEventHandler.saving) {
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(new GuiReplayManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -40,6 +40,8 @@ public class ConnectionEventHandler {
|
|||||||
|
|
||||||
private static boolean isRecording = false;
|
private static boolean isRecording = false;
|
||||||
|
|
||||||
|
public static boolean saving = false;
|
||||||
|
|
||||||
public static boolean isRecording() {
|
public static boolean isRecording() {
|
||||||
return isRecording;
|
return isRecording;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -142,6 +144,8 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
ConnectionEventHandler.saving = true;
|
||||||
|
|
||||||
ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime);
|
ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime);
|
||||||
String json = gson.toJson(metaData);
|
String json = gson.toJson(metaData);
|
||||||
|
|
||||||
@@ -173,8 +177,11 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
|
|||||||
zos.close();
|
zos.close();
|
||||||
|
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
||||||
|
ConnectionEventHandler.saving = false;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
ConnectionEventHandler.saving = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user