Skip to content

Commit

Permalink
7.1.6.27: AISwimming: not to follow too close in the water,
Browse files Browse the repository at this point in the history
- excepts BegMove
- close #18
  • Loading branch information
Verclene committed Apr 27, 2016
1 parent 019c9bc commit 29f18a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ public boolean shouldExecute() {
*/
public boolean continueExecuting() {
toDistance = theMaid.getDistanceSqToEntity(theOwner);
if(theMaid.handleWaterMovement())
return !theMaid.isMaidWait()&&!theMaid.isSitting();
// if(theMaid.handleWaterMovement()) return !theMaid.isMaidWait()&&!theMaid.isSitting();
return !theMaid.getNavigator().noPath()
&&(toDistance > getMaxDist())
&& (toDistance > getMaxDist())
&& !theMaid.isSitting();
}

Expand Down Expand Up @@ -92,8 +91,9 @@ public void resetTask() {
* Updates the task
*/
public void updateTask() {
theMaid.getLookHelper().setLookPositionWithEntity(theOwner, 10F,
theMaid.getVerticalFaceSpeed());
if (toDistance - getMaxDist() > 1.0) {
theMaid.getLookHelper().setLookPositionWithEntity(theOwner, 10F, theMaid.getVerticalFaceSpeed());
}

if (theMaid.isSitting()) {
return;
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/net/blacklab/lmr/entity/ai/EntityAILMSwimming.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.blacklab.lmr.entity.ai;

import net.blacklab.lmr.LittleMaidReengaged;
import net.blacklab.lmr.entity.EntityLittleMaid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
Expand All @@ -21,12 +22,7 @@ public EntityAILMSwimming(EntityLiving par1EntityLiving) {

@Override
public boolean shouldExecute() {
if(theEntity instanceof EntityLittleMaid){
if(theEntity.isInWater()) return true;
}
return ((theEntity.getNavigator().noPath() ?
(theEntity.isInsideOfMaterial(Material.water)) : theEntity.isInWater())
|| theEntity.isInLava());
return theEntity.isInWater() || theEntity.isInsideOfMaterial(Material.water) || theEntity.isInLava();
}

@Override
Expand All @@ -41,39 +37,44 @@ public void updateTask() {
}
EntityLittleMaid theMaid = (EntityLittleMaid) theEntity;
if(theMaid.isInWater()){
double xd = theEntity.posX;
double yd = theEntity.getEntityBoundingBox().minY;
double zd = theEntity.posZ;
double xd = theMaid.posX;
double yd = theMaid.getEntityBoundingBox().minY;
double zd = theMaid.posZ;
int x = MathHelper.floor_double(xd);
int z = MathHelper.floor_double(zd);
int y = MathHelper.floor_double(yd);
totalmotionY+= 0.05D*MathHelper.cos(theEntity.ticksExisted/8f);
// if(theEntity.worldObj.isAnyLiquid(new AxisAlignedBB(x, y, z, x, y+h+1, z))){
totalmotionY+= 0.03D * MathHelper.cos(theMaid.ticksExisted/16f);
// if(theMaid.worldObj.isAnyLiquid(new AxisAlignedBB(x, y, z, x, y+h+1, z))){
// totalmotionY += 0.05D;
// }

PathPoint pathPoint = null;
PathEntity pathEntity = theMaid.getPrevPathEntity();
PathEntity pathEntity = theMaid.getNavigator().getPath();

// Main AI
if(pathEntity!=null){
pathPoint = pathEntity.getFinalPathPoint();
theEntity.motionX = ((pathPoint.xCoord>x)?1:(pathPoint.xCoord<x)?-1:0) * theEntity.getAIMoveSpeed()/5d;
theEntity.motionZ = ((pathPoint.zCoord>z)?1:(pathPoint.zCoord<z)?-1:0) * theEntity.getAIMoveSpeed()/5d;
totalmotionY += ((pathPoint.yCoord>=y)?1:-1) * theEntity.getAIMoveSpeed()/5d;
theMaid.motionX = ((pathPoint.xCoord>x)?1:(pathPoint.xCoord<x)?-1:0) * theMaid.getAIMoveSpeed()/5d;
theMaid.motionZ = ((pathPoint.zCoord>z)?1:(pathPoint.zCoord<z)?-1:0) * theMaid.getAIMoveSpeed()/5d;
totalmotionY += ((pathPoint.yCoord>=y)?1:-1) * theMaid.getAIMoveSpeed()/3d;
}

if(theMaid.isInWater()){
IBlockState iState;

// Going ashore
if (pathPoint != null && Math.abs(pathPoint.yCoord - yd) < 3d && Math.pow(pathPoint.xCoord - xd, 2) + Math.pow(pathPoint.zCoord - zd, 2) < 9d &&
(iState = theMaid.worldObj.getBlockState(new BlockPos(pathPoint.xCoord,pathPoint.yCoord,pathPoint.zCoord))).getBlock().getMaterial(iState) != Material.water) {
totalmotionY += 0.1D;
theMaid.motionX *= 2d;
theMaid.motionZ *= 2d;
}
theEntity.motionY = totalmotionY;
}else{
theEntity.motionY = 0.04D;
theMaid.motionY = totalmotionY;
}
// Breathing
if (theMaid.getAir() == 0) {
theEntity.motionY += 0.2D;
LittleMaidReengaged.Debug("Breathing float");
theMaid.motionY += 0.1D;
}
}
}
Expand Down

0 comments on commit 29f18a5

Please sign in to comment.