/*
 * This file is part of PixelCam Mod, licensed under the Apache License, Version 2.0.
 *
 * Copyright (c) 2016 CrushedPixel <http://crushedpixel.eu>
 * Copyright (c) contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.replaymod.pixelcam.path;

import com.google.common.base.Preconditions;
import com.replaymod.pixelcam.renderer.TiltHandler;
import com.replaymod.pixelcam.command.CamCommand;
import com.replaymod.pixelcam.interpolation.Interpolation;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class TravellingProcess {

    private Minecraft mc = Minecraft.getMinecraft();

    private final Interpolation<Position> interpolation;
    private final long duration;

    private long startTime;

    private boolean active;

    public boolean isActive() {
        return active;
    }

    public TravellingProcess(Interpolation<Position> interpolation, long duration) {
        this.interpolation = interpolation;
        this.duration = duration;

        MinecraftForge.EVENT_BUS.register(this);
    }

    public void start() {
        Preconditions.checkState(!active);

        startTime = System.currentTimeMillis();
        active = true;
    }

    public void stop() {
        Preconditions.checkState(active);

        active = false;
    }

    @SubscribeEvent
    public void onRenderTick(TickEvent.RenderTickEvent event) {
        if(!active) return;

        long current = System.currentTimeMillis();

        float progress = Math.min(1, (current - startTime) / (float)duration);

        Position pos = new Position();

        interpolation.applyPoint(progress, pos);

        mc.thePlayer.setPositionAndRotation(pos.getX(), pos.getY(), pos.getZ(), pos.getYaw(), pos.getPitch());

        //this fixes camera jerking
        mc.thePlayer.prevRotationYaw = mc.thePlayer.rotationYaw;
        mc.thePlayer.prevRotationPitch = mc.thePlayer.rotationPitch;

        TiltHandler.setTilt(pos.getTilt());

        if(progress >= 1) {
            CamCommand.sendSuccessMessage(new TextComponentTranslation("pixelcam.commands.cam.start.finished"));
            active = false;
        }
    }

}

@@ -824,60 +824,8 @@
 ns;%0A
-import com.replaymod.pixelcam.renderer.TiltHandler;%0A
 impo
@@ -870,16 +870,16 @@
 ommand;%0A
+
 import c
@@ -921,32 +921,84 @@
 .Interpolation;%0A
+import com.replaymod.pixelcam.renderer.TiltHandler;%0A
 import net.minec
@@ -1426,24 +1426,59 @@
  duration;%0A%0A
+    private boolean wasSpectator;%0A%0A
     private 
@@ -1867,32 +1867,137 @@
 tate(!active);%0A%0A
+        wasSpectator = mc.thePlayer.isSpectator();%0A        mc.thePlayer.sendChatMessage(%22/gamemode 3%22);%0A%0A
         startTim
@@ -2118,32 +2118,104 @@
 State(active);%0A%0A
+        if(!wasSpectator) mc.thePlayer.sendChatMessage(%22/gamemode 1%22);%0A%0A
         active =
@@ -3041,38 +3041,30 @@
             
-active = false
+stop()
 ;%0A        %7D%0A

Set gamemode to spectator mode when travelling a camera path