修复快艇准星,添加炮塔旋转音效

This commit is contained in:
Atsuihsio 2025-03-09 19:40:28 +08:00
parent 1857d94855
commit 01c1de470a
16 changed files with 137 additions and 25 deletions

View file

@ -198,7 +198,8 @@ public class VehicleHudOverlay {
if (player.getVehicle() instanceof LandArmorEntity iLand && iLand.isDriver(player)
&& iLand instanceof WeaponVehicleEntity weaponVehicle
&& iLand instanceof MobileVehicleEntity mobileVehicle) {
&& iLand instanceof MobileVehicleEntity mobileVehicle
&& !(player.getVehicle() instanceof SpeedboatEntity)) {
poseStack.pushPose();
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);

View file

@ -32,6 +32,8 @@ import org.joml.Math;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.client.overlay.VehicleHudOverlay.renderKillIndicator3P;
import static com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity.AMMO;
import static com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity.HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MACHINE_GUN_HEAT;
import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MG_AMMO;
@ -98,6 +100,12 @@ public class VehicleMgHudOverlay {
guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
}
// 快艇
if (player.getVehicle() instanceof SpeedboatEntity speedboat) {
double heat = speedboat.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : speedboat.getEntityData().get(AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
}
double heal = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth();
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HP " +
@ -114,7 +122,6 @@ public class VehicleMgHudOverlay {
private static boolean shouldRenderCrossHair(Player player) {
if (player == null) return false;
return !player.isSpectator()
&& (player.getVehicle() instanceof SpeedboatEntity
|| player.getVehicle() instanceof Yx100Entity yx100 && yx100.getNthEntity(1) == player);
&& (player.getVehicle() instanceof SpeedboatEntity || (player.getVehicle() instanceof Yx100Entity yx100 && yx100.getNthEntity(1) == player));
}
}

View file

@ -105,8 +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);
bone.setPosY(r * Mth.lerp(partialTick, (float) animatable.recoilShakeO, (float) animatable.getRecoilShake()) * 1.5f);
}
super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);

View file

@ -491,6 +491,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
float diffY = Mth.wrapDegrees(entityData.get(YAW) - this.getYRot());
float diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
turretTurnSound(diffX, diffY);
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -0.6f, 0.6f));
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(diffX, -2f, 2f), -45, 5f));

View file

@ -509,6 +509,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY);
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -74f, 7.5f));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -15, 15));

View file

@ -453,6 +453,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY);
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -32.5f, 15));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -20, 20));

View file

@ -339,6 +339,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
float diffY = Mth.wrapDegrees(entityData.get(YAW) - this.getYRot());
float diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
turretTurnSound(diffX, diffY);
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f));
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.5f * diffX, -3f, 3f), -85, 16.3f));
}

View file

@ -434,6 +434,8 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
float diffY = Mth.wrapDegrees(entityData.get(YAW) - this.getYRot());
float diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
turretTurnSound(diffX, diffY);
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.25f, 1.25f));
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.5f * diffX, -2f, 2f), -30, 4f));
}

View file

@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
@ -15,6 +16,7 @@ import com.atsuishio.superbwarfare.tools.AmmoType;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import com.mojang.math.Axis;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
@ -40,6 +42,8 @@ import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages;
import org.joml.Math;
import org.joml.Matrix4f;
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;
@ -53,7 +57,7 @@ import java.util.Comparator;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity, WeaponVehicleEntity {
public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity, WeaponVehicleEntity, LandArmorEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
@ -228,6 +232,14 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
@Override
public void vehicleShoot(Player player, int type) {
if (this.cannotFire) return;
Matrix4f transform = getBarrelTransform();
float x = 0;
float y = 0;
float z = 0;
Vector4f worldPosition = transformPosition(transform, x, y, z);
ProjectileEntity projectile = new ProjectileEntity(player.level())
.shooter(player)
@ -236,8 +248,8 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
.zoom(false);
projectile.bypassArmorRate(0.4f);
projectile.setPos(this.xo - this.getViewVector(1).scale(0.54).x - this.getDeltaMovement().x, this.yo + 3.0, this.zo - this.getViewVector(1).scale(0.54).z - this.getDeltaMovement().z);
projectile.shoot(player, player.getLookAngle().x, player.getLookAngle().y + (zooming() ? 0.002f : -0.009f), player.getLookAngle().z, 20,
projectile.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
projectile.shoot(player, getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, 20,
(float) 0.4);
this.level().addFreshEntity(projectile);
@ -337,10 +349,48 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
Entity driver = this.getFirstPassenger();
if (driver == null) return;
float gunAngle = -Math.clamp(-140f, 140f, Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot()));
float gunAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot());
this.setTurretYRot(gunAngle);
this.setTurretXRot(driver.getXRot() - this.getXRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY);
this.setTurretXRot(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -40, 40));
this.setTurretYRot(Mth.clamp(this.getTurretYRot() + Mth.clamp(0.95f * diffY, -40, 40), -140, 140));
}
public Matrix4f getBarrelTransform() {
Matrix4f transformT = getTurretTransform();
float x = 0f;
float y = 0.5088375f;
float z = 0.04173125f;
Vector4f worldPosition = transformPosition(transformT, x, y, z);
Matrix4f transform = new Matrix4f();
transform.translate(worldPosition.x, worldPosition.y, worldPosition.z);
transform.rotate(Axis.YP.rotationDegrees(getTurretYRot() - getYRot()));
transform.rotate(Axis.XP.rotationDegrees(getTurretXRot()));
transform.rotate(Axis.ZP.rotationDegrees(getRoll()));
return transform;
}
public Matrix4f getTurretTransform() {
Matrix4f transformT = getVehicleTransform();
float x = 0f;
float y = 2.4616625f;
float z = -0.565625f;
Vector4f worldPosition = transformPosition(transformT, x, y, z);
Matrix4f transform = new Matrix4f();
transform.translate(worldPosition.x, worldPosition.y, worldPosition.z);
transform.rotate(Axis.YP.rotationDegrees(getTurretYRot() - getYRot()));
transform.rotate(Axis.XP.rotationDegrees(getXRot()));
transform.rotate(Axis.ZP.rotationDegrees(getRoll()));
return transform;
}
public float getTurretYRot() {
@ -514,4 +564,46 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
public int getWeaponType(int index) {
return index == 0 ? 0 : -1;
}
@Override
public float turretYRotO() {
return turretYRotO;
}
@Override
public float turretYRot() {
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);
}
public final Vec3 getBarrelVector(float pPartialTicks) {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}
public float getBarrelYRot(float pPartialTick) {
return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot());
}
@Override
public Vec3 getGunVec(float ticks) {
return getBarrelVector(ticks);
}
}

