/*
 * 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.ai;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerCapabilities;
import net.minecraft.util.math.BlockPos;
import tk.wurst_client.WurstClient;

public class PathUtils
{
	private static PlayerCapabilities playerCaps;
	
	public static boolean isSafe(BlockPos pos)
	{
		Material material = getMaterial(pos);
		int id = getID(pos);
		boolean alwaysSafe = !material.blocksMovement() && id != 132;// tripwire
		if(isCreative())
			return alwaysSafe;
		Material materialBelow = getMaterial(pos.add(0, -1, 0));
		return alwaysSafe && material != Material.LAVA
			&& materialBelow != Material.CACTUS && material != Material.FIRE;
	}
	
	@SuppressWarnings("deprecation")
	public static boolean isSolid(BlockPos pos)
	{
		return Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock()
			.getMaterial(Minecraft.getMinecraft().theWorld.getBlockState(pos))
			.blocksMovement()
			|| getMaterial(pos) == Material.WATER
				&& WurstClient.INSTANCE.mods.jesusMod.isActive();
	}
	
	public static boolean isFallable(BlockPos pos)
	{
		for(int i = -1; i >= (isNoFall() ? -256 : -3); i--)
			if(isSolid(pos.add(0, i, 0)))
				return true;
		return false;
	}
	
	public static boolean isClimbable(BlockPos pos)
	{
		if(isSolid(pos.add(0, -1, 0))
			|| WurstClient.INSTANCE.mods.spiderMod.isActive()
			|| getID(pos) == 65 || isFlyable(pos))
			if(isSolid(pos.add(0, 0, -1)) || isSolid(pos.add(0, 0, 1))
				|| isSolid(pos.add(1, 0, 0)) || isSolid(pos.add(-1, 0, 0)))
				return true;
		return false;
	}
	
	public static boolean isNoFall()
	{
		return WurstClient.INSTANCE.mods.noFallMod.isActive() || isCreative();
	}
	
	public static boolean isCreative()
	{
		if(playerCaps == null)
			playerCaps = Minecraft.getMinecraft().thePlayer.capabilities;
		return playerCaps.isCreativeMode;
	}
	
	public static boolean isFlyable(BlockPos pos)
	{
		if(playerCaps == null)
			playerCaps = Minecraft.getMinecraft().thePlayer.capabilities;
		return WurstClient.INSTANCE.mods.flightMod.isActive()
			|| playerCaps.isFlying
			|| !WurstClient.INSTANCE.mods.noSlowdownMod.isActive()
				&& getMaterial(pos) == Material.WATER;
	}
	
	public static int getCost(BlockPos current, BlockPos next)
	{
		Material nextMaterial = getMaterial(next);
		if(nextMaterial == Material.WATER)
			if(WurstClient.INSTANCE.mods.noSlowdownMod.isActive())
				return 1;
			else if(WurstClient.INSTANCE.mods.antiKnockbackMod.isActive())
				return 2;
			else
				return 3;
		else if(nextMaterial == Material.LAVA)
			return 5;
		return 1;
	}
	
	@SuppressWarnings("deprecation")
	private static Material getMaterial(BlockPos pos)
	{
		return Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock()
			.getMaterial(Minecraft.getMinecraft().theWorld.getBlockState(pos));
	}
	
	private static int getID(BlockPos pos)
	{
		return Block.getIdFromBlock(
			Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock());
	}
}

@@ -594,16 +594,22 @@
  static 
+final 
 PlayerCa
@@ -629,16 +629,195 @@
 ayerCaps
+ =%0A%09%09Minecraft.getMinecraft().thePlayer.capabilities;%0A%09private static final WurstClient wurst = WurstClient.INSTANCE;%0A%09private static final Minecraft mc = Minecraft.getMinecraft()
 ;%0A%09%0A%09pub
@@ -1315,32 +1315,10 @@
 urn 
-Minecraft.getMinecraft()
+mc
 .the
@@ -1373,32 +1373,10 @@
 ial(
-Minecraft.getMinecraft()
+mc
 .the
@@ -1400,20 +1400,16 @@
 te(pos))
-%0A%09%09%09
 .blocksM
@@ -1466,36 +1466,21 @@
 %0A%09%09%09%09&& 
-W
+w
 urst
-Client.INSTANCE
 .mods.je
@@ -1766,35 +1766,17 @@
  0))
-%0A%09%09%09%7C%7C W
+ %7C%7C w
 urst
-Client.INSTANCE
 .mod
@@ -2050,36 +2050,21 @@
 %09return 
-W
+w
 urst
-Client.INSTANCE
 .mods.no
@@ -2147,98 +2147,8 @@
 %0A%09%7B%0A
-%09%09if(playerCaps == null)%0A%09%09%09playerCaps = Minecraft.getMinecraft().thePlayer.capabilities;%0A
 %09%09re
@@ -2238,98 +2238,8 @@
 %0A%09%7B%0A
-%09%09if(playerCaps == null)%0A%09%09%09playerCaps = Minecraft.getMinecraft().thePlayer.capabilities;%0A
 %09%09re
@@ -2243,36 +2243,21 @@
 %09return 
-W
+w
 urst
-Client.INSTANCE
 .mods.fl
@@ -2274,20 +2274,17 @@
 Active()
-%0A%09%09%09
+ 
 %7C%7C playe
@@ -2305,36 +2305,21 @@
 %0A%09%09%09%7C%7C !
-W
+w
 urst
-Client.INSTANCE
 .mods.no
@@ -2540,36 +2540,21 @@
 )%0A%09%09%09if(
-W
+w
 urst
-Client.INSTANCE
 .mods.no
@@ -2602,36 +2602,21 @@
 else if(
-W
+w
 urst
-Client.INSTANCE
 .mods.an
@@ -2850,32 +2850,10 @@
 urn 
-Minecraft.getMinecraft()
+mc
 .the
@@ -2908,32 +2908,10 @@
 ial(
-Minecraft.getMinecraft()
+mc
 .the
@@ -3019,36 +3019,10 @@
 ock(
-%0A%09%09%09Minecraft.getMinecraft()
+mc
 .the

Clean up PathUtils