001package net.minecraft.entity.ai; 002 003import java.util.Random; 004import net.minecraft.entity.EntityCreature; 005import net.minecraft.util.MathHelper; 006import net.minecraft.util.Vec3; 007import net.minecraft.world.World; 008 009public 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 vec3 = this.findPossibleShelter(); 046 047 if (vec3 == null) 048 { 049 return false; 050 } 051 else 052 { 053 this.shelterX = vec3.xCoord; 054 this.shelterY = vec3.yCoord; 055 this.shelterZ = vec3.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 random = this.theCreature.getRNG(); 080 081 for (int i = 0; i < 10; ++i) 082 { 083 int j = MathHelper.floor_double(this.theCreature.posX + (double)random.nextInt(20) - 10.0D); 084 int k = MathHelper.floor_double(this.theCreature.boundingBox.minY + (double)random.nextInt(6) - 3.0D); 085 int l = MathHelper.floor_double(this.theCreature.posZ + (double)random.nextInt(20) - 10.0D); 086 087 if (!this.theWorld.canBlockSeeTheSky(j, k, l) && this.theCreature.getBlockPathWeight(j, k, l) < 0.0F) 088 { 089 return this.theWorld.getWorldVec3Pool().getVecFromPool((double)j, (double)k, (double)l); 090 } 091 } 092 093 return null; 094 } 095}