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