Added a modifiable and toggleable flying height limit to NPCs

This commit is contained in:
luisc committed 2022-01-13 05:28:20 -06:00
1 parent 04def38b63
commit 555ceb741f
5 files changed
+81 -6

No files matched your search

@@ -3,6 +3,7 @@ package noppes.npcs.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@@ -36,10 +37,26 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
return;
}
int blockY = (int) this.posY;
double heightOffGround = 0;
if(this.ai.hasFlyLimit) {
for (blockY = (int) this.posY; blockY > 0; blockY--) {
heightOffGround = this.posY - blockY;
if (this.worldObj.getBlock((int) this.posX, blockY, (int) this.posZ) != Blocks.air || heightOffGround > this.ai.flyHeightLimit){
break;
}
}
}
if (!this.onGround && !this.velocityChanged && this.motionY < 0 && this.hurtTime == 0)
{
this.motionY *= this.ai.flyGravity;
this.velocityChanged = true;
if(heightOffGround >= this.ai.flyHeightLimit && this.ai.hasFlyLimit){
this.motionY *= 0.8D;
this.velocityChanged = true;
} else {
this.motionY *= this.ai.flyGravity;
this.velocityChanged = true;
}
}
}