优化javelin的目标锁定

This commit is contained in:
Atsuishio 2025-06-08 15:26:09 +08:00 committed by Light_Quanta
parent 0c43f29918
commit 6633cc7723
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -116,14 +116,12 @@ public class JavelinItem extends GunItem {
} }
Entity targetEntity = EntityFindUtil.findEntity(player.level(), tag.getString("TargetEntity")); Entity targetEntity = EntityFindUtil.findEntity(player.level(), tag.getString("TargetEntity"));
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
if (tag.getInt("GuideType") == 0) { if (tag.getInt("GuideType") == 0) {
if (seekingEntity != null && seekingEntity == targetEntity) { if (targetEntity != null && VectorTool.calculateAngle(player.getViewVector(1), player.getEyePosition().vectorTo(targetEntity.getBoundingBox().getCenter())) < 8) {
tag.putInt("SeekTime", tag.getInt("SeekTime") + 1); tag.putInt("SeekTime", tag.getInt("SeekTime") + 1);
if (tag.getInt("SeekTime") > 0 && (!seekingEntity.getPassengers().isEmpty() || seekingEntity instanceof VehicleEntity) && seekingEntity.tickCount % 3 == 0) { if (tag.getInt("SeekTime") > 0 && (!targetEntity.getPassengers().isEmpty() || targetEntity instanceof VehicleEntity) && targetEntity.tickCount % 3 == 0) {
seekingEntity.level().playSound(null, seekingEntity.getOnPos(), seekingEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKING_WARNING.get(), SoundSource.PLAYERS, 1, 1f); targetEntity.level().playSound(null, targetEntity.getOnPos(), targetEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKING_WARNING.get(), SoundSource.PLAYERS, 1, 1f);
} }
} else { } else {
tag.putInt("SeekTime", 0); tag.putInt("SeekTime", 0);
@ -133,12 +131,12 @@ public class JavelinItem extends GunItem {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCK.get(), 1, 1); SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCK.get(), 1, 1);
} }
if (seekingEntity != null && tag.getInt("SeekTime") > 20) { if (targetEntity != null && tag.getInt("SeekTime") > 20) {
if (player instanceof ServerPlayer serverPlayer) { if (player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCKON.get(), 1, 1); SoundTool.playLocalSound(serverPlayer, ModSounds.JAVELIN_LOCKON.get(), 1, 1);
} }
if ((!seekingEntity.getPassengers().isEmpty() || seekingEntity instanceof VehicleEntity) && seekingEntity.tickCount % 2 == 0) { if ((!targetEntity.getPassengers().isEmpty() || targetEntity instanceof VehicleEntity) && targetEntity.tickCount % 2 == 0) {
seekingEntity.level().playSound(null, seekingEntity.getOnPos(), seekingEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKED_WARNING.get(), SoundSource.PLAYERS, 1, 0.95f); targetEntity.level().playSound(null, targetEntity.getOnPos(), targetEntity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.LOCKED_WARNING.get(), SoundSource.PLAYERS, 1, 0.95f);
} }
} }
@ -161,6 +159,12 @@ public class JavelinItem extends GunItem {
} }
} }
} }
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);
if (seekingEntity instanceof DecoyEntity) {
tag.putInt("SeekTime", 0);
}
} }
} else { } else {
tag.putInt("SeekTime", 0); tag.putInt("SeekTime", 0);