调整标枪导弹制导逻辑

This commit is contained in:
Atsuihsio 2025-02-01 16:23:36 +08:00
parent a6877a273a
commit f20aa72fda
7 changed files with 69 additions and 54 deletions

View file

@ -37,13 +37,8 @@ public class JavelinMissileRenderer extends GeoEntityRenderer<JavelinMissileEnti
@Override
public void render(JavelinMissileEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
poseStack.pushPose();
if (entityIn.tickCount > 3) {
poseStack.mulPose(Axis.YP.rotationDegrees(90 - Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot())));
poseStack.mulPose(Axis.ZP.rotationDegrees(Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot()) - 90));
} else {
poseStack.mulPose(Axis.YP.rotationDegrees(Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()) - 90));
poseStack.mulPose(Axis.ZP.rotationDegrees(90 + Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot())));
}
super.render(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn);
poseStack.popPose();
}

View file

@ -10,7 +10,6 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.*;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet;
@ -196,16 +195,12 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
if (entity != null) {
if (entity.level() instanceof ServerLevel) {
this.entityData.set(TARGET_X, (float) entity.getX());
this.entityData.set(TARGET_Y, (float) entity.getEyeY());
this.entityData.set(TARGET_Y, (float) entity.getY() + 0.5f * entity.getBbHeight());
this.entityData.set(TARGET_Z, (float) entity.getZ());
if ((!entity.getPassengers().isEmpty() || entity instanceof VehicleEntity) && entity.tickCount %((int)Math.max(0.04 * this.distanceTo(entity),2)) == 0) {
entity.level().playSound(null, entity.getOnPos(), entity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.MISSILE_WARNING.get(), SoundSource.PLAYERS, 2, 1f);
}
}
} else {
this.entityData.set(TARGET_X, (float)(this.getX() + this.getDeltaMovement().scale(10).x));
this.entityData.set(TARGET_Y, (float)(this.getY() + this.getDeltaMovement().scale(10).y));
this.entityData.set(TARGET_Z, (float)(this.getZ() + this.getDeltaMovement().scale(10).z));
}
@ -213,7 +208,31 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
double ex = this.entityData.get(TARGET_X);
double pz = this.getZ();
double ez = this.entityData.get(TARGET_Z);
boolean dir = Math.sqrt(Math.pow(px - ex, 2) + Math.pow(pz - ez, 2)) < 10;
boolean dir = Math.sqrt(Math.pow(px - ex, 2) + Math.pow(pz - ez, 2)) < 30;
Vec3 targetPos = new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + (entity instanceof EnderDragon ? -3 : 0), this.entityData.get(TARGET_Z));
if (entity != null) {
Vec3 toVec = getEyePosition().vectorTo(targetPos).normalize();
if (this.tickCount > 3) {
if (entityData.get(TOP)) {
if (!dir) {
Vec3 targetTopPos = new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + Mth.clamp(5 * this.tickCount, 0, 90), this.entityData.get(TARGET_Z));
Vec3 toTopVec = getEyePosition().vectorTo(targetTopPos).normalize();
setDeltaMovement(getDeltaMovement().add(toTopVec.scale(0.5)));
} else {
boolean lostTarget = this.getY() < entity.getY();
if (!lostTarget) {
setDeltaMovement(getDeltaMovement().add(toVec.scale(0.8)).scale(0.95));
}
}
} else {
boolean lostTarget = (VectorTool.calculateAngle(getDeltaMovement(), toVec) > 80);
if (!lostTarget) {
setDeltaMovement(getDeltaMovement().add(toVec.scale(0.8)).scale(0.9));
}
}
}
}
if (this.tickCount == 4) {
if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {
@ -222,26 +241,7 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
}
}
if (this.tickCount > 3) {
if (entityData.get(TOP)) {
if (!dir) {
this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + Mth.clamp(4 * this.tickCount, 0, 90), this.entityData.get(TARGET_Z)));
} else {
this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + (entity instanceof EnderDragon ? -3 : 0), this.entityData.get(TARGET_Z)));
this.setDeltaMovement(this.getDeltaMovement().multiply(1.03, 1.03, 1.03));
}
} else {
this.look(EntityAnchorArgument.Anchor.EYES, new Vec3(this.entityData.get(TARGET_X), this.entityData.get(TARGET_Y) + (entity instanceof EnderDragon ? -3 : 0), this.entityData.get(TARGET_Z)));
}
}
if (this.tickCount > 4) {
this.setDeltaMovement(new Vec3(
0.7f * this.getDeltaMovement().x + (dir ? 3 : 1.3f) * this.getLookAngle().x,
0.7f * this.getDeltaMovement().y + (dir ? 3 : 1.3f) * this.getLookAngle().y,
0.7f * this.getDeltaMovement().z + (dir ? 3 : 1.3f) * this.getLookAngle().z
));
if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.xo, this.yo, this.zo, 1, 0, 0, 0, 0, true);
}
@ -255,6 +255,17 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
}
this.discard();
}
// 控制速度
if (this.getDeltaMovement().length() < 3) {
this.setDeltaMovement(this.getDeltaMovement().multiply(1.06, 1.06, 1.06));
}
if (this.getDeltaMovement().length() > 3.3) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.9, 0.9, 0.9));
}
this.setDeltaMovement(this.getDeltaMovement().multiply(0.96, 0.96, 0.96));
}
private void causeExplode(HitResult result) {
@ -275,19 +286,6 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
ParticleTool.spawnSmallExplosionParticles(this.level(), result.getLocation());
}
private void look(EntityAnchorArgument.Anchor pAnchor, Vec3 pTarget) {
Vec3 vec3 = pAnchor.apply(this);
double d0 = (pTarget.x - vec3.x) * 0.2;
double d1 = (pTarget.y - vec3.y) * 0.2;
double d2 = (pTarget.z - vec3.z) * 0.2;
double d3 = Math.sqrt(d0 * d0 + d2 * d2);
this.setXRot(Mth.wrapDegrees((float) (-(Mth.atan2(d1, d3) * 57.2957763671875))));
this.setYRot(Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F));
this.setYHeadRot(this.getYRot());
this.xRotO = this.getXRot();
this.yRotO = this.getYRot();
}
private PlayState movementPredicate(AnimationState<JavelinMissileEntity> event) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle"));
}

