修复其他船螺旋桨同步旋转的问题

This commit is contained in:
Atsuihsio 2024-12-12 17:53:24 +08:00
parent 61c9dd1c92
commit edb1738d76
3 changed files with 20 additions and 13 deletions

View file

@ -9,12 +9,11 @@ import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState; import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel; import software.bernie.geckolib.model.GeoModel;
import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.DELTA_ROT; import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.*;
import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.POWER;
public class SpeedboatModel extends GeoModel<SpeedboatEntity> { public class SpeedboatModel extends GeoModel<SpeedboatEntity> {
public static float lerpRotY = 0f; public static float lerpRotY = 0f;
public static float rotorSpeed = 0f; public float rotorSpeed = 0f;
@Override @Override
public ResourceLocation getAnimationResource(SpeedboatEntity entity) { public ResourceLocation getAnimationResource(SpeedboatEntity entity) {
@ -39,8 +38,7 @@ public class SpeedboatModel extends GeoModel<SpeedboatEntity> {
CoreGeoBone rotor = getAnimationProcessor().getBone("Rotor"); CoreGeoBone rotor = getAnimationProcessor().getBone("Rotor");
CoreGeoBone duo = getAnimationProcessor().getBone("duo"); CoreGeoBone duo = getAnimationProcessor().getBone("duo");
rotorSpeed = Mth.lerp(0.1f * times, rotorSpeed, 10 * animatable.getEntityData().get(POWER)); rotor.setRotZ(5 * animatable.getEntityData().get(ROTOR));
rotor.setRotZ(rotor.getRotZ() + rotorSpeed);
lerpRotY = Mth.lerp(0.5f * times, lerpRotY, animatable.getEntityData().get(POWER) > 0 ? animatable.getEntityData().get(DELTA_ROT) : -animatable.getEntityData().get(DELTA_ROT)); lerpRotY = Mth.lerp(0.5f * times, lerpRotY, animatable.getEntityData().get(POWER) > 0 ? animatable.getEntityData().get(DELTA_ROT) : -animatable.getEntityData().get(DELTA_ROT));

View file

@ -52,6 +52,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
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);
public static final EntityDataAccessor<Float> ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final float MAX_HEALTH = CannonConfig.MK42_HP.get(); public static final float MAX_HEALTH = CannonConfig.MK42_HP.get();
@ -82,6 +83,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.entityData.define(ROT_Y, 0f); this.entityData.define(ROT_Y, 0f);
this.entityData.define(DELTA_ROT, 0f); this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(POWER, 0f); this.entityData.define(POWER, 0f);
this.entityData.define(ROTOR, 0f);
} }
@Override @Override
@ -90,6 +92,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
compound.putFloat("Energy", this.entityData.get(ENERGY)); compound.putFloat("Energy", this.entityData.get(ENERGY));
compound.putFloat("Power", this.entityData.get(POWER)); compound.putFloat("Power", this.entityData.get(POWER));
compound.putFloat("DeltaRot", this.entityData.get(DELTA_ROT)); compound.putFloat("DeltaRot", this.entityData.get(DELTA_ROT));
compound.putFloat("Rotor", this.entityData.get(ROTOR));
} }
@Override @Override
@ -97,6 +100,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.entityData.set(ENERGY, compound.getFloat("Energy")); this.entityData.set(ENERGY, compound.getFloat("Energy"));
this.entityData.set(POWER, compound.getFloat("Power")); this.entityData.set(POWER, compound.getFloat("Power"));
this.entityData.set(DELTA_ROT, compound.getFloat("DeltaRot")); this.entityData.set(DELTA_ROT, compound.getFloat("DeltaRot"));
this.entityData.set(ROTOR, compound.getFloat("Rotor"));
if (compound.contains("Health")) { if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health")); this.entityData.set(HEALTH, compound.getFloat("Health"));
} else { } else {
@ -217,7 +221,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
if (this.isInWater()) { if (this.isInWater()) {
fluidFloat = -0.025 + 0.05 * getSubmergedHeight(this); fluidFloat = -0.025 + 0.05 * getSubmergedHeight(this);
float f = 0.87f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; float f = 0.7f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90;
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length()))); this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length())));
this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f)); this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f));
} else if (this.onGround()) { } else if (this.onGround()) {
@ -298,11 +302,11 @@ 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.getPersistentData().getBoolean("forward")) { if (this.getPersistentData().getBoolean("forward")) {
this.entityData.set(POWER, this.entityData.get(POWER) + 0.08f); this.entityData.set(POWER, this.entityData.get(POWER) + 0.02f);
} }
if (this.getPersistentData().getBoolean("backward")) { if (this.getPersistentData().getBoolean("backward")) {
this.entityData.set(POWER, this.entityData.get(POWER) - 0.12f); this.entityData.set(POWER, this.entityData.get(POWER) - 0.02f);
if (this.getPersistentData().getBoolean("left")) { if (this.getPersistentData().getBoolean("left")) {
diffY = Mth.clamp(diffY + 1f, 0, 5); diffY = Mth.clamp(diffY + 1f, 0, 5);
handleSetDiffY(diffY); handleSetDiffY(diffY);
@ -324,10 +328,8 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.inputUp || this.inputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1f), false); level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.inputUp || this.inputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1f), false);
} }
this.entityData.set(POWER, this.entityData.get(POWER) * 0.3f); this.entityData.set(POWER, this.entityData.get(POWER) * 0.9f);
this.entityData.set(ROTOR, this.entityData.get(ROTOR) + this.entityData.get(POWER));
this.flyDist = this.entityData.get(POWER);
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()) {

View file

@ -2,11 +2,16 @@
"format_version": "1.8.0", "format_version": "1.8.0",
"animations": { "animations": {
"animation.speedboat.idle": { "animation.speedboat.idle": {
"loop": true "loop": true,
"animation_length": 1,
"blend_weight": "10",
"start_delay": "10"
}, },
"animation.speedboat.forward": { "animation.speedboat.forward": {
"loop": true, "loop": true,
"animation_length": 0.5, "animation_length": 0.5,
"blend_weight": "10",
"start_delay": "10",
"bones": { "bones": {
"Rotor": { "Rotor": {
"rotation": { "rotation": {
@ -19,6 +24,8 @@
"animation.speedboat.backward": { "animation.speedboat.backward": {
"loop": true, "loop": true,
"animation_length": 0.5, "animation_length": 0.5,
"blend_weight": "10",
"start_delay": "10",
"bones": { "bones": {
"Rotor": { "Rotor": {
"rotation": { "rotation": {