Disabled Head rotation while saving replay video

Made video rendering possible while Minecraft is in background
This commit is contained in:
Marius Metzger
2015-03-08 22:51:50 +01:00
parent 5ce12162ce
commit b4ce266375
14 changed files with 122 additions and 143 deletions

View File

@@ -1,5 +1,7 @@
package eu.crushedpixel.replaymod;
import java.io.File;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
@@ -12,11 +14,11 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import eu.crushedpixel.replaymod.api.client.ApiClient;
import eu.crushedpixel.replaymod.editor.ReplayTrimmer;
import eu.crushedpixel.replaymod.events.GuiEventHandler;
import eu.crushedpixel.replaymod.events.GuiReplayOverlay;
import eu.crushedpixel.replaymod.events.KeyInputHandler;
import eu.crushedpixel.replaymod.events.RecordingHandler;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
@@ -106,6 +108,7 @@ public class ReplayMod
e.printStackTrace();
}
//ReplayTrimmer.trim(new File("/Users/mariusmetzger/toTrim.mcpr"), new File("/Users/mariusmetzger/trimmed.mcpr"), 1000*60, 2000*60);
//if(AuthenticationHandler.isBlacklisted(Minecraft.getMinecraft().getSession().getPlayerID())) {
//System.exit(0);
//}

View File

