优化A10锁定框

This commit is contained in:
Atsuishio 2025-05-10 14:13:32 +08:00 committed by Light_Quanta
parent 7b767f228d
commit f357ae669d
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
16 changed files with 87 additions and 44 deletions

View file

@ -45,11 +45,16 @@ public class AircraftOverlay implements LayeredDraw.Layer {
public static final ResourceLocation ID = Mod.loc("aircraft_hud");
private static float lerpVy = 1;
private static float lerpLock = 1;
private static float lerpG = 1;
private static final ResourceLocation FRAME = Mod.loc("textures/screens/frame/frame.png");
private static final ResourceLocation FRAME_TARGET = Mod.loc("textures/screens/frame/frame_target.png");
private static final ResourceLocation FRAME_LOCK = Mod.loc("textures/screens/frame/frame_lock.png");
private static final ResourceLocation FRAME = Mod.loc("textures/screens/aircraft/frame.png");
private static final ResourceLocation FRAME_TARGET = Mod.loc("textures/screens/aircraft/frame_target.png");
private static final ResourceLocation FRAME_LOCK = Mod.loc("textures/screens/aircraft/frame_lock.png");
private static final ResourceLocation IND_1 = Mod.loc("textures/screens/aircraft/locking_ind1.png");
private static final ResourceLocation IND_2 = Mod.loc("textures/screens/aircraft/locking_ind2.png");
private static final ResourceLocation IND_3 = Mod.loc("textures/screens/aircraft/locking_ind3.png");
private static final ResourceLocation IND_4 = Mod.loc("textures/screens/aircraft/locking_ind4.png");
@Override
public void render(GuiGraphics guiGraphics, @NotNull DeltaTracker deltaTracker) {
@ -107,7 +112,12 @@ public class AircraftOverlay implements LayeredDraw.Layer {
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
RenderSystem.setShaderColor(1, 1, 1, 1);
preciseBlit(guiGraphics, Mod.loc("textures/screens/aircraft/hud_base.png"), x - 160, y - 160, 0, 0, 320, 320, 320, 320);
if (mobileVehicle instanceof A10Entity && weaponVehicle.getWeaponIndex(0) == 3) {
preciseBlit(guiGraphics, Mod.loc("textures/screens/aircraft/hud_base_missile.png"), x - 160, y - 160, 0, 0, 320, 320, 320, 320);
} else {
preciseBlit(guiGraphics, Mod.loc("textures/screens/aircraft/hud_base.png"), x - 160, y - 160, 0, 0, 320, 320, 320, 320);
}
//指南针
preciseBlit(guiGraphics, Mod.loc("textures/screens/compass.png"), x - 128, y - 122, 128 + ((float) 64 / 45 * mobileVehicle.getYRot()), 0, 256, 16, 512, 16);
@ -265,7 +275,7 @@ public class AircraftOverlay implements LayeredDraw.Layer {
if (mobileVehicle instanceof A10Entity a10Entity && a10Entity.getWeaponIndex(0) == 3) {
Entity targetEntity = EntityFindUtil.findEntity(player.level(), a10Entity.getTargetUuid());
List<Entity> entities = SeekTool.seekCustomSizeEntities(a10Entity, player.level(), 384, 20, 0.9);
List<Entity> entities = SeekTool.seekCustomSizeEntities(a10Entity, player.level(), 384, 20, 0.9, true);
for (var e : entities) {
Vec3 pos3 = new Vec3(Mth.lerp(partialTick, e.xo, e.getX()), Mth.lerp(partialTick, e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(partialTick, e.zo, e.getZ()));
@ -280,7 +290,19 @@ public class AircraftOverlay implements LayeredDraw.Layer {
float x = (float) point.x;
float y = (float) point.y;
RenderHelper.preciseBlit(guiGraphics, lockOn ? FRAME_LOCK : nearest ? FRAME_TARGET : FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
if (lockOn) {
RenderHelper.preciseBlit(guiGraphics, FRAME_LOCK, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
} else if (nearest) {
lerpLock = Mth.lerp(partialTick, lerpLock, a10Entity.lockTime);
float lockTime = Mth.clamp(20 - lerpLock, 0, 20);
RenderHelper.preciseBlit(guiGraphics, IND_1, x - 12, y - 12 - lockTime, 24, 24, 0, 0, 24, 24, 24, 24);
RenderHelper.preciseBlit(guiGraphics, IND_2, x - 12, y - 12 + lockTime, 24, 24, 0, 0, 24, 24, 24, 24);
RenderHelper.preciseBlit(guiGraphics, IND_3, x - 12 - lockTime, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
RenderHelper.preciseBlit(guiGraphics, IND_4, x - 12 + lockTime, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
RenderHelper.preciseBlit(guiGraphics, FRAME_TARGET, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
} else {
RenderHelper.preciseBlit(guiGraphics, FRAME, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24);
}
poseStack.popPose();
}
}

View file

@ -128,6 +128,11 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
}
}
@Override
public float getHealth() {
return 200;
}
@Override
public void addAdditionalSaveData(@NotNull CompoundTag compound) {
super.addAdditionalSaveData(compound);

View file

@ -20,6 +20,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
@ -52,9 +53,9 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float damage = 1000.0f;
private float damage = 1100.0f;
private float explosion_damage = 150f;
private float explosion_radius = 11f;
private float explosion_radius = 9f;
private boolean distracted = false;
public Agm65Entity(EntityType<? extends Agm65Entity> type, Level world) {
@ -199,13 +200,13 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D
entity.level().playSound(null, entity.getOnPos(), entity instanceof Pig ? SoundEvents.PIG_HURT : ModSounds.MISSILE_WARNING.get(), SoundSource.PLAYERS, 2, 1f);
}
Vec3 targetPos = new Vec3(entity.getX(), entity.getEyeY() + (entity instanceof EnderDragon ? -3 : 0), entity.getZ()).add(entity.getDeltaMovement());
Vec3 targetPos = new Vec3(entity.getX(), entity.getEyeY() + (entity instanceof EnderDragon ? -3 : 0), entity.getZ());
Vec3 toVec = getEyePosition().vectorTo(targetPos).normalize();
if (this.tickCount > 8) {
boolean lostTarget = (VectorTool.calculateAngle(getDeltaMovement(), toVec) > 80);
if (!lostTarget) {
setDeltaMovement(getDeltaMovement().add(toVec.scale(1)).scale(0.87));
setDeltaMovement(getDeltaMovement().add(toVec.scale(1.4)).scale(0.75).add(entity.getDeltaMovement()));
}
}
}
@ -224,6 +225,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D
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);
}
this.setDeltaMovement(this.getDeltaMovement().multiply(1.06, 1.06, 1.06));
}
if (this.tickCount > 200 || this.isInWater() || this.entityData.get(HEALTH) <= 0) {
@ -235,16 +237,9 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D
this.discard();
}
// 控制速度
if (this.getDeltaMovement().length() < 6) {
this.setDeltaMovement(this.getDeltaMovement().multiply(1.06, 1.06, 1.06));
}
float f = (float) Mth.clamp(1 - 0.005 * getDeltaMovement().length(), 0.001, 1);
if (this.getDeltaMovement().length() > 7) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.95, 0.95, 0.95));
}
this.setDeltaMovement(this.getDeltaMovement().multiply(0.99, 0.99, 0.99));
this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f));
}
private void causeExplode(HitResult result) {
@ -271,7 +266,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D
@Override
protected double getDefaultGravity() {
return 0.1;
return tickCount > 8 ? 0 : 0.15F;
}
@Override

View file

@ -29,8 +29,8 @@ import software.bernie.geckolib.util.GeckoLibUtil;
public class Mk82Entity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, AerialBombEntity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mk82Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float explosion_damage = 520f;
private float explosion_radius = 14f;
private float explosion_damage = 650f;
private float explosion_radius = 11f;
public Mk82Entity(EntityType<? extends Mk82Entity> type, Level world) {
super(type, world);

View file

@ -90,24 +90,24 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
return new VehicleWeapon[][]{
new VehicleWeapon[]{
new SmallCannonShellWeapon()
.damage(VehicleConfig.BMP_2_CANNON_DAMAGE.get())
.explosionDamage(VehicleConfig.BMP_2_CANNON_EXPLOSION_DAMAGE.get().floatValue())
.explosionRadius(VehicleConfig.BMP_2_CANNON_EXPLOSION_RADIUS.get().floatValue())
.damage(25)
.explosionDamage(10)
.explosionRadius(4)
.sound(ModSounds.INTO_CANNON.get())
.icon(Mod.loc("textures/screens/vehicle_weapon/cannon_30mm.png")),
new HeliRocketWeapon()
.damage(VehicleConfig.AH_6_ROCKET_DAMAGE.get())
.explosionDamage(VehicleConfig.AH_6_ROCKET_EXPLOSION_DAMAGE.get())
.explosionRadius(VehicleConfig.AH_6_ROCKET_EXPLOSION_RADIUS.get())
.damage(100)
.explosionDamage(50)
.explosionRadius(6)
.sound(ModSounds.INTO_MISSILE.get()),
new Mk82Weapon()
.explosionDamage(520)
.explosionRadius(14)
.explosionDamage(650)
.explosionRadius(11)
.sound(ModSounds.INTO_MISSILE.get()),
new Agm65Weapon()
.damage(1000)
.damage(1100)
.explosionDamage(150)
.explosionRadius(11)
.explosionRadius(9)
.sound(ModSounds.INTO_MISSILE.get()),
}
};
@ -302,7 +302,7 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
resetSeek(player);
}
Entity entity = SeekTool.seekCustomSizeEntitiy(this, this.level(), 384, 20, 0.9);
Entity entity = SeekTool.seekCustomSizeEntitiy(this, this.level(), 384, 20, 0.9, true);
if (entity != null) {
if (lockTime == 0) {
setTargetUuid(String.valueOf(entity.getUUID()));
@ -414,11 +414,12 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.setPropellerRot(this.getPropellerRot() + 30 * this.entityData.get(POWER));
if (!onGround() && getDeltaMovement().dot(getViewVector(1)) * 72 > 120) {
// 起落架
if (!onGround() && getDeltaMovement().dot(getViewVector(1)) * 72 > 140) {
flyTime = Math.min(flyTime + 1, 20);
}
if (getDeltaMovement().dot(getViewVector(1)) * 72 < 120 && fly) {
if (getDeltaMovement().dot(getViewVector(1)) * 72 < 140 && fly) {
flyTime = Math.max(flyTime - 1, 0);
}
@ -783,20 +784,20 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
Vector4f worldPosition;
if (this.getEntityData().get(LOADED_MISSILE) == 4) {
worldPosition = transformPosition(transform, 1.56875f, -0.943f, 0.1272f);
worldPosition = transformPosition(transform, 1.56875f, -0.943f - 0.5f, 0.1272f);
} else if (this.getEntityData().get(LOADED_MISSILE) == 3) {
worldPosition = transformPosition(transform, -1.56875f, -0.943f, 0.1272f);
worldPosition = transformPosition(transform, -1.56875f, -0.943f - 0.5f, 0.1272f);
} else if (this.getEntityData().get(LOADED_MISSILE) == 2) {
worldPosition = transformPosition(transform, 3.9321875f, -0.88680625f, 0.12965f);
worldPosition = transformPosition(transform, 3.9321875f, -0.88680625f - 0.5f, 0.12965f);
} else {
worldPosition = transformPosition(transform, -3.9321875f, -0.88680625f, 0.12965f);
worldPosition = transformPosition(transform, -3.9321875f, -0.88680625f - 0.5f, 0.12965f);
}
if (locked) {
Agm65Entity.setTargetUuid(getTargetUuid());
}
Agm65Entity.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
Agm65Entity.shoot(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z, (float) getDeltaMovement().length() * 0.8f, 1);
Agm65Entity.shoot(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z, (float) getDeltaMovement().length() + 1, 1);
player.level().addFreshEntity(Agm65Entity);
BlockPos pos = BlockPos.containing(new Vec3(worldPosition.x, worldPosition.y, worldPosition.z));

View file

@ -6,7 +6,7 @@ import net.minecraft.world.entity.LivingEntity;
public class Agm65Weapon extends VehicleWeapon {
public float damage = 1000, explosionDamage = 150, explosionRadius = 11;
public float damage = 1100, explosionDamage = 150, explosionRadius = 9;
public Agm65Weapon() {
this.icon = Mod.loc("textures/screens/vehicle_weapon/agm_65.png");

View file

@ -6,7 +6,7 @@ import net.minecraft.world.entity.LivingEntity;
public class Mk82Weapon extends VehicleWeapon {
public float explosionDamage = 520, explosionRadius = 14;
public float explosionDamage = 650, explosionRadius = 11;
public Mk82Weapon() {
this.icon = Mod.loc("textures/screens/vehicle_weapon/mk_82.png");

View file

@ -17,12 +17,16 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.StreamSupport;
public class SeekTool {
@ -62,12 +66,13 @@ public class SeekTool {
.orElse(null);
}
public static Entity seekCustomSizeEntitiy(Entity entity, Level level, double seekRange, double seekAngle, double size) {
public static Entity seekCustomSizeEntitiy(Entity entity, Level level, double seekRange, double seekAngle, double size, boolean checkOnGround) {
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
.filter(e -> {
if (e.distanceTo(entity) <= seekRange && calculateAngle(e, entity) < seekAngle
&& e != entity
&& baseFilter(e)
&& (!checkOnGround || isOnGround(e))
&& e.getBoundingBox().getSize() >= size
&& smokeFilter(e)
&& e.getVehicle() == null
@ -121,13 +126,14 @@ public class SeekTool {
}).toList();
}
public static List<Entity> seekCustomSizeEntities(Entity entity, Level level, double seekRange, double seekAngle, double size) {
public static List<Entity> seekCustomSizeEntities(Entity entity, Level level, double seekRange, double seekAngle, double size, boolean checkOnGround) {
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
.filter(e -> {
if (e.distanceTo(entity) <= seekRange && calculateAngle(e, entity) < seekAngle
&& e != entity
&& e.getBoundingBox().getSize() >= size
&& baseFilter(e)
&& (!checkOnGround || isOnGround(e))
&& smokeFilter(e)
&& e.getVehicle() == null
&& (!e.isAlliedTo(entity) || e.getTeam() == null || e.getTeam().getName().equals("TDM"))) {
@ -206,6 +212,20 @@ public class SeekTool {
|| includedByConfig(entity);
}
public static boolean isOnGround(Entity entity) {
AtomicBoolean onGround = new AtomicBoolean(false);
AABB aabb = entity.getBoundingBox().expandTowards(0, -10, 0);
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
BlockState blockstate = entity.level().getBlockState(pos);
if (!blockstate.is(Blocks.AIR)) {
onGround.set(true);
}
});
return entity.onGround() || entity.isInWater() || onGround.get();
}
public static boolean smokeFilter(Entity pEntity) {
var Box = pEntity.getBoundingBox().inflate(8);

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B