Fix (character, portal, enchantment) animations during speed up / slowed down path playback and rendering

This commit is contained in:
johni0702
2016-09-02 12:50:18 +02:00
parent 8d1a3f28d1
commit 0691ef9886
11 changed files with 107 additions and 74 deletions

View File

@@ -87,6 +87,11 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
*/
protected int lastTimeStamp;
/**
* @see #currentTimeStamp()
*/
protected int currentTimeStamp;
/**
* The replay file.
*/
@@ -207,11 +212,18 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
/**
* Return the timestamp of the last packet sent.
* Return a fake {@link Minecraft#getSystemTime()} value that respects slowdown/speedup/pause and works in both,
* sync and async mode.
* Note: For sync mode this returns the last value passed to {@link #sendPacketsTill(int)}.
* @return The timestamp in milliseconds since the start of the replay
*/
public int currentTimeStamp() {
return lastTimeStamp;
if (asyncMode) {
int timePassed = (int) (System.currentTimeMillis() - lastPacketSent);
return lastTimeStamp + (int) (timePassed * getReplaySpeed());
} else {
return lastTimeStamp;
}
}
/**
@@ -746,9 +758,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
// Process packet
channelRead(ctx, pd.bytes);
// Store last timestamp
lastTimeStamp = nextTimeStamp;
} catch (EOFException eof) {
// Shit! We hit the end before finishing our job! What shall we do now?
// well, let's just pretend we're done...
@@ -761,6 +770,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
// This might be required if we change to async mode anytime soon
lastPacketSent = System.currentTimeMillis();
lastTimeStamp = timestamp;
}
} catch (Exception e) {
e.printStackTrace();