Refactored and reformatted code to use less static variables
This commit is contained in:
@@ -1,105 +1,105 @@
|
||||
package eu.crushedpixel.replaymod.replay;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import scala.actors.threadpool.Arrays;
|
||||
import net.minecraft.entity.DataWatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Rotations;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A Data Watcher which is applied to the Camera Entity to avoid both NPEs and the Screen constantly jittering (because of the entity being dead)
|
||||
*/
|
||||
public class LesserDataWatcher extends DataWatcher {
|
||||
|
||||
public LesserDataWatcher(Entity owner) {
|
||||
super(owner);
|
||||
}
|
||||
public LesserDataWatcher(Entity owner) {
|
||||
super(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObject(int id, Object object) {
|
||||
}
|
||||
@Override
|
||||
public void addObject(int id, Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addObjectByDataType(int id, int type) {
|
||||
}
|
||||
@Override
|
||||
public void addObjectByDataType(int id, int type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getWatchableObjectByte(int id) {
|
||||
return 10;
|
||||
}
|
||||
@Override
|
||||
public byte getWatchableObjectByte(int id) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getWatchableObjectShort(int id) {
|
||||
return 10;
|
||||
}
|
||||
@Override
|
||||
public short getWatchableObjectShort(int id) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWatchableObjectInt(int id) {
|
||||
return 10;
|
||||
}
|
||||
@Override
|
||||
public int getWatchableObjectInt(int id) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWatchableObjectFloat(int id) {
|
||||
return 10f;
|
||||
}
|
||||
@Override
|
||||
public float getWatchableObjectFloat(int id) {
|
||||
return 10f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWatchableObjectString(int id) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getWatchableObjectString(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getWatchableObjectItemStack(int id) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getWatchableObjectItemStack(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rotations getWatchableObjectRotations(int id) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Rotations getWatchableObjectRotations(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateObject(int id, Object newData) {
|
||||
}
|
||||
@Override
|
||||
public void updateObject(int id, Object newData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObjectWatched(int id) {
|
||||
}
|
||||
@Override
|
||||
public void setObjectWatched(int id) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasObjectChanged() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasObjectChanged() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getChanged() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List getChanged() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(PacketBuffer buffer) throws IOException {
|
||||
}
|
||||
@Override
|
||||
public void writeTo(PacketBuffer buffer) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getAllWatched() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List getAllWatched() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatchedObjectsFromList(List p_75687_1_) {
|
||||
}
|
||||
@Override
|
||||
public void updateWatchedObjectsFromList(List p_75687_1_) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsBlank() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean getIsBlank() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_111144_e() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_111144_e() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
package eu.crushedpixel.replaymod.replay;
|
||||
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
|
||||
public class OpenEmbeddedChannel extends EmbeddedChannel {
|
||||
|
||||
private boolean ignoreClose = false;
|
||||
|
||||
public OpenEmbeddedChannel(NetworkManager networkManager) {
|
||||
super(networkManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finish() {
|
||||
System.out.println("wanted to finish");
|
||||
ignoreClose = true;
|
||||
private boolean ignoreClose = false;
|
||||
|
||||
public OpenEmbeddedChannel(NetworkManager networkManager) {
|
||||
super(networkManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finish() {
|
||||
System.out.println("wanted to finish");
|
||||
ignoreClose = true;
|
||||
return super.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public ChannelFuture close() {
|
||||
if(ignoreClose) {
|
||||
ignoreClose = false;
|
||||
return null;
|
||||
}
|
||||
if(ignoreClose) {
|
||||
ignoreClose = false;
|
||||
return null;
|
||||
}
|
||||
return pipeline().close();
|
||||
}
|
||||
|
||||
public ChannelFuture manualClose() {
|
||||
return pipeline().close();
|
||||
}
|
||||
|
||||
public ChannelFuture manualClose() {
|
||||
return pipeline().close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.replay;
|
||||
|
||||
import gnu.trove.iterator.TIntObjectIterator;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.MessageDeserializer;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
|
||||
public class PacketDeserializer extends MessageDeserializer {
|
||||
|
||||
private final EnumPacketDirection direction;
|
||||
private Field directionMaps;
|
||||
private EnumConnectionState state;
|
||||
|
||||
public PacketDeserializer(EnumPacketDirection direction) {
|
||||
super(direction);
|
||||
this.direction = direction;
|
||||
try {
|
||||
directionMaps = EnumConnectionState.class.getDeclaredField(MCPNames.field("field_179247_h"));
|
||||
directionMaps.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Packet getPacket(EnumPacketDirection direction, int packetId) throws InstantiationException, IllegalAccessException
|
||||
{
|
||||
Map map = ((Map)directionMaps.get(state));
|
||||
BiMap biMap = ((BiMap)map.get(direction));
|
||||
if(biMap == null) {
|
||||
System.out.println("BiMap is null!");
|
||||
}
|
||||
Class oclass = (Class)biMap.get(Integer.valueOf(packetId));
|
||||
return oclass == null ? null : (Packet)oclass.newInstance();
|
||||
}
|
||||
|
||||
public void setEnumConnectionState(EnumConnectionState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext p_decode_1_,
|
||||
ByteBuf p_decode_2_, List p_decode_3_) throws IOException,
|
||||
InstantiationException, IllegalAccessException {
|
||||
|
||||
if (p_decode_2_.readableBytes() != 0)
|
||||
{
|
||||
PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_);
|
||||
int i = packetbuffer.readVarIntFromBuffer();
|
||||
|
||||
Field state_by_id = null;
|
||||
try {
|
||||
state_by_id = EnumConnectionState.class.getDeclaredField(MCPNames.field("field_150764_e"));
|
||||
state_by_id.setAccessible(true);
|
||||
state = (EnumConnectionState)((TIntObjectMap)state_by_id.get(null)).get(i);
|
||||
TIntObjectMap map = (TIntObjectMap)state_by_id.get(null);
|
||||
TIntObjectIterator it = map.iterator();
|
||||
while(it.hasNext()) {
|
||||
it.advance();
|
||||
System.out.println(it.key() +" | "+it.value().getClass());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(state == null) {
|
||||
System.out.println("state is null");
|
||||
}
|
||||
//Packet packet = getPacket(this.direction, i);
|
||||
Packet packet = state.getPacket(EnumPacketDirection.CLIENTBOUND, i);
|
||||
|
||||
if (packet == null)
|
||||
{
|
||||
throw new IOException("Bad packet id " + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.readPacketData(packetbuffer);
|
||||
|
||||
if (packetbuffer.readableBytes() > 0)
|
||||
{
|
||||
throw new IOException("Packet " + ((EnumConnectionState)p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()).getId() + "/" + i + " (" + packet.getClass().getSimpleName() + ") was larger than I expected, found " + packetbuffer.readableBytes() + " bytes extra whilst reading packet " + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
p_decode_3_.add(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.replay;
|
||||
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
|
||||
public class PacketInfo {
|
||||
|
||||
private byte[] bytes;
|
||||
private EnumConnectionState connectionState;
|
||||
private int packetID;
|
||||
|
||||
public PacketInfo(byte[] bytes, EnumConnectionState connectionState,
|
||||
int packetID) {
|
||||
super();
|
||||
this.bytes = bytes;
|
||||
this.connectionState = connectionState;
|
||||
this.packetID = packetID;
|
||||
}
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
public void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
public EnumConnectionState getConnectionState() {
|
||||
return connectionState;
|
||||
}
|
||||
public void setConnectionState(EnumConnectionState connectionState) {
|
||||
this.connectionState = connectionState;
|
||||
}
|
||||
public int getPacketID() {
|
||||
return packetID;
|
||||
}
|
||||
public void setPacketID(int packetID) {
|
||||
this.packetID = packetID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,17 @@
|
||||
package eu.crushedpixel.replaymod.replay;
|
||||
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.holders.*;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -9,436 +19,327 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageRequests;
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.KeyframeComparator;
|
||||
import eu.crushedpixel.replaymod.holders.Position;
|
||||
import eu.crushedpixel.replaymod.holders.PositionKeyframe;
|
||||
import eu.crushedpixel.replaymod.holders.TimeKeyframe;
|
||||
|
||||
public class ReplayHandler {
|
||||
|
||||
private static NetworkManager networkManager;
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
private static ReplaySender replaySender;
|
||||
private static OpenEmbeddedChannel channel;
|
||||
|
||||
private static int realTimelinePosition = 0;
|
||||
|
||||
private static Keyframe selectedKeyframe;
|
||||
|
||||
private static boolean inPath = false;
|
||||
|
||||
private static CameraEntity cameraEntity;
|
||||
|
||||
private static List<Keyframe> keyframes = new ArrayList<Keyframe>();
|
||||
|
||||
private static boolean inReplay = false;
|
||||
|
||||
public static long lastExit = 0;
|
||||
|
||||
private static Entity currentEntity = null;
|
||||
|
||||
public static void insertPacketInstantly(Packet p) {
|
||||
if(replaySender != null) {
|
||||
try {
|
||||
replaySender.channelRead(null, p);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void spectateEntity(Entity e) {
|
||||
currentEntity = e;
|
||||
mc.setRenderViewEntity(currentEntity);
|
||||
}
|
||||
|
||||
public static Entity getSpectatedEntity() {
|
||||
return currentEntity;
|
||||
}
|
||||
|
||||
public static void spectateCamera() {
|
||||
if(currentEntity != null) {
|
||||
Position prev = new Position(currentEntity);
|
||||
cameraEntity.movePath(prev);
|
||||
}
|
||||
currentEntity = cameraEntity;
|
||||
mc.setRenderViewEntity(cameraEntity);
|
||||
}
|
||||
|
||||
public static boolean isCamera() {
|
||||
return currentEntity == cameraEntity;
|
||||
}
|
||||
|
||||
public static void setInPath(boolean replaying) {
|
||||
inPath = replaying;
|
||||
}
|
||||
|
||||
public static void resetToleratedTimestamp() {
|
||||
if(replaySender != null) replaySender.resetToleratedTimeStamp();
|
||||
}
|
||||
|
||||
public static void stopHurrying() {
|
||||
if(replaySender != null) replaySender.stopHurrying();
|
||||
}
|
||||
|
||||
public static void startPath(boolean save) {
|
||||
if(!ReplayHandler.isInPath()) ReplayProcess.startReplayProcess(save);
|
||||
}
|
||||
|
||||
public static void interruptReplay() {
|
||||
ReplayProcess.stopReplayProcess(false);
|
||||
}
|
||||
|
||||
public static boolean isInPath() {
|
||||
return inPath;
|
||||
}
|
||||
|
||||
public static void setCameraEntity(CameraEntity entity) {
|
||||
if(entity == null) return;
|
||||
cameraEntity = entity;
|
||||
spectateCamera();
|
||||
}
|
||||
|
||||
public static CameraEntity getCameraEntity() {
|
||||
return cameraEntity;
|
||||
}
|
||||
|
||||
public static int getDesiredTimestamp() {
|
||||
return replaySender == null ? 0 : (int)replaySender.getDesiredTimestamp();
|
||||
}
|
||||
|
||||
public static int getReplayTime() {
|
||||
return replaySender == null ? 0 : (int)replaySender.currentTimeStamp();
|
||||
}
|
||||
|
||||
public static void sortKeyframes() {
|
||||
Collections.sort(keyframes, new KeyframeComparator());
|
||||
}
|
||||
|
||||
public static void addKeyframe(Keyframe keyframe) {
|
||||
keyframes.add(keyframe);
|
||||
selectKeyframe(keyframe);
|
||||
}
|
||||
|
||||
public static void removeKeyframe(Keyframe keyframe) {
|
||||
keyframes.remove(keyframe);
|
||||
if(keyframe == selectedKeyframe) {
|
||||
selectKeyframe(null);
|
||||
} else {
|
||||
sortKeyframes();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getKeyframeIndex(TimeKeyframe timeKeyframe) {
|
||||
int index = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf == timeKeyframe) return index;
|
||||
else if(kf instanceof TimeKeyframe) index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getKeyframeIndex(PositionKeyframe posKeyframe) {
|
||||
int index = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf == posKeyframe) return index;
|
||||
else if(kf instanceof PositionKeyframe) index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getPosKeyframeCount() {
|
||||
int size = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf instanceof PositionKeyframe) size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public static int getTimeKeyframeCount() {
|
||||
int size = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf instanceof TimeKeyframe) size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public static TimeKeyframe getClosestTimeKeyframeForRealTime(int realTime, int tolerance) {
|
||||
List<TimeKeyframe> found = new ArrayList<TimeKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof TimeKeyframe)) continue;
|
||||
if(Math.abs(kf.getRealTimestamp()-realTime) <= tolerance) {
|
||||
found.add((TimeKeyframe)kf);
|
||||
}
|
||||
}
|
||||
|
||||
TimeKeyframe closest = null;
|
||||
|
||||
for(TimeKeyframe kf : found) {
|
||||
if(closest == null || Math.abs(closest.getTimestamp()-realTime) > Math.abs(kf.getRealTimestamp()-realTime)) {
|
||||
closest = kf;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static PositionKeyframe getClosestPlaceKeyframeForRealTime(int realTime, int tolerance) {
|
||||
List<PositionKeyframe> found = new ArrayList<PositionKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof PositionKeyframe)) continue;
|
||||
if(Math.abs(kf.getRealTimestamp()-realTime) <= tolerance) {
|
||||
found.add((PositionKeyframe)kf);
|
||||
}
|
||||
}
|
||||
|
||||
PositionKeyframe closest = null;
|
||||
|
||||
for(PositionKeyframe kf : found) {
|
||||
if(closest == null || Math.abs(closest.getRealTimestamp()-realTime) > Math.abs(kf.getRealTimestamp()-realTime)) {
|
||||
closest = kf;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static PositionKeyframe getPreviousPositionKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
List<PositionKeyframe> found = new ArrayList<PositionKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof PositionKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() < realTime) {
|
||||
found.add((PositionKeyframe)kf);
|
||||
}
|
||||
}
|
||||
|
||||
if(found.size() > 0)
|
||||
return found.get(found.size()-1); //last element is nearest
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static PositionKeyframe getNextPositionKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof PositionKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() >= realTime) {
|
||||
return (PositionKeyframe)kf; //first found element is next
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TimeKeyframe getPreviousTimeKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
List<TimeKeyframe> found = new ArrayList<TimeKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof TimeKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() < realTime) {
|
||||
found.add((TimeKeyframe)kf);
|
||||
}
|
||||
}
|
||||
|
||||
if(found.size() > 0)
|
||||
return found.get(found.size()-1); //last element is nearest
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static TimeKeyframe getNextTimeKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof TimeKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() >= realTime) {
|
||||
return (TimeKeyframe)kf; //first found element is next
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Keyframe> getKeyframes() {
|
||||
return new ArrayList<Keyframe>(keyframes);
|
||||
}
|
||||
|
||||
public static void resetKeyframes() {
|
||||
keyframes = new ArrayList<Keyframe>();
|
||||
|
||||
selectKeyframe(null);
|
||||
}
|
||||
|
||||
public static void setReplayTime(int pos) {
|
||||
if(replaySender != null) {
|
||||
replaySender.jumpToTime(pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHurrying() {
|
||||
if(replaySender != null) {
|
||||
return replaySender.isHurrying();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getReplayLength() {
|
||||
if(replaySender != null) {
|
||||
return replaySender.replayLength();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static boolean isSelected(Keyframe kf) {
|
||||
return kf == selectedKeyframe;
|
||||
}
|
||||
|
||||
public static void selectKeyframe(Keyframe kf) {
|
||||
selectedKeyframe = kf;
|
||||
sortKeyframes();
|
||||
}
|
||||
|
||||
public static boolean isInReplay() {
|
||||
return inReplay;
|
||||
}
|
||||
|
||||
public static boolean isPaused() {
|
||||
if(replaySender != null) {
|
||||
return replaySender.paused();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setSpeed(double d) {
|
||||
if(replaySender != null) {
|
||||
replaySender.setReplaySpeed(d);
|
||||
}
|
||||
}
|
||||
|
||||
public static double getSpeed() {
|
||||
if(replaySender != null) {
|
||||
return replaySender.getReplaySpeed();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void startReplay(File file) throws NoSuchMethodException, SecurityException, NoSuchFieldException {
|
||||
|
||||
ChatMessageRequests.initialize();
|
||||
mc.ingameGUI.getChatGUI().clearChatMessages();
|
||||
resetKeyframes();
|
||||
|
||||
if(replaySender != null) {
|
||||
replaySender.terminateReplay();
|
||||
}
|
||||
|
||||
if(channel != null) {
|
||||
channel.close();
|
||||
}
|
||||
|
||||
networkManager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
|
||||
INetHandlerPlayClient pc = new NetHandlerPlayClient(mc, (GuiScreen)null, networkManager, new GameProfile(UUID.randomUUID(), "Player"));
|
||||
networkManager.setNetHandler(pc);
|
||||
|
||||
channel = new OpenEmbeddedChannel(networkManager);
|
||||
|
||||
replaySender = new ReplaySender(file, networkManager);
|
||||
channel.pipeline().addFirst(replaySender);
|
||||
channel.pipeline().fireChannelActive();
|
||||
|
||||
try {
|
||||
ReplayMod.overlay.resetUI();
|
||||
} catch(Exception e) {}
|
||||
|
||||
//Load lighting and trigger update
|
||||
ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled());
|
||||
|
||||
inReplay = true;
|
||||
}
|
||||
|
||||
public static void restartReplay() {
|
||||
//mc.setRenderViewEntity(mc.thePlayer);
|
||||
mc.ingameGUI.getChatGUI().clearChatMessages();
|
||||
|
||||
if(channel != null) {
|
||||
channel.close();
|
||||
}
|
||||
|
||||
networkManager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
|
||||
INetHandlerPlayClient pc = new NetHandlerPlayClient(mc, (GuiScreen)null, networkManager, new GameProfile(UUID.randomUUID(), "Player"));
|
||||
networkManager.setNetHandler(pc);
|
||||
|
||||
EmbeddedChannel channel = new OpenEmbeddedChannel(networkManager);
|
||||
|
||||
channel.pipeline().addFirst(replaySender);
|
||||
channel.pipeline().fireChannelActive();
|
||||
|
||||
ChannelPipeline pipeline = networkManager.channel().pipeline();
|
||||
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ReplayMod.overlay.resetUI();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
inReplay = true;
|
||||
}
|
||||
|
||||
public static void endReplay() {
|
||||
if(replaySender != null) {
|
||||
replaySender.terminateReplay();
|
||||
}
|
||||
|
||||
resetKeyframes();
|
||||
|
||||
/*
|
||||
if(channel != null && channel.isOpen()) {
|
||||
channel.close();
|
||||
}
|
||||
*/
|
||||
|
||||
inReplay = false;
|
||||
}
|
||||
|
||||
public static Keyframe getSelected() {
|
||||
return selectedKeyframe;
|
||||
}
|
||||
|
||||
public static int getRealTimelineCursor() {
|
||||
return realTimelinePosition;
|
||||
}
|
||||
|
||||
public static void setRealTimelineCursor(int pos) {
|
||||
realTimelinePosition = pos;
|
||||
}
|
||||
|
||||
private static Position lastPosition = null;
|
||||
public static void setLastPosition(Position position) {
|
||||
lastPosition = position;
|
||||
}
|
||||
public static long lastExit = 0;
|
||||
private static NetworkManager networkManager;
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
//private static ReplaySender replaySender;
|
||||
private static OpenEmbeddedChannel channel;
|
||||
private static int realTimelinePosition = 0;
|
||||
private static Keyframe selectedKeyframe;
|
||||
private static boolean inPath = false;
|
||||
private static CameraEntity cameraEntity;
|
||||
private static List<Keyframe> keyframes = new ArrayList<Keyframe>();
|
||||
private static boolean inReplay = false;
|
||||
private static Entity currentEntity = null;
|
||||
private static Position lastPosition = null;
|
||||
|
||||
public static void spectateEntity(Entity e) {
|
||||
currentEntity = e;
|
||||
mc.setRenderViewEntity(currentEntity);
|
||||
}
|
||||
|
||||
public static void spectateCamera() {
|
||||
if(currentEntity != null) {
|
||||
Position prev = new Position(currentEntity);
|
||||
cameraEntity.movePath(prev);
|
||||
}
|
||||
currentEntity = cameraEntity;
|
||||
mc.setRenderViewEntity(cameraEntity);
|
||||
}
|
||||
|
||||
public static boolean isCamera() {
|
||||
return currentEntity == cameraEntity;
|
||||
}
|
||||
|
||||
public static void startPath(boolean save) {
|
||||
if(!ReplayHandler.isInPath()) ReplayProcess.startReplayProcess(save);
|
||||
}
|
||||
|
||||
public static void interruptReplay() {
|
||||
ReplayProcess.stopReplayProcess(false);
|
||||
}
|
||||
|
||||
public static boolean isInPath() {
|
||||
return inPath;
|
||||
}
|
||||
|
||||
public static void setInPath(boolean replaying) {
|
||||
inPath = replaying;
|
||||
}
|
||||
|
||||
public static CameraEntity getCameraEntity() {
|
||||
return cameraEntity;
|
||||
}
|
||||
|
||||
public static void setCameraEntity(CameraEntity entity) {
|
||||
if(entity == null) return;
|
||||
cameraEntity = entity;
|
||||
spectateCamera();
|
||||
}
|
||||
|
||||
public static void sortKeyframes() {
|
||||
Collections.sort(keyframes, new KeyframeComparator());
|
||||
}
|
||||
|
||||
public static void addKeyframe(Keyframe keyframe) {
|
||||
keyframes.add(keyframe);
|
||||
selectKeyframe(keyframe);
|
||||
}
|
||||
|
||||
public static void removeKeyframe(Keyframe keyframe) {
|
||||
keyframes.remove(keyframe);
|
||||
if(keyframe == selectedKeyframe) {
|
||||
selectKeyframe(null);
|
||||
} else {
|
||||
sortKeyframes();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getKeyframeIndex(TimeKeyframe timeKeyframe) {
|
||||
int index = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf == timeKeyframe) return index;
|
||||
else if(kf instanceof TimeKeyframe) index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getKeyframeIndex(PositionKeyframe posKeyframe) {
|
||||
int index = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf == posKeyframe) return index;
|
||||
else if(kf instanceof PositionKeyframe) index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getPosKeyframeCount() {
|
||||
int size = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf instanceof PositionKeyframe) size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public static int getTimeKeyframeCount() {
|
||||
int size = 0;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(kf instanceof TimeKeyframe) size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public static TimeKeyframe getClosestTimeKeyframeForRealTime(int realTime, int tolerance) {
|
||||
List<TimeKeyframe> found = new ArrayList<TimeKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof TimeKeyframe)) continue;
|
||||
if(Math.abs(kf.getRealTimestamp() - realTime) <= tolerance) {
|
||||
found.add((TimeKeyframe) kf);
|
||||
}
|
||||
}
|
||||
|
||||
TimeKeyframe closest = null;
|
||||
|
||||
for(TimeKeyframe kf : found) {
|
||||
if(closest == null || Math.abs(closest.getTimestamp() - realTime) > Math.abs(kf.getRealTimestamp() - realTime)) {
|
||||
closest = kf;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static PositionKeyframe getClosestPlaceKeyframeForRealTime(int realTime, int tolerance) {
|
||||
List<PositionKeyframe> found = new ArrayList<PositionKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof PositionKeyframe)) continue;
|
||||
if(Math.abs(kf.getRealTimestamp() - realTime) <= tolerance) {
|
||||
found.add((PositionKeyframe) kf);
|
||||
}
|
||||
}
|
||||
|
||||
PositionKeyframe closest = null;
|
||||
|
||||
for(PositionKeyframe kf : found) {
|
||||
if(closest == null || Math.abs(closest.getRealTimestamp() - realTime) > Math.abs(kf.getRealTimestamp() - realTime)) {
|
||||
closest = kf;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static PositionKeyframe getPreviousPositionKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
List<PositionKeyframe> found = new ArrayList<PositionKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof PositionKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() < realTime) {
|
||||
found.add((PositionKeyframe) kf);
|
||||
}
|
||||
}
|
||||
|
||||
if(found.size() > 0)
|
||||
return found.get(found.size() - 1); //last element is nearest
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static PositionKeyframe getNextPositionKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof PositionKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() >= realTime) {
|
||||
return (PositionKeyframe) kf; //first found element is next
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TimeKeyframe getPreviousTimeKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
List<TimeKeyframe> found = new ArrayList<TimeKeyframe>();
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof TimeKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() < realTime) {
|
||||
found.add((TimeKeyframe) kf);
|
||||
}
|
||||
}
|
||||
|
||||
if(found.size() > 0)
|
||||
return found.get(found.size() - 1); //last element is nearest
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static TimeKeyframe getNextTimeKeyframe(int realTime) {
|
||||
if(keyframes.isEmpty()) return null;
|
||||
for(Keyframe kf : keyframes) {
|
||||
if(!(kf instanceof TimeKeyframe)) continue;
|
||||
if(kf.getRealTimestamp() >= realTime) {
|
||||
return (TimeKeyframe) kf; //first found element is next
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Keyframe> getKeyframes() {
|
||||
return new ArrayList<Keyframe>(keyframes);
|
||||
}
|
||||
|
||||
public static void resetKeyframes() {
|
||||
keyframes = new ArrayList<Keyframe>();
|
||||
|
||||
selectKeyframe(null);
|
||||
}
|
||||
|
||||
public static boolean isSelected(Keyframe kf) {
|
||||
return kf == selectedKeyframe;
|
||||
}
|
||||
|
||||
public static void selectKeyframe(Keyframe kf) {
|
||||
selectedKeyframe = kf;
|
||||
sortKeyframes();
|
||||
}
|
||||
|
||||
public static boolean isInReplay() {
|
||||
return inReplay;
|
||||
}
|
||||
|
||||
public static void startReplay(File file) throws NoSuchMethodException, SecurityException, NoSuchFieldException {
|
||||
|
||||
ReplayMod.chatMessageHandler.initialize();
|
||||
mc.ingameGUI.getChatGUI().clearChatMessages();
|
||||
resetKeyframes();
|
||||
|
||||
ReplayMod.replaySender.terminateReplay();
|
||||
|
||||
if(channel != null) {
|
||||
channel.close();
|
||||
}
|
||||
|
||||
networkManager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
|
||||
INetHandlerPlayClient pc = new NetHandlerPlayClient(mc, (GuiScreen) null, networkManager, new GameProfile(UUID.randomUUID(), "Player"));
|
||||
networkManager.setNetHandler(pc);
|
||||
|
||||
channel = new OpenEmbeddedChannel(networkManager);
|
||||
|
||||
ReplayMod.replaySender = new ReplaySender(file, networkManager);
|
||||
channel.pipeline().addFirst(ReplayMod.replaySender);
|
||||
channel.pipeline().fireChannelActive();
|
||||
|
||||
try {
|
||||
ReplayMod.overlay.resetUI();
|
||||
} catch(Exception e) {}
|
||||
|
||||
//Load lighting and trigger update
|
||||
ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled());
|
||||
|
||||
inReplay = true;
|
||||
}
|
||||
|
||||
public static void restartReplay() {
|
||||
mc.ingameGUI.getChatGUI().clearChatMessages();
|
||||
|
||||
if(channel != null) {
|
||||
channel.close();
|
||||
}
|
||||
|
||||
networkManager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
|
||||
INetHandlerPlayClient pc = new NetHandlerPlayClient(mc, (GuiScreen) null, networkManager, new GameProfile(UUID.randomUUID(), "Player"));
|
||||
networkManager.setNetHandler(pc);
|
||||
|
||||
EmbeddedChannel channel = new OpenEmbeddedChannel(networkManager);
|
||||
|
||||
channel.pipeline().addFirst(ReplayMod.replaySender);
|
||||
channel.pipeline().fireChannelActive();
|
||||
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ReplayMod.overlay.resetUI();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
inReplay = true;
|
||||
}
|
||||
|
||||
public static void endReplay() {
|
||||
if(ReplayMod.replaySender != null) {
|
||||
ReplayMod.replaySender.terminateReplay();
|
||||
}
|
||||
|
||||
resetKeyframes();
|
||||
|
||||
public static Position getLastPosition() {
|
||||
return lastPosition;
|
||||
}
|
||||
|
||||
public static File getReplayFile() {
|
||||
if(replaySender != null) {
|
||||
return replaySender.getReplayFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
inReplay = false;
|
||||
}
|
||||
|
||||
public static Keyframe getSelected() {
|
||||
return selectedKeyframe;
|
||||
}
|
||||
|
||||
public static int getRealTimelineCursor() {
|
||||
return realTimelinePosition;
|
||||
}
|
||||
|
||||
public static void setRealTimelineCursor(int pos) {
|
||||
realTimelinePosition = pos;
|
||||
}
|
||||
|
||||
public static Position getLastPosition() {
|
||||
return lastPosition;
|
||||
}
|
||||
|
||||
public static void setLastPosition(Position position) {
|
||||
lastPosition = position;
|
||||
}
|
||||
|
||||
public static File getReplayFile() {
|
||||
if(ReplayMod.replaySender != null) {
|
||||
return ReplayMod.replaySender.getReplayFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
package eu.crushedpixel.replaymod.replay;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiDownloadTerrain;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.ChunkRenderContainer;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.chunk.RenderChunk;
|
||||
import net.minecraft.client.renderer.entity.RenderEntity;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageRequests;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageRequests.ChatMessageType;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler.ChatMessageType;
|
||||
import eu.crushedpixel.replaymod.gui.GuiCancelRender;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Position;
|
||||
@@ -21,371 +10,370 @@ import eu.crushedpixel.replaymod.holders.TimeKeyframe;
|
||||
import eu.crushedpixel.replaymod.interpolation.LinearPoint;
|
||||
import eu.crushedpixel.replaymod.interpolation.LinearTimestamp;
|
||||
import eu.crushedpixel.replaymod.interpolation.SplinePoint;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.timer.EnchantmentTimer;
|
||||
import eu.crushedpixel.replaymod.timer.MCTimerHandler;
|
||||
import eu.crushedpixel.replaymod.video.ScreenCapture;
|
||||
import eu.crushedpixel.replaymod.video.VideoWriter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.chunk.RenderChunk;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ReplayProcess {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static long startRealTime;
|
||||
private static int lastRealReplayTime;
|
||||
private static long lastRealTime = 0;
|
||||
|
||||
private static boolean linear = false;
|
||||
|
||||
private static Position lastPosition = null;
|
||||
private static int lastTimestamp = -1;
|
||||
|
||||
private static SplinePoint motionSpline = null;
|
||||
private static LinearPoint motionLinear = null;
|
||||
private static LinearTimestamp timeLinear = null;
|
||||
|
||||
private static double lastSpeed = 1f;
|
||||
|
||||
private static double previousReplaySpeed = 0;
|
||||
|
||||
private static boolean calculated = false;
|
||||
|
||||
private static boolean isVideoRecording = false;
|
||||
|
||||
public static boolean isVideoRecording() {
|
||||
return isVideoRecording;
|
||||
}
|
||||
|
||||
public static void startReplayProcess(boolean record) {
|
||||
ReplayHandler.selectKeyframe(null);
|
||||
|
||||
firstTime = true;
|
||||
|
||||
isVideoRecording = record;
|
||||
lastPosition = null;
|
||||
motionSpline = null;
|
||||
motionLinear = null;
|
||||
timeLinear = null;
|
||||
calculated = false;
|
||||
requestFinish = false;
|
||||
|
||||
ReplayHandler.resetToleratedTimestamp();
|
||||
|
||||
ChatMessageRequests.initialize();
|
||||
if(ReplayHandler.getPosKeyframeCount() < 2 && ReplayHandler.getTimeKeyframeCount() < 2) {
|
||||
ChatMessageRequests.addChatMessage("At least 2 position or time keyframes required!", ChatMessageType.WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
blocked = deepBlock = false;
|
||||
|
||||
startRealTime = System.currentTimeMillis();
|
||||
lastRealTime = startRealTime;
|
||||
lastRealReplayTime = 0;
|
||||
lastTimestamp = -1;
|
||||
lastSpeed = 1f;
|
||||
linear = ReplayMod.replaySettings.isLinearMovement();
|
||||
ReplayHandler.sortKeyframes();
|
||||
ReplayHandler.setInPath(true);
|
||||
previousReplaySpeed = ReplayHandler.getSpeed();
|
||||
|
||||
EnchantmentTimer.resetRecordingTime();
|
||||
|
||||
TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1);
|
||||
if(tf != null) {
|
||||
int ts = tf.getTimestamp();
|
||||
if(ts < ReplayHandler.getReplayTime()) {
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
ReplayHandler.setReplayTime(ts);
|
||||
}
|
||||
|
||||
ChatMessageRequests.addChatMessage("Replay started!", ChatMessageType.INFORMATION);
|
||||
|
||||
if(isVideoRecording()) {
|
||||
MCTimerHandler.setTimerSpeed(1f);
|
||||
MCTimerHandler.setPassiveTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopReplayProcess(boolean finished) {
|
||||
if(!ReplayHandler.isInPath()) return;
|
||||
if(finished) ChatMessageRequests.addChatMessage("Replay finished!", ChatMessageType.INFORMATION);
|
||||
else {
|
||||
ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION);
|
||||
if(isVideoRecording()) {
|
||||
VideoWriter.abortRecording();
|
||||
}
|
||||
}
|
||||
ReplayHandler.setInPath(false);
|
||||
ReplayHandler.stopHurrying();
|
||||
MCTimerHandler.setActiveTimer();
|
||||
ReplayHandler.setSpeed(previousReplaySpeed);
|
||||
ReplayHandler.setSpeed(0);
|
||||
}
|
||||
|
||||
private static boolean blocked = false;
|
||||
private static boolean deepBlock = false;
|
||||
|
||||
private static boolean requestFinish = false;
|
||||
|
||||
public static void unblockAndTick(boolean justCheck) {
|
||||
if(!deepBlock) blocked = false;
|
||||
if(!blocked || !isVideoRecording())
|
||||
ReplayProcess.tickReplay(justCheck);
|
||||
}
|
||||
|
||||
public static void tickReplay(boolean justCheck) {
|
||||
pathTick(isVideoRecording(), justCheck);
|
||||
}
|
||||
|
||||
private static float lastPartialTicks, lastRenderPartialTicks;
|
||||
private static int lastTicks;
|
||||
|
||||
private static boolean resetTimer = false;
|
||||
|
||||
private static boolean firstTime = false;
|
||||
|
||||
private static void pathTick(boolean recording, boolean justCheck) {
|
||||
if(ReplayHandler.isHurrying()) {
|
||||
lastRealTime = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
lastPartialTicks = 100;
|
||||
lastRenderPartialTicks = 100;
|
||||
lastTicks = 100;
|
||||
MCTimerHandler.setRenderPartialTicks(100);
|
||||
MCTimerHandler.setPartialTicks(100);
|
||||
MCTimerHandler.setTicks(100);
|
||||
System.out.println(ReplayHandler.getReplayTime());
|
||||
}
|
||||
|
||||
if(recording && ((ReplayMod.replaySettings.getWaitForChunks() && RenderChunk.renderChunksUpdated != 0) || mc.currentScreen instanceof GuiCancelRender)) {
|
||||
if(!firstTime) {
|
||||
MCTimerHandler.setTimerSpeed(0f);
|
||||
MCTimerHandler.setPartialTicks(0f);
|
||||
MCTimerHandler.setRenderPartialTicks(0f);
|
||||
MCTimerHandler.setTicks(0);
|
||||
resetTimer = true;
|
||||
}
|
||||
return;
|
||||
} else if (recording && ReplayMod.replaySettings.getWaitForChunks()) {
|
||||
MCTimerHandler.setTimerSpeed((float)lastSpeed);
|
||||
//MCTimerHandler.setRenderPartialTicks(lastRenderPartialTicks);
|
||||
if(resetTimer) {
|
||||
MCTimerHandler.setPartialTicks(lastPartialTicks);
|
||||
MCTimerHandler.setRenderPartialTicks(lastRenderPartialTicks);
|
||||
MCTimerHandler.setTicks(lastTicks);
|
||||
resetTimer = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(justCheck) return;
|
||||
|
||||
if(recording) {
|
||||
if(blocked) return;
|
||||
|
||||
deepBlock = true;
|
||||
blocked = true;
|
||||
}
|
||||
|
||||
int posCount = ReplayHandler.getPosKeyframeCount();
|
||||
int timeCount = ReplayHandler.getTimeKeyframeCount();
|
||||
|
||||
if(!linear && motionSpline == null) {
|
||||
//set up spline path
|
||||
motionSpline = new SplinePoint();
|
||||
for(Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
if(kf instanceof PositionKeyframe) {
|
||||
PositionKeyframe pkf = (PositionKeyframe)kf;
|
||||
Position pos = pkf.getPosition();
|
||||
motionSpline.addPoint(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(linear && motionLinear == null) {
|
||||
//set up linear path
|
||||
motionLinear = new LinearPoint();
|
||||
for(Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
if(kf instanceof PositionKeyframe) {
|
||||
PositionKeyframe pkf = (PositionKeyframe)kf;
|
||||
Position pos = pkf.getPosition();
|
||||
motionLinear.addPoint(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(timeLinear == null) {
|
||||
timeLinear = new LinearTimestamp();
|
||||
for(Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
if(kf instanceof TimeKeyframe) {
|
||||
timeLinear.addPoint(((TimeKeyframe)kf).getTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!calculated) {
|
||||
calculated = true;
|
||||
if(posCount > 1 && motionSpline != null)
|
||||
motionSpline.calcSpline();
|
||||
}
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
long timeStep;
|
||||
if(recording) {
|
||||
timeStep = 1000/ReplayMod.replaySettings.getVideoFramerate();
|
||||
} else {
|
||||
timeStep = curTime - lastRealTime;
|
||||
}
|
||||
|
||||
int curRealReplayTime = (int)(lastRealReplayTime + timeStep);
|
||||
|
||||
PositionKeyframe lastPos = ReplayHandler.getPreviousPositionKeyframe(curRealReplayTime);
|
||||
PositionKeyframe nextPos = ReplayHandler.getNextPositionKeyframe(curRealReplayTime);
|
||||
|
||||
ReplayHandler.setRealTimelineCursor(curRealReplayTime);
|
||||
|
||||
int lastPosStamp = 0;
|
||||
int nextPosStamp = 0;
|
||||
|
||||
if(nextPos != null || lastPos != null) {
|
||||
if(nextPos != null) {
|
||||
nextPosStamp = nextPos.getRealTimestamp();
|
||||
} else {
|
||||
nextPosStamp = lastPos.getRealTimestamp();
|
||||
}
|
||||
|
||||
if(lastPos != null) {
|
||||
lastPosStamp = lastPos.getRealTimestamp();
|
||||
} else {
|
||||
lastPosStamp = nextPos.getRealTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
TimeKeyframe lastTime = ReplayHandler.getPreviousTimeKeyframe(curRealReplayTime);
|
||||
TimeKeyframe nextTime = ReplayHandler.getNextTimeKeyframe(curRealReplayTime);
|
||||
|
||||
int lastTimeStamp = 0;
|
||||
int nextTimeStamp = 0;
|
||||
|
||||
double curSpeed = 0;
|
||||
|
||||
if(timeCount > 1 && (nextTime != null || lastTime != null)) {
|
||||
|
||||
if(nextTime != null && lastTime != null && nextTime.getRealTimestamp() == lastTime.getRealTimestamp()) {
|
||||
curSpeed = 0;
|
||||
} else {
|
||||
if(nextTime != null) {
|
||||
nextTimeStamp = nextTime.getRealTimestamp();
|
||||
} else {
|
||||
nextTimeStamp = lastTime.getRealTimestamp();
|
||||
}
|
||||
|
||||
if(lastTime != null) {
|
||||
lastTimeStamp = lastTime.getRealTimestamp();
|
||||
} else {
|
||||
lastTimeStamp = nextTime.getRealTimestamp();
|
||||
}
|
||||
|
||||
if(!(nextTime == null || lastTime == null)) {
|
||||
if(lastTimeStamp == nextTimeStamp) curSpeed = 0f;
|
||||
else curSpeed = ((double)((nextTime.getTimestamp()-lastTime.getTimestamp())))/((double)((nextTimeStamp-lastTimeStamp)));
|
||||
}
|
||||
|
||||
if(lastTimeStamp == nextTimeStamp) {
|
||||
curSpeed = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int currentPosDiff = nextPosStamp - lastPosStamp;
|
||||
int currentPos = curRealReplayTime - lastPosStamp;
|
||||
|
||||
float currentPosStepPerc = (float)currentPos/(float)currentPosDiff; //The percentage of the travelled path between the current positions
|
||||
if(Float.isInfinite(currentPosStepPerc)) currentPosStepPerc = 0;
|
||||
|
||||
int currentTimeDiff = nextTimeStamp - lastTimeStamp;
|
||||
int currentTime = curRealReplayTime - lastTimeStamp;
|
||||
|
||||
float currentTimeStepPerc = (float)currentTime/(float)currentTimeDiff; //The percentage of the travelled path between the current timestamps
|
||||
if(Float.isInfinite(currentTimeStepPerc)) currentTimeStepPerc = 0;
|
||||
|
||||
float splinePos = ((float)ReplayHandler.getKeyframeIndex(lastPos) + currentPosStepPerc)/(float)(posCount-1);
|
||||
float timePos = ((float)ReplayHandler.getKeyframeIndex(lastTime) + currentTimeStepPerc)/(float)(timeCount-1);
|
||||
|
||||
Position pos = null;
|
||||
if(posCount > 1) {
|
||||
if(!linear) {
|
||||
pos = motionSpline.getPoint(Math.max(0, Math.min(1, splinePos)));
|
||||
} else {
|
||||
pos = motionLinear.getPoint(Math.max(0, Math.min(1, splinePos)));
|
||||
}
|
||||
} else {
|
||||
if(posCount == 1) {
|
||||
pos = ReplayHandler.getNextPositionKeyframe(-1).getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
Integer curTimestamp = null;
|
||||
if(timeLinear != null && timeCount > 1) {
|
||||
curTimestamp = timeLinear.getPoint(Math.max(0, Math.min(1, timePos)));
|
||||
}
|
||||
|
||||
if(pos != null) {
|
||||
ReplayHandler.getCameraEntity().movePath(pos);
|
||||
}
|
||||
|
||||
if(curSpeed > 0) {
|
||||
ReplayHandler.setSpeed(curSpeed);
|
||||
lastSpeed = curSpeed;
|
||||
}
|
||||
|
||||
if(recording) {
|
||||
MCTimerHandler.updateTimer((1f/ReplayMod.replaySettings.getVideoFramerate()));
|
||||
EnchantmentTimer.increaseRecordingTime((1000/ReplayMod.replaySettings.getVideoFramerate()));
|
||||
}
|
||||
|
||||
lastPartialTicks = MCTimerHandler.getPartialTicks();
|
||||
lastRenderPartialTicks = MCTimerHandler.getRenderTicks();
|
||||
lastTicks = MCTimerHandler.getTicks();
|
||||
|
||||
if(curTimestamp != null && curTimestamp != ReplayHandler.getDesiredTimestamp()) ReplayHandler.setReplayTime(curTimestamp);
|
||||
|
||||
//splinePos = (index of last entry + add) / total entries
|
||||
|
||||
lastRealReplayTime = curRealReplayTime;
|
||||
lastRealTime = curTime;
|
||||
|
||||
if(isVideoRecording()) {
|
||||
try {
|
||||
if(!VideoWriter.isRecording() && ReplayHandler.isInPath()) {
|
||||
VideoWriter.startRecording(mc.displayWidth, mc.displayHeight);
|
||||
} else {
|
||||
final BufferedImage screen = ScreenCapture.captureScreen();
|
||||
VideoWriter.writeImage(screen);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(requestFinish) {
|
||||
stopReplayProcess(true);
|
||||
requestFinish = false;
|
||||
if(recording) {
|
||||
VideoWriter.endRecording();
|
||||
}
|
||||
}
|
||||
|
||||
if((splinePos >= 1 || posCount <= 1) && (timePos >= 1 || timeCount <= 1)) {
|
||||
requestFinish = true;
|
||||
}
|
||||
|
||||
if(recording) {
|
||||
deepBlock = false;
|
||||
}
|
||||
}
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static long startRealTime;
|
||||
private static int lastRealReplayTime;
|
||||
private static long lastRealTime = 0;
|
||||
|
||||
private static boolean linear = false;
|
||||
|
||||
private static Position lastPosition = null;
|
||||
private static int lastTimestamp = -1;
|
||||
|
||||
private static SplinePoint motionSpline = null;
|
||||
private static LinearPoint motionLinear = null;
|
||||
private static LinearTimestamp timeLinear = null;
|
||||
|
||||
private static double lastSpeed = 1f;
|
||||
|
||||
private static double previousReplaySpeed = 0;
|
||||
|
||||
private static boolean calculated = false;
|
||||
|
||||
private static boolean isVideoRecording = false;
|
||||
private static boolean blocked = false;
|
||||
private static boolean deepBlock = false;
|
||||
private static boolean requestFinish = false;
|
||||
private static float lastPartialTicks, lastRenderPartialTicks;
|
||||
private static int lastTicks;
|
||||
private static boolean resetTimer = false;
|
||||
private static boolean firstTime = false;
|
||||
|
||||
public static boolean isVideoRecording() {
|
||||
return isVideoRecording;
|
||||
}
|
||||
|
||||
public static void startReplayProcess(boolean record) {
|
||||
ReplayHandler.selectKeyframe(null);
|
||||
|
||||
firstTime = true;
|
||||
|
||||
isVideoRecording = record;
|
||||
lastPosition = null;
|
||||
motionSpline = null;
|
||||
motionLinear = null;
|
||||
timeLinear = null;
|
||||
calculated = false;
|
||||
requestFinish = false;
|
||||
|
||||
ReplayMod.replaySender.resetToleratedTimeStamp();
|
||||
|
||||
ReplayMod.chatMessageHandler.initialize();
|
||||
if(ReplayHandler.getPosKeyframeCount() < 2 && ReplayHandler.getTimeKeyframeCount() < 2) {
|
||||
ReplayMod.chatMessageHandler.addChatMessage("At least 2 position or time keyframes required!", ChatMessageType.WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
blocked = deepBlock = false;
|
||||
|
||||
startRealTime = System.currentTimeMillis();
|
||||
lastRealTime = startRealTime;
|
||||
lastRealReplayTime = 0;
|
||||
lastTimestamp = -1;
|
||||
lastSpeed = 1f;
|
||||
linear = ReplayMod.replaySettings.isLinearMovement();
|
||||
ReplayHandler.sortKeyframes();
|
||||
ReplayHandler.setInPath(true);
|
||||
previousReplaySpeed = ReplayMod.replaySender.getReplaySpeed();
|
||||
|
||||
EnchantmentTimer.resetRecordingTime();
|
||||
|
||||
TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1);
|
||||
if(tf != null) {
|
||||
int ts = tf.getTimestamp();
|
||||
if(ts < ReplayMod.replaySender.currentTimeStamp()) {
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
ReplayMod.replaySender.jumpToTime(ts);
|
||||
}
|
||||
|
||||
ReplayMod.chatMessageHandler.addChatMessage("Replay started!", ChatMessageType.INFORMATION);
|
||||
|
||||
if(isVideoRecording()) {
|
||||
MCTimerHandler.setTimerSpeed(1f);
|
||||
MCTimerHandler.setPassiveTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopReplayProcess(boolean finished) {
|
||||
if(!ReplayHandler.isInPath()) return;
|
||||
if(finished) ReplayMod.chatMessageHandler.addChatMessage("Replay finished!", ChatMessageType.INFORMATION);
|
||||
else {
|
||||
ReplayMod.chatMessageHandler.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION);
|
||||
if(isVideoRecording()) {
|
||||
VideoWriter.abortRecording();
|
||||
}
|
||||
}
|
||||
ReplayHandler.setInPath(false);
|
||||
ReplayMod.replaySender.stopHurrying();
|
||||
MCTimerHandler.setActiveTimer();
|
||||
ReplayMod.replaySender.setReplaySpeed(previousReplaySpeed);
|
||||
ReplayMod.replaySender.setReplaySpeed(0);
|
||||
}
|
||||
|
||||
public static void unblockAndTick(boolean justCheck) {
|
||||
if(!deepBlock) blocked = false;
|
||||
if(!blocked || !isVideoRecording())
|
||||
ReplayProcess.tickReplay(justCheck);
|
||||
}
|
||||
|
||||
public static void tickReplay(boolean justCheck) {
|
||||
pathTick(isVideoRecording(), justCheck);
|
||||
}
|
||||
|
||||
private static void pathTick(boolean recording, boolean justCheck) {
|
||||
if(ReplayMod.replaySender.isHurrying()) {
|
||||
lastRealTime = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
lastPartialTicks = 100;
|
||||
lastRenderPartialTicks = 100;
|
||||
lastTicks = 100;
|
||||
MCTimerHandler.setRenderPartialTicks(100);
|
||||
MCTimerHandler.setPartialTicks(100);
|
||||
MCTimerHandler.setTicks(100);
|
||||
}
|
||||
|
||||
if(recording && ((ReplayMod.replaySettings.getWaitForChunks() && RenderChunk.renderChunksUpdated != 0) || mc.currentScreen instanceof GuiCancelRender)) {
|
||||
if(!firstTime) {
|
||||
MCTimerHandler.setTimerSpeed(0f);
|
||||
MCTimerHandler.setPartialTicks(0f);
|
||||
MCTimerHandler.setRenderPartialTicks(0f);
|
||||
MCTimerHandler.setTicks(0);
|
||||
resetTimer = true;
|
||||
}
|
||||
return;
|
||||
} else if(recording && ReplayMod.replaySettings.getWaitForChunks()) {
|
||||
MCTimerHandler.setTimerSpeed((float) lastSpeed);
|
||||
//MCTimerHandler.setRenderPartialTicks(lastRenderPartialTicks);
|
||||
if(resetTimer) {
|
||||
MCTimerHandler.setPartialTicks(lastPartialTicks);
|
||||
MCTimerHandler.setRenderPartialTicks(lastRenderPartialTicks);
|
||||
MCTimerHandler.setTicks(lastTicks);
|
||||
resetTimer = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(justCheck) return;
|
||||
|
||||
if(recording) {
|
||||
if(blocked) return;
|
||||
|
||||
deepBlock = true;
|
||||
blocked = true;
|
||||
}
|
||||
|
||||
int posCount = ReplayHandler.getPosKeyframeCount();
|
||||
int timeCount = ReplayHandler.getTimeKeyframeCount();
|
||||
|
||||
if(!linear && motionSpline == null) {
|
||||
//set up spline path
|
||||
motionSpline = new SplinePoint();
|
||||
for(Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
if(kf instanceof PositionKeyframe) {
|
||||
PositionKeyframe pkf = (PositionKeyframe) kf;
|
||||
Position pos = pkf.getPosition();
|
||||
motionSpline.addPoint(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(linear && motionLinear == null) {
|
||||
//set up linear path
|
||||
motionLinear = new LinearPoint();
|
||||
for(Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
if(kf instanceof PositionKeyframe) {
|
||||
PositionKeyframe pkf = (PositionKeyframe) kf;
|
||||
Position pos = pkf.getPosition();
|
||||
motionLinear.addPoint(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(timeLinear == null) {
|
||||
timeLinear = new LinearTimestamp();
|
||||
for(Keyframe kf : ReplayHandler.getKeyframes()) {
|
||||
if(kf instanceof TimeKeyframe) {
|
||||
timeLinear.addPoint(((TimeKeyframe) kf).getTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!calculated) {
|
||||
calculated = true;
|
||||
if(posCount > 1 && motionSpline != null)
|
||||
motionSpline.calcSpline();
|
||||
}
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
long timeStep;
|
||||
if(recording) {
|
||||
timeStep = 1000 / ReplayMod.replaySettings.getVideoFramerate();
|
||||
} else {
|
||||
timeStep = curTime - lastRealTime;
|
||||
}
|
||||
|
||||
int curRealReplayTime = (int) (lastRealReplayTime + timeStep);
|
||||
|
||||
PositionKeyframe lastPos = ReplayHandler.getPreviousPositionKeyframe(curRealReplayTime);
|
||||
PositionKeyframe nextPos = ReplayHandler.getNextPositionKeyframe(curRealReplayTime);
|
||||
|
||||
ReplayHandler.setRealTimelineCursor(curRealReplayTime);
|
||||
|
||||
int lastPosStamp = 0;
|
||||
int nextPosStamp = 0;
|
||||
|
||||
if(nextPos != null || lastPos != null) {
|
||||
if(nextPos != null) {
|
||||
nextPosStamp = nextPos.getRealTimestamp();
|
||||
} else {
|
||||
nextPosStamp = lastPos.getRealTimestamp();
|
||||
}
|
||||
|
||||
if(lastPos != null) {
|
||||
lastPosStamp = lastPos.getRealTimestamp();
|
||||
} else {
|
||||
lastPosStamp = nextPos.getRealTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
TimeKeyframe lastTime = ReplayHandler.getPreviousTimeKeyframe(curRealReplayTime);
|
||||
TimeKeyframe nextTime = ReplayHandler.getNextTimeKeyframe(curRealReplayTime);
|
||||
|
||||
int lastTimeStamp = 0;
|
||||
int nextTimeStamp = 0;
|
||||
|
||||
double curSpeed = 0;
|
||||
|
||||
if(timeCount > 1 && (nextTime != null || lastTime != null)) {
|
||||
|
||||
if(nextTime != null && lastTime != null && nextTime.getRealTimestamp() == lastTime.getRealTimestamp()) {
|
||||
curSpeed = 0;
|
||||
} else {
|
||||
if(nextTime != null) {
|
||||
nextTimeStamp = nextTime.getRealTimestamp();
|
||||
} else {
|
||||
nextTimeStamp = lastTime.getRealTimestamp();
|
||||
}
|
||||
|
||||
if(lastTime != null) {
|
||||
lastTimeStamp = lastTime.getRealTimestamp();
|
||||
} else {
|
||||
lastTimeStamp = nextTime.getRealTimestamp();
|
||||
}
|
||||
|
||||
if(!(nextTime == null || lastTime == null)) {
|
||||
if(lastTimeStamp == nextTimeStamp) curSpeed = 0f;
|
||||
else
|
||||
curSpeed = ((double) ((nextTime.getTimestamp() - lastTime.getTimestamp()))) / ((double) ((nextTimeStamp - lastTimeStamp)));
|
||||
}
|
||||
|
||||
if(lastTimeStamp == nextTimeStamp) {
|
||||
curSpeed = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int currentPosDiff = nextPosStamp - lastPosStamp;
|
||||
int currentPos = curRealReplayTime - lastPosStamp;
|
||||
|
||||
float currentPosStepPerc = (float) currentPos / (float) currentPosDiff; //The percentage of the travelled path between the current positions
|
||||
if(Float.isInfinite(currentPosStepPerc)) currentPosStepPerc = 0;
|
||||
|
||||
int currentTimeDiff = nextTimeStamp - lastTimeStamp;
|
||||
int currentTime = curRealReplayTime - lastTimeStamp;
|
||||
|
||||
float currentTimeStepPerc = (float) currentTime / (float) currentTimeDiff; //The percentage of the travelled path between the current timestamps
|
||||
if(Float.isInfinite(currentTimeStepPerc)) currentTimeStepPerc = 0;
|
||||
|
||||
float splinePos = ((float) ReplayHandler.getKeyframeIndex(lastPos) + currentPosStepPerc) / (float) (posCount - 1);
|
||||
float timePos = ((float) ReplayHandler.getKeyframeIndex(lastTime) + currentTimeStepPerc) / (float) (timeCount - 1);
|
||||
|
||||
Position pos = null;
|
||||
if(posCount > 1) {
|
||||
if(!linear) {
|
||||
pos = motionSpline.getPoint(Math.max(0, Math.min(1, splinePos)));
|
||||
} else {
|
||||
pos = motionLinear.getPoint(Math.max(0, Math.min(1, splinePos)));
|
||||
}
|
||||
} else {
|
||||
if(posCount == 1) {
|
||||
pos = ReplayHandler.getNextPositionKeyframe(-1).getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
Integer curTimestamp = null;
|
||||
if(timeLinear != null && timeCount > 1) {
|
||||
curTimestamp = timeLinear.getPoint(Math.max(0, Math.min(1, timePos)));
|
||||
}
|
||||
|
||||
if(pos != null) {
|
||||
ReplayHandler.getCameraEntity().movePath(pos);
|
||||
}
|
||||
|
||||
if(curSpeed > 0) {
|
||||
ReplayMod.replaySender.setReplaySpeed(curSpeed);
|
||||
lastSpeed = curSpeed;
|
||||
}
|
||||
|
||||
if(recording) {
|
||||
MCTimerHandler.updateTimer((1f / ReplayMod.replaySettings.getVideoFramerate()));
|
||||
EnchantmentTimer.increaseRecordingTime((1000 / ReplayMod.replaySettings.getVideoFramerate()));
|
||||
}
|
||||
|
||||
lastPartialTicks = MCTimerHandler.getPartialTicks();
|
||||
lastRenderPartialTicks = MCTimerHandler.getRenderTicks();
|
||||
lastTicks = MCTimerHandler.getTicks();
|
||||
|
||||
if(curTimestamp != null && curTimestamp != ReplayMod.replaySender.getDesiredTimestamp())
|
||||
ReplayMod.replaySender.jumpToTime(curTimestamp);
|
||||
|
||||
//splinePos = (index of last entry + add) / total entries
|
||||
|
||||
lastRealReplayTime = curRealReplayTime;
|
||||
lastRealTime = curTime;
|
||||
|
||||
if(isVideoRecording()) {
|
||||
try {
|
||||
if(!VideoWriter.isRecording() && ReplayHandler.isInPath()) {
|
||||
VideoWriter.startRecording(mc.displayWidth, mc.displayHeight);
|
||||
} else {
|
||||
final BufferedImage screen = ScreenCapture.captureScreen();
|
||||
VideoWriter.writeImage(screen);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(requestFinish) {
|
||||
stopReplayProcess(true);
|
||||
requestFinish = false;
|
||||
if(recording) {
|
||||
VideoWriter.endRecording();
|
||||
}
|
||||
}
|
||||
|
||||
if((splinePos >= 1 || posCount <= 1) && (timePos >= 1 || timeCount <= 1)) {
|
||||
requestFinish = true;
|
||||
}
|
||||
|
||||
if(recording) {
|
||||
deepBlock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,25 +4,25 @@ import net.minecraft.network.play.server.S03PacketTimeUpdate;
|
||||
|
||||
public class TimeHandler {
|
||||
|
||||
private static long actualDaytime;
|
||||
private static long desiredDaytime;
|
||||
|
||||
private static boolean timeOverridden = false;
|
||||
|
||||
public static boolean isTimeOverridden() {
|
||||
return timeOverridden;
|
||||
}
|
||||
|
||||
public static void setDesiredDaytime(long ddt) {
|
||||
desiredDaytime = ddt;
|
||||
}
|
||||
|
||||
public static void setTimeOverridden(boolean overridden) {
|
||||
timeOverridden = overridden;
|
||||
}
|
||||
|
||||
public static S03PacketTimeUpdate getTimePacket(S03PacketTimeUpdate packet) {
|
||||
if(!timeOverridden) return packet;
|
||||
return new S03PacketTimeUpdate(packet.func_149366_c(), desiredDaytime, true);
|
||||
}
|
||||
private static long actualDaytime;
|
||||
private static long desiredDaytime;
|
||||
|
||||
private static boolean timeOverridden = false;
|
||||
|
||||
public static boolean isTimeOverridden() {
|
||||
return timeOverridden;
|
||||
}
|
||||
|
||||
public static void setTimeOverridden(boolean overridden) {
|
||||
timeOverridden = overridden;
|
||||
}
|
||||
|
||||
public static void setDesiredDaytime(long ddt) {
|
||||
desiredDaytime = ddt;
|
||||
}
|
||||
|
||||
public static S03PacketTimeUpdate getTimePacket(S03PacketTimeUpdate packet) {
|
||||
if(!timeOverridden) return packet;
|
||||
return new S03PacketTimeUpdate(packet.func_149366_c(), desiredDaytime, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,32 @@
|
||||
package eu.crushedpixel.replaymod.replay.spectate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.gui.GuiSpectateSelection;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpectateHandler {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static Predicate<EntityPlayer> playerPredicate = new Predicate<EntityPlayer>() {
|
||||
@Override
|
||||
public boolean apply(EntityPlayer input) {
|
||||
if(input instanceof CameraEntity || input == mc.thePlayer) return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public static void openSpectateSelection() {
|
||||
if(!ReplayHandler.isInReplay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<EntityPlayer> players = mc.theWorld.getEntities(EntityPlayer.class, playerPredicate);
|
||||
mc.displayGuiScreen(new GuiSpectateSelection(players));
|
||||
}
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static Predicate<EntityPlayer> playerPredicate = new Predicate<EntityPlayer>() {
|
||||
@Override
|
||||
public boolean apply(EntityPlayer input) {
|
||||
if(input instanceof CameraEntity || input == mc.thePlayer) return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public static void openSpectateSelection() {
|
||||
if(!ReplayHandler.isInReplay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<EntityPlayer> players = mc.theWorld.getEntities(EntityPlayer.class, playerPredicate);
|
||||
mc.displayGuiScreen(new GuiSpectateSelection(players));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user