From d6cbba6f54a4b73a9034b95b0e8d866f8203d894 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Wed, 5 Mar 2025 20:46:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0YX-100=E4=BA=8C=E5=8F=B7?= =?UTF-8?q?=E4=BD=8D=E7=9A=84=E5=B0=84=E5=87=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/client/ClickHandler.java | 6 +- .../client/renderer/entity/Yx100Renderer.java | 7 + .../entity/vehicle/Ah6Entity.java | 10 +- .../entity/vehicle/AnnihilatorEntity.java | 6 +- .../entity/vehicle/Bmp2Entity.java | 4 +- .../entity/vehicle/Lav150Entity.java | 4 +- .../entity/vehicle/Mk42Entity.java | 6 +- .../entity/vehicle/Mle1934Entity.java | 6 +- .../entity/vehicle/SpeedboatEntity.java | 4 +- .../entity/vehicle/Yx100Entity.java | 445 +++++++++++++----- .../entity/vehicle/Yx100GunEntity.java | 4 +- .../vehicle/base/ArmedVehicleEntity.java | 4 +- .../event/ClientEventHandler.java | 77 +-- .../superbwarfare/mixins/CameraMixin.java | 6 +- .../mixins/MouseHandlerMixin.java | 8 +- .../network/message/VehicleFireMessage.java | 2 +- .../assets/superbwarfare/geo/yx_100.geo.json | 4 +- 17 files changed, 413 insertions(+), 190 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index 91548decd..e2367d577 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -119,7 +119,7 @@ public class ClickHandler { if (stack.is(ModTags.Items.GUN) || stack.is(ModItems.MONITOR.get()) || stack.is(ModItems.LUNGE_MINE.get()) - || (player.getVehicle() instanceof ArmedVehicleEntity iVehicle && iVehicle.isDriver(player)) + || (player.getVehicle() instanceof ArmedVehicleEntity) || (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) { if (button == ModKeyMappings.FIRE.getKey().getValue()) { handleWeaponFirePress(player, stack); @@ -310,8 +310,8 @@ public class ClickHandler { } - if (player.getVehicle() instanceof ArmedVehicleEntity iVehicle && iVehicle.banHand(player)) { - if (iVehicle.isDriver(player)) { + if (player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.banHand(player)) { + if (player.getVehicle() instanceof VehicleEntity pVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player))) { ClientEventHandler.holdFireVehicle = true; } return; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/Yx100Renderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/Yx100Renderer.java index 93254f4d7..4353239b4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/Yx100Renderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/Yx100Renderer.java @@ -65,6 +65,13 @@ public class Yx100Renderer extends GeoEntityRenderer { bone.setRotX(-Mth.lerp(partialTick, animatable.turretXRotO, animatable.getTurretXRot()) * Mth.DEG_TO_RAD); } + if (name.equals("jiqiang")) { + bone.setRotY(Mth.lerp(partialTick, animatable.gunYRotO, animatable.getGunYRot()) * Mth.DEG_TO_RAD - (animatable.getNthEntity(1) == null ? 0 : Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD)); + } + if (name.equals("qiangguan")) { + bone.setRotX(-Mth.lerp(partialTick, animatable.gunXRotO, animatable.getGunXRot()) * Mth.DEG_TO_RAD); + } + if (name.equals("flare")) { bone.setRotZ((float) (0.5 * (Math.random() - 0.5))); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index a64de3fc6..596bd6372 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -155,7 +155,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity propellerRotO = this.getPropellerRot(); super.baseTick(); - setZRot(getRoll() * 0.99f); + setZRot(getRoll() * (backInputDown ? 0.9f : 0.99f)); if (heat > 0) { heat--; @@ -352,14 +352,14 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(POWER), 0.0f)); Vector3f direction = getRightDirection().mul(-Math.sin(this.getRoll() * Mth.DEG_TO_RAD) * this.entityData.get(PROPELLER_ROT)); - setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(backInputDown ? 0.1 : 2.5))); + setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(3))); // if (passenger instanceof Player player) { // player.displayClientMessage(Component.literal(this.getRoll() + ""), true); // } Vector3f directionZ = getForwardDirection().mul(-Math.cos((this.getXRot() + 90) * Mth.DEG_TO_RAD) * this.entityData.get(PROPELLER_ROT)); - setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(backInputDown ? 0.1 : 2))); + setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(3))); if (this.entityData.get(POWER) > 0.04f) { engineStartOver = true; @@ -527,7 +527,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); Matrix4f transform = getVehicleTransform(); @@ -700,7 +700,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { return 360; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index 8737c2410..58206865d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -126,7 +126,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, if (stack.is(ModItems.CROWBAR.get()) && !player.isCrouching()) { if (this.entityData.get(COOL_DOWN) == 0) { - vehicleShoot(player); + vehicleShoot(player, 0); entityData.set(SHOOTER_UUID, player.getStringUUID()); } return InteractionResult.SUCCESS; @@ -442,7 +442,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { if (this.entityData.get(COOL_DOWN) > 0) { return; } @@ -588,7 +588,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { return 0; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 1e2c3c4a8..566eb5669 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -308,7 +308,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { Matrix4f transform = getBarrelTransform(); if (getWeaponType(0) == 0) { if (this.cannotFire) return; @@ -716,7 +716,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { if (getWeaponType(0) == 0) { return 250; } else if (getWeaponType(0) == 1) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index 89ac5b723..2443fffba 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -277,7 +277,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); Matrix4f transform = getBarrelTransform(); @@ -662,7 +662,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { if (getWeaponType(0) == 0) { return 300; } else if (getWeaponType(0) == 1) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index a24f08412..5a88d7292 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -108,7 +108,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity if (stack.getItem() instanceof CannonShellItem) { if (this.entityData.get(COOL_DOWN) == 0) { - vehicleShoot(player); + vehicleShoot(player, 0); } return InteractionResult.SUCCESS; } @@ -253,7 +253,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { if (this.entityData.get(COOL_DOWN) > 0) { return; } @@ -397,7 +397,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { return 0; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index b66708212..409f8f018 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -113,7 +113,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt if (stack.getItem() instanceof CannonShellItem) { if (this.entityData.get(COOL_DOWN) == 0) { - vehicleShoot(player); + vehicleShoot(player, 0); } return InteractionResult.SUCCESS; } @@ -265,7 +265,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { if (this.entityData.get(COOL_DOWN) > 0) { return; } @@ -491,7 +491,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { return 0; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java index 36ed0eea6..552739797 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -225,7 +225,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo * 机枪塔开火 */ @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { if (this.cannotFire) return; ProjectileEntity projectile = new ProjectileEntity(player.level()) @@ -497,7 +497,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { return 500; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index 48a99fedf..889fa35fe 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -4,16 +4,14 @@ import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; +import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; 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.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import com.mojang.math.Axis; import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; @@ -39,6 +37,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -70,11 +69,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); + public static final EntityDataAccessor MG_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor LOADED_AMMO = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor WEAPON_TYPE = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); + public static final EntityDataAccessor PASSENGER_WEAPON_TYPE = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor TRACK_L = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor TRACK_R = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); + public static final EntityDataAccessor MACHINE_GUN_HEAT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final float MAX_HEALTH = 500; public static final int MAX_ENERGY = 5000000; @@ -84,6 +87,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public float turretXRot; public float turretYRotO; public float turretXRotO; + + public float gunYRot; + public float gunXRot; + public float gunYRotO; + public float gunXRotO; public float leftWheelRot; public float rightWheelRot; public float leftWheelRotO; @@ -93,6 +101,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public double recoilShakeO; public int reloadCoolDown; + public boolean cannotFire; + public Yx100Entity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.YX_100.get(), world); } @@ -106,13 +116,17 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti protected void defineSynchedData() { super.defineSynchedData(); 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(DELTA_ROT, 0f); this.entityData.define(WEAPON_TYPE, 0); + this.entityData.define(PASSENGER_WEAPON_TYPE, 0); 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(MACHINE_GUN_HEAT, 0); } @Override @@ -120,6 +134,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti super.addAdditionalSaveData(compound); compound.putInt("LoadedAmmo", this.entityData.get(LOADED_AMMO)); compound.putInt("WeaponType", getWeaponType(0)); + compound.putInt("PassengerWeaponType", getWeaponType(1)); } @Override @@ -127,6 +142,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti super.readAdditionalSaveData(compound); this.entityData.set(LOADED_AMMO, compound.getInt("LoadedAmmo")); setWeaponType(0, compound.getInt("WeaponType")); + setWeaponType(1, compound.getInt("PassengerWeaponType")); } @Override @@ -169,6 +185,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public void baseTick() { turretYRotO = this.getTurretYRot(); turretXRotO = this.getTurretXRot(); + gunYRotO = this.getGunYRot(); + gunXRotO = this.getGunXRot(); leftWheelRotO = this.getLeftWheelRot(); rightWheelRotO = this.getRightWheelRot(); recoilShakeO = this.getRecoilShake(); @@ -177,10 +195,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti 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); } @@ -201,6 +215,14 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.entityData.set(FIRE_ANIM, this.entityData.get(FIRE_ANIM) - 1); } + if (this.entityData.get(FIRE_TIME) > 0) { + this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1); + } + + if (this.entityData.get(MACHINE_GUN_HEAT) > 0) { + this.entityData.set(MACHINE_GUN_HEAT, this.entityData.get(MACHINE_GUN_HEAT) - 1); + } + if (reloadCoolDown == 70 && this.getFirstPassenger() instanceof Player player) { SoundTool.playLocalSound(player, ModSounds.YX_100_RELOAD.get()); } @@ -212,6 +234,20 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.handleAmmo(); } + if (this.entityData.get(MACHINE_GUN_HEAT) < 40) { + cannotFire = false; + } + + Entity gunner = this.getNthEntity(1); + if (gunner instanceof Player player) { + if (this.entityData.get(MACHINE_GUN_HEAT) > 100) { + cannotFire = true; + if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) { + SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_OVERHEAT.get(), 1f, 1f); + } + } + } + if (this.onGround()) { float f0 = 0.54f + 0.25f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.05 * this.getDeltaMovement().horizontalDistance()))); @@ -244,6 +280,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti collideHardBlock(); } + turretAngle(); gunnerAngle(); lowHealthWarning(); this.refreshDimensions(); @@ -258,14 +295,18 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } private void handleAmmo() { - if (!(this.getFirstPassenger() instanceof Player player)) return; + boolean hasCreativeAmmo = false; - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + if (this.getFirstPassenger() instanceof Player player) { + hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + } if (hasCreativeAmmo) { this.entityData.set(AMMO, 9999); + this.entityData.set(MG_AMMO, 9999); } else { this.entityData.set(AMMO, countItem(getCurrentAmmoItem())); + this.entityData.set(MG_AMMO, countItem(ModItems.HEAVY_AMMO.get())); } if (this.getEntityData().get(LOADED_AMMO) == 0 @@ -288,107 +329,164 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } @Override - public void vehicleShoot(Player player) { - if (reloadCoolDown > 0) return; + public void vehicleShoot(Player player, int type) { + if (reloadCoolDown == 0 && type == 0) { + Matrix4f transform = getBarrelTransform(); + float hitDamage, explosionRadius, explosionDamage, fireProbability; + int fireTime, durability; + float v; - Matrix4f transform = getBarrelTransform(); - float hitDamage, explosionRadius, explosionDamage, fireProbability; - int fireTime, durability; - float v; - - if (getWeaponType(0) == 0) { - hitDamage = 500; - explosionRadius = 4; - explosionDamage = 100; - fireProbability = 0; - fireTime = 0; - durability = 60; - v = 40; - } else if (getWeaponType(0) == 1) { - hitDamage = 100; - explosionRadius = 10; - explosionDamage = 150; - fireProbability = 0.18F; - fireTime = 2; - durability = 1; - v = 25; - } else { - throw new IllegalStateException("Unexpected value: " + getWeaponType(0)); - } - - Vector4f worldPosition = transformPosition(transform, 0, 0, 0); - - CannonShellEntity entityToSpawn = new CannonShellEntity(player, level(), hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime) - .durability(durability); - - entityToSpawn.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); - entityToSpawn.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, v, 0.02f); - level().addFreshEntity(entityToSpawn); - - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.YX_100_FIRE_3P.get(), 8, 1); - serverPlayer.playSound(ModSounds.YX_100_FAR.get(), 16, 1); - serverPlayer.playSound(ModSounds.YX_100_VERYFAR.get(), 32, 1); + if (getWeaponType(0) == 0) { + hitDamage = 500; + explosionRadius = 4; + explosionDamage = 100; + fireProbability = 0; + fireTime = 0; + durability = 60; + v = 40; + } else if (getWeaponType(0) == 1) { + hitDamage = 100; + explosionRadius = 10; + explosionDamage = 150; + fireProbability = 0.18F; + fireTime = 2; + durability = 1; + v = 25; + } else { + throw new IllegalStateException("Unexpected value: " + getWeaponType(0)); } - } - this.entityData.set(FIRE_ANIM, 40); - this.entityData.set(LOADED_AMMO, 0); - this.consumeEnergy(10000); - this.entityData.set(YAW, getTurretYRot()); + Vector4f worldPosition = transformPosition(transform, 0, 0, 0); - reloadCoolDown = 80; + CannonShellEntity entityToSpawn = new CannonShellEntity(player, level(), hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime) + .durability(durability); - if (this.level() instanceof ServerLevel server) { - server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, - this.getX() + 5 * getBarrelVector(1).x, - this.getY() + 0.1, - this.getZ() + 5 * getBarrelVector(1).z, - 300, 6, 0.02, 6, 0.005); + entityToSpawn.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); + entityToSpawn.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, v, 0.02f); + level().addFreshEntity(entityToSpawn); - double x = worldPosition.x + 9 * getBarrelVector(1).x; - double y = worldPosition.y + 9 * getBarrelVector(1).y; - double z = worldPosition.z + 9 * getBarrelVector(1).z; + if (!player.level().isClientSide) { + if (player instanceof ServerPlayer serverPlayer) { + serverPlayer.playSound(ModSounds.YX_100_FIRE_3P.get(), 8, 1); + serverPlayer.playSound(ModSounds.YX_100_FAR.get(), 16, 1); + serverPlayer.playSound(ModSounds.YX_100_VERYFAR.get(), 32, 1); + } + } - server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 10, 0.4, 0.4, 0.4, 0.0075); - server.sendParticles(ParticleTypes.CLOUD, x, y, z, 10, 0.4, 0.4, 0.4, 0.0075); + this.entityData.set(FIRE_ANIM, 40); + this.entityData.set(LOADED_AMMO, 0); + this.consumeEnergy(10000); + this.entityData.set(YAW, getTurretYRot()); - int count = 6; + reloadCoolDown = 80; - for (float i = 9.5f; i < 23; i += .5f) { + if (this.level() instanceof ServerLevel server) { server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, - worldPosition.x + i * getBarrelVector(1).x, - worldPosition.y + i * getBarrelVector(1).y, - worldPosition.z + i * getBarrelVector(1).z, - Mth.clamp(count--, 1, 5), 0.15, 0.15, 0.15, 0.0025); + this.getX() + 5 * getBarrelVector(1).x, + this.getY() + 0.1, + this.getZ() + 5 * getBarrelVector(1).z, + 300, 6, 0.02, 6, 0.005); + + double x = worldPosition.x + 9 * getBarrelVector(1).x; + double y = worldPosition.y + 9 * getBarrelVector(1).y; + double z = worldPosition.z + 9 * getBarrelVector(1).z; + + server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 10, 0.4, 0.4, 0.4, 0.0075); + server.sendParticles(ParticleTypes.CLOUD, x, y, z, 10, 0.4, 0.4, 0.4, 0.0075); + + int count = 6; + + for (float i = 9.5f; i < 23; i += .5f) { + server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, + worldPosition.x + i * getBarrelVector(1).x, + worldPosition.y + i * getBarrelVector(1).y, + worldPosition.z + i * getBarrelVector(1).z, + Mth.clamp(count--, 1, 5), 0.15, 0.15, 0.15, 0.0025); + } + + Vector4f worldPositionL = transformPosition(transform, -0.35f, 0, 0); + Vector4f worldPositionR = transformPosition(transform, 0.35f, 0, 0); + + for (float i = 3f; i < 6; i += .5f) { + server.sendParticles(ParticleTypes.CLOUD, + worldPositionL.x + i * getBarrelVector(1).x, + worldPositionL.y + i * getBarrelVector(1).y, + worldPositionL.z + i * getBarrelVector(1).z, + 1, 0.025, 0.025, 0.025, 0.0015); + + server.sendParticles(ParticleTypes.CLOUD, + worldPositionR.x + i * getBarrelVector(1).x, + worldPositionR.y + i * getBarrelVector(1).y, + worldPositionR.z + i * getBarrelVector(1).z, + 1, 0.025, 0.025, 0.025, 0.0015); + } } - Vector4f worldPositionL = transformPosition(transform, -0.35f, 0, 0); - Vector4f worldPositionR = transformPosition(transform, 0.35f, 0, 0); - for (float i = 3f; i < 6; i += .5f) { - server.sendParticles(ParticleTypes.CLOUD, - worldPositionL.x + i * getBarrelVector(1).x, - worldPositionL.y + i * getBarrelVector(1).y, - worldPositionL.z + i * getBarrelVector(1).z, - 1, 0.025, 0.025, 0.025, 0.0015); + Level level = player.level(); + final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); - server.sendParticles(ParticleTypes.CLOUD, - worldPositionR.x + i * getBarrelVector(1).x, - worldPositionR.y + i * getBarrelVector(1).y, - worldPositionR.z + i * getBarrelVector(1).z, - 1, 0.025, 0.025, 0.025, 0.0015); + for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(8), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { + if (target instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(10, 8, 40, this.getX(), this.getEyeY(), this.getZ())); + } } } + if (type == 1) { + if (this.cannotFire) return; - Level level = player.level(); - final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); + Matrix4f transform = getGunTransform(); + Vector4f worldPosition = transformPosition(transform, 0, 0, 0); - for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(8), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { - if (target instanceof ServerPlayer serverPlayer) { - ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(10, 8, 40, this.getX(), this.getEyeY(), this.getZ())); + ProjectileEntity projectile = new ProjectileEntity(player.level()) + .shooter(player) + .damage(VehicleConfig.SPEEDBOAT_GUN_DAMAGE.get()) + .headShot(2f) + .zoom(false); + + projectile.bypassArmorRate(1f); + projectile.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); + projectile.shoot(getGunVector(1).x, getGunVector(1).y + 0.005f, getGunVector(1).z, 20, 0.02f); + this.level().addFreshEntity(projectile); + + float pitch = this.entityData.get(MACHINE_GUN_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(MACHINE_GUN_HEAT))); + + if (!player.level().isClientSide) { + if (player instanceof ServerPlayer serverPlayer) { + serverPlayer.playSound(ModSounds.M_2_FIRE_3P.get(), 4, pitch); + serverPlayer.playSound(ModSounds.M_2_FAR.get(), 12, pitch); + serverPlayer.playSound(ModSounds.M_2_VERYFAR.get(), 24, pitch); + } + } + + this.entityData.set(FIRE_TIME, 2); + this.entityData.set(MACHINE_GUN_HEAT, this.entityData.get(MACHINE_GUN_HEAT) + 3); + + Level level = player.level(); + final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); + + for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { + if (target instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 5, this.getX(), this.getEyeY(), this.getZ())); + } + } + + boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + + if (!hasCreativeAmmo) { + ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { + if (stack.is(ModItems.AMMO_BOX.get())) { + return AmmoType.HEAVY.get(stack) > 0; + } + return false; + }).findFirst().orElse(ItemStack.EMPTY); + + if (!ammoBox.isEmpty()) { + AmmoType.HEAVY.add(ammoBox, -1); + } else { + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); + } } } } @@ -405,6 +503,18 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return -Mth.lerp(pPartialTick, turretYRotO - this.yRotO, getTurretYRot() - this.getYRot()); } + public Vec3 getGunVector(float pPartialTicks) { + return this.calculateViewVector(this.getGunXRot(pPartialTicks), this.getGunYRot(pPartialTicks)); + } + + public float getGunXRot(float pPartialTicks) { + return Mth.lerp(pPartialTicks, gunXRotO - this.xRotO, getGunXRot() - this.getXRot()); + } + + public float getGunYRot(float pPartialTick) { + return -Mth.lerp(pPartialTick, gunYRotO - this.yRotO, getGunYRot() - this.getYRot()); + } + @Override public void travel() { Entity passenger0 = this.getFirstPassenger(); @@ -466,23 +576,39 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } } - private void gunnerAngle() { + private void turretAngle() { Entity driver = this.getFirstPassenger(); if (!(driver instanceof Player)) return; - float gunAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot()); + float turretAngle = -Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot()); float diffY; float diffX; - diffY = Mth.wrapDegrees(gunAngle - getTurretYRot() + 0.05f); + diffY = Mth.wrapDegrees(turretAngle - getTurretYRot() + 0.05f); diffX = Mth.wrapDegrees(driver.getXRot() - this.getTurretXRot()); - 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); + 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); - this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, min, max), -30f, 4f)); - this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.9f * diffY, -4.5f, 4.5f)); + this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -30f, 4f)); + this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.9f * diffY, min, max)); + } + + private void gunnerAngle() { + Entity gunner = this.getNthEntity(1); + if (!(gunner instanceof Player)) return; + + float gunAngle = -Mth.wrapDegrees(gunner.getYHeadRot() - this.getYRot()); + + float diffY; + float diffX; + + diffY = Mth.wrapDegrees(gunAngle - getGunYRot()); + diffX = Mth.wrapDegrees(gunner.getXRot() - this.getGunXRot()); + + this.setGunXRot(Mth.clamp(this.getGunXRot() + Mth.clamp(0.95f * diffX, -10, 10), -50f, 10f)); + this.setGunYRot(this.getGunYRot() + Mth.clamp(0.9f * diffY, -18, 18)); } @Override @@ -505,6 +631,22 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return turretXRot; } + public float gunYRotO() { + return gunYRotO; + } + + public float gunYRot() { + return gunYRot; + } + + public float gunXRotO() { + return gunXRotO; + } + + public float gunXRot() { + return gunXRot; + } + @Override public Vec3 getBarrelVec(float ticks) { return getBarrelVector(ticks); @@ -526,6 +668,22 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.turretXRot = pTurretXRot; } + public float getGunYRot() { + return this.gunYRot; + } + + public void setGunYRot(float pGunYRot) { + this.gunYRot = pGunYRot; + } + + public float getGunXRot() { + return this.gunXRot; + } + + public void setGunXRot(float pGunXRot) { + this.gunXRot = pGunXRot; + } + public float getLeftWheelRot() { return this.leftWheelRot; } @@ -564,21 +722,29 @@ 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(); +// 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.getSeatIndex(passenger); + int i = this.getOrderedPassengers().indexOf(passenger); - Vector4f worldPosition = transformPosition(transform, x, y, z); - - if (passenger instanceof Yx100GunEntity) { - worldPosition = transformPosition(transform, -x, y + 2, z); + if (i == 0) { + Vector4f worldPosition = transformPosition(transform, 0.8669625f, 0.2f, 0.6076875f); + passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); + callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); + } else if (i == 1) { + Vector4f worldPosition = transformPosition(transform, -0.87890625f, 0.5f, -0.6640625f); + passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); + callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } - - passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); - callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } public int getMaxPassengers() { @@ -600,6 +766,21 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return transform; } + public Matrix4f getGunTransform() { + Matrix4f transformT = getTurretTransform(); + float x = -0.87890625f; + float y = 2f; + float z = -0.6640625f; + 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; @@ -651,12 +832,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } protected void clampRotation(Entity entity) { - float f = Mth.wrapDegrees(entity.getXRot()); - float f1 = Mth.clamp(f, -30F, 4F); - entity.xRotO += f1 - f; - entity.setXRot(entity.getXRot() + f1 - f); - if (entity.level().isClientSide && entity == getFirstPassenger()) { + float f = Mth.wrapDegrees(entity.getXRot()); + float f1 = Mth.clamp(f, -30F, 4F); + entity.xRotO += f1 - f; + entity.setXRot(entity.getXRot() + f1 - f); + Minecraft mc = Minecraft.getInstance(); if (mc.options.getCameraType() == CameraType.FIRST_PERSON) { entity.setYBodyRot(this.getYRot()); @@ -666,6 +847,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti entity.setYRot(entity.getYRot() + f3 - f2); entity.setYBodyRot(this.getYRot()); } + } else if (entity == getNthEntity(1)) { + float f = Mth.wrapDegrees(entity.getXRot()); + float f1 = Mth.clamp(f, -50F, 10F); + entity.xRotO += f1 - f; + entity.setXRot(entity.getXRot() + f1 - f); } } @@ -702,13 +888,28 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { + if (player == getNthEntity(0)) { + return 15; + } + + if (player == getNthEntity(1)) { + return 600; + } return 15; } @Override public boolean canShoot(Player player) { - return this.entityData.get(LOADED_AMMO) > 0; + if (player == getNthEntity(0)) { + return this.entityData.get(LOADED_AMMO) > 0; + } + + if (player == getNthEntity(1)) { + return (this.entityData.get(MG_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; + } + + return false; } @Override @@ -763,12 +964,18 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public int getWeaponType(int index) { - return index == 0 ? entityData.get(WEAPON_TYPE) : -1; + if (index == 0) { + return entityData.get(WEAPON_TYPE); + } else if (index == 1) { + return entityData.get(PASSENGER_WEAPON_TYPE); + } + return -1; } @Override public void setWeaponType(int index, int type) { if (index == 0) entityData.set(WEAPON_TYPE, type); + if (index == 1) entityData.set(PASSENGER_WEAPON_TYPE, type); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100GunEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100GunEntity.java index 6e8e6c2b6..5b932395b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100GunEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100GunEntity.java @@ -111,7 +111,7 @@ public class Yx100GunEntity extends VehicleEntity implements GeoEntity, CannonEn } @Override - public void vehicleShoot(Player player) { + public void vehicleShoot(Player player, int type) { } @@ -160,7 +160,7 @@ public class Yx100GunEntity extends VehicleEntity implements GeoEntity, CannonEn } @Override - public int mainGunRpm() { + public int mainGunRpm(Player player) { return 600; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java index 6b3928b95..cbed13063 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java @@ -10,7 +10,7 @@ public interface ArmedVehicleEntity { * * @param player 玩家 */ - void vehicleShoot(Player player); + void vehicleShoot(Player player, int type); /** * 判断指定玩家是否是载具驾驶员 @@ -30,7 +30,7 @@ public interface ArmedVehicleEntity { * * @return 射速 */ - int mainGunRpm(); + int mainGunRpm(Player player); /** * 当前情况载具是否可以开火 diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 41dc0233e..6f865689f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -64,6 +64,7 @@ import java.util.function.Supplier; import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.COAX_HEAT; import static com.atsuishio.superbwarfare.entity.vehicle.SpeedboatEntity.HEAT; +import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.MACHINE_GUN_HEAT; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ClientEventHandler { @@ -701,8 +702,8 @@ public class ClientEventHandler { holdFireVehicle = false; } - if (player.getVehicle() instanceof ArmedVehicleEntity iVehicle && iVehicle.isDriver(player) && iVehicle.canShoot(player)) { - int rpm = iVehicle.mainGunRpm(); + if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player)) && iVehicle.canShoot(player)) { + int rpm = iVehicle.mainGunRpm(player); if (rpm == 0) { rpm = 240; } @@ -718,8 +719,8 @@ public class ClientEventHandler { } if (clientTimerVehicle.getProgress() >= cooldown) { - ModUtils.PACKET_HANDLER.sendToServer(new VehicleFireMessage(0)); - playVehicleClientSounds(player, iVehicle); + ModUtils.PACKET_HANDLER.sendToServer(new VehicleFireMessage(pVehicle.getSeatIndex(player))); + playVehicleClientSounds(player, iVehicle, pVehicle.getSeatIndex(player)); clientTimerVehicle.setProgress((clientTimerVehicle.getProgress() - cooldown)); } } else if (clientTimerVehicle.getProgress() >= cooldown) { @@ -730,47 +731,51 @@ public class ClientEventHandler { } } - public static void playVehicleClientSounds(Player player, ArmedVehicleEntity iVehicle) { + public static void playVehicleClientSounds(Player player, WeaponVehicleEntity iVehicle, int type) { if (iVehicle instanceof SpeedboatEntity speedboat) { float pitch = speedboat.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - speedboat.getEntityData().get(HEAT))); player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); } - if (iVehicle instanceof WeaponVehicleEntity) { - if (iVehicle instanceof Ah6Entity ah6Entity) { - float pitch = ah6Entity.heat <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.heat)); - if (ah6Entity.getWeaponType(0) == 0) { - ah6Entity.heat += 5; - player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch); - } else if (ah6Entity.getWeaponType(0) == 1) { - player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1); - } + if (iVehicle instanceof Ah6Entity ah6Entity) { + float pitch = ah6Entity.heat <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.heat)); + if (ah6Entity.getWeaponType(0) == 0) { + ah6Entity.heat += 5; + player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch); + } else if (ah6Entity.getWeaponType(0) == 1) { + player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1); + } + } + if (iVehicle instanceof Lav150Entity lav150) { + if (lav150.getWeaponType(0) == 0) { + float pitch = lav150.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(HEAT))); + player.playSound(ModSounds.LAV_CANNON_FIRE_1P.get(), 1f, pitch); + player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); + } else if (lav150.getWeaponType(0) == 1) { + float pitch = lav150.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(COAX_HEAT))); + player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); } - if (iVehicle instanceof Lav150Entity lav150) { - if (lav150.getWeaponType(0) == 0) { - float pitch = lav150.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(HEAT))); - player.playSound(ModSounds.LAV_CANNON_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (lav150.getWeaponType(0) == 1) { - float pitch = lav150.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); - } + } + if (iVehicle instanceof Bmp2Entity bmp2) { + if (bmp2.getWeaponType(0) == 0) { + float pitch = bmp2.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(HEAT))); + player.playSound(ModSounds.BMP_CANNON_FIRE_1P.get(), 1f, pitch); + player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); + } else if (bmp2.getWeaponType(0) == 1) { + float pitch = bmp2.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(COAX_HEAT))); + player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); + } else if (bmp2.getWeaponType(0) == 2) { + player.playSound(ModSounds.BMP_MISSILE_FIRE_1P.get(), 1f, 1); } - if (iVehicle instanceof Bmp2Entity bmp2) { - if (bmp2.getWeaponType(0) == 0) { - float pitch = bmp2.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(HEAT))); - player.playSound(ModSounds.BMP_CANNON_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (bmp2.getWeaponType(0) == 1) { - float pitch = bmp2.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); - } else if (bmp2.getWeaponType(0) == 2) { - player.playSound(ModSounds.BMP_MISSILE_FIRE_1P.get(), 1f, 1); - } - } - if (iVehicle instanceof Yx100Entity) { + } + if (iVehicle instanceof Yx100Entity yx100) { + if (type == 1) { + float pitch = yx100.getEntityData().get(MACHINE_GUN_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(MACHINE_GUN_HEAT))); + player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); + player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); + } else { player.playSound(ModSounds.YX_100_FIRE_1P.get(), 1f, 1); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java index 01d110509..b323e76ac 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java @@ -94,9 +94,9 @@ public abstract class CameraMixin { setRotation(-Mth.lerp(partialTicks, yx100.turretYRotO - yx100.yRotO, yx100.getTurretYRot() - yx100.getYRot()), Mth.lerp(partialTicks, yx100.turretXRotO - yx100.xRotO, yx100.getTurretXRot() - yx100.getXRot())); setPosition(Mth.lerp(partialTicks, player.xo, player.getX()), Mth.lerp(partialTicks, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTicks, player.zo, player.getZ())); info.cancel(); - } else { - setRotation(Mth.lerp(partialTicks, player.yHeadRotO, player.getYHeadRot()), Mth.lerp(partialTicks, player.xRotO, player.getXRot())); - setPosition(Mth.lerp(partialTicks, player.xo, player.getX()) - 6 * player.getViewVector(partialTicks).x, Mth.lerp(partialTicks, player.yo + player.getEyeHeight() + 1, player.getEyeY() + 1) - 6 * player.getViewVector(partialTicks).y, Mth.lerp(partialTicks, player.zo, player.getZ()) - 6 * player.getViewVector(partialTicks).z); + } else if (yx100.getNthEntity(1) == player) { + setRotation(-Mth.lerp(partialTicks, yx100.gunYRotO - yx100.yRotO, yx100.getGunYRot() - yx100.getYRot()), Mth.lerp(partialTicks, yx100.gunXRotO - yx100.xRotO, yx100.getGunXRot() - yx100.getXRot())); + setPosition(Mth.lerp(partialTicks, player.xo, player.getX()), Mth.lerp(partialTicks, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTicks, player.zo, player.getZ())); info.cancel(); } return; diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java index 65227b842..9b2fef0f4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java @@ -61,8 +61,12 @@ public class MouseHandlerMixin { return ClientEventHandler.zoomVehicle ? 0.22 : 0.27; } - if (player.getVehicle() instanceof Yx100Entity) { - return ClientEventHandler.zoomVehicle ? 0.17 : 0.22; + if (player.getVehicle() instanceof Yx100Entity yx100) { + if (player == yx100.getFirstPassenger()) { + return ClientEventHandler.zoomVehicle ? 0.17 : 0.22; + } else if (player ==yx100.getNthEntity(1)){ + return ClientEventHandler.zoomVehicle ? 0.27 : 0.35; + } } if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround() && ah6Entity.getFirstPassenger() == player) { diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/VehicleFireMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/VehicleFireMessage.java index d6d408c46..cee88be12 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/VehicleFireMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/VehicleFireMessage.java @@ -29,7 +29,7 @@ public class VehicleFireMessage { var player = context.getSender(); if (player.getVehicle() instanceof ArmedVehicleEntity iVehicle) { - iVehicle.vehicleShoot(player); + iVehicle.vehicleShoot(player, message.type); } } }); diff --git a/src/main/resources/assets/superbwarfare/geo/yx_100.geo.json b/src/main/resources/assets/superbwarfare/geo/yx_100.geo.json index 7cae7e70e..10401e6c0 100644 --- a/src/main/resources/assets/superbwarfare/geo/yx_100.geo.json +++ b/src/main/resources/assets/superbwarfare/geo/yx_100.geo.json @@ -7379,9 +7379,9 @@ ] }, { - "name": "QQQJ2", + "name": "qiangguan", "parent": "jiqiang", - "pivot": [-14.075, 61.82839, -26.40625], + "pivot": [-14.03469, 61.31016, 9.60856], "cubes": [ { "origin": [-16.36015, 58.61995, -2.03125],