2021-06-13 16:22:06 -04:00
|
|
|
package noppes.npcs.entity;
|
|
|
|
|
|
2022-11-15 00:31:58 -05:00
|
|
|
import net.minecraft.util.MathHelper;
|
2022-11-14 20:22:50 -06:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
|
import net.minecraft.util.Vec3;
|
2021-06-13 16:22:06 -04:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
public abstract class EntityNPCFlying extends EntityNPCInterface {
|
|
|
|
|
|
2022-11-07 13:01:57 -06:00
|
|
|
public boolean flyLimitAllow = false;
|
|
|
|
|
|
2022-11-15 00:48:35 -05:00
|
|
|
public EntityNPCFlying(World world) {
|
|
|
|
|
super(world);
|
|
|
|
|
}
|
2021-06-13 16:22:06 -04:00
|
|
|
|
2022-11-15 00:48:35 -05:00
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public boolean canFly() {
|
2025-02-10 21:32:55 -05:00
|
|
|
return ais.movementType == 1;
|
2022-11-15 00:48:35 -05:00
|
|
|
}
|
2021-07-10 00:48:03 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void fall(float distance) {
|
2025-03-12 20:12:01 -04:00
|
|
|
if (!canFly())
|
2022-11-15 00:48:35 -05:00
|
|
|
super.fall(distance);
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void updateFallState(double p_180433_1_, boolean p_180433_3_) {
|
2025-03-12 20:12:01 -04:00
|
|
|
if (!canFly())
|
2022-11-15 00:48:35 -05:00
|
|
|
super.updateFallState(p_180433_1_, p_180433_3_);
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-02-22 01:52:47 -06:00
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public boolean isOnLadder() {
|
2022-02-22 01:52:47 -06:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 14:08:14 -04:00
|
|
|
@Override
|
|
|
|
|
public void onLivingUpdate() {
|
|
|
|
|
super.onLivingUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-06 00:20:22 -05:00
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_) {
|
2025-11-06 00:20:22 -05:00
|
|
|
if (handleMountedMovement(p_70612_1_, p_70612_2_))
|
|
|
|
|
return;
|
2025-03-12 20:12:01 -04:00
|
|
|
if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) {
|
2022-11-15 00:48:35 -05:00
|
|
|
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
|
2021-12-01 15:31:05 -06:00
|
|
|
return;
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-14 20:22:50 -06:00
|
|
|
boolean aboveLimit = false;
|
2022-11-04 23:56:09 -05:00
|
|
|
double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ);
|
2022-11-14 20:22:50 -06:00
|
|
|
if (heightOffGround < 0) {
|
2025-03-12 20:12:01 -04:00
|
|
|
Vec3 pos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
|
|
|
|
Vec3 posLimit = Vec3.createVectorHelper(this.posX, this.posY - this.ais.flyHeightLimit, this.posZ);
|
|
|
|
|
MovingObjectPosition mob = this.worldObj.rayTraceBlocks(pos, posLimit, true);
|
2022-11-14 20:22:50 -06:00
|
|
|
if (mob == null || mob.typeOfHit == MovingObjectPosition.MovingObjectType.MISS) {
|
|
|
|
|
aboveLimit = true;
|
|
|
|
|
}
|
2025-02-10 21:32:55 -05:00
|
|
|
} else if (heightOffGround > this.ais.flyHeightLimit) {
|
2022-11-14 20:22:50 -06:00
|
|
|
aboveLimit = true;
|
|
|
|
|
}
|
2025-02-10 21:32:55 -05:00
|
|
|
if (aboveLimit && this.ais.hasFlyLimit || (heightOffGround < Math.ceil(this.height) && this.motionY == 0)) {
|
2022-11-07 13:01:57 -06:00
|
|
|
this.flyLimitAllow = false;
|
|
|
|
|
if (!this.getNavigator().noPath() && this.motionY > 0) {
|
|
|
|
|
this.motionY = 0;
|
|
|
|
|
} else {
|
2022-11-15 00:48:35 -05:00
|
|
|
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
|
2022-11-07 13:01:57 -06:00
|
|
|
return;
|
|
|
|
|
}
|
2022-02-22 01:52:47 -06:00
|
|
|
}
|
2022-11-07 13:01:57 -06:00
|
|
|
this.flyLimitAllow = true;
|
2022-02-27 23:23:41 -06:00
|
|
|
|
|
|
|
|
double d3 = this.motionY;
|
2022-11-15 00:48:35 -05:00
|
|
|
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
|
2022-02-27 23:23:41 -06:00
|
|
|
this.motionY = d3;
|
|
|
|
|
|
2022-11-05 04:10:00 -05:00
|
|
|
if (this.getNavigator().noPath()) {
|
2025-02-10 21:32:55 -05:00
|
|
|
this.motionY = -Math.abs(this.ais.flyGravity);
|
2022-11-05 04:10:00 -05:00
|
|
|
}
|
2022-06-29 03:48:00 -05:00
|
|
|
|
2022-11-10 12:34:05 -05:00
|
|
|
this.updateLimbSwing();
|
2022-06-29 03:48:00 -05:00
|
|
|
this.velocityChanged = true;
|
2022-02-22 01:52:47 -06:00
|
|
|
}
|
2022-11-10 12:34:05 -05:00
|
|
|
|
|
|
|
|
public void updateLimbSwing() {
|
|
|
|
|
this.prevLimbSwingAmount = this.limbSwingAmount;
|
|
|
|
|
double distanceX = this.posX - this.prevPosX;
|
|
|
|
|
double distanceZ = this.posZ - this.prevPosZ;
|
|
|
|
|
float distance = MathHelper.sqrt_double(distanceX * distanceX + distanceZ * distanceZ) * 4.0F;
|
|
|
|
|
if (distance > 1.0F) {
|
|
|
|
|
distance = 1.0F;
|
|
|
|
|
}
|
|
|
|
|
this.limbSwingAmount += (distance - this.limbSwingAmount) * 0.4F;
|
|
|
|
|
this.limbSwing += this.limbSwingAmount;
|
|
|
|
|
}
|
2025-11-06 00:20:22 -05:00
|
|
|
|
|
|
|
|
@Override
|
2025-11-06 02:00:55 -05:00
|
|
|
protected void doMountedMovement(float strafe, float forward, float moveSpeed) {
|
2025-11-06 00:20:22 -05:00
|
|
|
if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) {
|
2025-11-06 02:00:55 -05:00
|
|
|
super.doMountedMovement(strafe, forward, moveSpeed);
|
2025-11-06 00:20:22 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean aboveLimit = false;
|
|
|
|
|
double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ);
|
|
|
|
|
if (heightOffGround < 0) {
|
|
|
|
|
Vec3 pos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
|
|
|
|
Vec3 posLimit = Vec3.createVectorHelper(this.posX, this.posY - this.ais.flyHeightLimit, this.posZ);
|
|
|
|
|
MovingObjectPosition mob = this.worldObj.rayTraceBlocks(pos, posLimit, true);
|
|
|
|
|
if (mob == null || mob.typeOfHit == MovingObjectPosition.MovingObjectType.MISS) {
|
|
|
|
|
aboveLimit = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (heightOffGround > this.ais.flyHeightLimit) {
|
|
|
|
|
aboveLimit = true;
|
|
|
|
|
}
|
|
|
|
|
if (aboveLimit && this.ais.hasFlyLimit || (heightOffGround < Math.ceil(this.height) && this.motionY == 0)) {
|
|
|
|
|
this.flyLimitAllow = false;
|
|
|
|
|
if (!this.getNavigator().noPath() && this.motionY > 0) {
|
|
|
|
|
this.motionY = 0;
|
|
|
|
|
} else {
|
2025-11-06 02:00:55 -05:00
|
|
|
super.doMountedMovement(strafe, forward, moveSpeed);
|
2025-11-06 00:20:22 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.flyLimitAllow = true;
|
|
|
|
|
|
|
|
|
|
double d3 = this.motionY;
|
2025-11-06 02:00:55 -05:00
|
|
|
super.doMountedMovement(strafe, forward, moveSpeed);
|
2025-11-06 00:20:22 -05:00
|
|
|
this.motionY = d3;
|
|
|
|
|
|
|
|
|
|
if (this.getNavigator().noPath()) {
|
|
|
|
|
this.motionY = -Math.abs(this.ais.flyGravity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.updateLimbSwing();
|
|
|
|
|
this.velocityChanged = true;
|
|
|
|
|
}
|
2021-06-13 16:22:06 -04:00
|
|
|
}
|