2021-07-10 00:48:03 -04:00
|
|
|
package noppes.npcs.ai.pathfinder;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
|
|
|
import net.minecraft.entity.ai.EntityMoveHelper;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
2022-11-07 13:01:57 -06:00
|
|
|
import noppes.npcs.entity.EntityNPCFlying;
|
2021-07-10 00:48:03 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
|
2021-12-07 03:57:57 -06:00
|
|
|
public class FlyingMoveHelper extends EntityMoveHelper{
|
2021-12-08 15:50:58 -06:00
|
|
|
private final EntityNPCInterface entity;
|
2021-07-10 00:48:03 -04:00
|
|
|
|
2021-12-07 03:57:57 -06:00
|
|
|
private double posX;
|
|
|
|
|
private double posY;
|
|
|
|
|
private double posZ;
|
|
|
|
|
private double speed;
|
2022-11-07 01:40:24 -05:00
|
|
|
public boolean update;
|
2021-07-10 00:48:03 -04:00
|
|
|
|
|
|
|
|
public FlyingMoveHelper(EntityNPCInterface entity){
|
|
|
|
|
super(entity);
|
|
|
|
|
this.entity = entity;
|
2021-12-07 03:57:57 -06:00
|
|
|
this.posX = entity.posX;
|
|
|
|
|
this.posY = entity.posY;
|
|
|
|
|
this.posZ = entity.posZ;
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-07 03:57:57 -06:00
|
|
|
public void onUpdateMoveHelper() {
|
|
|
|
|
if (this.update) {
|
|
|
|
|
this.update = false;
|
2021-12-08 04:00:28 -06:00
|
|
|
|
2022-05-04 03:06:40 -05:00
|
|
|
double speed = this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
|
2022-05-04 04:10:14 -05:00
|
|
|
double verticalSpeed = this.speed * this.entity.ai.flySpeed/8.0D;
|
2022-11-07 14:48:47 -05:00
|
|
|
this.entity.setAIMoveSpeed((float)speed);
|
2021-12-08 04:00:28 -06:00
|
|
|
|
2021-07-10 00:48:03 -04:00
|
|
|
double d0 = this.posX - this.entity.posX;
|
2022-05-04 04:10:14 -05:00
|
|
|
double d1 = this.posY - this.entity.posY;
|
2021-12-08 04:00:28 -06:00
|
|
|
double d2 = this.posZ - this.entity.posZ;
|
|
|
|
|
double d4 = d0 * d0 + d1 * d1 + d2 * d2;
|
2022-02-18 03:34:20 -06:00
|
|
|
double d5 = MathHelper.sqrt_double(d4);
|
2022-08-28 00:12:15 -05:00
|
|
|
speed = Math.min(d5/5.0D,speed);
|
2022-02-18 03:34:20 -06:00
|
|
|
|
2024-01-24 00:10:24 -05:00
|
|
|
// its here louis!
|
|
|
|
|
// This is the hurt time that stuns the NPC!!!!!!
|
|
|
|
|
// if (this.entity.hurtTime == 0 && d4 > 0.5D) {
|
|
|
|
|
if (d4 >= 0.5D) {
|
2022-05-04 03:06:40 -05:00
|
|
|
this.entity.motionX += (speed * (d0 / d5) - this.entity.motionX) * speed;
|
|
|
|
|
this.entity.motionZ += (speed * (d2 / d5) - this.entity.motionZ) * speed;
|
2021-12-08 15:34:41 -06:00
|
|
|
|
2022-11-07 13:01:57 -06:00
|
|
|
if (((EntityNPCFlying)this.entity).flyLimitAllow || !this.entity.ai.hasFlyLimit) {
|
2022-05-04 04:10:14 -05:00
|
|
|
this.entity.motionY = verticalSpeed * (d1 / d5);
|
2022-05-15 01:21:06 -05:00
|
|
|
if (this.entity.motionY > 0) {
|
|
|
|
|
this.entity.motionY += 0.1D;
|
|
|
|
|
}
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
2022-02-22 01:52:47 -06:00
|
|
|
|
|
|
|
|
this.entity.velocityChanged = true;
|
2022-11-13 23:49:49 -06:00
|
|
|
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw,(float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)),20.0F);
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 21:44:17 -05:00
|
|
|
private float limitAngle(float angleIn, float lower, float upper)
|
2021-12-07 03:57:57 -06:00
|
|
|
{
|
2022-11-06 21:44:17 -05:00
|
|
|
float f = MathHelper.wrapAngleTo180_float(lower - angleIn);
|
2021-07-10 00:48:03 -04:00
|
|
|
|
2022-11-06 21:44:17 -05:00
|
|
|
if (f > upper)
|
2021-12-07 03:57:57 -06:00
|
|
|
{
|
2022-11-06 21:44:17 -05:00
|
|
|
f = upper;
|
2021-12-07 03:57:57 -06:00
|
|
|
}
|
2021-07-10 00:48:03 -04:00
|
|
|
|
2022-11-06 21:44:17 -05:00
|
|
|
if (f < -upper)
|
2021-12-07 03:57:57 -06:00
|
|
|
{
|
2022-11-06 21:44:17 -05:00
|
|
|
f = -upper;
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-06 21:44:17 -05:00
|
|
|
float f1 = angleIn + f;
|
|
|
|
|
|
|
|
|
|
if (f1 < 0.0F)
|
|
|
|
|
{
|
|
|
|
|
f1 += 360.0F;
|
|
|
|
|
}
|
|
|
|
|
else if (f1 > 360.0F)
|
|
|
|
|
{
|
|
|
|
|
f1 -= 360.0F;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return f1;
|
2021-12-07 03:57:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the speed and location to move to
|
|
|
|
|
*/
|
|
|
|
|
public void setMoveTo(double p_75642_1_, double p_75642_3_, double p_75642_5_, double p_75642_7_)
|
|
|
|
|
{
|
|
|
|
|
this.posX = p_75642_1_;
|
|
|
|
|
this.posY = p_75642_3_;
|
|
|
|
|
this.posZ = p_75642_5_;
|
|
|
|
|
this.speed = p_75642_7_;
|
|
|
|
|
this.update = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isUpdating()
|
|
|
|
|
{
|
|
|
|
|
return this.update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getSpeed()
|
|
|
|
|
{
|
|
|
|
|
return this.speed;
|
2021-07-10 00:48:03 -04:00
|
|
|
}
|
|
|
|
|
}
|