添加xy100履带,修复开火动画缺失

This commit is contained in:
Atsuihsio 2025-03-10 03:09:28 +08:00
parent 80a53089a4
commit 37b0320068
5 changed files with 2416 additions and 245 deletions

View file

@ -3,8 +3,14 @@ package com.atsuishio.superbwarfare.client.model.entity;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.TRACK_L;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.TRACK_R;
public class Yx100Model extends GeoModel<Yx100Entity> {
@Override
@ -35,91 +41,79 @@ public class Yx100Model extends GeoModel<Yx100Entity> {
return ModUtils.loc("textures/entity/yx_100.png");
}
// @Override
// public void setCustomAnimations(Yx100Entity animatable, long instanceId, AnimationState<Yx100Entity> animationState) {
// for (int i = 0; i < 50; i++) {
// CoreGeoBone trackL = getAnimationProcessor().getBone("trackL" + i);
// CoreGeoBone trackLRot = getAnimationProcessor().getBone("trackLRot" + i);
// CoreGeoBone trackR = getAnimationProcessor().getBone("trackR" + i);
// CoreGeoBone trackRRot = getAnimationProcessor().getBone("trackRRot" + i);
//
// float t = animatable.getEntityData().get(TRACK_L) + 2 * i;
//
// if (t >= 100) {
// t -= 100;
// }
//
// trackAnimation(trackL, trackLRot, t);
//
// float t2 = animatable.getEntityData().get(TRACK_R) + 2 * i;
//
// if (t2 >= 100) {
// t2 -= 100;
// }
//
// trackAnimation(trackR, trackRRot, t2);
// }
// }
//
// public void trackAnimation(CoreGeoBone track, CoreGeoBone trackRot, float t) {
// if (t < 37.5) {
// track.setPosY(0);
// track.setPosZ(3 * t);
// trackRot.setRotX(0);
// }
//
// if (t >= 37.5 && t < 39.5) {
// track.setPosY(-(t - 37.5f) * 3 * 0.7071f);
// track.setPosZ(3 * 37.5f + (t - 37.5f) * 3 * 0.7071f);
// trackRot.setRotX(45 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 39.5 && t < 41.5) {
// track.setPosY(-5.3f - (t - 39.5f) * 3);
// track.setPosZ(116);
// trackRot.setRotX(90 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 41.5 && t < 43) {
// track.setPosY(-11.6f - (t - 41.5f) * 3 * 0.7071f);
// track.setPosZ(115 - (t - 41.5f) * 3 * 0.7071f);
// trackRot.setRotX(135 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 43 && t < 49.5) {
// track.setPosY(-15.6f - (t - 43f) * 3 * 0.45f);
// track.setPosZ(109.5f - (t - 43f) * 3 * 0.75f);
// trackRot.setRotX(150 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 49.5 && t < 76.5) {
// track.setPosY(-23.5f);
// track.setPosZ(95f - (t - 49.5f) * 3);
// trackRot.setRotX(180 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 76.5 && t < 83.5) {
// track.setPosY(-23.5f + (t - 76.5f) * 3 * 0.45f);
// track.setPosZ(13.5f - (t - 76.5f) * 3 * 0.75f);
// trackRot.setRotX(210 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 83.5 && t < 85.5) {
// track.setPosY(-12.7f + (t - 83.5f) * 3 * 0.7071f);
// track.setPosZ(-3.5f - (t - 83.5f) * 3 * 0.7071f);
// trackRot.setRotX(225 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 85.5 && t < 87) {
// track.setPosY(-9.2f + (t - 85.5f) * 3);
// track.setPosZ(-6.9f);
// trackRot.setRotX(270 * Mth.DEG_TO_RAD);
// }
//
// if (t >= 87 && t < 89) {
// track.setPosY(-4.3f + (t - 87f) * 3 * 0.7071f);
// track.setPosZ(-6.9f + (t - 87f) * 3 * 0.7071f);
// trackRot.setRotX(315 * Mth.DEG_TO_RAD);
// }
// }
@Override
public void setCustomAnimations(Yx100Entity animatable, long instanceId, AnimationState<Yx100Entity> animationState) {
for (int i = 0; i < 40; i++) {
CoreGeoBone trackL = getAnimationProcessor().getBone("trackL" + i);
CoreGeoBone trackLRot = getAnimationProcessor().getBone("trackLRot" + i);
CoreGeoBone trackR = getAnimationProcessor().getBone("trackR" + i);
CoreGeoBone trackRRot = getAnimationProcessor().getBone("trackRRot" + i);
float t = animatable.getEntityData().get(TRACK_L) + 2 * i;
if (t >= 80) {
t -= 80;
}
trackAnimation(trackL, trackLRot, t);
float t2 = animatable.getEntityData().get(TRACK_R) + 2 * i;
if (t2 >= 80) {
t2 -= 80;
}
trackAnimation(trackR, trackRRot, t2);
}
}
public void trackAnimation(CoreGeoBone track, CoreGeoBone trackRot, float t) {
if (t < 34.5) {
track.setPosY(0);
track.setPosZ(4f * t);
trackRot.setRotX(0);
}
if (t >= 34.5 && t < 35.75) {
track.setPosY(-(t - 34.5f) * 4f * 0.7071f);
track.setPosZ(4f * 34.5f + (t - 34.5f) * 4f * 0.7071f);
trackRot.setRotX(45 * Mth.DEG_TO_RAD);
}
if (t >= 35.75 && t < 37.75) {
track.setPosY(-4f - (t - 35.75f) * 4f);
track.setPosZ(142);
trackRot.setRotX(90 * Mth.DEG_TO_RAD);
}
if (t >= 37.75 && t < 44) {
track.setPosY(-11.4f - (t - 37.75f) * 4.5f * 0.42f);
track.setPosZ(141f - (t - 37.75f) * 4.5f * 0.75f);
trackRot.setRotX(150 * Mth.DEG_TO_RAD);
}
if (t >= 44 && t < 70.75) {
track.setPosY(-21.5f);
track.setPosZ(120f - (t - 44f) * 4);
trackRot.setRotX(180 * Mth.DEG_TO_RAD);
}
if (t >= 70.75 && t < 77) {
track.setPosY(-21f + (t - 70.75f) * 4.5F * 0.42f);
track.setPosZ(11.4f - (t - 70.75f) * 4.5f * 0.75f);
trackRot.setRotX(210 * Mth.DEG_TO_RAD);
}
if (t >= 77 && t < 78.25) {
track.setPosY(-7.8f + (t - 77f) * 4f);
track.setPosZ(-10.6f);
trackRot.setRotX(270 * Mth.DEG_TO_RAD);
}
if (t >= 78.25 && t < 80) {
track.setPosY(-2.3f + (t - 78.25f) * 4 * 0.7071f);
track.setPosZ(-9.6f + (t - 78.25f) * 4 * 0.7071f);
trackRot.setRotX(315 * Mth.DEG_TO_RAD);
}
}
}

