/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package net.wurstclient.features.mods;

import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.wurstclient.compatibility.WMinecraft;
import net.wurstclient.events.listeners.UpdateListener;
import net.wurstclient.features.HelpPage;
import net.wurstclient.features.Mod;
import net.wurstclient.features.SearchTags;

@SearchTags({"free camera", "spectator"})
@HelpPage("Mods/Freecam")
@Mod.Bypasses
@Mod.DontSaveState
public final class FreecamMod extends Mod implements UpdateListener
{
	private EntityOtherPlayerMP fakePlayer = null;
	private double oldX;
	private double oldY;
	private double oldZ;
	
	public FreecamMod()
	{
		super("Freecam", "Allows you to fly out of your body.\n"
			+ "Looks similar to spectator mode.");
	}
	
	@Override
	public void onEnable()
	{
		oldX = WMinecraft.getPlayer().posX;
		oldY = WMinecraft.getPlayer().posY;
		oldZ = WMinecraft.getPlayer().posZ;
		fakePlayer = new EntityOtherPlayerMP(WMinecraft.getWorld(),
			WMinecraft.getPlayer().getGameProfile());
		fakePlayer.clonePlayer(WMinecraft.getPlayer(), true);
		fakePlayer.copyLocationAndAnglesFrom(WMinecraft.getPlayer());
		fakePlayer.rotationYawHead = WMinecraft.getPlayer().rotationYawHead;
		WMinecraft.getWorld().addEntityToWorld(-69, fakePlayer);
		wurst.events.add(UpdateListener.class, this);
	}
	
	@Override
	public void onUpdate()
	{
		WMinecraft.getPlayer().motionX = 0;
		WMinecraft.getPlayer().motionY = 0;
		WMinecraft.getPlayer().motionZ = 0;
		WMinecraft.getPlayer().jumpMovementFactor =
			wurst.mods.flightMod.speed.getValueF() / 10;
		if(mc.gameSettings.keyBindJump.pressed)
			WMinecraft.getPlayer().motionY +=
				wurst.mods.flightMod.speed.getValue();
		if(mc.gameSettings.keyBindSneak.pressed)
			WMinecraft.getPlayer().motionY -=
				wurst.mods.flightMod.speed.getValue();
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
		WMinecraft.getPlayer().setPositionAndRotation(oldX, oldY, oldZ,
			WMinecraft.getPlayer().rotationYaw,
			WMinecraft.getPlayer().rotationPitch);
		WMinecraft.getWorld().removeEntityFromWorld(-69);
		fakePlayer = null;
		mc.renderGlobal.loadRenderers();
	}
}

@@ -315,64 +315,8 @@
 s;%0A%0A
-import net.minecraft.client.entity.EntityOtherPlayerMP;%0A
 impo
@@ -538,16 +538,63 @@
 rchTags;
+%0Aimport net.wurstclient.utils.EntityFakePlayer;
 %0A%0A@Searc
@@ -773,29 +773,26 @@
 e Entity
-Other
+Fake
 Player
-MP
  fakePla
@@ -798,81 +798,8 @@
 ayer
- = null;%0A%09private double oldX;%0A%09private double oldY;%0A%09private double oldZ
 ;%0A%09%0A
@@ -972,522 +972,289 @@
 %7B%0A%09%09
-oldX = WMinecraft.getPlayer().posX;%0A%09%09oldY = WMinecraft.getPlayer().posY;%0A%09%09oldZ = WMinecraft.getPlayer().posZ;%0A%09%09fakePlayer = new EntityOtherPlayerMP(WMinecraft.getWorld
+fakePlayer = new EntityFakePlayer();%0A%09%09%0A%09%09wurst.events.add(UpdateListener.class, this);%0A%09%7D%0A%09%0A%09@Override%0A%09public void onDisable
 ()
-,
 %0A%09
-%09%09WMinecraft.getPlayer().getGameProfile());%0A%09%09fakePlayer.clonePlayer(WMinecraft.getPlayer(), true);%0A%09%09fakePlayer.copyLocationAndAnglesFrom(WMinecraft.getPlayer());%0A%09%09fakePlayer.rotationYawHead = WMinecraft.getPlayer().rotationYawHead;%0A%09%09WMinecraft.getWorld().addEntityToWorld(-69, fakePlayer);%0A%09%09wurst.events.add(UpdateListener.class, this
+%7B%0A%09%09wurst.events.remove(UpdateListener.class, this);%0A%09%09%0A%09%09fakePlayer.resetPlayerPosition();%0A%09%09fakePlayer.despawn();%0A%09%09%0A%09%09mc.renderGlobal.loadRenderers(
 );%0A%09
@@ -1405,24 +1405,27 @@
 otionZ = 0;%0A
+%09%09%0A
 %09%09WMinecraft
@@ -1504,17 +1504,21 @@
 F() / 10
-;
+F;%0A%09%09
 %0A%09%09if(mc
@@ -1632,16 +1632,19 @@
 alue();%0A
+%09%09%0A
 %09%09if(mc.
@@ -1765,356 +1765,6 @@
 %0A%09%7D%0A
-%09%0A%09@Override%0A%09public void onDisable()%0A%09%7B%0A%09%09wurst.events.remove(UpdateListener.class, this);%0A%09%09WMinecraft.getPlayer().setPositionAndRotation(oldX, oldY, oldZ,%0A%09%09%09WMinecraft.getPlayer().rotationYaw,%0A%09%09%09WMinecraft.getPlayer().rotationPitch);%0A%09%09WMinecraft.getWorld().removeEntityFromWorld(-69);%0A%09%09fakePlayer = null;%0A%09%09mc.renderGlobal.loadRenderers();%0A%09%7D%0A
 %7D%0A

Update FreecamMod