添加在弹射物击中载具精确位置的特效

This commit is contained in:
Atsuishio 2025-06-17 11:45:42 +08:00 committed by Light_Quanta
parent 5ac84a8938
commit 9dd109c926
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
8 changed files with 20 additions and 54 deletions

View file

@ -190,8 +190,9 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
if (obbVec != null) {
hitPos = new Vec3(obbVec);
if (this.level() instanceof ServerLevel serverLevel) {
this.level().playSound(null, BlockPos.containing(hitPos), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), hitPos.x, hitPos.y, hitPos.z, 2, 0, 0, 0, 0.2, false);
sendParticle(serverLevel, ParticleTypes.SMOKE, hitPos.x, hitPos.y, hitPos.z, 3, 0, 0, 0, 0.01, false);
sendParticle(serverLevel, ParticleTypes.SMOKE, hitPos.x, hitPos.y, hitPos.z, 2, 0, 0, 0, 0.01, false);
}
}
}

View file

@ -174,11 +174,6 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.playSound(ModSounds.WHEEL_STEP.get(), (float) (getDeltaMovement().length() * 0.2), random.nextFloat() * 0.1f + 1f);
}
@Override
public boolean sendFireStarParticleOnHurt() {
return false;
}
@Override
public DamageModifier getDamageModifier() {
return super.getDamageModifier()

View file

@ -98,14 +98,8 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
return Mth.lerp(0.6f * tickDelta, pitchO, getBodyPitch());
}
@Override
public boolean sendFireStarParticleOnHurt() {
return false;
}
@Override
public boolean playHitSoundOnHurt() {
return false;
public DroneEntity(EntityType<? extends DroneEntity> type, Level world, float moveX, float moveY, float moveZ) {
super(type, world);
}
@Override

View file

@ -78,10 +78,6 @@ public class MortarEntity extends VehicleEntity implements GeoEntity {
return 0.2F;
}
@Override
public boolean sendFireStarParticleOnHurt() {
return false;
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {

View file

@ -100,11 +100,6 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
this.playSound(ModSounds.WHEEL_STEP.get(), (float) (getDeltaMovement().length() * 0.3), random.nextFloat() * 0.1f + 1f);
}
@Override
public boolean sendFireStarParticleOnHurt() {
return false;
}
@Override
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
if (player.getMainHandItem().is(Items.MELON) && !entityData.get(MELON)) {

View file

@ -90,11 +90,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
this.playSound(ModSounds.WHEEL_STEP.get(), (float) (getDeltaMovement().length() * 0.3), random.nextFloat() * 0.15f + 1);
}
@Override
public boolean sendFireStarParticleOnHurt() {
return false;
}
@Override
public void baseTick() {
if (jumpCoolDown > 0 && onGround()) {

View file

@ -72,7 +72,6 @@ import java.util.Objects;
import java.util.function.Function;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public abstract class VehicleEntity extends Entity {
@ -430,33 +429,9 @@ public abstract class VehicleEntity extends Entity {
}
this.onHurt(computedAmount, source.getEntity(), true);
// 显示火花粒子效果
if (this.sendFireStarParticleOnHurt() && this.level() instanceof ServerLevel serverLevel) {
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 0.5 * getBbHeight(), this.getZ(), 2, 0.4, 0.4, 0.4, 0.2, false);
}
// 播放受击音效
if (this.playHitSoundOnHurt()) {
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
}
return super.hurt(source, computedAmount);
}
/**
* 受击时是否显示火花粒子效果
*/
public boolean sendFireStarParticleOnHurt() {
return true;
}
/**
* 受击时是否播放受击音效
*/
public boolean playHitSoundOnHurt() {
return true;
}
/**
* 控制载具伤害免疫
*

View file

@ -1,6 +1,12 @@
package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.init.ModParticleTypes;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ProjectileUtil;
@ -17,6 +23,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Optional;
import java.util.function.Predicate;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
@Mixin(ProjectileUtil.class)
public class ProjectileUtilMixin {
@ -35,7 +43,14 @@ public class ProjectileUtilMixin {
if (optional.isPresent()) {
double d1 = pStartVec.distanceToSqr(new Vec3(optional.get()));
if (d1 < Double.MAX_VALUE) {
cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.get())));
EntityHitResult hitResult = new EntityHitResult(entity, new Vec3(optional.get()));
cir.setReturnValue(hitResult);
if (pLevel instanceof ServerLevel serverLevel && pProjectile.getDeltaMovement().lengthSqr() > 0.01) {
Vec3 hitPos = hitResult.getLocation();
pLevel.playSound(null, BlockPos.containing(hitPos), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), hitPos.x, hitPos.y, hitPos.z, 2, 0, 0, 0, 0.2, false);
sendParticle(serverLevel, ParticleTypes.SMOKE, hitPos.x, hitPos.y, hitPos.z, 2, 0, 0, 0, 0.01, false);
}
}
}
}