From dbae5c3c52971318e132393c5d67755439a078ee Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Fri, 13 Dec 2024 03:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=82=AE=E5=A1=94=E7=9A=84?= =?UTF-8?q?=E8=BD=AC=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/model/entity/SpeedboatModel.java | 9 ++- .../renderer/entity/SpeedboatRenderer.java | 1 + .../superbwarfare/entity/SpeedboatEntity.java | 76 +++++++++++-------- .../entity/projectile/ProjectileEntity.java | 1 - 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java index 63f41ee9c..029210c22 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.client.model.entity; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.entity.SpeedboatEntity; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; import software.bernie.geckolib.core.animation.AnimationState; import software.bernie.geckolib.model.GeoModel; @@ -29,11 +30,15 @@ public class SpeedboatModel extends GeoModel { @Override public void setCustomAnimations(SpeedboatEntity animatable, long instanceId, AnimationState animationState) { - CoreGeoBone rotor = getAnimationProcessor().getBone("Rotor"); CoreGeoBone duo = getAnimationProcessor().getBone("duo"); rotor.setRotZ(5 * animatable.getEntityData().get(ROTOR)); - duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? 0.5f : -0.5f) * animatable.getEntityData().get(DELTA_ROT)); + duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? -0.5f : 0.5f) * animatable.getEntityData().get(DELTA_ROT)); + + CoreGeoBone turret = getAnimationProcessor().getBone("paota"); + CoreGeoBone gun = getAnimationProcessor().getBone("gun"); + turret.setRotY(animatable.getEntityData().get(GUN_YAW) * Mth.DEG_TO_RAD); + gun.setRotX(-animatable.getEntityData().get(GUN_PITCH) * Mth.DEG_TO_RAD); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java index 1d2d0249a..4c2cda496 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java @@ -37,6 +37,7 @@ public class SpeedboatRenderer extends GeoEntityRenderer { public void render(SpeedboatEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) { poseStack.pushPose(); poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()))); + poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot()))); super.render(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn); poseStack.popPose(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java index 42c991547..db15565d9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.config.server.CannonConfig; import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; +import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.tools.CustomExplosion; @@ -27,6 +28,7 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; @@ -53,6 +55,8 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor GUN_YAW = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor GUN_PITCH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final float MAX_HEALTH = CannonConfig.MK42_HP.get(); @@ -80,6 +84,8 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, this.entityData.define(DELTA_ROT, 0f); this.entityData.define(POWER, 0f); this.entityData.define(ROTOR, 0f); + this.entityData.define(GUN_YAW, 0f); + this.entityData.define(GUN_PITCH, 0f); } @Override @@ -205,27 +211,21 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, @Override public void baseTick() { super.baseTick(); - double fluidFloat = -0.04; + + double fluidFloat; + fluidFloat = -0.05 + 0.1 * getSubmergedHeight(this); + this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); this.move(MoverType.SELF, this.getDeltaMovement()); - if (this.isInWater()) { - fluidFloat = -0.025 + 0.05 * getSubmergedHeight(this); - float f = 0.7f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; + if (this.onGround()) { + this.setDeltaMovement(this.getDeltaMovement().multiply(0.2, 0.85, 0.2)); + } else if (this.isInWater()) { + float f = 0.73f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length()))); this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f)); - } else if (this.onGround()) { - this.setDeltaMovement(this.getDeltaMovement().multiply(0.2, 0.85, 0.2)); - } else { - this.setDeltaMovement(this.getDeltaMovement().multiply(0.99, 0.85, 0.99)); } - float f = 0.85f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; - this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length()))); - this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f)); - - this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); - if (this.level() instanceof ServerLevel) { this.entityData.set(ROT_Y, this.getYRot()); } @@ -244,6 +244,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, } collideBlock(); + gunnerAngle(); this.refreshDimensions(); } @@ -258,18 +259,16 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, double f = Math.min(entitySize / thisSize, 2); double f1 = Math.min(thisSize / entitySize, 4); - entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z); if (!(entity instanceof TargetEntity)) { this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z); } - if (velocity.length() > 0.2 && entity.isAlive()) { + if (velocity.length() > 0.2 && entity.isAlive() && !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)) { if (!this.level().isClientSide) { this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1); } - if (!(entity instanceof ItemEntity)) { - entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger() ), (float) (25 * velocity.length())); - } + entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z); + entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger() ), (float) (25 * velocity.length())); } } } @@ -294,19 +293,19 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, if (this.getPersistentData().getBoolean("backward")) { this.entityData.set(POWER, this.entityData.get(POWER) - 0.02f); - if (this.getPersistentData().getBoolean("left")) { - diffY = Mth.clamp(diffY + 1f, 0, 5); + if (this.getPersistentData().getBoolean("right")) { + diffY = Mth.clamp(diffY + 1f, 0, 10); handleSetDiffY(diffY); - } else if (this.getPersistentData().getBoolean("right")) { - diffY = Mth.clamp(diffY - 1f, -5, 0); + } else if (this.getPersistentData().getBoolean("left")) { + diffY = Mth.clamp(diffY - 1f, -10, 0); handleSetDiffY(diffY); } } else { - if (this.getPersistentData().getBoolean("left")) { - diffY = Mth.clamp(diffY - 1f, -5, 0); + if (this.getPersistentData().getBoolean("right")) { + diffY = Mth.clamp(diffY - 1f, -10, 0); handleSetDiffY(diffY); - } else if (this.getPersistentData().getBoolean("right")) { - diffY = Mth.clamp(diffY + 1f, 0, 5); + } else if (this.getPersistentData().getBoolean("left")) { + diffY = Mth.clamp(diffY + 1f, 0, 10); handleSetDiffY(diffY); } } @@ -319,14 +318,29 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, this.entityData.set(ROTOR, this.entityData.get(ROTOR) + this.entityData.get(POWER)); this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.8f); + double movementZ = Math.cos(calculateAngle(new Vec3(this.getDeltaMovement().x, 0, this.getDeltaMovement().z), new Vec3(this.getLookAngle().x, 0,this.getLookAngle().z))) * this.getDeltaMovement().horizontalDistance(); + + this.setXRot((float) Mth.lerp(0.1, this.getXRot(),-4f * movementZ)); + if (this.isInWater() || this.isUnderWater()) { - this.setYRot(this.entityData.get(ROT_Y) + this.entityData.get(DELTA_ROT)); + this.setYRot(this.entityData.get(ROT_Y) - this.entityData.get(DELTA_ROT)); this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale(this.entityData.get(POWER)))); } } + private void gunnerAngle() { + Entity gunner = this.getFirstPassenger(); + if (gunner != null) { + + float diffX = gunner.getXRot() - this.getXRot(); + + this.entityData.set(GUN_YAW, (float) Mth.lerp(0.05, this.entityData.get(GUN_YAW), calculateAngle(new Vec3(gunner.getLookAngle().x, 0,gunner.getLookAngle().z), new Vec3(this.getLookAngle().x, 0,this.getLookAngle().z)))); + this.entityData.set(GUN_PITCH, (float) Mth.lerp(0.1, this.entityData.get(GUN_PITCH), diffX)); + } + } + private void handleSetDiffY(float diffY) { - this.entityData.set(DELTA_ROT, (float) Mth.clamp(diffY * 1.3 * Math.max(4 * this.getDeltaMovement().length(), 0.5), -2 ,2)); + this.entityData.set(DELTA_ROT, (float) Mth.clamp(diffY * 1.3 * Math.max(8 * this.getDeltaMovement().length(), 0.5), -2 ,2)); } private void handleClientSync() { @@ -358,8 +372,8 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, protected void positionRider(Entity pPassenger, MoveFunction pCallback) { super.positionRider(pPassenger, pCallback); if (this.hasPassenger(pPassenger) && (this.isInWater() || this.isUnderWater())) { - pPassenger.setYRot(pPassenger.getYRot() + 1.27f * this.entityData.get(DELTA_ROT)); - pPassenger.setYHeadRot(pPassenger.getYHeadRot() + 1.27f * this.entityData.get(DELTA_ROT)); + pPassenger.setYRot(pPassenger.getYRot() - 1.27f * this.entityData.get(DELTA_ROT)); + pPassenger.setYHeadRot(pPassenger.getYHeadRot() - 1.27f * this.entityData.get(DELTA_ROT)); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index 7741ba630..bf50baea3 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -583,7 +583,6 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa public void shoot(Player player, double vecX, double vecY, double vecZ, float velocity, float spread) { Vec3 vec3 = (new Vec3(vecX, vecY, vecZ)).normalize(). add(this.random.triangle(0.0D, 0.0172275D * (double) spread), this.random.triangle(0.0D, 0.0172275D * (double) spread), this.random.triangle(0.0D, 0.0172275D * (double) spread)). - add(player.getDeltaMovement().x, player.onGround() ? 0.0 : 0.05 * player.getDeltaMovement().y, player.getDeltaMovement().z). scale(velocity); this.setDeltaMovement(vec3); double d0 = vec3.horizontalDistance();