Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uk.co.ijay.earlyfuture.entity.ai;
- import uk.co.ijay.earlyfuture.EarlyFuture;
- import net.minecraft.entity.EntityCreature;
- import net.minecraft.entity.ai.EntityAIBase;
- import net.minecraft.world.World;
- public abstract class EntityAIMoveToBlock extends EntityAIBase
- {
- private final EntityCreature entityCreature;
- private final double field_179492_d;
- protected int field_179496_a;
- private int field_179493_e;
- private int field_179490_f;
- protected int destinationBlockX;
- protected int destinationBlockY;
- protected int destinationBlockZ;
- private boolean field_179491_g;
- private int field_179497_h;
- private static final String __OBFID = "CL_00002252";
- public EntityAIMoveToBlock(EntityCreature p_i45888_1_, double p_i45888_2_, int p_i45888_4_)
- {
- this.destinationBlockX = 0;
- this.destinationBlockY = 0;
- this.destinationBlockZ = 0;
- this.entityCreature = p_i45888_1_;
- this.field_179492_d = p_i45888_2_;
- this.field_179497_h = p_i45888_4_;
- this.setMutexBits(5);
- }
- @Override
- public boolean shouldExecute()
- {
- EarlyFuture.LOG.info("Called shouldExecute()");
- if(this.field_179496_a > 0)
- {
- --this.field_179496_a;
- return false;
- }
- else
- {
- EarlyFuture.LOG.info("Got past the first hurdle");
- this.field_179496_a = 200 + this.entityCreature.getRNG().nextInt(200);
- return this.func_179489_g();
- }
- }
- @Override
- public boolean continueExecuting()
- {
- return this.field_179493_e >= -this.field_179490_f
- && this.field_179493_e <= 1200
- && this.isTargetBlock(this.entityCreature.worldObj, this.destinationBlockX, this.destinationBlockY,
- this.destinationBlockZ);
- }
- @Override
- public void startExecuting()
- {
- this.entityCreature.getNavigator().tryMoveToXYZ((double) ((float) this.destinationBlockX) + 0.5D,
- (double) (this.destinationBlockY + 1), (double) ((float) this.destinationBlockZ) + 0.5D,
- this.field_179492_d);
- this.field_179493_e = 0;
- this.field_179490_f = this.entityCreature.getRNG().nextInt(this.entityCreature.getRNG().nextInt(1200) + 1200) + 1200;
- }
- @Override
- public void resetTask()
- {
- }
- @Override
- public void updateTask()
- {
- if(this.entityCreature.getDistanceSq(this.destinationBlockX + 0.5D, this.destinationBlockY + 1.5D,
- this.destinationBlockZ + 0.5D) > 1.0D)
- {
- this.field_179491_g = false;
- ++this.field_179493_e;
- if(this.field_179493_e % 40 == 0)
- {
- this.entityCreature.getNavigator().tryMoveToXYZ((double) ((float) this.destinationBlockX) + 0.5D,
- (double) (this.destinationBlockY + 1), (double) ((float) this.destinationBlockZ) + 0.5D,
- this.field_179492_d);
- }
- }
- else
- {
- this.field_179491_g = true;
- --this.field_179493_e;
- }
- }
- protected boolean func_179487_f()
- {
- return this.field_179491_g;
- }
- private boolean func_179489_g()
- {
- int i = this.field_179497_h;
- boolean flag = true;
- double posX = this.entityCreature.posX;
- double posY = this.entityCreature.posY;
- double posZ = this.entityCreature.posZ;
- for(int j = 0; j <= 1; j = j > 0 ? -j : 1 - j)
- {
- for(int k = 0; k < i; ++k)
- {
- for(int l = 0; l <= k; l = l > 0 ? -l : 1 - l)
- {
- for(int i1 = l < k && l > -k ? k : 0; i1 <= k; i1 = i1 > 0 ? -i1 : 1 - i1)
- {
- double posX1 = posX + l;
- double posY1 = posY + j - 1;
- double posZ1 = posZ + i1;
- if(this.entityCreature.isWithinHomeDistance((int) posX1, (int) posY1, (int) posZ1)
- && this.isTargetBlock(this.entityCreature.worldObj, posX1, posY1, posZ1))
- {
- this.destinationBlockX = (int) posX1;
- this.destinationBlockY = (int) posY1;
- this.destinationBlockZ = (int) posZ1;
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- protected abstract boolean isTargetBlock(World worldIn, double targetX, double targetY, double targetZ);
- }
Advertisement
Add Comment
Please, Sign In to add comment