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;
|
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-07 03:57:57 -06:00
|
|
|
if(!canFly() || this.isJumping){
|
2021-12-01 15:31:05 -06:00
|
|
|
super.onLivingUpdate();
|
|
|
|
|
return;
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 00:49:10 -06:00
|
|
|
double speed = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
|
|
|
|
|
double speedMult = 0.6000000238418579D/0.5D;
|
2021-12-01 15:31:05 -06:00
|
|
|
|
2021-12-05 15:04:03 -06:00
|
|
|
if(isEntityAlive()) {
|
|
|
|
|
if (!this.worldObj.isRemote) {
|
2021-12-07 03:57:57 -06:00
|
|
|
Entity target = this.getAttackTarget();
|
|
|
|
|
if (target != null && target.isEntityAlive()) {
|
|
|
|
|
double d0 = target.posX - this.posX;
|
|
|
|
|
double d1 = target.posY - this.posY;
|
|
|
|
|
double d2 = target.posZ - this.posZ;
|
|
|
|
|
double d4 = d0 * d0 + d1 * d1 + d2 * d2;
|
2021-12-01 15:31:05 -06:00
|
|
|
|
2021-12-06 00:10:10 -06:00
|
|
|
if(this.hurtTime == 0) {
|
2021-12-07 03:57:57 -06:00
|
|
|
if (this.posY != target.posY) {
|
|
|
|
|
if (this.motionY * Math.signum(this.posY - target.posY) > 0.0D) {
|
2021-12-06 00:10:10 -06:00
|
|
|
this.motionY = 0.0D;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-07 03:57:57 -06:00
|
|
|
this.motionY -= Math.signum(this.posY - target.posY) * (speed * speedMult) * this.ai.flySpeed;
|
2021-12-06 00:10:10 -06:00
|
|
|
}
|
|
|
|
|
|
2021-12-07 03:57:57 -06:00
|
|
|
if (d4 > 0.5D) {
|
|
|
|
|
double d5 = MathHelper.sqrt_double(d4);
|
2021-12-06 00:10:10 -06:00
|
|
|
this.motionX += (d0 / d5 * speed - this.motionX) * speed * speedMult;
|
|
|
|
|
this.motionZ += (d2 / d5 * speed - this.motionZ) * speed * speedMult;
|
|
|
|
|
}
|
2021-12-05 15:04:03 -06:00
|
|
|
}
|
2021-12-01 15:31:05 -06:00
|
|
|
|
2021-12-05 15:04:03 -06:00
|
|
|
this.rotationYaw = (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI));
|
2021-12-06 00:10:10 -06:00
|
|
|
} else {
|
|
|
|
|
if (!this.onGround && this.motionY < 0.0D)
|
|
|
|
|
{
|
|
|
|
|
this.motionY *= 0.6D;
|
|
|
|
|
}
|
2021-12-01 15:31:05 -06:00
|
|
|
}
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 15:04:03 -06:00
|
|
|
if (this.motionX * this.motionX + this.motionZ * this.motionZ > 0.05000000074505806D && isEntityAlive()) {
|
|
|
|
|
this.rotationYaw = (float) Math.atan2(this.motionZ, this.motionX) * (180F / (float) Math.PI) - 90.0F;
|
|
|
|
|
}
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 15:31:05 -06:00
|
|
|
super.onLivingUpdate();
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isOnLadder(){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-06-13 16:22:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|