001 package net.minecraft.entity.ai; 002 003 import java.util.Random; 004 import net.minecraft.entity.EntityCreature; 005 import net.minecraft.util.MathHelper; 006 import net.minecraft.util.Vec3; 007 import net.minecraft.world.World; 008 009 public class EntityAIFleeSun extends EntityAIBase 010 { 011 private EntityCreature theCreature; 012 private double shelterX; 013 private double shelterY; 014 private double shelterZ; 015 private float movementSpeed; 016 private World theWorld; 017 018 public EntityAIFleeSun(EntityCreature par1EntityCreature, float par2) 019 { 020 this.theCreature = par1EntityCreature; 021 this.movementSpeed = par2; 022 this.theWorld = par1EntityCreature.worldObj; 023 this.setMutexBits(1); 024 } 025 026 /** 027 * Returns whether the EntityAIBase should begin execution. 028 */ 029 public boolean shouldExecute() 030 { 031 if (!this.theWorld.isDaytime()) 032 { 033 return false; 034 } 035 else if (!this.theCreature.isBurning()) 036 { 037 return false; 038 } 039 else if (!this.theWorld.canBlockSeeTheSky(MathHelper.floor_double(this.theCreature.posX), (int)this.theCreature.boundingBox.minY, MathHelper.floor_double(this.theCreature.posZ))) 040 { 041 return false; 042 } 043 else 044 { 045 Vec3 var1 = this.findPossibleShelter(); 046 047 if (var1 == null) 048 { 049 return false; 050 } 051 else 052 { 053 this.shelterX = var1.xCoord; 054 this.shelterY = var1.yCoord; 055 this.shelterZ = var1.zCoord; 056 return true; 057 } 058 } 059 } 060 061 /** 062 * Returns whether an in-progress EntityAIBase should continue executing 063 */ 064 public boolean continueExecuting() 065 { 066 return !this.theCreature.getNavigator().noPath(); 067 } 068 069 /** 070 * Execute a one shot task or start executing a continuous task 071 */ 072 public void startExecuting() 073 { 074 this.theCreature.getNavigator().tryMoveToXYZ(this.shelterX, this.shelterY, this.shelterZ, this.movementSpeed); 075 } 076 077 private Vec3 findPossibleShelter() 078 { 079 Random var1 = this.theCreature.getRNG(); 080 081 for (int var2 = 0; var2 < 10; ++var2) 082 { 083 int var3 = MathHelper.floor_double(this.theCreature.posX + (double)var1.nextInt(20) - 10.0D); 084 int var4 = MathHelper.floor_double(this.theCreature.boundingBox.minY + (double)var1.nextInt(6) - 3.0D); 085 int var5 = MathHelper.floor_double(this.theCreature.posZ + (double)var1.nextInt(20) - 10.0D); 086 087 if (!this.theWorld.canBlockSeeTheSky(var3, var4, var5) && this.theCreature.getBlockPathWeight(var3, var4, var5) < 0.0F) 088 { 089 return this.theWorld.getWorldVec3Pool().getVecFromPool((double)var3, (double)var4, (double)var5); 090 } 091 } 092 093 return null; 094 } 095 }