From 21d3f106373b54fb7a66505f652958dcb0a51c6d Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Fri, 31 Jan 2025 03:19:59 +0800 Subject: [PATCH] =?UTF-8?q?=20=E8=B0=83=E6=95=B4=E6=B1=A4=E5=A7=86F6F?= =?UTF-8?q?=E8=B7=B3=E6=9C=BA=E5=90=8E=E4=B8=8D=E5=9B=9E=E6=AD=A3=E8=A7=92?= =?UTF-8?q?=E5=BA=A6=EF=BC=8C=E8=BD=BD=E5=85=B7=E4=BC=9A=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=B8=8A=E4=B8=80=E4=B8=AA=E9=A9=BE=E9=A9=B6=E5=91=98=E7=9A=84?= =?UTF-8?q?UUID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/MobileVehicleEntity.java | 8 +++++--- .../superbwarfare/entity/vehicle/Tom6Entity.java | 14 ++++++++------ .../entity/vehicle/VehicleEntity.java | 8 ++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java index c5d3db0bb..c8d80e8f6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.LaserEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModSounds; +import com.atsuishio.superbwarfare.tools.EntityFindUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -129,13 +130,14 @@ public class MobileVehicleEntity extends EnergyVehicleEntity { super.move(movementType, movement); if (level() instanceof ServerLevel) { if (lastTickSpeed < 0.3 || collisionCoolDown > 0) return; + Entity driver = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_DRIVER_UUID)); if ((verticalCollision)) { if (this instanceof IHelicopterEntity) { - this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (20 * ((lastTickSpeed - 0.3) * (lastTickSpeed - 0.3)))); + this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (20 * ((lastTickSpeed - 0.3) * (lastTickSpeed - 0.3)))); this.bounceVertical(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite()); } else if (Mth.abs((float) lastTickVerticalSpeed) > 0.6) { - this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (48 * ((Mth.abs((float) lastTickVerticalSpeed) - 0.6) * (lastTickSpeed - 0.4) * (lastTickSpeed - 0.4)))); + this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (48 * ((Mth.abs((float) lastTickVerticalSpeed) - 0.6) * (lastTickSpeed - 0.4) * (lastTickSpeed - 0.4)))); if (!this.level().isClientSide) { this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1); } @@ -144,7 +146,7 @@ public class MobileVehicleEntity extends EnergyVehicleEntity { } if (this.horizontalCollision) { - this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (36 * ((lastTickSpeed - 0.4) * (lastTickSpeed - 0.4)))); + this.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, driver == null ? this : driver), (float) (36 * ((lastTickSpeed - 0.4) * (lastTickSpeed - 0.4)))); this.bounceHorizontal(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite()); if (!this.level().isClientSide) { this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1); 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 c4556f05b..92da4495e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java @@ -121,7 +121,9 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { f = (float) Mth.clamp(0.759f + 0.041f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99); - this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale((0.24) * this.getDeltaMovement().length()))); + boolean forward = Mth.abs((float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) < 90; + + this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale((forward ? 0.24 : -0.24) * this.getDeltaMovement().length()))); this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f)); if (onGround()) { @@ -146,11 +148,11 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { this.rightInputDown = false; this.forwardInputDown = false; this.backInputDown = false; - this.setZRot(this.roll * 0.8f); - this.setXRot(this.getXRot() * 0.7f); - this.entityData.set(POWER, this.entityData.get(POWER) * 0.98f); + this.entityData.set(POWER, this.entityData.get(POWER) * 0.95f); if (onGround()) { - this.setDeltaMovement(this.getDeltaMovement().multiply(0.8, 1, 0.8)); + this.setDeltaMovement(this.getDeltaMovement().multiply(0.96, 1, 0.96)); + } else { + this.setXRot(Mth.clamp(this.getXRot() + 0.1f, -89, 89)); } } else if (passenger instanceof Player player) { if (level().isClientSide && this.getEnergy() > 0) { @@ -163,7 +165,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { } if (backInputDown || downInputDown) { - this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.006f, onGround() ? -0.12f : 0.04f)); + this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - (this.entityData.get(POWER) > 0 ? 0.006f : 0.001f), onGround() ? -0.12f : 0.04f)); } if (!onGround()) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index 44262ac61..2958ed5f4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -42,6 +42,7 @@ public class VehicleEntity extends Entity { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); protected static final EntityDataAccessor LAST_ATTACKER_UUID = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.STRING); + protected static final EntityDataAccessor LAST_DRIVER_UUID = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.STRING); protected int interpolationSteps; protected double x; @@ -84,11 +85,13 @@ public class VehicleEntity extends Entity { protected void defineSynchedData() { this.entityData.define(HEALTH, this.getMaxHealth()); this.entityData.define(LAST_ATTACKER_UUID, "undefined"); + this.entityData.define(LAST_DRIVER_UUID, "undefined"); } @Override protected void readAdditionalSaveData(CompoundTag compound) { this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker")); + this.entityData.set(LAST_DRIVER_UUID, compound.getString("LastDriver")); this.entityData.set(HEALTH, compound.getFloat("Health")); } @@ -96,6 +99,7 @@ public class VehicleEntity extends Entity { public void addAdditionalSaveData(CompoundTag compound) { compound.putFloat("Health", this.entityData.get(HEALTH)); compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID)); + compound.putString("LastDriver", this.entityData.get(LAST_DRIVER_UUID)); } @Override @@ -264,6 +268,10 @@ public class VehicleEntity extends Entity { } } + if (getFirstPassenger() != null) { + this.entityData.set(LAST_DRIVER_UUID, getFirstPassenger().getStringUUID()); + } + this.refreshDimensions(); }