@@ -109,14 +109,14 @@ public class CameraEntity extends EntityPlayer {
}
public void moveAbsolute(double x, double y, double z) {
if(ReplayHandler.isReplaying()) return;
if(ReplayHandler.isInPath()) return;
this.lastTickPosX = this.prevPosX = this.posX = x;
this.lastTickPosY = this.prevPosY = this.posY = y;
this.lastTickPosZ = this.prevPosZ = this.posZ = z;
}
public void moveRelative(double x, double y, double z) {
if(ReplayHandler.isReplaying()) return;
if(ReplayHandler.isInPath()) return;
this.lastTickPosX = this.prevPosX = this.posX = this.posX+x;
this.lastTickPosY = this.prevPosY = this.posY = this.posY+y;
this.lastTickPosZ = this.prevPosZ = this.posZ = this.posZ+z;

View File

@@ -82,13 +82,13 @@ public class GuiEventHandler {
return;
}
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
if(ReplayHandler.replayActive()) {
if(ReplayHandler.isInReplay()) {
event.setCanceled(true);
}
}
else if(event.gui instanceof GuiDisconnected) {
if(!ReplayHandler.replayActive() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
if(!ReplayHandler.isInReplay() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
event.setCanceled(true);
}
}
@@ -111,7 +111,7 @@ public class GuiEventHandler {
@SubscribeEvent
public void onInit(InitGuiEvent event) {
if(event.gui instanceof GuiIngameMenu && ReplayHandler.replayActive()) {
if(event.gui instanceof GuiIngameMenu && ReplayHandler.isInReplay()) {
for(GuiButton b : new ArrayList<GuiButton>(event.buttonList)) {
if(b.id == 1) {
b.displayString = "Exit Replay";
@@ -164,7 +164,7 @@ public class GuiEventHandler {
mc.displayGuiScreen(new GuiReplaySettings(event.gui));
}
if(ReplayHandler.replayActive() && event.gui instanceof GuiIngameMenu && event.button.id == GuiConstants.EXIT_REPLAY_BUTTON) {
if(ReplayHandler.isInReplay() && event.gui instanceof GuiIngameMenu && event.button.id == GuiConstants.EXIT_REPLAY_BUTTON) {
ReplayHandler.endReplay();
event.button.enabled = false;

View File

@@ -24,6 +24,7 @@ import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
@@ -89,6 +90,17 @@ public class GuiReplayOverlay extends Gui {
private boolean mouseDown = false;
private static boolean requestScreenshot = false;
private static Field isGamePaused;
static {
try {
isGamePaused = Minecraft.class.getDeclaredField(MCPNames.field("field_71445_n"));
isGamePaused.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
//private Field drawBlockOutline;
@@ -106,32 +118,41 @@ public class GuiReplayOverlay extends Gui {
//@SubscribeEvent TODO
public void renderHand(RenderHandEvent event) {
if(ReplayHandler.replayActive()) {
if(ReplayHandler.isInReplay()) {
event.setCanceled(true);
}
}
@SubscribeEvent
public void tick(TickEvent event) {
if(!ReplayHandler.replayActive()) return;
if(ReplayHandler.isReplaying() && !ReplayProcess.isVideoRecording()) ReplayProcess.tickReplay();
if(!ReplayHandler.isInReplay()) return;
if(ReplayHandler.isInPath() && !ReplayProcess.isVideoRecording()) ReplayProcess.tickReplay();
ReplayProcess.unblock();
if(ReplayHandler.getCameraEntity() != null)
ReplayHandler.getCameraEntity().updateMovement();
if(!ReplayHandler.isReplaying()) onMouseMove(new MouseEvent());
if(!ReplayHandler.isInPath()) onMouseMove(new MouseEvent());
FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent());
}
private double lastX, lastY, lastZ;
private float lastPitch, lastYaw;
@SubscribeEvent
public void onChangeView(MouseEvent event) {
if(ReplayHandler.isInPath()) {
event.setCanceled(true);
}
}
@SubscribeEvent
public void onRenderWorld(RenderWorldLastEvent event)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, IOException {
if(!ReplayHandler.replayActive()) return;
if(!ReplayHandler.isInReplay()) return;
if(ReplayHandler.isCamera()) ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity());
if(ReplayHandler.replayActive() && ReplayHandler.isPaused()) {
if(ReplayHandler.isInReplay() && ReplayHandler.isPaused()) {
if(mc != null && mc.thePlayer != null)
MinecraftTicker.runMouseKeyboardTick(mc);
}
@@ -150,6 +171,9 @@ public class GuiReplayOverlay extends Gui {
requestScreenshot = false;
ReplayScreenshot.saveScreenshot(mc.getFramebuffer());
}
if(mc.isGamePaused() && ReplayHandler.isInPath()) {
isGamePaused.set(mc, false);
}
}
public void resetUI() throws Exception {
@@ -171,7 +195,7 @@ public class GuiReplayOverlay extends Gui {
@SubscribeEvent
public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException {
if(!ReplayHandler.replayActive() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) {
if(!ReplayHandler.isInReplay() || FMLClientHandler.instance().isGUIOpen(GuiSpectateSelection.class) || VideoWriter.isRecording()) {
return;
}
@@ -189,7 +213,7 @@ public class GuiReplayOverlay extends Gui {
GL11.glEnable(GL11.GL_BLEND);
// drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false);
if(!ReplayHandler.replayActive()) {
if(!ReplayHandler.isInReplay()) {
return;
}
@@ -718,7 +742,7 @@ public class GuiReplayOverlay extends Gui {
int dx = 0;
int dy = 0;
boolean play = ReplayHandler.isReplaying();
boolean play = ReplayHandler.isInPath();
hover = false;
if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
@@ -742,7 +766,7 @@ public class GuiReplayOverlay extends Gui {
//Handling the click on the Replay starter
if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) {
if(ReplayHandler.isReplaying()) {
if(ReplayHandler.isInPath()) {
ReplayHandler.interruptReplay();
} else {
ReplayHandler.startPath(false);
@@ -827,7 +851,7 @@ public class GuiReplayOverlay extends Gui {
@SubscribeEvent
public void onMouseMove(MouseEvent event) {
if(!ReplayHandler.replayActive()) return;
if(!ReplayHandler.isInReplay()) return;
boolean flag = Display.isActive();
flag = true;

View File

@@ -21,7 +21,7 @@ public class KeyInputHandler {
@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
if(!ReplayHandler.replayActive()) return;
if(!ReplayHandler.isInReplay()) return;
if(mc.currentScreen != null) {
return;
}

View File

@@ -24,6 +24,7 @@ import net.minecraft.client.renderer.ActiveRenderInfo;
import com.google.gson.Gson;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.gui.GuiReplaySaving;
import eu.crushedpixel.replaymod.holders.PacketData;
@@ -33,17 +34,17 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
protected Long startTime = null;
protected String name;
protected String worldName;
private boolean singleplayer;
protected long lastSentPacket = 0;
protected boolean alive = true;
protected DataWriter dataWriter;
private Gson gson = new Gson();
protected Set<String> players = new HashSet<String>();
public void setWorldName(String worldName) {
@@ -65,12 +66,12 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
DataOutputStream out = new DataOutputStream(bos);
dataWriter = new DataWriter(out);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
dataWriter.requestFinish(players);
}
public class DataWriter {
private boolean active = true;
@@ -80,27 +81,24 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
public void writeData(PacketData data) {
queue.add(data);
}
Thread outputThread = new Thread(new Runnable() {
@Override
public void run() {
HashMap<Class, Integer> counts = new HashMap<Class, Integer>();
while(active) {
PacketData dataReciever = queue.poll();
if(dataReciever != null) {
//write the ByteBuf to the given OutputStream
byte[] array = dataReciever.getByteArray();
if(array != null) {
try {
stream.writeInt(dataReciever.getTimestamp()); //Timestamp
stream.writeInt(array.length); //Lenght
stream.write(array); //Content
ReplayFileIO.writePacket(dataReciever, stream);
stream.flush();
} catch(Exception e) {
e.printStackTrace();
@@ -127,7 +125,7 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
for(Entry<Class, Integer> entries : counts.entrySet()) {
System.out.println(entries.getKey()+ "| "+entries.getValue());
}
}
});
@@ -140,7 +138,6 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
public void requestFinish(Set<String> players) {
active = false;
byte[] buffer = new byte[1024];
try {
GuiReplaySaving.replaySaving = true;
@@ -150,9 +147,9 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
if(split.length > 0) {
mcversion = split[0];
}
String[] pl = players.toArray(new String[players.size()]);
ReplayMetaData metaData = new ReplayMetaData(singleplayer, worldName, (int) lastSentPacket, startTime, pl, mcversion);
String json = gson.toJson(metaData);
@@ -162,29 +159,10 @@ public abstract class DataListener extends ChannelInboundHandlerAdapter {
File archive = new File(folder, name+ConnectionEventHandler.ZIP_FILE_EXTENSION);
archive.createNewFile();
FileOutputStream fos = new FileOutputStream(archive);
ZipOutputStream zos = new ZipOutputStream(fos);
zos.putNextEntry(new ZipEntry("metaData.json"));
PrintWriter pw = new PrintWriter(zos);
pw.write(json);
pw.flush();
zos.closeEntry();
zos.putNextEntry(new ZipEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION));
FileInputStream fis = new FileInputStream(file);
int len;
while((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
fis.close();
zos.closeEntry();
zos.close();
file.delete();
ReplayFileIO.writeReplayFile(archive, file, metaData);
file.delete();
GuiReplaySaving.replaySaving = false;
} catch(Exception e) {
e.printStackTrace();

View File

@@ -19,6 +19,7 @@ import net.minecraft.network.play.server.S0DPacketCollectItem;
import net.minecraft.network.play.server.S0FPacketSpawnMob;
import eu.crushedpixel.replaymod.chat.ChatMessageRequests;
import eu.crushedpixel.replaymod.chat.ChatMessageRequests.ChatMessageType;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.reflection.MCPNames;
@@ -32,8 +33,6 @@ public class PacketListener extends DataListener {
private ChannelHandlerContext context = null;
private static final PacketSerializer packetSerializer = new PacketSerializer(EnumPacketDirection.CLIENTBOUND);
public void saveOnly(Packet packet) {
try {
if(packet instanceof S0CPacketSpawnPlayer) {
@@ -69,7 +68,7 @@ public class PacketListener extends DataListener {
if(packet instanceof S0DPacketCollectItem) {
if(mc.thePlayer != null ||
((S0DPacketCollectItem) packet).func_149353_d() == mc.thePlayer.getEntityId()) {
((S0DPacketCollectItem)packet).func_149353_d() == mc.thePlayer.getEntityId()) {
super.channelRead(ctx, msg);
return;
}
@@ -115,10 +114,6 @@ public class PacketListener extends DataListener {
if(startTime == null) startTime = System.currentTimeMillis();
int timestamp = (int)(System.currentTimeMillis() - startTime);
//Converts the packet back to a ByteBuffer for correct saving
ByteBuf bb = Unpooled.buffer();
if(packet instanceof S0FPacketSpawnMob) {
DataWatcher l = (DataWatcher)spawnMobDataWatcher.get(packet);
@@ -135,14 +130,8 @@ public class PacketListener extends DataListener {
spawnPlayerDataWatcher.set(packet, dw);
}
}
packetSerializer.encode(ctx, packet, bb);
bb.readerIndex(0);
byte[] array = new byte[bb.readableBytes()];
bb.readBytes(array);
bb.readerIndex(0);
byte[] array = ReplayFileIO.serializePacket(packet);
return new PacketData(array, timestamp);
}

View File

@@ -24,31 +24,24 @@ public class PacketSerializer extends MessageSerializer {
}
@Override
public void encode(ChannelHandlerContext p_encode_1_, Packet p_encode_2_, ByteBuf p_encode_3_) throws IOException {
//super.encode(p_encode_1_, p_encode_2_, p_encode_3_);
Integer integer = ((EnumConnectionState)p_encode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()).getPacketId(EnumPacketDirection.CLIENTBOUND, p_encode_2_);
public void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf byteBuf) throws IOException {
EnumConnectionState state = ((EnumConnectionState)ctx.channel().attr(NetworkManager.attrKeyConnectionState).get());
encode(state, packet, byteBuf);
}
public void encode(EnumConnectionState state, Packet packet, ByteBuf byteBuf) {
Integer integer = state.getPacketId(EnumPacketDirection.CLIENTBOUND, packet);
if (integer == null)
{
if (integer == null) {
return;
}
else
{
PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_);
} else {
PacketBuffer packetbuffer = new PacketBuffer(byteBuf);
packetbuffer.writeVarIntToBuffer(integer.intValue());
try
{
if (p_encode_2_ instanceof S0CPacketSpawnPlayer)
{
//p_encode_2_ = p_encode_2_; FML: Kill warning
}
p_encode_2_.writePacketData(packetbuffer);
try {
packet.writePacketData(packetbuffer);
}
catch (Throwable throwable)
{
catch (Throwable throwable) {
throwable.printStackTrace();
}
}

View File

@@ -30,6 +30,9 @@ public class ReplayMetaData {
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public long getDate() {
return date;
}

View File

@@ -8,8 +8,6 @@ public class PacketInfo {
private EnumConnectionState connectionState;
private int packetID;
public PacketInfo(byte[] bytes, EnumConnectionState connectionState,
int packetID) {
super();

View File

@@ -40,13 +40,13 @@ public class ReplayHandler {
private static Keyframe selectedKeyframe;
private static boolean isReplaying = false;
private static boolean inPath = false;
private static CameraEntity cameraEntity;
private static List<Keyframe> keyframes = new ArrayList<Keyframe>();
private static boolean replayActive = false;
private static boolean inReplay = false;
public static long lastExit = 0;
@@ -93,20 +93,20 @@ public class ReplayHandler {
return gamma;
}
public static void setReplaying(boolean replaying) {
isReplaying = replaying;
public static void setInPath(boolean replaying) {
inPath = replaying;
}
public static void startPath(boolean save) {
if(!ReplayHandler.isReplaying()) ReplayProcess.startReplayProcess(save);
if(!ReplayHandler.isInPath()) ReplayProcess.startReplayProcess(save);
}
public static void interruptReplay() {
ReplayProcess.stopReplayProcess(false);
}
public static boolean isReplaying() {
return isReplaying;
public static boolean isInPath() {
return inPath;
}
public static void setCameraEntity(CameraEntity entity) {
@@ -309,8 +309,8 @@ public class ReplayHandler {
sortKeyframes();
}
public static boolean replayActive() {
return replayActive;
public static boolean isInReplay() {
return inReplay;
}
public static boolean isPaused() {
@@ -364,7 +364,7 @@ public class ReplayHandler {
//Load lighting and trigger update
ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled());
replayActive = true;
inReplay = true;
}
public static void restartReplay() {
@@ -390,7 +390,7 @@ public class ReplayHandler {
ReplayMod.overlay.resetUI();
} catch(Exception e) {}
replayActive = true;
inReplay = true;
}
public static void endReplay() {
@@ -406,7 +406,7 @@ public class ReplayHandler {
}
*/
replayActive = false;
inReplay = false;
}
public static Keyframe getSelected() {

View File

@@ -63,7 +63,7 @@ public class ReplayProcess {
lastTimestamp = -1;
linear = ReplayMod.replaySettings.isLinearMovement();
ReplayHandler.sortKeyframes();
ReplayHandler.setReplaying(true);
ReplayHandler.setInPath(true);
previousReplaySpeed = ReplayHandler.getSpeed();
TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1);
@@ -85,7 +85,7 @@ public class ReplayProcess {
@Override
public void run() {
while(ReplayHandler.isReplaying()) {
while(ReplayHandler.isInPath()) {
if(!blocked) {
mc.addScheduledTask(new Runnable() {
@Override
@@ -109,10 +109,10 @@ public class ReplayProcess {
}
public static void stopReplayProcess(boolean finished) {
if(!ReplayHandler.isReplaying()) return;
if(!ReplayHandler.isInPath()) return;
if(finished) ChatMessageRequests.addChatMessage("Replay finished!", ChatMessageType.INFORMATION);
else ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION);
ReplayHandler.setReplaying(false);
ReplayHandler.setInPath(false);
MCTimerHandler.setActiveTimer();
ReplayHandler.setSpeed(previousReplaySpeed);
ReplayHandler.setSpeed(0);
@@ -434,7 +434,7 @@ public class ReplayProcess {
//Video capturing, for testing purposes
if(isVideoRecording()) {
try {
if(!VideoWriter.isRecording() && ReplayHandler.isReplaying()) {
if(!VideoWriter.isRecording() && ReplayHandler.isInPath()) {
VideoWriter.startRecording(mc.displayWidth, mc.displayHeight);
} else {
VideoWriter.writeImage(ScreenCapture.captureScreen());

View File

@@ -15,7 +15,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.UUID;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiDownloadTerrain;
@@ -48,7 +47,6 @@ import net.minecraft.network.play.server.S30PacketWindowItems;
import net.minecraft.network.play.server.S36PacketSignEditorOpen;
import net.minecraft.network.play.server.S37PacketStatistics;
import net.minecraft.network.play.server.S38PacketPlayerListItem;
import net.minecraft.network.play.server.S38PacketPlayerListItem.AddPlayerData;
import net.minecraft.network.play.server.S39PacketPlayerAbilities;
import net.minecraft.network.play.server.S43PacketCamera;
import net.minecraft.network.play.server.S45PacketTitle;
@@ -63,11 +61,12 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.entities.CameraEntity;
import eu.crushedpixel.replaymod.events.RecordingHandler;
import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.holders.Position;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
@@ -86,7 +85,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
private long toleratedTimeStamp = Long.MAX_VALUE;
private File replayFile;
private PacketDeserializer ds = new PacketDeserializer(EnumPacketDirection.SERVERBOUND);
private boolean active = true;
private ZipFile archive;
private DataInputStream dis;
@@ -148,7 +146,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
setReplaySpeed(replaySpeed);
if((millis < currentTimeStamp && !isHurrying())) {
if(ReplayHandler.isReplaying()) {
if(ReplayHandler.isInPath()) {
if(millis < toleratedTimeStamp) {
return;
}
@@ -255,9 +253,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
lastPacketSent = System.currentTimeMillis();
ReplayHandler.restartReplay();
}
while(!terminate && !startFromBeginning && (!paused() || FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class))) {
try {
/*
* LOGIC:
* While behind desired timestamp, only send packets
@@ -270,15 +268,16 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
*/
if(!hurryToTimestamp && ReplayHandler.isReplaying()) {
if(!hurryToTimestamp && ReplayHandler.isInPath()) {
continue;
}
int timestamp = dis.readInt();
PacketData pd = ReplayFileIO.readPacketData(dis);
currentTimeStamp = timestamp;
currentTimeStamp = pd.getTimestamp();
//System.out.println(currentTimeStamp);
if(!ReplayHandler.isReplaying() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) {
if(!ReplayHandler.isInPath() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) {
//if(!hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) {
int timeWait = (int)Math.round((currentTimeStamp - lastTimeStamp)/replaySpeed);
long timeDiff = System.currentTimeMillis() - lastPacketSent;
@@ -287,15 +286,11 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
Thread.sleep(timeToSleep);
}
int bytes = dis.readInt();
byte[] bb = new byte[bytes];
dis.readFully(bb);
ReplaySender.this.channelRead(ctx, bb);
ReplaySender.this.channelRead(ctx, pd.getByteArray());
lastTimeStamp = currentTimeStamp;
if(ReplayHandler.isReplaying()) {
if(ReplayHandler.isInPath()) {
toleratedTimeStamp = lastTimeStamp;
} else {
toleratedTimeStamp = -1;
@@ -303,12 +298,12 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) {
hurryToTimestamp = false;
if(!ReplayHandler.isReplaying() || hasRestarted) {
if(!ReplayHandler.isInPath() || hasRestarted) {
MCTimerHandler.advanceRenderPartialTicks(5);
MCTimerHandler.advancePartialTicks(5);
MCTimerHandler.advanceTicks(5);
}
if(!ReplayHandler.isReplaying()) {
if(!ReplayHandler.isInPath()) {
Position pos = ReplayHandler.getLastPosition();
CameraEntity cam = ReplayHandler.getCameraEntity();
if(cam != null) {
@@ -320,17 +315,18 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
}
}
if(!ReplayHandler.isReplaying()) {
if(!ReplayHandler.isInPath()) {
setReplaySpeed(0);
}
hasRestarted = false;
}
} catch(EOFException eof) {
System.out.println("End of File encountered!");
dis = new DataInputStream(archive.getInputStream(replayEntry));
setReplaySpeed(0);
} catch(IOException e) {
//e.printStackTrace();
e.printStackTrace();
}
}
}
@@ -398,12 +394,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
byte[] ba = (byte[])msg;
try {
ByteBuf bb = Unpooled.wrappedBuffer(ba);
PacketBuffer pb = new PacketBuffer(bb);
int i = pb.readVarIntFromBuffer();
Packet p = EnumConnectionState.PLAY.getPacket(EnumPacketDirection.CLIENTBOUND, i);
Packet p = ReplayFileIO.deserializePacket(ba);
if(hurryToTimestamp) { //If hurrying, ignore some packets
if(p instanceof S45PacketTitle ||
@@ -425,8 +416,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(badPackets.contains(p.getClass())) return;
try {
p.readPacketData(pb);
if(p instanceof S1CPacketEntityMetadata) {
if((Integer)metadataPacketEntityId.get(p) == actualID) {
metadataPacketEntityId.set(p, RecordingHandler.entityID);
@@ -434,6 +423,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
if(p instanceof S01PacketJoinGame) {
//System.out.println("FOUND JOIN PACKET");
allowMovement = true;
int entId = (Integer)joinPacketEntityId.get(p);
actualID = entId;
@@ -493,7 +483,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(p instanceof S08PacketPlayerPosLook) {
final S08PacketPlayerPosLook ppl = (S08PacketPlayerPosLook)p;
if(ReplayHandler.isReplaying() && !hurryToTimestamp) return;
if(ReplayHandler.isInPath() && !hurryToTimestamp) return;
CameraEntity cent = ReplayHandler.getCameraEntity();
@@ -531,6 +521,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(p instanceof S43PacketCamera) {
return;
}
super.channelRead(ctx, p);
} catch(Exception e) {
System.out.println(p.getClass());
@@ -538,7 +529,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
} catch(Exception e) {
//e.printStackTrace();
e.printStackTrace();
}
}

View File

@@ -24,7 +24,7 @@ public class SpectateHandler {
};
public static void openSpectateSelection() {
if(!ReplayHandler.replayActive()) {
if(!ReplayHandler.isInReplay()) {
return;
}