PathNavigateFlying:

-Fixed pathfinder running into lava & water when it shouldn't.
FlyPathFinder:
-Simplified nodeTypeToOffset switch statement, removed unused function, and made air always return an open path node type.
EntityNPCInterface:
-Fixed "In Air" drowning type. Breathes underwater now.
EntityNPCFlying:
-Fixed NPCs still using flight movement when not being able to breathe.
ICustomNpc:
-Added canBreathe() function
This commit is contained in:
Luis C.M committed 2022-11-12 15:53:20 -06:00
1 parent aa4b1dd9fb
commit d86f571df6
6 files changed
+53 -37

No files matched your search

@@ -473,40 +473,30 @@ public class FlyPathFinder extends PathFinder
public int nodeTypeToOffset(PathNodeType nodeType) {
switch (nodeType) {
case BLOCKED:
return 0;
case OPEN:
return 2;
case WALKABLE:
return 1;
case TRAPDOOR:
return -4;
case FENCE:
return -3;
case LAVA:
return -2;
case WATER:
return -1;
case RAIL:
return 2;
case DANGER_FIRE:
return -1;
case DAMAGE_FIRE:
return -2;
case DANGER_CACTUS:
return -1;
case DAMAGE_CACTUS:
return -2;
case DANGER_OTHER:
return -1;
case DAMAGE_OTHER:
return -2;
case DOOR_OPEN:
return 1;
case WATER:
case DANGER_FIRE:
case DANGER_CACTUS:
case DANGER_OTHER:
return -1;
case BLOCKED:
case DOOR_WOOD_CLOSED:
return 0;
case DOOR_IRON_CLOSED:
return 0;
case WALKABLE:
case DOOR_OPEN:
return 1;
case OPEN:
case RAIL:
return 2;
}
return 1;
@@ -526,12 +516,6 @@ public class FlyPathFinder extends PathFinder
return pathpoint;
}
public NPCPathPoint getPointFromHash(int x, int y, int z)
{
int i = NPCPathPoint.makeHash(x, y, z);
return this.pointMap.lookup(i);
}
/**
* Returns a new FlyPathEntity for a given start and end point
*/
@@ -721,7 +705,7 @@ public class FlyPathFinder extends PathFinder
if (material == Material.air)
{
return drowningType == 2 ? PathNodeType.WATER : PathNodeType.OPEN;
return PathNodeType.OPEN;
}
else if (block != Blocks.trapdoor && block != Blocks.waterlily)
{
@@ -1,6 +1,7 @@
package noppes.npcs.ai.pathfinder;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.SharedMonsterAttributes;
@@ -438,7 +439,7 @@ public class PathNavigateFlying extends PathNavigate {
{
Vec3 pos17 = Vec3.createVectorHelper(startPos.xCoord,startPos.yCoord, startPos.zCoord);
Vec3 pos18 = Vec3.createVectorHelper(endPos.xCoord,endPos.yCoord, endPos.zCoord);
if (this.rayTraceBlocks(pos17, pos18, false, false, false, width, height))
if (this.rayTraceBlocks(pos17, pos18, true, false, false, width, height))
return false;
return true;
@@ -656,15 +657,19 @@ public class PathNavigateFlying extends PathNavigate {
Block block2 = this.worldObj.getBlock(l, i1, j1);
int meta2 = this.worldObj.getBlockMetadata(l, i1, j1);
if (block2 != Blocks.air && (!p_147447_4_ || block2.getCollisionBoundingBoxFromPool(this.worldObj, l, i1, j1) != null)
if ((!p_147447_4_ || block2.getCollisionBoundingBoxFromPool(this.worldObj, l, i1, j1) != null)
&& block2.canCollideCheck(meta2, p_147447_3_)) {
if (!block2.getBlocksMovement(this.worldObj, l, i1, j1)) {
if (block2.getMaterial() == Material.lava && !this.theEntity.isImmuneToFire() ||
block2.getMaterial() == Material.air && this.theEntity.stats.drowningType == 2 ||
block2.getMaterial() == Material.water && this.theEntity.stats.drowningType == 1 ||
!block2.getBlocksMovement(this.worldObj, l, i1, j1)) {
value = true;
l -= x;
i1 -= y;
j1 -= z;
break;
}
MovingObjectPosition movingobjectposition = block2.collisionRayTrace(this.worldObj, l, i1, j1, p_147447_1_, p_147447_2_);
if (movingobjectposition != null && movingobjectposition.typeOfHit != MovingObjectPosition.MovingObjectType.MISS) {
@@ -35,7 +35,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_)
{
if(!this.canFly() || this.hurtTime != 0) {
if(!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) {
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
return;
}
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.util.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.*;
@@ -415,10 +416,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
}
}
public boolean canBreathe() {
return this.isInWater() && this.stats.drowningType == 2 || !this.isInWater() && this.stats.drowningType == 1 || this.stats.drowningType == 0;
}
@Override
protected void updateAITasks()
{
if (this.isInWater() || this.stats.drowningType != 2) {
if (this.canBreathe()) {
this.getNavigator().onUpdateNavigation();
this.getMoveHelper().onUpdateMoveHelper();
try {
@@ -1054,7 +1059,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
this.setRevengeTarget(null);
this.deathTime = 0;
//fleeingTick = 0;
if(ai.returnToStart && !hasOwner())
if(ai.returnToStart && !hasOwner() && !this.isRemote())
setLocationAndAngles(getStartXPos(), getStartYPos(), getStartZPos(), rotationYaw, rotationPitch);
killedtime = 0;
extinguish();
@@ -1351,7 +1356,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
}
if (yy <= 0)
setDead();
yy += 0.5;
//yy += 0.5;
return yy;
}
@@ -1632,7 +1637,23 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
public boolean handleWaterMovement()
{
return stats.drowningType == 1 && super.handleWaterMovement();
if (stats.drowningType != 1) {
if (this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.4000000059604645D, 0.0D).contract(0.001D, 0.001D, 0.001D), Material.water, this)) {
this.fallDistance = 0.0F;
this.inWater = true;
this.setFire(0);
} else {
this.inWater = false;
}
return false;
} else {
return super.handleWaterMovement();
}
}
public boolean canBreatheUnderwater()
{
return stats.drowningType != 1;
}
public void setAvoidWater(boolean avoidWater) {
@@ -1071,6 +1071,10 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
npc.stats.drowningType = type;
}
public boolean canBreathe() {
return npc.canBreathe();
}
@Override
public long getAge(){
return npc.totalTicksAlive;
@@ -371,6 +371,8 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
*/
void setDrowningType(int type);
boolean canBreathe();
/**
* @param type The AnimationType
*/