diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java index 553e2e5bf..6f15bd615 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java @@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.TraceTool; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; @@ -444,10 +445,13 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit } // 玩家瞄准坐标 - var lookingAt = Vec3.atLowerCornerOf(entity.level().clip( + var lookingBlock = Vec3.atLowerCornerOf(entity.level().clip( new ClipContext(new Vec3(entity.getX(), entity.getEyeY(), entity.getZ()), new Vec3(entity.getX(), entity.getEyeY() + 1, entity.getZ()).add(entity.getLookAngle().scale(512)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos() ); + var lookingEntity = TraceTool.findLookingEntity(entity, 512); + + var lookingAt = lookingEntity != null ? lookingEntity.position() : lookingBlock; var barrelRoot = new Vector3d(4.95, 2.25, 0); barrelRoot.rotateY(-this.getYRot() * Mth.DEG_TO_RAD); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java index ef87f8282..87975952c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java @@ -13,10 +13,10 @@ public class TraceTool { public static boolean laserHeadshot = false; - public static Entity findLookingEntity(Entity player, double entityReach) { + public static Entity findLookingEntity(Entity entity, double entityReach) { double distance = entityReach * entityReach; - Vec3 eyePos = player.getEyePosition(1.0f); - HitResult hitResult = player.pick(entityReach, 1.0f, false); + Vec3 eyePos = entity.getEyePosition(1.0f); + HitResult hitResult = entity.pick(entityReach, 1.0f, false); if (hitResult.getType() != HitResult.Type.MISS) { distance = hitResult.getLocation().distanceToSqr(eyePos); double blockReach = 5; @@ -25,10 +25,10 @@ public class TraceTool { hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos)); } } - Vec3 viewVec = player.getViewVector(1.0F); + Vec3 viewVec = entity.getViewVector(1.0F); Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); - AABB aabb = player.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, p -> !p.isSpectator(), distance); + AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); + EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(entity, eyePos, toVec, aabb, p -> !p.isSpectator(), distance); if (entityhitresult != null) { Vec3 targetPos = entityhitresult.getLocation(); double distanceToTarget = eyePos.distanceToSqr(targetPos);