/*
 * Copyright  2014 - 2016 | 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 tk.wurst_client.mods;

import net.minecraft.entity.Entity;
import tk.wurst_client.ai.FollowAI;
import tk.wurst_client.events.listeners.UpdateListener;
import tk.wurst_client.mods.Mod.Bypasses;
import tk.wurst_client.mods.Mod.Info;
import tk.wurst_client.utils.EntityUtils;
import tk.wurst_client.utils.EntityUtils.TargetSettings;

@Info(
	description = "A bot that follows the closest entity.\n" + "Very annoying.",
	name = "Follow",
	help = "Mods/Follow")
@Bypasses(ghostMode = false)
public class FollowMod extends Mod implements UpdateListener
{
	private Entity entity;
	private FollowAI ai;
	
	private float range = 12F;
	private float distance = 1F;
	
	private TargetSettings targetSettingsFind = new TargetSettings()
	{
		@Override
		public boolean targetFriends()
		{
			return true;
		}
		
		@Override
		public float getRange()
		{
			return range;
		}
	};
	
	private TargetSettings targetSettingsKeep = new TargetSettings()
	{
		@Override
		public boolean targetFriends()
		{
			return true;
		}
		
		@Override
		public boolean targetBehindWalls()
		{
			return true;
		};
		
		@Override
		public boolean targetPlayers()
		{
			return true;
		}
		
		@Override
		public boolean targetAnimals()
		{
			return true;
		}
		
		@Override
		public boolean targetMonsters()
		{
			return true;
		}
		
		@Override
		public boolean targetGolems()
		{
			return true;
		}
		
		@Override
		public boolean targetSleepingPlayers()
		{
			return true;
		}
		
		@Override
		public boolean targetInvisiblePlayers()
		{
			return true;
		}
		
		@Override
		public boolean targetInvisibleMobs()
		{
			return true;
		}
		
		@Override
		public boolean targetTeams()
		{
			return false;
		}
	};
	
	@Override
	public String getRenderName()
	{
		if(entity != null)
			return "Following " + entity.getName();
		else
			return "Follow";
	}
	
	@Override
	public void onEnable()
	{
		if(entity == null)
			entity = EntityUtils.getClosestEntity(targetSettingsFind);
		
		if(entity == null)
		{
			setEnabled(false);
			return;
		}
		
		ai = new FollowAI(entity, distance);
		wurst.events.add(UpdateListener.class, this);
		wurst.chat.message("Now following " + entity.getName());
	}
	
	@Override
	public void onUpdate()
	{
		// check if player died
		if(mc.player.getHealth() <= 0)
		{
			setEnabled(false);
			return;
		}
		
		// check if entity died or entity disappeared
		if(!EntityUtils.isCorrectEntity(entity, targetSettingsKeep))
		{
			entity = EntityUtils.getClosestEntity(targetSettingsFind);
			
			if(entity == null)
			{
				setEnabled(false);
				return;
			}
			
			ai = new FollowAI(entity, distance);
		}
		
		// go to entity
		ai.update();
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
		
		if(ai != null)
			ai.stop();
		
		if(entity != null)
			wurst.chat.message("No longer following " + entity.getName());
		else
			wurst.chat.message("No longer following entity");
		
		entity = null;
	}
	
	public void setEntity(Entity entity)
	{
		this.entity = entity;
	}
}

@@ -511,16 +511,143 @@
 d.Info;%0A
+import tk.wurst_client.navigator.settings.SliderSetting;%0Aimport tk.wurst_client.navigator.settings.SliderSetting.ValueDisplay;%0A
 import t
@@ -680,16 +680,16 @@
 yUtils;%0A
-
 import t
@@ -1037,30 +1037,258 @@
 F;%0A%09
-private float 
+%0A%09public SliderSetting distance =%0A%09%09new SliderSetting(%22Distance%22, 1F, 1F, 12F, 0.5F, ValueDisplay.DECIMAL)%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09public void update()%0A%09%09%09%7B%0A%09%09%09%09entity = null;%0A%09%09%09%7D;%0A%09%09%7D;%0A%09%0A%09@Override%0A%09public void initSettings()%0A%09%7B%0A%09%09settings.add(
 distance
  = 1
@@ -1287,14 +1287,13 @@
 ance
- = 1F;
+);%0A%09%7D
 %0A%09%0A%09
@@ -2682,24 +2682,36 @@
 ty, distance
+.getValueF()
 );%0A%09%09wurst.e
@@ -3239,24 +3239,36 @@
 ty, distance
+.getValueF()
 );%0A%09%09%7D%0A%09%09%0A%09%09

Add Follow distance slider