View file

@ -311,9 +311,9 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 2.5f * this.entityData.get(PROPELLER_ROT));
}
this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 2f) * diffY * this.entityData.get(PROPELLER_ROT) - 0.5f * this.entityData.get(DELTA_ROT), -8f, 8f));
this.setXRot(Mth.clamp(this.getXRot() + ((this.onGround()) ? 0 : 1.4f) * diffX * this.entityData.get(PROPELLER_ROT), -80, 80));
this.setZRot(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.2f) * diffY * this.entityData.get(PROPELLER_ROT));
this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 2f) * diffY * this.entityData.get(PROPELLER_ROT) - 0.5f * this.entityData.get(DELTA_ROT), -10f, 10f));
this.setXRot(Mth.clamp(this.getXRot() + ((this.onGround()) ? 0 : 1.5f) * diffX * this.entityData.get(PROPELLER_ROT), -80, 80));
this.setZRot(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.25f) * diffY * this.entityData.get(PROPELLER_ROT));
}
if (this.level() instanceof ServerLevel) {
@ -327,14 +327,14 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
}
if (up && engineStartOver) {
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.002f, 0.12f));
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0032f, 0.12f));
}
if (engineStartOver) {
if (down) {
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.0375f));
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0022f, this.onGround() ? 0 : 0.01f));
} else if (backInputDown) {
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.052f));
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0022f, this.onGround() ? 0 : 0.052f));
if (passenger != null) {
passenger.setXRot(0.8f * passenger.getXRot());
}
@ -362,7 +362,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
}
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.95f);
this.entityData.set(PROPELLER_ROT, Mth.lerp(0.08f, this.entityData.get(PROPELLER_ROT), this.entityData.get(POWER)));
this.entityData.set(PROPELLER_ROT, Mth.lerp(0.5f, this.entityData.get(PROPELLER_ROT), this.entityData.get(POWER)));
this.setPropellerRot(this.getPropellerRot() + 30 * this.entityData.get(PROPELLER_ROT));
this.entityData.set(PROPELLER_ROT, this.entityData.get(PROPELLER_ROT) * 0.9995f);

View file

@ -580,6 +580,16 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ICha
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);

View file

@ -5,5 +5,7 @@ import net.minecraft.world.phys.Vec3;
public interface ILandArmorEntity extends IArmedVehicleEntity {
float turretYRotO();
float turretYRot();
float turretXRotO();
float turretXRot();
Vec3 getBarrelVec(float ticks);
}

View file

@ -547,6 +547,16 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
return turretYRot;
}
@Override
public float turretXRotO() {
return turretXRotO;
}
@Override
public float turretXRot() {
return turretXRot;
}
@Override
public Vec3 getBarrelVec(float ticks) {
return getBarrelVector(ticks);

View file

@ -55,7 +55,7 @@ public class MouseHandlerMixin {
}
if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround() && ah6Entity.getFirstPassenger() == player) {
return 0.3;
return 0.33;
}
if (player.getVehicle() instanceof Tom6Entity) {