View file

@ -84,7 +84,6 @@ public class Yx100Renderer extends GeoEntityRenderer<Yx100Entity> {
}
if (name.equals("base")) {
float a = animatable.getEntityData().get(YAW);
float r = (Mth.abs(a) - 90f) / 90f;
@ -106,7 +105,6 @@ public class Yx100Renderer extends GeoEntityRenderer<Yx100Entity> {
bone.setPosX(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 1f);
bone.setRotZ(r2 * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD * 1.5f);
}
super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}
}

View file

@ -68,7 +68,7 @@ import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> CANNON_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> MG_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
@ -76,7 +76,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public static final EntityDataAccessor<Float> TRACK_L = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> TRACK_R = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> GUN_FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> MACHINE_GUN_HEAT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final float MAX_HEALTH = 500;
@ -158,12 +158,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.entityData.define(AMMO, 0);
this.entityData.define(MG_AMMO, 0);
this.entityData.define(LOADED_AMMO, 0);
this.entityData.define(FIRE_ANIM, 0);
this.entityData.define(CANNON_FIRE_TIME, 0);
this.entityData.define(DELTA_ROT, 0f);
this.entityData.define(TRACK_L, 0f);
this.entityData.define(TRACK_R, 0f);
this.entityData.define(YAW, 0f);
this.entityData.define(FIRE_TIME, 0);
this.entityData.define(GUN_FIRE_TIME, 0);
this.entityData.define(MACHINE_GUN_HEAT, 0);
}
@ -229,32 +229,32 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
rightWheelRotO = this.getRightWheelRot();
recoilShakeO = this.getRecoilShake();
this.setRecoilShake(Math.pow(entityData.get(FIRE_ANIM), 4) * 0.0000007 * Math.sin(0.2 * Math.PI * (entityData.get(FIRE_ANIM) - 2.5)));
this.setRecoilShake(Math.pow(entityData.get(CANNON_FIRE_TIME), 4) * 0.0000007 * Math.sin(0.2 * Math.PI * (entityData.get(CANNON_FIRE_TIME) - 2.5)));
super.baseTick();
if (this.entityData.get(TRACK_R) < 0) {
this.entityData.set(TRACK_R, 100f);
this.entityData.set(TRACK_R, 80f);
}
if (this.entityData.get(TRACK_R) > 100) {
if (this.entityData.get(TRACK_R) > 80) {
this.entityData.set(TRACK_R, 0f);
}
if (this.entityData.get(TRACK_L) < 0) {
this.entityData.set(TRACK_L, 100f);
this.entityData.set(TRACK_L, 80f);
}
if (this.entityData.get(TRACK_L) > 100) {
if (this.entityData.get(TRACK_L) > 80) {
this.entityData.set(TRACK_L, 0f);
}
if (this.entityData.get(FIRE_ANIM) > 0) {
this.entityData.set(FIRE_ANIM, this.entityData.get(FIRE_ANIM) - 1);
if (this.entityData.get(CANNON_FIRE_TIME) > 0) {
this.entityData.set(CANNON_FIRE_TIME, this.entityData.get(CANNON_FIRE_TIME) - 1);
}
if (this.entityData.get(FIRE_TIME) > 0) {
this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1);
if (this.entityData.get(GUN_FIRE_TIME) > 0) {
this.entityData.set(GUN_FIRE_TIME, this.entityData.get(GUN_FIRE_TIME) - 1);
}
if (this.entityData.get(MACHINE_GUN_HEAT) > 0) {
@ -388,7 +388,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
}
this.entityData.set(FIRE_ANIM, 40);
this.entityData.set(CANNON_FIRE_TIME, 40);
this.entityData.set(LOADED_AMMO, 0);
this.consumeEnergy(10000);
this.entityData.set(YAW, getTurretYRot());
@ -472,7 +472,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
}
this.entityData.set(FIRE_TIME, 2);
this.entityData.set(GUN_FIRE_TIME, 2);
this.entityData.set(MACHINE_GUN_HEAT, this.entityData.get(MACHINE_GUN_HEAT) + 4);
Level level = player.level();
@ -861,24 +861,24 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.clampRotation(entity);
}
private PlayState firePredicate(AnimationState<Yx100Entity> event) {
if (this.entityData.get(FIRE_ANIM) > 20) {
private PlayState cannonShootPredicate(AnimationState<Yx100Entity> event) {
if (this.entityData.get(CANNON_FIRE_TIME) > 20) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.yx100.fire"));
}
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.yx100.idle"));
}
private PlayState gunFirePredicate(AnimationState<Yx100Entity> event) {
if (this.entityData.get(FIRE_TIME) > 0) {
private PlayState gunShootPredicate(AnimationState<Yx100Entity> event) {
if (this.entityData.get(GUN_FIRE_TIME) > 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.yx100.fire2"));
}
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.yx100.idle"));
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.yx100.idle2"));
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "movement", 0, this::firePredicate));
data.add(new AnimationController<>(this, "shoot", 0, this::gunFirePredicate));
data.add(new AnimationController<>(this, "cannon", 0, this::cannonShootPredicate));
data.add(new AnimationController<>(this, "gun", 0, this::gunShootPredicate));
}
@Override

View file

@ -131,6 +131,15 @@
}
}
},
"animation.yx100.idle2": {
"loop": true,
"animation_length": 0.5,
"bones": {
"flare": {
"scale": 0
}
}
},
"animation.yx100.fire2": {
"loop": "hold_on_last_frame",
"animation_length": 0.5,

File diff suppressed because it is too large Load diff