回滚载具近战受伤粒子和音效

This commit is contained in:
17146 2025-06-25 02:10:33 +08:00 committed by Light_Quanta
parent 5ccf5c48fc
commit dc6a704048
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
7 changed files with 65 additions and 4 deletions

View file

@ -165,6 +165,11 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.entityData.set(LOADED_MISSILE, compound.getInt("LoadedMissile"));
}
@Override
public boolean shouldSendHitParticles() {
return false;
}
@Override
protected void playStepSound(@NotNull BlockPos pPos, @NotNull BlockState pState) {
this.playSound(ModSounds.WHEEL_STEP.get(), (float) (getDeltaMovement().length() * 0.2), random.nextFloat() * 0.1f + 1f);

View file

@ -112,6 +112,16 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
return false;
}
@Override
public boolean shouldSendHitParticles() {
return false;
}
@Override
public boolean shouldSendHitSounds() {
return false;
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);

View file

@ -55,6 +55,11 @@ public class MortarEntity extends VehicleEntity implements GeoEntity {
this.entityData.set(YAW, yRot);
}
@Override
public boolean shouldSendHitParticles() {
return false;
}
@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
@ -65,7 +70,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity {
@Override
public boolean canBeCollidedWith() {
return false;
return super.canBeCollidedWith();
}
@Override

View file

@ -94,6 +94,11 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
this.entityData.set(MELON, compound.getBoolean("Melon"));
}
@Override
public boolean shouldSendHitParticles() {
return false;
}
@Override
@ParametersAreNonnullByDefault
protected void playStepSound(BlockPos pPos, BlockState pState) {

View file

@ -85,6 +85,11 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
super.readAdditionalSaveData(compound);
}
@Override
public boolean shouldSendHitParticles() {
return false;
}
@Override
protected void playStepSound(@NotNull BlockPos pPos, @NotNull BlockState pState) {
this.playSound(ModSounds.WHEEL_STEP.get(), (float) (getDeltaMovement().length() * 0.3), random.nextFloat() * 0.15f + 1);

View file

@ -291,6 +291,20 @@ public abstract class VehicleEntity extends Entity {
}
}
/**
* 受击时是否出现粒子效果
*/
public boolean shouldSendHitParticles() {
return true;
}
/**
* 受击时是否出现音效
*/
public boolean shouldSendHitSounds() {
return true;
}
public VehicleEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
this.setHealth(this.getMaxHealth());

View file

@ -4,9 +4,8 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.common.GameplayConfig;
import com.atsuishio.superbwarfare.config.server.MiscConfig;
import com.atsuishio.superbwarfare.data.gun.GunData;
import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.network.message.receive.SimulationDistanceMessage;
import com.atsuishio.superbwarfare.tools.InventoryTool;
@ -24,10 +23,13 @@ import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.AnvilUpdateEvent;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
@EventBusSubscriber
public class PlayerEventHandler {
@ -189,4 +191,19 @@ public class PlayerEventHandler {
event.setMaterialCost(1);
}
}
@SubscribeEvent
public static void onAttackEntity(AttackEntityEvent event) {
var target = event.getTarget();
if (target instanceof VehicleEntity vehicle) {
if (vehicle.shouldSendHitSounds()) {
vehicle.level().playSound(null, vehicle.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
}
if (vehicle.shouldSendHitParticles() && vehicle.level() instanceof ServerLevel serverLevel) {
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), vehicle.getX(), vehicle.getY() + 0.5 * vehicle.getBbHeight(), vehicle.getZ(),
2, 0.4, 0.4, 0.4, 0.2, false);
}
}
}
}