View file

@ -589,6 +589,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
diffY = Mth.wrapDegrees(turretAngle - getTurretYRot() + 0.05f);
diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot());
turretTurnSound(diffX, diffY);
float min = -5 + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
float max = 5 + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
@ -608,6 +610,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
diffY = Mth.wrapDegrees(gunAngle - getGunYRot());
diffX = Mth.wrapDegrees(gunner.getXRot() - this.getGunXRot());
turretTurnSound(diffX, diffY);
this.setGunXRot(Mth.clamp(this.getGunXRot() + Mth.clamp(0.95f * diffX, -10, 10), -60f, 12.5f));
this.setGunYRot(this.getGunYRot() + Mth.clamp(0.9f * diffY, -15, 15));
}
@ -728,18 +732,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
Matrix4f transform = getTurretTransform();
// float x = 0.8669625f;
// float y = 0.2f;
// float z = 0.6076875f;
// y += (float) passenger.getMyRidingOffset();
//
//
// Vector4f worldPosition = transformPosition(transform, x, y, z);
//
// if (passenger instanceof Yx100GunEntity) {
// worldPosition = transformPosition(transform, -x, y + 2, z);
// }
int i = this.getOrderedPassengers().indexOf(passenger);
if (i == 0) {

View file

@ -214,6 +214,12 @@ public abstract class VehicleEntity extends Entity {
roll = rot;
}
public void turretTurnSound(float diffX, float diffY) {
if (level().isClientSide && java.lang.Math.max(Mth.abs(diffX), Mth.abs(diffY)) > 0) {
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), ModSounds.TURRET_TURN.get(), this.getSoundSource(), (float) java.lang.Math.min(0.15 * (java.lang.Math.max(Mth.abs(diffX), Mth.abs(diffY))), 0.75), (random.nextFloat() * 0.05f + 0.95f), false);
}
}
public VehicleEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
this.setHealth(this.getMaxHealth());

View file

@ -422,5 +422,6 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> YX_100_FIRE_3P = REGISTRY.register("yx_100_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_fire_3p")));
public static final RegistryObject<SoundEvent> YX_100_FAR = REGISTRY.register("yx_100_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_far")));
public static final RegistryObject<SoundEvent> YX_100_VERYFAR = REGISTRY.register("yx_100_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_veryfar")));
public static final RegistryObject<SoundEvent> TURRET_TURN = REGISTRY.register("turret_turn", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("turret_turn")));
}

View file

@ -57,7 +57,7 @@ public abstract class CameraMixin {
CameraPos.rotateZ(-boat.getXRot() * Mth.DEG_TO_RAD);
CameraPos.rotateY(-yRot * Mth.DEG_TO_RAD);
setRotation(Mth.lerp(partialTicks, player.yBobO, player.yBob), Mth.lerp(partialTicks, player.xBobO, player.xBob));
setRotation(-Mth.lerp(partialTicks, boat.turretYRotO - boat.yRotO, boat.getTurretYRot() - boat.getYRot()), Mth.lerp(partialTicks, boat.turretXRotO - boat.xRotO, boat.getTurretXRot() - boat.getXRot()));
setPosition(Mth.lerp(partialTicks, boat.xo + CameraPos.x, boat.getX() + CameraPos.x), Mth.lerp(partialTicks, boat.yo + CameraPos.y, boat.getY() + CameraPos.y), Mth.lerp(partialTicks, boat.zo + CameraPos.z, boat.getZ() + CameraPos.z));
info.cancel();
return;

View file

@ -57,7 +57,7 @@ public class LungeMineAttackMessage {
}
Entity lookingEntity = EntityFindUtil.findEntity(player.level(), String.valueOf(message.uuid));
if (lookingEntity != null) {
lookingEntity.hurt(ModDamageTypes.causeLungeMineDamage(player.level().registryAccess(), player, player), lookingEntity instanceof VehicleEntity ? 450 : 150);
lookingEntity.hurt(ModDamageTypes.causeLungeMineDamage(player.level().registryAccess(), player, player), lookingEntity instanceof VehicleEntity ? 600 : 150);
causeLungeMineExplode(player.level(), player, lookingEntity);
}
} else if (message.type == 1) {

View file

@ -2907,5 +2907,13 @@
"stream": false
}
]
},
"turret_turn": {
"sounds": [
{
"name": "superbwarfare:turret_turn",
"stream": false
}
]
}
}