修复了可能导致NaN的问题

This commit is contained in:
17146 2024-12-11 20:52:24 +08:00
parent 3c1bb24f27
commit 3d067fdbf4

View file

@ -40,13 +40,16 @@ import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ROT_Y = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private boolean inputLeft;
private boolean inputRight;
private boolean inputUp;
@ -90,6 +93,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.entityData.set(HEALTH, MAX_HEALTH);
}
}
@Override
public boolean canCollideWith(Entity pEntity) {
return canVehicleCollide(this, pEntity);
@ -100,10 +104,12 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
public static boolean canVehicleCollide(Entity pVehicle, Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !pVehicle.isPassengerOfSameVehicle(pEntity);
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean isPushable() {
return false;
@ -224,7 +230,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));
if (this.level() instanceof ServerLevel) {
this.entityData.set(ROT_Y, this.getYRot());
}
@ -248,7 +253,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
diffY = (float) Mth.lerp(0.1 * diffY, diffY, 0);
if (this.inputUp) {
this.entityData.set(POWER, this.entityData.get(POWER) + 0.05f);
}
@ -280,7 +284,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.8f);
if (this.isInWater() || this.isUnderWater()) {
this.setYRot(this.entityData.get(ROT_Y) + this.entityData.get(DELTA_ROT));
this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.entityData.get(ROT_Y) * 0.017453292F) * this.entityData.get(POWER), 0.0, Mth.cos(this.entityData.get(ROT_Y) * 0.017453292F) * this.entityData.get(POWER)));
@ -335,7 +338,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
double startLength = move.length();
double endLength = view.length();
if (startLength > 0.0D && endLength > 0.0D) {
return Math.toDegrees(Math.acos(move.dot(view) / (startLength * endLength)));
return Math.toDegrees(Math.acos(Mth.clamp(move.dot(view) / (startLength * endLength), -1, 1)));
} else {
return 0.0D;
}
@ -358,7 +361,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.setPos(d0, d1, d2);
this.setRot(this.getYRot(), this.getXRot());
}
}
@Override