BloodMagic/src/main/java/WayofTime/bloodmagic/entity/ai/EntityAIProtectAlly.java

98 lines
3 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.entity.ai;
2017-08-15 21:30:48 -07:00
import WayofTime.bloodmagic.entity.mob.EntityAspectedDemonBase;
import WayofTime.bloodmagic.entity.mob.EntityCorruptedSheep;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
2017-08-15 21:30:48 -07:00
import java.util.List;
public class EntityAIProtectAlly extends EntityAIBase {
/**
* The entity owner of this AITask
*/
private final EntityCorruptedSheep entity;
2017-08-15 21:30:48 -07:00
/**
* The world the grass eater entity is eating from
*/
private final World world;
2017-08-15 21:30:48 -07:00
/**
* Number of ticks since the entity started to eat grass
*/
int castTimer;
2017-08-15 21:30:48 -07:00
public EntityAIProtectAlly(EntityCorruptedSheep entity) {
this.entity = entity;
2016-12-12 19:56:36 -08:00
this.world = entity.getEntityWorld();
this.setMutexBits(7);
}
2017-08-15 21:30:48 -07:00
public int getCastTimer() {
return this.castTimer;
}
/**
* Returns whether the EntityAIBase should begin execution.
*/
@Override
2017-08-15 21:30:48 -07:00
public boolean shouldExecute() {
AxisAlignedBB bb = new AxisAlignedBB(entity.posX - 0.5, entity.posY - 0.5, entity.posZ - 0.5, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5).grow(5);
List<EntityLivingBase> list = world.getEntitiesWithinAABB(EntityLivingBase.class, bb, new EntityAspectedDemonBase.WillTypePredicate(entity.getType()));
2017-08-15 21:30:48 -07:00
for (EntityLivingBase testEntity : list) {
if (testEntity != this.entity) {
if (this.entity.canProtectAlly(testEntity)) {
return true;
}
}
}
return false;
}
/**
* Execute a one shot task or start executing a continuous task
*/
@Override
2017-08-15 21:30:48 -07:00
public void startExecuting() {
this.castTimer = 100;
this.world.setEntityState(this.entity, (byte) 53);
this.entity.getNavigator().clearPathEntity();
}
/**
* Resets the task
*/
@Override
2017-08-15 21:30:48 -07:00
public void resetTask() {
this.castTimer = 0;
}
/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
@Override
2017-08-15 21:30:48 -07:00
public boolean shouldContinueExecuting() {
return castTimer > 0;
}
/**
* Updates the task
*/
@Override
2017-08-15 21:30:48 -07:00
public void updateTask() {
this.castTimer = Math.max(0, this.castTimer - 1);
2017-08-15 21:30:48 -07:00
if (castTimer == 0) {
AxisAlignedBB bb = new AxisAlignedBB(entity.posX - 0.5, entity.posY - 0.5, entity.posZ - 0.5, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5).grow(5);
List<EntityLivingBase> list = world.getEntitiesWithinAABB(EntityLivingBase.class, bb, new EntityAspectedDemonBase.WillTypePredicate(entity.getType()));
2017-08-15 21:30:48 -07:00
for (EntityLivingBase testEntity : list) {
if (testEntity != this.entity) {
if (this.entity.applyProtectionToAlly(testEntity)) {
return;
}
}
}
}
}
}