From 1001d7f2a7feab2c27836ec472d5c41874539fe3 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Tue, 18 Mar 2025 21:46:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96=E7=AC=AC=E4=B8=89=E4=BA=BA?= =?UTF-8?q?=E7=A7=B0=E7=9B=B8=E6=9C=BA=E4=BD=8D=E7=BD=AE=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Ah6Entity.java | 6 +++ .../entity/vehicle/AnnihilatorEntity.java | 6 +++ .../entity/vehicle/Bmp2Entity.java | 6 +++ .../entity/vehicle/Lav150Entity.java | 7 +++ .../entity/vehicle/Mk42Entity.java | 6 +++ .../entity/vehicle/Mle1934Entity.java | 6 +++ .../entity/vehicle/SpeedboatEntity.java | 11 +++-- .../entity/vehicle/Tom6Entity.java | 6 +++ .../entity/vehicle/Yx100Entity.java | 10 +++++ .../base/ThirdPersonCameraPosition.java | 4 ++ .../entity/vehicle/base/VehicleEntity.java | 12 +++++ .../superbwarfare/mixins/CameraMixin.java | 45 +++---------------- 12 files changed, 81 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ThirdPersonCameraPosition.java 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 022ce5160..51fa97bbd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.entity.projectile.FlareDecoyEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.HeliRocketWeapon; @@ -111,6 +112,11 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(7, 1, -2.7); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); 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 f585aed75..2fa01b78d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.EnergyVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.LaserWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; @@ -95,6 +96,11 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(16, 1.3, 0); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); 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 b3f0baabc..3e4d27f09 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon; @@ -104,6 +105,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(3, 1, 0); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); 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 235e8bea4..0c4345193 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon; @@ -64,6 +65,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt public static final float MAX_HEALTH = VehicleConfig.LAV_150_HP.get(); public static final int MAX_ENERGY = VehicleConfig.LAV_150_MAX_ENERGY.get(); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); + public Lav150Entity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.LAV_150.get(), world); } @@ -93,6 +95,11 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(2.75, 1, 0); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); 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 6fd489845..05f1b2594 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.CannonShellWeapon; @@ -102,6 +103,11 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(8, 1, 0); + } + @Override public void addAdditionalSaveData(CompoundTag compound) { super.addAdditionalSaveData(compound); 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 a17e6a634..dc7472627 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.CannonShellWeapon; @@ -95,6 +96,11 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(10, 1.3, 0); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); 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 41585fc8b..ebaa16a51 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -3,10 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; -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.base.*; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; @@ -81,6 +78,11 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(3, 1, 0); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); @@ -335,6 +337,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo transform.rotate(Axis.ZP.rotationDegrees(Mth.lerp(ticks, prevRoll, getRoll()))); return transform; } + @Override public SoundEvent getEngineSound() { return ModSounds.BOAT_ENGINE.get(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java index bc7ed2418..300e7ab79 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.projectile.MelonBombEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; @@ -61,6 +62,11 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { this.setMaxUpStep(0.5f); } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return new ThirdPersonCameraPosition(4, 1, 0); + } + @Override protected void defineSynchedData() { super.defineSynchedData(); 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 e5c7c83bc..9c3e0697e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.CannonShellWeapon; @@ -126,6 +127,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti }; } + @Override + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int index) { + return switch (index) { + case 0 -> new ThirdPersonCameraPosition(5, 1.5, -0.8669625); + case 1 -> new ThirdPersonCameraPosition(-0.5, 2, 0); + default -> null; + }; + } + @Override protected void defineSynchedData() { super.defineSynchedData(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ThirdPersonCameraPosition.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ThirdPersonCameraPosition.java new file mode 100644 index 000000000..8b645fa09 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ThirdPersonCameraPosition.java @@ -0,0 +1,4 @@ +package com.atsuishio.superbwarfare.entity.vehicle.base; + +public record ThirdPersonCameraPosition(double distance, double y, double z) { +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java index 1080507a2..2256358b1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java @@ -208,6 +208,17 @@ public abstract class VehicleEntity extends Entity { return orderedPassengers.indexOf(entity); } + + /** + * 第三人称视角相机位置重载,返回null表示不进行修改 + * + * @param seatIndex 座位索引 + */ + @Nullable + public ThirdPersonCameraPosition getThirdPersonCameraPosition(int seatIndex) { + return null; + } + public float getRoll() { return roll; } @@ -885,4 +896,5 @@ public abstract class VehicleEntity extends Entity { public void setGunXRot(float pGunXRot) { this.gunXRot = pGunXRot; } + } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java index 2f5ff4ff3..07d8e7891 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.mixins; import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModTags; @@ -154,47 +155,11 @@ public abstract class CameraMixin { return; } - if (thirdPerson && entity.getVehicle() instanceof Mk42Entity) { - move(-getMaxZoom(8), 1, 0.0); - return; - } - if (thirdPerson && entity.getVehicle() instanceof Mle1934Entity) { - move(-getMaxZoom(10), 1.3, 0.0); - return; - } - if (thirdPerson && entity.getVehicle() instanceof AnnihilatorEntity) { - move(-getMaxZoom(16), 1.3, 0.0); - return; - } - if (thirdPerson && entity.getVehicle() instanceof SpeedboatEntity && !ClientEventHandler.zoomVehicle) { - move(-getMaxZoom(3), 1, 0.0); - return; - } - if (thirdPerson && entity.getVehicle() instanceof Ah6Entity) { - move(-getMaxZoom(7), 1, -2.7); - return; - } + if (!thirdPerson || !(entity.getVehicle() instanceof VehicleEntity vehicle)) return; - if (thirdPerson && entity.getVehicle() instanceof Tom6Entity) { - move(-getMaxZoom(4), 1, 0); - return; - } - - if (thirdPerson && entity.getVehicle() instanceof Lav150Entity && !ClientEventHandler.zoomVehicle) { - move(-getMaxZoom(2.75), 1, 0.0); - return; - } - - if (thirdPerson && entity.getVehicle() instanceof Bmp2Entity && !ClientEventHandler.zoomVehicle) { - move(-getMaxZoom(3), 1, 0.0); - } - - if (thirdPerson && entity.getVehicle() instanceof Yx100Entity yx100 && !ClientEventHandler.zoomVehicle) { - if (yx100.getFirstPassenger() == entity) { - move(-getMaxZoom(5), 1.5, -0.8669625f); - } else if (yx100.getNthEntity(1) == entity) { - move(-getMaxZoom(-0.5), 2, 0); - } + var cameraPosition = vehicle.getThirdPersonCameraPosition(vehicle.getSeatIndex(entity)); + if (cameraPosition != null) { + move(-getMaxZoom(cameraPosition.distance()), cameraPosition.y(), cameraPosition.z()); } }