From 4621ac08b659edc7d3dda3b46850b0c29ab85fca Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Thu, 27 Feb 2025 04:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=82=AE=E5=A1=94=E7=B4=A2?= =?UTF-8?q?=E6=95=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/LaserTowerEntity.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java index 1f9e3d4ff..95d7f3c6e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java @@ -63,6 +63,7 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, public static final float MAX_HEALTH = 100; public static final int MAX_ENERGY = 500000; public static final int SHOOT_COST = 5000; + public int changeTargetTimer = 5000; public LaserTowerEntity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.LASER_TOWER.get(), world); @@ -281,6 +282,10 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, this.setRot(this.getYRot(), this.getXRot()); if (this.entityData.get(COOL_DOWN) == 0 && VectorTool.calculateAngle(getViewVector(1), targetVec) < 1) { + changeTargetTimer++; + } + + if (this.entityData.get(COOL_DOWN) == 0 && VectorTool.calculateAngle(getViewVector(1), targetVec) < 1 && NoClip(target)) { this.entityData.set(COOL_DOWN, 40); @@ -293,31 +298,42 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, target.hurt(ModDamageTypes.causeLaserStaticDamage(this.level().registryAccess(), this, this.getOwner()), (float) 15); target.invulnerableTime = 0; entityData.set(LASER_LENGTH, distanceTo(target)); - entityData.set(TARGET_UUID, "none"); if (Math.random() < 0.25 && target instanceof LivingEntity living) { living.setSecondsOnFire(2); } + if (!target.isAlive()) { + entityData.set(TARGET_UUID, "none"); + } this.consumeEnergy(SHOOT_COST); } + } else { entityData.set(TARGET_UUID, "none"); } + + if (changeTargetTimer > 60) { + entityData.set(TARGET_UUID, "none"); + changeTargetTimer = 0; + } } public Entity seekNearLivingEntity(double seekRange) { return StreamSupport.stream(EntityFindUtil.getEntities(level()).getAll().spliterator(), false) .filter(e -> { // TODO 自定义目标列表 - if (e.distanceTo(this) <= seekRange && ( - (e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) + if (e.distanceTo(this) <= seekRange && ((e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) )) { - return level().clip(new ClipContext(this.getEyePosition(), e.getEyePosition(), - ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() != HitResult.Type.BLOCK; + return NoClip(e); } return false; }).min(Comparator.comparingDouble(e -> e.distanceTo(this))).orElse(null); } + public boolean NoClip(Entity target) { + return level().clip(new ClipContext(this.getEyePosition(), target.getEyePosition(), + ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() != HitResult.Type.BLOCK; + } + private PlayState movementPredicate(AnimationState event) { if (this.entityData.get(COOL_DOWN) > 10) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lt.fire"));