2021-06-13 16:22:06 -04:00
|
|
|
package noppes.npcs.entity;
|
|
|
|
|
|
2021-12-01 15:31:05 -06:00
|
|
|
import net.minecraft.entity.Entity;
|
2021-12-03 00:49:10 -06:00
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
|
|
|
import net.minecraft.entity.ai.EntityAISwimming;
|
2022-01-13 05:28:20 -06:00
|
|
|
import net.minecraft.init.Blocks;
|
2021-06-13 16:22:06 -04:00
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
public abstract class EntityNPCFlying extends EntityNPCInterface {
|
|
|
|
|
|
|
|
|
|
public EntityNPCFlying(World world) {
|
|
|
|
|
super(world);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 00:48:03 -04:00
|
|
|
@Override
|
|
|
|
|
public boolean canFly(){
|
|
|
|
|
return ai.movementType == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void fall(float distance) {
|
|
|
|
|
if(!canFly())
|
|
|
|
|
super.fall(distance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void updateFallState(double p_180433_1_, boolean p_180433_3_) {
|
|
|
|
|
if(!canFly())
|
|
|
|
|
super.updateFallState(p_180433_1_, p_180433_3_);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 15:31:05 -06:00
|
|
|
public void onLivingUpdate()
|
|
|
|
|
{
|
2021-12-08 04:41:41 -06:00
|
|
|
super.onLivingUpdate();
|
|
|
|
|
if(!canFly()){
|
2021-12-01 15:31:05 -06:00
|
|
|
return;
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-01-13 05:28:20 -06:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:43:27 -06:00
|
|
|
if (!this.onGround && !this.velocityChanged && this.motionY < 0 && this.hurtTime == 0)
|
2021-12-08 04:00:28 -06:00
|
|
|
{
|
2022-01-13 05:28:20 -06:00
|
|
|
if(heightOffGround >= this.ai.flyHeightLimit && this.ai.hasFlyLimit){
|
|
|
|
|
this.motionY *= 0.8D;
|
|
|
|
|
this.velocityChanged = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.motionY *= this.ai.flyGravity;
|
|
|
|
|
this.velocityChanged = true;
|
|
|
|
|
}
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isOnLadder(){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-06-13 16:22:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|