添加坦克后座动画

This commit is contained in:
Atsuihsio 2025-03-04 01:11:37 +08:00
parent 464ae57e91
commit dcd40da7f0
9 changed files with 6263 additions and 5673 deletions

View file

@ -9,7 +9,7 @@ public class Yx100Model extends GeoModel<Yx100Entity> {
@Override
public ResourceLocation getAnimationResource(Yx100Entity entity) {
return null;
return ModUtils.loc("animations/yx_100.animation.json");
}
@Override

View file

@ -190,7 +190,10 @@ public class VehicleHudOverlay {
&& iLand instanceof MobileVehicleEntity mobileVehicle) {
poseStack.pushPose();
poseStack.translate(Mth.clamp(-8 * ClientEventHandler.turnRot[1], -10, 10), Mth.clamp(-8 * ClientEventHandler.turnRot[0], -10, 10), 0);
poseStack.translate(Mth.clamp(-8 * ClientEventHandler.turnRot[1], -10, 10), Mth.clamp(-8 * ClientEventHandler.turnRot[0], -10, 10) - 0.3 * ClientEventHandler.shakeTime + 5 * ClientEventHandler.cameraRoll, 0);
poseStack.rotateAround(Axis.ZP.rotationDegrees(-0.5f * ClientEventHandler.cameraRoll), w / 2f, h / 2f, 0);
RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
@ -214,6 +217,14 @@ public class VehicleHudOverlay {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2f + 112, h - 71, 0, 0.0F, 1, 16, 1, 16);
// 不同武器种类的准星
if (multiWeaponVehicle instanceof Yx100Entity) {
if (multiWeaponVehicle.getWeaponType() == 0) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/tank_cannon_cross_ap.png"), k, l, 0, 0.0F, i, j, i, j);
} else if (multiWeaponVehicle.getWeaponType() == 1) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/tank_cannon_cross_he.png"), k, l, 0, 0.0F, i, j, i, j);
}
} else {
if (multiWeaponVehicle.getWeaponType() == 0) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cannon_cross.png"), k, l, 0, 0.0F, i, j, i, j);
} else if (multiWeaponVehicle.getWeaponType() == 1) {
@ -221,6 +232,7 @@ public class VehicleHudOverlay {
} else if (multiWeaponVehicle.getWeaponType() == 2) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j);
}
}
// 指南针
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16);

View file

@ -14,6 +14,8 @@ import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.YAW;
public class Yx100Renderer extends GeoEntityRenderer<Yx100Entity> {
public Yx100Renderer(EntityRendererProvider.Context renderManager) {
@ -73,6 +75,30 @@ public class Yx100Renderer extends GeoEntityRenderer<Yx100Entity> {
bone.setRotY((System.currentTimeMillis() % 36000000) / 300f);
}
if (name.equals("base")) {
float a = animatable.getEntityData().get(YAW);
float r = (Mth.abs(a) - 90f) / 90f;
bone.setPosZ(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 1.5f);
bone.setRotX(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * Mth.DEG_TO_RAD);
float r2;
if (Mth.abs(a) <= 90f) {
r2 = a / 90f;
} else {
if (a < 0) {
r2 = (180f + a) / 90f;
} else {
r2 = (180f - a) / 90f;
}
}
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.75f);
}
super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}
}

View file

