优化部分投射物写法

This commit is contained in:
17146 2025-06-17 16:52:28 +08:00 committed by Light_Quanta
parent 8bccd8426b
commit 7be151d630
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -127,6 +127,9 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
if (compound.contains("Radius")) { if (compound.contains("Radius")) {
this.explosionRadius = compound.getFloat("Radius"); this.explosionRadius = compound.getFloat("Radius");
} }
if (compound.contains("Durability")) {
this.durability = compound.getInt("Durability");
}
} }
@Override @Override
@ -136,6 +139,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
compound.putFloat("Damage", this.damage); compound.putFloat("Damage", this.damage);
compound.putFloat("ExplosionDamage", this.explosionDamage); compound.putFloat("ExplosionDamage", this.explosionDamage);
compound.putFloat("Radius", this.explosionRadius); compound.putFloat("Radius", this.explosionRadius);
compound.putInt("Durability", this.durability);
} }
@Override @Override
@ -146,11 +150,9 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
@Override @Override
protected void onHitEntity(EntityHitResult result) { protected void onHitEntity(EntityHitResult result) {
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle()) if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return; return;
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return;
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) { if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
@ -166,10 +168,10 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
} }
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
apExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i))); causeExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i)), this.explosionRadius * 0.5f, false);
} }
causeExplode(result.getLocation()); causeExplode(result.getLocation(), this.explosionRadius, true);
this.discard(); this.discard();
} }
} }
@ -183,7 +185,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
if (hardness == -1) { if (hardness == -1) {
this.discard(); this.discard();
causeExplode(blockHitResult.getLocation()); causeExplode(blockHitResult.getLocation(), this.explosionRadius, true);
return; return;
} else { } else {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) { if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
@ -191,7 +193,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
} }
} }
causeExplode(blockHitResult.getLocation()); causeExplode(blockHitResult.getLocation(), this.explosionRadius, true);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i)); Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
@ -203,7 +205,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
if (ExplosionConfig.EXPLOSION_DESTROY.get()) { if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true); this.level().destroyBlock(pos, true);
} }
apExplode(hitPos); causeExplode(hitPos, this.explosionRadius * 0.5f, false);
}); });
} }
} }
@ -213,7 +215,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
} }
} }
private void causeExplode(Vec3 vec3) { private void causeExplode(Vec3 vec3, float radius, boolean isHuge) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this, this,
@ -222,31 +224,17 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
vec3.x, vec3.x,
vec3.y, vec3.y,
vec3.z, vec3.z,
explosionRadius, radius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1); setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), vec3); if (isHuge) {
} ParticleTool.spawnHugeExplosionParticles(this.level(), vec3);
} else {
private void apExplode(Vec3 vec3) { ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
CustomExplosion explosion = new CustomExplosion(this.level(), this, }
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
} }
@Override @Override