| 1 | package net.minecraft.entity.ai;
|
| 2 |
|
| 3 | import net.minecraft.entity.EntityCreature;
|
| 4 | import net.minecraft.util.BlockPos;
|
| 5 | import net.minecraft.util.Vec3;
|
| 6 | import net.minecraft.village.Village;
|
| 7 | import net.minecraft.village.VillageDoorInfo;
|
| 8 |
|
| 9 | public class EntityAIMoveIndoors extends EntityAIBase
|
| 10 | {
|
| 11 | private EntityCreature entityObj;
|
| 12 | private VillageDoorInfo doorInfo;
|
| 13 | private int insidePosX = -1;
|
| 14 | private int insidePosZ = -1;
|
| 15 |
|
| 16 | public EntityAIMoveIndoors(EntityCreature entityObjIn)
|
| 17 | {
|
| 18 | this.entityObj = entityObjIn;
|
| 19 | this.setMutexBits(1);
|
| 20 | }
|
| 21 |
|
| 22 | /**
|
| 23 | * Returns whether the EntityAIBase should begin execution.
|
| 24 | */
|
| 25 | public boolean shouldExecute()
|
| 26 | {
|
| 27 | BlockPos blockpos = new BlockPos(this.entityObj);
|
| 28 |
|
| 29 | if ((!this.entityObj.worldObj.isDaytime() || this.entityObj.worldObj.isRaining() && !this.entityObj.worldObj.getBiomeGenForCoords(blockpos).canRain()) && !this.entityObj.worldObj.provider.getHasNoSky())
|
| 30 | {
|
| 31 | if (this.entityObj.getRNG().nextInt(50) != 0)
|
| 32 | {
|
| 33 | return false;
|
| 34 | }
|
| 35 | else if (this.insidePosX != -1 && this.entityObj.getDistanceSq((double)this.insidePosX, this.entityObj.posY, (double)this.insidePosZ) < 4.0D)
|
| 36 | {
|
| 37 | return false;
|
| 38 | }
|
| 39 | else
|
| 40 | {
|
| 41 | Village village = this.entityObj.worldObj.getVillageCollection().getNearestVillage(blockpos, 14);
|
| 42 |
|
| 43 | if (village == null)
|
| 44 | {
|
| 45 | return false;
|
| 46 | }
|
| 47 | else
|
| 48 | {
|
| 49 | this.doorInfo = village.getDoorInfo(blockpos);
|
| 50 | return this.doorInfo != null;
|
| 51 | }
|
| 52 | }
|
| 53 | }
|
| 54 | else
|
| 55 | {
|
| 56 | return false;
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Returns whether an in-progress EntityAIBase should continue executing
|
| 62 | */
|
| 63 | public boolean continueExecuting()
|
| 64 | {
|
| 65 | return !this.entityObj.getNavigator().noPath();
|
| 66 | }
|
| 67 |
|
| 68 | /**
|
| 69 | * Execute a one shot task or start executing a continuous task
|
| 70 | */
|
| 71 | public void startExecuting()
|
| 72 | {
|
| 73 | this.insidePosX = -1;
|
| 74 | BlockPos blockpos = this.doorInfo.getInsideBlockPos();
|
| 75 | int i = blockpos.getX();
|
| 76 | int j = blockpos.getY();
|
| 77 | int k = blockpos.getZ();
|
| 78 |
|
| 79 | if (this.entityObj.getDistanceSq(blockpos) > 256.0D)
|
| 80 | {
|
| 81 | Vec3 vec3 = RandomPositionGenerator.findRandomTargetBlockTowards(this.entityObj, 14, 3, new Vec3((double)i + 0.5D, (double)j, (double)k + 0.5D));
|
| 82 |
|
| 83 | if (vec3 != null)
|
| 84 | {
|
| 85 | this.entityObj.getNavigator().tryMoveToXYZ(vec3.xCoord, vec3.yCoord, vec3.zCoord, 1.0D);
|
| 86 | }
|
| 87 | }
|
| 88 | else
|
| 89 | {
|
| 90 | this.entityObj.getNavigator().tryMoveToXYZ((double)i + 0.5D, (double)j, (double)k + 0.5D, 1.0D);
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | /**
|
| 95 | * Resets the task
|
| 96 | */
|
| 97 | public void resetTask()
|
| 98 | {
|
| 99 | this.insidePosX = this.doorInfo.getInsideBlockPos().getX();
|
| 100 | this.insidePosZ = this.doorInfo.getInsideBlockPos().getZ();
|
| 101 | this.doorInfo = null;
|
| 102 | }
|
| 103 | }
|
| 104 |
|