@ -14,6 +14,7 @@ import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
@ -21,6 +22,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity;
@ -43,6 +45,10 @@ import org.joml.Vector4f;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.core.animation.AnimationController;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator;
@ -59,6 +65,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
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 float MAX_HEALTH = 400;
public static final int MAX_ENERGY = 5000000;
@ -72,6 +79,9 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public float rightWheelRot;
public float leftWheelRotO;
public float rightWheelRotO;
public double recoilShake;
public double recoilShakeO;
public int reloadCoolDown;
public Yx100Entity(PlayMessages.SpawnEntity packet, Level world) {
@ -93,6 +103,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.entityData.define(WEAPON_TYPE, 0);
this.entityData.define(TRACK_L, 0f);
this.entityData.define(TRACK_R, 0f);
this.entityData.define(YAW, 0f);
}
@Override
@ -125,12 +136,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
.immuneTo(DamageTypes.PLAYER_ATTACK)
.immuneTo(ModTags.DamageTypes.PROJECTILE)
.immuneTo(ModDamageTypes.VEHICLE_STRIKE)
.multiply(0.75f, DamageTypes.EXPLOSION)
.multiply(0.23f, ModDamageTypes.CUSTOM_EXPLOSION)
.multiply(0.23f, ModDamageTypes.PROJECTILE_BOOM)
.multiply(0.13f, ModDamageTypes.MINE)
.multiply(0.15f, ModDamageTypes.LUNGE_MINE)
.multiply(0.2f, ModDamageTypes.CANNON_FIRE)
.multiply(0.6f, DamageTypes.EXPLOSION)
.multiply(0.2f, ModDamageTypes.CUSTOM_EXPLOSION)
.multiply(0.2f, ModDamageTypes.PROJECTILE_BOOM)
.multiply(0.1f, ModDamageTypes.MINE)
.multiply(0.1f, ModDamageTypes.LUNGE_MINE)
.multiply(0.15f, ModDamageTypes.CANNON_FIRE)
.multiply(0.05f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
.reduce(9);
}
@ -151,9 +162,16 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
turretXRotO = this.getTurretXRot();
leftWheelRotO = this.getLeftWheelRot();
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)));
super.baseTick();
// if (this.getFirstPassenger() instanceof Player player) {
// player.displayClientMessage(Component.literal(FormatTool.format1D(this.getRecoilShake(), " °")),false);
// }
if (this.entityData.get(TRACK_R) < 0) {
this.entityData.set(TRACK_R, 100f);
}
@ -315,9 +333,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
}
}
this.entityData.set(FIRE_ANIM, 20);
this.entityData.set(FIRE_ANIM, 40);
this.entityData.set(LOADED_AMMO, 0);
this.consumeEnergy(10000);
this.entityData.set(YAW, getTurretYRot());
reloadCoolDown = 80;
@ -478,6 +497,14 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.rightWheelRot = pRightWheelRot;
}
public double getRecoilShake() {
return this.recoilShake;
}
public void setRecoilShake(double pRecoilShake) {
this.recoilShake = pRecoilShake;
}
@Override
public SoundEvent getEngineSound() {
return ModSounds.BMP_ENGINE.get();
@ -590,21 +617,16 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.clampRotation(entity);
}
// private PlayState firePredicate(AnimationState<Yx100Entity> event) {
// if (this.entityData.get(FIRE_ANIM) > 1 && entityData.get(WEAPON_TYPE) == 0) {
// return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire"));
// }
//
// if (this.entityData.get(FIRE_ANIM) > 0 && entityData.get(WEAPON_TYPE) == 1) {
// return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2"));
// }
//
// return event.setAndContinue(RawAnimation.begin().thenLoop("animation.lav.idle"));
// }
private PlayState firePredicate(AnimationState<Yx100Entity> event) {
if (this.entityData.get(FIRE_ANIM) > 20) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.yx100.fire"));
}
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.yx100.idle"));
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
// data.add(new AnimationController<>(this, "movement", 0, this::firePredicate));
data.add(new AnimationController<>(this, "movement", 0, this::firePredicate));
}
@Override
@ -659,8 +681,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
@Override
public void changeWeapon(int scroll) {
if (entityData.get(LOADED_AMMO) > 0 && this.reloadCoolDown == 0) {
this.reloadCoolDown = 80;
if (entityData.get(LOADED_AMMO) > 0) {
if (entityData.get(WEAPON_TYPE) == 0) {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.AP_5_INCHES.get())).findFirst().ifPresent(stack -> stack.grow(1));
} else if (entityData.get(WEAPON_TYPE) == 1) {
@ -670,6 +691,13 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
entityData.set(LOADED_AMMO, 0);
}
this.reloadCoolDown = 80;
if (this.getFirstPassenger() instanceof ServerPlayer player) {
var clientboundstopsoundpacket = new ClientboundStopSoundPacket(ModSounds.YX_100_RELOAD.get().getLocation(), SoundSource.PLAYERS);
player.connection.send(clientboundstopsoundpacket);
}
var type = (entityData.get(WEAPON_TYPE) + scroll + 2) % 2;
entityData.set(WEAPON_TYPE, type);
@ -678,7 +706,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
case 1 -> ModSounds.INTO_CANNON.get();
default -> throw new IllegalStateException("Unexpected type: " + type);
};
this.level().playSound(null, this, sound, this.getSoundSource(), 1, 1);
}

