允许歼灭者炮瞄准角度修正在瞄准实体时也生效

This commit is contained in:
Light_Quanta 2024-12-06 23:51:48 +08:00
parent 82d138679d
commit faf061610d
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 11 additions and 7 deletions

View file

@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SoundTool; import com.atsuishio.superbwarfare.tools.SoundTool;
import com.atsuishio.superbwarfare.tools.TraceTool;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes; 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)), 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() 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); var barrelRoot = new Vector3d(4.95, 2.25, 0);
barrelRoot.rotateY(-this.getYRot() * Mth.DEG_TO_RAD); barrelRoot.rotateY(-this.getYRot() * Mth.DEG_TO_RAD);

View file

@ -13,10 +13,10 @@ public class TraceTool {
public static boolean laserHeadshot = false; 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; double distance = entityReach * entityReach;
Vec3 eyePos = player.getEyePosition(1.0f); Vec3 eyePos = entity.getEyePosition(1.0f);
HitResult hitResult = player.pick(entityReach, 1.0f, false); HitResult hitResult = entity.pick(entityReach, 1.0f, false);
if (hitResult.getType() != HitResult.Type.MISS) { if (hitResult.getType() != HitResult.Type.MISS) {
distance = hitResult.getLocation().distanceToSqr(eyePos); distance = hitResult.getLocation().distanceToSqr(eyePos);
double blockReach = 5; 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)); 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); 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); AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D);
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, p -> !p.isSpectator(), distance); EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(entity, eyePos, toVec, aabb, p -> !p.isSpectator(), distance);
if (entityhitresult != null) { if (entityhitresult != null) {
Vec3 targetPos = entityhitresult.getLocation(); Vec3 targetPos = entityhitresult.getLocation();
double distanceToTarget = eyePos.distanceToSqr(targetPos); double distanceToTarget = eyePos.distanceToSqr(targetPos);