package hmggirlfront.entity.mob.ai;

import java.util.List;

import gvclib.mod_GVCLib;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.world.GVCExplosionBase;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.ai.RandomPositionGenerator;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.Chunk;

public abstract class IBCAI_EntityMoveS
{
	public static void newmove(EntityGVCLivingBase entity, int id, float sp, float turnspeed, double max, double range1, double attack_range) {
		int fps = mod_GVCLib.proxy.getFPS();
		if(fps < 15)return;
		Chunk chunk = entity.world.getChunkFromBlockCoords(new BlockPos(entity.posX, entity.posY, entity.posZ));
		if (chunk.isEmpty())return;
		entity.sneak = false;
		boolean ta = false;
		double range = range1;
		/*if(entity.getattacktask()){
			range = range2;
		}*/
		//entity.motionY *= 0.98;
		if (entity.isPotionActive(MobEffects.SLOWNESS))
        {
			sp = sp * 0.5F;
        }
		if (entity.isPotionActive(MobEffects.BLINDNESS))
        {
			sp = sp * 0.1F;
        }
		
		if(entity.getMoveT() == 1){
			{
				MoveT(entity, sp * 0.8, 1, entity.getMoveX(), entity.getMoveY(), entity.getMoveZ(), id);
			}
			if(entity.posX == entity.getMoveX() && entity.posY == entity.getMoveY() && entity.posZ == entity.getMoveZ()) {
				entity.setMoveT(0);
			}
			{
				List<Entity> llist = entity.world.getEntitiesWithinAABBExcludingEntity(entity,
						entity.getEntityBoundingBox().expand(entity.motionX, entity.motionY, entity.motionZ)
								.grow(range));
				if (llist != null) {
					for (int lj = 0; lj < llist.size(); lj++) {
						Entity entity1 = (Entity) llist.get(lj);
						if (entity1.canBeCollidedWith() && entity1 != null && entity.getHealth() > 0.0F) {
							boolean flag = entity.getEntitySenses().canSee(entity1);
							if (entity.CanAttack(entity1) && entity1 != null) {
								if (entity.targetentity == entity1) {
									{
										double d51 = entity1.posX - entity.posX;
										double d71 = entity1.posZ - entity.posZ;
										double d61 = entity1.posY - entity.posY;
										double d11 = entity.posY - (entity1.posY);
										double d31 = (double) MathHelper.sqrt(d51 * d51 + d71 * d71);
										float f111 = (float) (-(Math.atan2(d11, d31) * 180.0D / Math.PI));
										entity.rotation = entity.rotationYaw = entity.rotationYawHead = entity.renderYawOffset 
												= -((float) Math.atan2(d51, d71)) * 180.0F / (float) Math.PI;
										entity.rotationp = entity.prevRotationPitch = entity.rotationp = entity.rotationPitch = -f111
												+ entity.angle_offset;
										if (flag) {
											entity.targetentity = (EntityLivingBase) entity1;
											
											double ddx = Math.abs(d51);
											double ddz = Math.abs(d71);
											entity.noflag = 0;
											++entity.discover_count;
											entity.targetentity_lastposX = entity1.posX;
											entity.targetentity_lastposY = entity1.posY;
											entity.targetentity_lastposZ = entity1.posZ;
											if ((ddx < attack_range && ddz < attack_range)) {
												entity.setFTMode(1);
											}else {
												entity.setFTMode(0);
											}
										}else {
											entity.discover_count = 0;
											entity.setFTMode(0);
										}
										
										ta = true;
									}
									
									break;
								} else if (entity.targetentity == null) {
									if (entity.CanAttack(entity1) && flag) {
										
										entity.targetentity = (EntityLivingBase) entity1;
										ta = true;
										break;
									}
								}
							}
						}
					}
				}
			}
			if(entity.getAIType() == 1 && id == 0) {
				ta = true;
			}
		}
		else if(entity.getMoveT() == 2){
			List<Entity> llist = entity.world.getEntitiesWithinAABBExcludingEntity(entity, entity
					.getEntityBoundingBox().expand(entity.motionX, entity.motionY, entity.motionZ).grow(range*2));
			if (llist != null) {
				for (int lj = 0; lj < llist.size(); lj++) {
					Entity entity1 = (Entity) llist.get(lj);
					if (entity1.canBeCollidedWith()) {
						boolean flag = entity.getEntitySenses().canSee(entity1);
						if (entity.CanAttack(entity1) && entity1 != null) {//target
							
							if (entity.targetentity == entity1
									&& ((EntityLivingBase) entity1).getHealth() > 0.0F) {
								double d5 = entity1.posX - entity.posX;
								double d7 = entity1.posZ - entity.posZ;
								double d6 = entity1.posY - entity.posY;
								double d1 = entity.posY - (entity1.posY);
								double d3 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7);
								float f11 = (float) (-(Math.atan2(d1, d3) * 180.0D / Math.PI));
								entity.rotationYawHead = entity.rotation = entity.rote = entity.renderYawOffset 
										= -((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI;
								entity.rotationp = entity.rotationPitch = -f11 + entity.angle_offset;
								if (flag) {
									
									double ddx = Math.abs(d5);
									double ddz = Math.abs(d7);
									if ((ddx > max || ddz > max)) {
										MoveS(entity, sp, 1, entity1.posX, entity1.posY, entity1.posZ, id);
									}
									entity.noflag = 0;
									++entity.discover_count;
									entity.targetentity_lastposX = entity1.posX;
									entity.targetentity_lastposY = entity1.posY;
									entity.targetentity_lastposZ = entity1.posZ;
									if ((ddx <= attack_range && ddz <= attack_range)) {
										entity.setFTMode(1);
									}else {
										entity.setFTMode(0);
									}
								} else {
									++entity.noflag;
									entity.discover_count = 0;
									entity.setFTMode(0);
									if(entity.noflag > 20) 
									{
										//MoveS(entity, sp, 1, entity1.posX, entity1.posY, entity1.posZ, id);
										entity.getNavigator().tryMoveToXYZ(entity1.posX, entity1.posY, entity1.posZ, sp * 10);
										entity.noflag = 0;
									}
								}

								if (flag) {
									entity.targetentity = (EntityLivingBase) entity1;
								}
								break;
							} 
						}//target
						
					}
				}
			}
		}
		else
		{
			List<Entity> llist = entity.world.getEntitiesWithinAABBExcludingEntity(entity, entity
					.getEntityBoundingBox().expand(entity.motionX, entity.motionY, entity.motionZ).grow(range));
			if (llist != null) {
				for (int lj = 0; lj < llist.size(); lj++) {
					Entity entity1 = (Entity) llist.get(lj);
					if (entity1.canBeCollidedWith()) {
						boolean flag = entity.getEntitySenses().canSee(entity1);
						if (entity.CanAttack(entity1) && entity1 != null) {//target
							
							if (entity.targetentity == entity1
									&& ((EntityLivingBase) entity1).getHealth() > 0.0F) {
								double d5 = entity1.posX - entity.posX;
								double d7 = entity1.posZ - entity.posZ;
								double d6 = entity1.posY - entity.posY;
								double d1 = entity.posY - (entity1.posY);
								double d3 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7);
								float f11 = (float) (-(Math.atan2(d1, d3) * 180.0D / Math.PI));
								
								if (flag) {
									entity.rotationYawHead = entity.rotation = entity.rote = entity.renderYawOffset = entity.rotationYaw
											= (-((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI) ;
									//entity.rotationYaw = entity.renderYawOffset = -((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI;
									entity.rotationp = entity.rotationPitch = -f11 + entity.angle_offset;
									double ddx = Math.abs(d5);
									double ddz = Math.abs(d7);
									if ((ddx > max || ddz > max)) {
										MoveS(entity, sp, 1, entity1.posX, entity1.posY, entity1.posZ, id);
									}
									entity.noflag = 0;
									++entity.discover_count;
									entity.targetentity_lastposX = entity1.posX;
									entity.targetentity_lastposY = entity1.posY;
									entity.targetentity_lastposZ = entity1.posZ;
									if ((ddx <= attack_range && ddz <= attack_range)) {
										entity.setFTMode(1);
									}else {
										entity.setFTMode(0);
									}
								} else {
									++entity.noflag;
									entity.discover_count = 0;
									entity.setFTMode(0);
									if(entity.noflag < 100) {
										{
											MoveS(entity, sp, 1, entity1.posX, entity1.posY, entity1.posZ, id);
										}
									}
								}

								if (flag) {
									entity.targetentity = (EntityLivingBase) entity1;
								}
								break;
							} 
						}//target
						
					}
				}
			}
		}
		if(!entity.getattacktask() && entity.find_enemy_count <= 0){
			stay(entity, id);
		}
		/*{
			float f3 = (float) (entity.rotationYaw - entity.rotationYawHead);
			 if(entity.rotationYaw != entity.rotationYawHead){
        		if(f3 > 1){
					if(f3 > 180F){
						entity.rotationYaw = entity.rotationYaw + 1;
					}else{
						entity.rotationYaw = entity.rotationYaw - 1;
					}
				}
				else if(f3 < -1){
					if(f3 < -180F){
						entity.rotationYaw = entity.rotationYaw - 1;
					}else{
						entity.rotationYaw = entity.rotationYaw + 1;
					}
				}
	            }
		}*/
		/*{
			if(entity.rotationYaw > 180F){
				entity.rotationYaw = -179F;
			}
			if(entity.rotationYaw < -180F){
				entity.rotationYaw = 179F;
			}
			if(entity.rotationYawHead > 360F || entity.rotationYawHead < -360F){
				entity.rotationYawHead = 0;
			}
			if(entity.rotationYawHead > 180F){
				entity.rotationYawHead = -179F;
			}
			if(entity.rotationYawHead < -180F){
				entity.rotationYawHead = 179F;
			}
			float f3 = (float) (entity.rotationYawHead - entity.rotationYaw);
			 if(entity.rotationYawHead != entity.rotationYaw){
				 if(f3 <= turnspeed && f3 >= -turnspeed){
					 
				 }
				 else if(f3 > 1){
 					if(f3 > 180F){
 						entity.rotationYaw = entity.rotationYaw - turnspeed;
 					}else{
 						entity.rotationYaw = entity.rotationYaw + turnspeed;
 					}
 				}
 				else if(f3 < -1){
 					if(f3 < -180F){
 						entity.rotationYaw = entity.rotationYaw + turnspeed;
 					}else{
 						entity.rotationYaw = entity.rotationYaw - turnspeed;
 					}
 				}
	            }
		}*/
	}
	
	
	
	public static void MoveS(EntityGVCLivingBase entity, double speed, double han, double ex, double ey, double ez, int id){
		{// 1
//			if(!entity.world.isRemote)
			{
				//this.motionY = 0.2D;
				double ix = 0;
				double iz = 0;
				double iy = entity.motionY;
				float f12 = entity.rotationYaw * (2 * (float) Math.PI / 360);
				float f22 = entity.rotationPitch * (2 * (float) Math.PI / 360);

				double x = entity.posX;
				double y = entity.posY;
				double z = entity.posZ;
				
				double d5 = ex - entity.posX;
				double d7 = ez - entity.posZ;
				
				double root = Math.sqrt(d5 * d5 + d7 * d7);
				
				double offset_speed = 1.0;
				if(entity.getFTMode() == 0) {
					offset_speed = 1.25;
				}
				
				float off = 0;
	//			entity.rotationYaw = entity.renderYawOffset = -((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI;
				float yaw = entity.rotationYawHead * (2 * (float) Math.PI / 360);
				double mox = 0;
				double moy = entity.motionY;
				double moz = 0;
				mox -= MathHelper.sin(yaw) * speed * 1;
				moz += MathHelper.cos(yaw) * speed * 1;
				if (entity.onGround) {
					
				}
				entity.stepHeight = entity.height * 0.8F;
				
				boolean flag = true;
				{
					Vec3d lock = Vec3d.fromPitchYaw(entity.rotationPitch, entity.rotationYawHead);//entity.getForward();
					BlockPos pos0 = new BlockPos(entity.posX + lock.x * 1, entity.posY - 0,entity.posZ + lock.z * 1);
					BlockPos pos1 = new BlockPos(entity.posX + lock.x * 1, entity.posY - 1,entity.posZ + lock.z * 1);
					BlockPos pos2 = new BlockPos(entity.posX + lock.x * 1, entity.posY - 2,entity.posZ + lock.z * 1);
					
					BlockPos pos3 = new BlockPos(entity.posX + lock.x * 1, entity.posY + 1,entity.posZ + lock.z * 1);
					BlockPos pos4 = new BlockPos(entity.posX + lock.x * 1, entity.posY + 2,entity.posZ + lock.z * 1);
					if (entity.world.getBlockState(pos0).getBlock() == Blocks.LAVA
							|| entity.world.getBlockState(pos0).getBlock() == Blocks.FLOWING_LAVA) {
						 flag = false;
					}
					if (entity.world.getBlockState(pos1).getBlock() == Blocks.LAVA
							|| entity.world.getBlockState(pos1).getBlock() == Blocks.FLOWING_LAVA) {
						 flag = false;
					}
					if (entity.world.getBlockState(pos2).getBlock() == Blocks.LAVA
							|| entity.world.getBlockState(pos2).getBlock() == Blocks.FLOWING_LAVA) {
						 flag = false;
					}
					
					if (entity.world.getBlockState(pos0).getBlock() == Blocks.AIR
							&& entity.world.getBlockState(pos1).getBlock() == Blocks.AIR
							&& entity.world.getBlockState(pos2).getBlock() == Blocks.AIR) {
						 flag = false;
					}
					
					if (entity.world.getBlockState(pos0).getBlock() == Blocks.IRON_BARS
							|| entity.world.getBlockState(pos3).getBlock() == Blocks.IRON_BARS) {
						 flag = false;
					}
				}
				
				//if(entity.world.rand.nextInt(4) == 0) 
				if(flag){
					//entity.getNavigator().tryMoveToXYZ(ex, ey, ez, speed * 10);
					{
						entity.motionX = mox;
						entity.motionZ = moz;
						//entity.motionY = y;
						entity.move(MoverType.PLAYER, entity.motionX, entity.motionY, entity.motionZ);
					}
				}
				
			}
		} // 1
	}
	
	public static void stay(EntityGVCLivingBase entity, int id) {
		entity.setMobMode(0);
		double xPosition = 0;
	    double yPosition = 0;
	    double zPosition = 0;
		if (entity.getIdleTime() >= 100)
        {
        }
        else if (entity.getRNG().nextInt(120) != 0)
        {
        }
        else
        {
            Vec3d vec3 = RandomPositionGenerator.findRandomTarget(entity, 10, 7);

            if (vec3 == null)
            {
            }
            else
            {
                xPosition = vec3.x;
                yPosition = vec3.y;
                zPosition = vec3.z;
            }
            entity.rotation = entity.rotationYawHead = entity.getRNG().nextInt(120) - 60;
        }
		{
			if(entity.rote > 180F){
				entity.rote = -179F;
			}
			if(entity.rote < -180F){
				entity.rote = 179F;
			}
			float f3 = (float) (entity.rotationYawHead - entity.rote);
			 if(entity.rotationYawHead != entity.rote){
         		if(f3 > 1){
 					if(f3 > 180F){
 						entity.rotationYaw = entity.rotationYaw + 1;
 					}else{
 						entity.rotationYaw = entity.rotationYaw - 1;
 					}
 				}
 				else if(f3 < -1){
 					if(f3 < -180F){
 						entity.rotationYaw = entity.rotationYaw - 1;
 					}else{
 						entity.rotationYaw = entity.rotationYaw + 1;
 					}
 				}
	            }
		}
		//if(id != 0 && entity.getMoveT() != 3) {
		if(entity.getMoveT() != 3) {
			entity.getNavigator().tryMoveToXYZ(xPosition, yPosition, zPosition, 1D);
		}
		if(entity.isRiding()) {
		}
	}
	
	public static final PropertyDirection FACING = BlockHorizontal.FACING;
	public static void MoveT(EntityGVCLivingBase entity, double speed, double han, double ex, double ey, double ez, int id){
		{// 1
			if(!entity.world.isRemote)
			{
				double ix = 0;
				double iz = 0;
				double iy = entity.motionY;
				float f12 = entity.rotationYaw * (2 * (float) Math.PI / 360);
				float f22 = entity.rotationPitch * (2 * (float) Math.PI / 360);

				double x = entity.posX;
				double y = entity.posY;
				double z = entity.posZ;
				
				double d5 = ex - entity.posX;
				double d7 = ez - entity.posZ;
				
				double root = Math.sqrt(d5 * d5 + d7 * d7);
				
				float off = 0;
				entity.rotationYaw = entity.renderYawOffset = -((float) Math.atan2(d5, d7)) * 180.0F / (float) Math.PI;
				float yaw = entity.rotationYaw * (2 * (float) Math.PI / 360);
				entity.stepHeight = entity.height * 0.8F;
				Vec3d lock = Vec3d.fromPitchYaw(entity.rotationPitch, entity.rotationYaw);//entity.getForward();
				if(id == 0) {
					double mox = 0;
					double moy = entity.motionY;
					double moz = 0;
					float yawoffset = 0F;
					for(int xx = 0; xx < 2; ++xx){
						for(int zz = 0; zz < 2; ++zz){
							//for(int yy = 0; yy < 3; ++yy)
							{
								BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY - 1,entity.posZ + lock.z * zz);
								BlockPos pos2 = new BlockPos(entity.posX + lock.x * xx, entity.posY - 2,entity.posZ + lock.z * zz);
								if (entity.world.getBlockState(pos1).getBlock() == Blocks.AIR
										&&entity.world.getBlockState(pos2).getBlock() == Blocks.AIR) {
									double xyaw = 0;
									double zyaw = 0;
									xyaw -= MathHelper.sin(yaw + 1.57F) * xx;
									zyaw += MathHelper.cos(yaw + 1.57F) * zz;
									BlockPos pos3 = new BlockPos(entity.posX + xyaw, entity.posY - 1,entity.posZ + zyaw);
									BlockPos pos4 = new BlockPos(entity.posX + xyaw, entity.posY - 2,entity.posZ + zyaw);
									if (entity.world.getBlockState(pos3).getBlock() == Blocks.AIR
											&&entity.world.getBlockState(pos4).getBlock() == Blocks.AIR) {
										yawoffset = -1.57F;
									}else {
										yawoffset = 1.57F;
									}
								}
							}
						}
					}
					mox -= MathHelper.sin(yaw) * speed * 1;
					moz += MathHelper.cos(yaw) * speed * 1;
					if(entity.getAIType() != 1) 
					{
						/*if(entity.cooltime4 > 20){
							entity.getNavigator().tryMoveToXYZ(ex, ey, ez, speed * 10);
							entity.cooltime4 = 0;
						}*/
						{
							BlockPos pos0 = new BlockPos(entity.posX, entity.posY + 0,entity.posZ);
							BlockPos pos1 = new BlockPos(entity.posX, entity.posY + 1,entity.posZ);
							if (entity.world.getBlockState(pos0).getBlock() instanceof BlockLadder 
									|| entity.world.getBlockState(pos1).getBlock() instanceof BlockLadder) {
								entity.motionY = 0.2;
							}
							entity.motionX = mox;
							entity.motionZ = moz;
							//entity.motionY = y;
							entity.move(MoverType.PLAYER, entity.motionX, entity.motionY, entity.motionZ);
						}
						{
							boolean extime = false;
							for(int xx = 0; xx < 2; ++xx){
								for(int zz = 0; zz < 2; ++zz){
									{
										//BlockPos pos0 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 0,entity.posZ + lock.z * zz);
										BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 1,entity.posZ + lock.z * zz);
										if ( getBlockfalse(entity.world.getBlockState(pos1).getBlock())) {
											extime = true;
										}
									}
								}
							}
							if(extime){
								++entity.w5barst;
								entity.swingArm(EnumHand.MAIN_HAND);
								{
									if(entity.getAIType3() == 1) {
										if (!entity.world.isRemote) {
											for(int xx = 0; xx < 2; ++xx){
												for(int zz = 0; zz < 2; ++zz){
													BlockPos pos0 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 0,entity.posZ + lock.z * zz);
													BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 1,entity.posZ + lock.z * zz);
														{
							        						IBlockState iblockstate = entity.world.getBlockState(pos0);
							        		                Block block = iblockstate.getBlock();
							        		                if (iblockstate.getMaterial() != Material.AIR 
							        		                		&& (entity.w5barst >= block.getBlockHardness(iblockstate, entity.world, pos0) * 100))
							        		                {
							        		                    block.dropBlockAsItemWithChance(entity.world, pos0, entity.world.getBlockState(pos0), 1.0F, 0);
							        		                    entity.world.setBlockToAir(pos0);
							        		                    entity.w5barst = 0;
							        		                }
														}
														{
							        						IBlockState iblockstate = entity.world.getBlockState(pos1);
							        		                Block block = iblockstate.getBlock();
							        		                if (iblockstate.getMaterial() != Material.AIR
							        		                		&& (entity.w5barst >= block.getBlockHardness(iblockstate, entity.world, pos1) * 100))
							        		                {
							        		                    block.dropBlockAsItemWithChance(entity.world, pos1, entity.world.getBlockState(pos1), 1.0F, 0);
							        		                    entity.world.setBlockToAir(pos1);
							        		                    entity.w5barst = 0;
							        		                }
														}
												}
											}
						    			}
									}else if(entity.w5barst >= 200){
										if (!entity.world.isRemote) {
											BlockPos pos1 = new BlockPos(entity.posX, entity.posY - 0,entity.posZ);
											entity.world.setBlockState(pos1, Blocks.PLANKS.getDefaultState(), 2);
											entity.setPositionAndUpdate(entity.posX, entity.posY + 1.5D,entity.posZ);
						    			}
										entity.w5barst = 0;
									}
									
								}
							}else{
								entity.w5barst = 0;
							}
						}
					}
				}else if(id == 1 && !entity.isRiding()) {
					double mox = 0;
					double moy = entity.motionY;
					double moz = 0;
					mox -= MathHelper.sin(yaw) * speed * 0.75;
					moz += MathHelper.cos(yaw) * speed * 0.75;
					if(entity.cooltime4 > 40){
						
						for(int xx = 0; xx < 2; ++xx){
							for(int zz = 0; zz < 2; ++zz){
								//for(int yy = 0; yy < 3; ++yy)
								{
									BlockPos pos0 = new BlockPos(entity.posX + lock.x * xx, entity.posY - 0,entity.posZ + lock.z * zz);
									BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY - 1,entity.posZ + lock.z * zz);
									BlockPos pos2 = new BlockPos(entity.posX + lock.x * xx, entity.posY - 2,entity.posZ + lock.z * zz);
									if (getBlock(entity.world.getBlockState(pos0).getBlock())
											&& getBlock(entity.world.getBlockState(pos1).getBlock())
											&& getBlock(entity.world.getBlockState(pos2).getBlock())) {
										entity.swingArm(EnumHand.MAIN_HAND);
										entity.cooltime4 = 0;
										entity.world.setBlockState(pos1, Blocks.PLANKS.getDefaultState(), 2);
									}
								}
								{
									BlockPos pos0 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 0,entity.posZ + lock.z * zz);
									BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 1,entity.posZ + lock.z * zz);
									BlockPos pos2 = new BlockPos(entity.posX + lock.x * (xx - 1), entity.posY + 0,entity.posZ + lock.z * (zz - 1));
									BlockPos pos3 = new BlockPos(entity.posX + lock.x * (xx - 1), entity.posY + 1,entity.posZ + lock.z * (zz - 1));
									if ((entity.world.getBlockState(pos0).getBlock() != Blocks.AIR 
											&& entity.world.getBlockState(pos0).getBlock() != Blocks.LADDER 
											&& entity.world.getBlockState(pos2).getBlock() != Blocks.LADDER)
											&&(entity.world.getBlockState(pos1).getBlock() != Blocks.AIR 
											&& entity.world.getBlockState(pos1).getBlock() != Blocks.LADDER
											&& entity.world.getBlockState(pos3).getBlock() != Blocks.LADDER)) {
										entity.swingArm(EnumHand.MAIN_HAND);
										entity.cooltime4 = 0;
										int meta =2;
										EnumFacing enumfacing1 = entity.getAdjustedHorizontalFacing();
										if(enumfacing1 == EnumFacing.NORTH)meta = 3;//2
										if(enumfacing1 == EnumFacing.SOUTH)meta = 2;//3
										if(enumfacing1 == EnumFacing.WEST)meta = 5;//4
										if(enumfacing1 == EnumFacing.EAST)meta = 4;//5
										//System.out.println(String.format("%1$3d", meta));
										EnumFacing enumfacing = EnumFacing.getFront(meta);
										if(enumfacing1 != null && enumfacing != null) {
										entity.world.setBlockState(pos2, Blocks.LADDER.getDefaultState().withProperty(FACING, enumfacing), 2);
										entity.world.setBlockState(pos3,Blocks.LADDER.getDefaultState().withProperty(FACING, enumfacing), 2);
										}
									}
								}
								{
									BlockPos pos2 = new BlockPos(entity.posX, entity.posY + entity.height,entity.posZ);
									BlockPos pos11 = new BlockPos(entity.posX + lock.x * xx, entity.posY +0,entity.posZ + lock.z * zz);
									BlockPos pos12 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 1,entity.posZ + lock.z * zz);
									if (entity.world.getBlockState(pos2).getBlock() != Blocks.AIR
											&& (entity.world.getBlockState(pos11).getBlock() != Blocks.LADDER
													&& entity.world.getBlockState(pos12).getBlock() != Blocks.LADDER)){
										{
											++entity.w5barst;
											entity.swingArm(EnumHand.MAIN_HAND);
											BlockPos pos0 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 0,entity.posZ + lock.z * zz);
											BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 1,entity.posZ + lock.z * zz);
											{
				        						IBlockState iblockstate = entity.world.getBlockState(pos1);
				        		                Block block = iblockstate.getBlock();
				        		                if (iblockstate.getMaterial() != Material.AIR
				        		                		&& (entity.w5barst >= block.getBlockHardness(iblockstate, entity.world, pos1) * 100))
				        		                {
				        		                    block.dropBlockAsItemWithChance(entity.world, pos1, entity.world.getBlockState(pos1), 1.0F, 0);
				        		                    entity.world.setBlockToAir(pos1);
				        		                    entity.w5barst = 0;
				        		                }
											}
											{
				        						IBlockState iblockstate = entity.world.getBlockState(pos0);
				        		                Block block = iblockstate.getBlock();
				        		                if (iblockstate.getMaterial() != Material.AIR
				        		                		&& (entity.w5barst >= block.getBlockHardness(iblockstate, entity.world, pos1) * 100))
				        		                {
				        		                    block.dropBlockAsItemWithChance(entity.world, pos0, entity.world.getBlockState(pos0), 1.0F, 0);
				        		                    entity.world.setBlockToAir(pos0);
				        		                    entity.w5barst = 0;
				        		                }
											}
											
										}
									}else {
										entity.w5barst = 0;
									}
								}
								
							}
						}
						
						{
							BlockPos pos0 = new BlockPos(entity.posX, entity.posY + 0,entity.posZ);
							BlockPos pos1 = new BlockPos(entity.posX, entity.posY + 1,entity.posZ);
							if (entity.world.getBlockState(pos0).getBlock() instanceof BlockLadder 
									|| entity.world.getBlockState(pos1).getBlock() instanceof BlockLadder) {
								entity.motionY = 0.2;
							}
							entity.motionX = mox;
							entity.motionZ = moz;
							//entity.motionY = y;
							entity.move(MoverType.PLAYER, entity.motionX, entity.motionY, entity.motionZ);
						}
					}
				}else if(id == 2) {
					double mox = 0;
					double moy = entity.motionY;
					double moz = 0;
					mox -= MathHelper.sin(yaw) * speed * 0.5;
					moz += MathHelper.cos(yaw) * speed * 0.5;
					{
						boolean extime = false;
						for(int xx = 0; xx < 2; ++xx){
							for(int zz = 0; zz < 2; ++zz){
								{
									BlockPos pos0 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 0,entity.posZ + lock.z * zz);
									BlockPos pos1 = new BlockPos(entity.posX + lock.x * xx, entity.posY + 1,entity.posZ + lock.z * zz);
									if ((entity.world.getBlockState(pos0).getBlock() != Blocks.AIR )
											&&(entity.world.getBlockState(pos1).getBlock() != Blocks.AIR)) {
										extime = true;
									}
								}
							}
						}
						if(extime){
							++entity.w5barst;
							entity.swingArm(EnumHand.MAIN_HAND);
							if(entity.w5barst >= 100) {
								if (!entity.world.isRemote) {
				    				GVCExplosionBase.ExplosionKai(entity, entity, entity.posX, entity.posY, entity.posZ, 3.5F, false,  true);
				    				if (!entity.world.isRemote) {
				    					entity.setDead();
				    				}
				    			}
								entity.w5barst = 0;
							}
						}else{
							entity.w5barst = 0;
						}
						{
							BlockPos pos0 = new BlockPos(entity.posX, entity.posY + 0,entity.posZ);
							if (entity.world.getBlockState(pos0).getBlock() instanceof BlockLadder) {
								entity.motionY = 0.2;
							}
							entity.motionX = mox;
							entity.motionZ = moz;
							//entity.motionY = y;
							entity.move(MoverType.PLAYER, entity.motionX, entity.motionY, entity.motionZ);
						}
					}
				}
				
			}
		} // 1
	}
	
	public static boolean getBlock(Block block) {
		boolean flag = false;
		if(block == Blocks.WATER
				|| block == Blocks.FLOWING_WATER
				|| block == Blocks.LAVA
				|| block == Blocks.FLOWING_LAVA
				|| block == Blocks.AIR) {
			flag = true;
		}
		return flag;
		
	}
	public static boolean getBlockfalse(Block block) {
		boolean flag = false;
		if(block != Blocks.WATER
				&& block != Blocks.FLOWING_WATER
				&& block != Blocks.LAVA
				&& block != Blocks.FLOWING_LAVA
				&& block != Blocks.AIR) {
			flag = true;
		}
		return flag;
		
	}
}