View file

@ -154,6 +154,10 @@ public class ClientEventHandler {
public static CameraType lastCameraType;
public static float cameraPitch;
public static float cameraYaw;
public static float cameraRoll;
@SubscribeEvent
public static void handleWeaponTurn(RenderHandEvent event) {
@ -835,7 +839,7 @@ public class ClientEventHandler {
float pitch = event.getPitch();
float roll = event.getRoll();
shakeTime = Mth.lerp(0.25 * times, shakeTime, 0);
shakeTime = Mth.lerp(0.175 * times, shakeTime, 0);
if (player != null && shakeTime > 0) {
float shakeRadiusAmplitude = (float) Mth.clamp(1 - player.position().distanceTo(new Vec3(shakePos[0], shakePos[1], shakePos[2])) / shakeRadius, 0, 1);
@ -843,16 +847,20 @@ public class ClientEventHandler {
boolean onVehicle = player.getVehicle() != null;
if (shakeType > 0) {
event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * (onVehicle ? 0.15 : 1))));
event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.4 : 1))));
event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.4 : 1))));
event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * (onVehicle ? 0.4 : 1))));
} else {
event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * (onVehicle ? 0.15 : 1))));
event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.4 : 1))));
event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.4 : 1))));
event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * (onVehicle ? 0.4 : 1))));
}
}
cameraPitch = event.getPitch();
cameraYaw = event.getYaw();
cameraRoll = event.getRoll();
if (player != null && player.getVehicle() instanceof IArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) {
return;
}

View file

@ -0,0 +1,109 @@
{
"format_version": "1.8.0",
"animations": {
"animation.yx100.idle": {
"loop": true
},
"animation.yx100.fire": {
"loop": "hold_on_last_frame",
"animation_length": 1,
"bones": {
"bone": {
"position": {
"0.0": [0, 0, 0],
"0.0083": [0, 0, 9.25],
"0.0917": {
"pre": [0, 0, 5.64],
"post": [0, 0, 5.64],
"lerp_mode": "catmullrom"
},
"0.175": {
"post": [0, 0, 2.65],
"lerp_mode": "catmullrom"
},
"0.3": {
"post": [0, 0, 0.62],
"lerp_mode": "catmullrom"
},
"0.4833": {
"post": [0, 0, 0],
"lerp_mode": "catmullrom"
}
}
},
"barrelroot": {
"rotation": {
"0.0": {
"post": [0, 0, 0],
"lerp_mode": "catmullrom"
},
"0.0417": {
"post": [-1.86, 0, 0],
"lerp_mode": "catmullrom"
},
"0.0917": {
"post": [-2, 0, 0],
"lerp_mode": "catmullrom"
},
"0.175": {
"post": [-0.38, 0, 0],
"lerp_mode": "catmullrom"
},
"0.2833": {
"post": [1.34, 0, 0],
"lerp_mode": "catmullrom"
},
"0.375": {
"post": [0.88, 0, 0],
"lerp_mode": "catmullrom"
},
"0.4667": {
"post": [-0.24, 0, 0],
"lerp_mode": "catmullrom"
},
"0.6333": {
"post": [0, 0, 0],
"lerp_mode": "catmullrom"
}
}
},
"bone5": {
"rotation": {
"0.0": {
"post": [0, 0, 0],
"lerp_mode": "catmullrom"
},
"0.0417": {
"post": [1.86, 0, 0],
"lerp_mode": "catmullrom"
},
"0.0917": {
"post": [2, 0, 0],
"lerp_mode": "catmullrom"
},
"0.175": {
"post": [0.38, 0, 0],
"lerp_mode": "catmullrom"
},
"0.2833": {
"post": [-1.34, 0, 0],
"lerp_mode": "catmullrom"
},
"0.375": {
"post": [-0.88, 0, 0],
"lerp_mode": "catmullrom"
},
"0.4667": {
"post": [0.24, 0, 0],
"lerp_mode": "catmullrom"
},
"0.6333": {
"post": [0, 0, 0],
"lerp_mode": "catmullrom"
}
}
}
}
}
}
}

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB