Skip to content

Commit

Permalink
Initial port of "fear" ai module over to new system (#17, #22).
Browse files Browse the repository at this point in the history
  • Loading branch information
allaryin committed Mar 14, 2016
1 parent 1b415df commit 2a78dd6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 27 deletions.
73 changes: 71 additions & 2 deletions src/main/java/fairies/ai/FairyAIFear.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,82 @@
package fairies.ai;

import fairies.FairyConfig;
import fairies.FairyFactions;
import fairies.entity.EntityFairy;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.pathfinding.PathEntity;

public class FairyAIFear extends EntityAIBase {

private EntityFairy theFairy;
protected double speed;

public FairyAIFear(EntityFairy fairy, double speedIn) {
this.theFairy = fairy;
this.speed = speedIn;

this.setMutexBits(1);
}

@Override
public boolean shouldExecute() {
// TODO Auto-generated method stub
return false;
EntityLivingBase entityFear = this.theFairy.getEntityFear();
if( entityFear == null ) {
return false;
} else if( entityFear.isDead ) {
this.theFairy.setEntityFear(null);
return false;
} else if( !this.theFairy.hasPath()
&& this.theFairy.canEntityBeSeen(entityFear)
&& this.theFairy.willCower() ) {

float dist = this.theFairy.getDistanceToEntity(entityFear);
if( dist > FairyConfig.BEHAVIOR_FEAR_RANGE ) {
return false;
}
}
return true;
}

@Override
public void startExecuting() {
FairyFactions.LOGGER.debug(this.theFairy.toString()+": starting fear");
final PathEntity dest = this.theFairy.roam(this.theFairy.getEntityFear(), this.theFairy, EntityFairy.PATH_AWAY);
this.theFairy.setCryTime( this.theFairy.getCryTime() + 120 );
this.theFairy.getNavigator().setPath(dest, this.speed);
}

@Override
public boolean continueExecuting() {
return !this.theFairy.getNavigator().noPath();
}

/*
* Original fear handler method from EntityFairy
*
private void handleFear() {
if (getEntityFear() != null) {
if (getEntityFear().isDead) {
// Don't fear the dead.
setEntityFear(null);
} else if (!hasPath() && canEntityBeSeen(getEntityFear())
&& willCower()) {
float dist = getDistanceToEntity(getEntityFear());
// Run from entityFear if you can see it and it is close.
if (dist < FairyConfig.BEHAVIOR_FEAR_RANGE) {
PathEntity dest = roam(getEntityFear(), this, PATH_AWAY);
if (dest != null) {
// setPathToEntity(dest);
this.getNavigator().setPath(dest, this.getAIMoveSpeed());
setCryTime(getCryTime() + 120);
}
}
}
}
}
*/

}
28 changes: 3 additions & 25 deletions src/main/java/fairies/entity/EntityFairy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fairies.FairyFactions;
import fairies.Loc;
import fairies.Version;
import fairies.ai.FairyAIFear;
import fairies.ai.FairyJob;
import fairies.world.FairyGroupGenerator;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -105,12 +106,10 @@ public EntityLivingBase getEntityToAttack() {
public float sinage; // what does this mean?
//private boolean flag; // flagged for what, precisely?
private boolean createGroup;
private int listActions;
public int witherTime;
private ItemStack tempItem;
private boolean isSwinging;
private int particleCount;
private boolean flyBlocked;

public EntityFairy(World world) {
super(world);
Expand Down Expand Up @@ -141,6 +140,8 @@ public boolean apply(Entity p_apply_1_)
}));
this.targetTasks.addTask(5, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, false));
*/

this.tasks.addTask(2, new FairyAIFear(this, 2.0D));

// fairy-specific init
setSkin(rand.nextInt(4));
Expand Down Expand Up @@ -923,29 +924,6 @@ && canEntityBeSeen(fairy)) {
}
}

private void handleFear() {
if (getEntityFear() != null) {
if (getEntityFear().isDead) {
// Don't fear the dead.
setEntityFear(null);
} else if (!hasPath() && canEntityBeSeen(getEntityFear())
&& willCower()) {
float dist = getDistanceToEntity(getEntityFear());

// Run from entityFear if you can see it and it is close.
if (dist < FairyConfig.BEHAVIOR_FEAR_RANGE) {
PathEntity dest = roam(getEntityFear(), this, PATH_AWAY);

if (dest != null) {
// setPathToEntity(dest);
this.getNavigator().setPath(dest, this.getAIMoveSpeed());
setCryTime(getCryTime() + 120);
}
}
}
}
}

private void handleRuler() {
// TODO: create constants for all of these ranges and time limits

Expand Down

0 comments on commit 2a78dd6

Please sign in to comment.