修复了可能导致NaN的问题
This commit is contained in:
parent
3c1bb24f27
commit
3d067fdbf4
1 changed files with 17 additions and 15 deletions
|
@ -40,13 +40,16 @@ import software.bernie.geckolib.core.animation.AnimatableManager;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity {
|
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> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> ENERGY = 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> 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> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Float> POWER = 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();
|
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
|
||||||
|
|
||||||
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
private boolean inputLeft;
|
private boolean inputLeft;
|
||||||
private boolean inputRight;
|
private boolean inputRight;
|
||||||
private boolean inputUp;
|
private boolean inputUp;
|
||||||
|
@ -90,6 +93,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
this.entityData.set(HEALTH, MAX_HEALTH);
|
this.entityData.set(HEALTH, MAX_HEALTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canCollideWith(Entity pEntity) {
|
public boolean canCollideWith(Entity pEntity) {
|
||||||
return canVehicleCollide(this, 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) {
|
public static boolean canVehicleCollide(Entity pVehicle, Entity pEntity) {
|
||||||
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !pVehicle.isPassengerOfSameVehicle(pEntity);
|
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !pVehicle.isPassengerOfSameVehicle(pEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeCollidedWith() {
|
public boolean canBeCollidedWith() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPushable() {
|
public boolean isPushable() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -224,7 +230,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
|
|
||||||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));
|
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));
|
||||||
|
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
this.entityData.set(ROT_Y, this.getYRot());
|
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);
|
diffY = (float) Mth.lerp(0.1 * diffY, diffY, 0);
|
||||||
|
|
||||||
|
|
||||||
if (this.inputUp) {
|
if (this.inputUp) {
|
||||||
this.entityData.set(POWER, this.entityData.get(POWER) + 0.05f);
|
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);
|
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.8f);
|
||||||
|
|
||||||
|
|
||||||
if (this.isInWater() || this.isUnderWater()) {
|
if (this.isInWater() || this.isUnderWater()) {
|
||||||
this.setYRot(this.entityData.get(ROT_Y) + this.entityData.get(DELTA_ROT));
|
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)));
|
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 startLength = move.length();
|
||||||
double endLength = view.length();
|
double endLength = view.length();
|
||||||
if (startLength > 0.0D && endLength > 0.0D) {
|
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 {
|
} else {
|
||||||
return 0.0D;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +361,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
this.setPos(d0, d1, d2);
|
this.setPos(d0, d1, d2);
|
||||||
this.setRot(this.getYRot(), this.getXRot());
|
this.setRot(this.getYRot(), this.getXRot());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue