调整数值,添加C4音效

This commit is contained in:
Atsuihsio 2025-03-21 13:55:23 +08:00
parent 806053a404
commit fdc7016c72
9 changed files with 71 additions and 28 deletions

View file

@ -1,10 +1,10 @@
package com.atsuishio.superbwarfare.entity; package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -21,7 +21,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.Projectile;
@ -45,7 +44,6 @@ public class C4Entity extends Projectile implements GeoEntity {
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING); protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING);
protected static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING); protected static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
protected boolean inGround; protected boolean inGround;
protected boolean onEntity; protected boolean onEntity;
@ -63,23 +61,11 @@ public class C4Entity extends Projectile implements GeoEntity {
@Override @Override
protected void defineSynchedData() { protected void defineSynchedData() {
this.entityData.define(LAST_ATTACKER_UUID, "undefined"); this.entityData.define(LAST_ATTACKER_UUID, "undefined");
this.entityData.define(HEALTH, 10f);
this.entityData.define(TARGET_UUID, "undefined"); this.entityData.define(TARGET_UUID, "undefined");
} }
@Override
public boolean isPickable() {
return !this.isRemoved();
}
@Override
public boolean hurt(DamageSource source, float amount) {
return false;
}
@Override @Override
public void addAdditionalSaveData(CompoundTag compound) { public void addAdditionalSaveData(CompoundTag compound) {
compound.putFloat("Health", this.entityData.get(HEALTH));
compound.putString("Target", this.entityData.get(TARGET_UUID)); compound.putString("Target", this.entityData.get(TARGET_UUID));
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID)); compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
@ -90,10 +76,6 @@ public class C4Entity extends Projectile implements GeoEntity {
@Override @Override
public void readAdditionalSaveData(CompoundTag compound) { public void readAdditionalSaveData(CompoundTag compound) {
if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health"));
}
if (compound.contains("LastAttacker")) { if (compound.contains("LastAttacker")) {
this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker")); this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker"));
} }
@ -130,6 +112,14 @@ public class C4Entity extends Projectile implements GeoEntity {
this.explode(); this.explode();
} }
if (ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get() - tickCount > 39 && tickCount %((20 * (ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get() - tickCount)) / ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get() + 1) == 0) {
this.level().playSound(null, this.getOnPos(), ModSounds.C4_BEEP.get(), SoundSource.PLAYERS, 1, 1);
}
if (tickCount == ExplosionConfig.C4_EXPLOSION_COUNTDOWN.get() - 39) {
this.level().playSound(null, this.getOnPos(), ModSounds.C4_FINAL.get(), SoundSource.PLAYERS, 2, 1);
}
Vec3 motion = this.getDeltaMovement(); Vec3 motion = this.getDeltaMovement();
if (this.xRotO == 0.0F && this.yRotO == 0.0F && !this.inGround) { if (this.xRotO == 0.0F && this.yRotO == 0.0F && !this.inGround) {
double d0 = motion.horizontalDistance(); double d0 = motion.horizontalDistance();
@ -319,22 +309,25 @@ public class C4Entity extends Projectile implements GeoEntity {
this.inGround = true; this.inGround = true;
} }
public void explode() { private void explode() {
if (!this.level().isClientSide()) { Vec3 pos = position();
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
ModUtils.queueServerWork(1, () -> this.triggerExplode(this)); if (onEntity) {
Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID));
if (target != null) {
pos = target.position();
} }
this.discard();
} }
private void triggerExplode(Entity target) {
CustomExplosion explosion = new CustomExplosion(level(), this, CustomExplosion explosion = new CustomExplosion(level(), this,
ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(),
target.getX(), target.getY(), target.getZ(), ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level(), explosion); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(level(), explosion);
ParticleTool.spawnHugeExplosionParticles(level(), position()); ParticleTool.spawnHugeExplosionParticles(level(), position());
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
this.discard();
} }
@Override @Override

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.C4Entity;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.EnergyVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.EnergyVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition;
@ -215,6 +216,18 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
.multiply(0.3f, ModDamageTypes.CANNON_FIRE) .multiply(0.3f, ModDamageTypes.CANNON_FIRE)
.multiply(0.04f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) .multiply(0.04f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
.custom((source, damage) -> getSourceAngle(source, 3) * damage) .custom((source, damage) -> getSourceAngle(source, 3) * damage)
.custom((source, damage) -> {
if (source.getDirectEntity() instanceof C4Entity) {
return 40f * damage;
}
return damage;
})
.custom((source, damage) -> {
if (source.getDirectEntity() instanceof DroneEntity) {
return 8f * damage;
}
return damage;
})
.reduce(12); .reduce(12);
} }

View file

@ -154,6 +154,12 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
.multiply(0.7f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) .multiply(0.7f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
.multiply(8.5f, ModDamageTypes.VEHICLE_STRIKE) .multiply(8.5f, ModDamageTypes.VEHICLE_STRIKE)
.custom((source, damage) -> getSourceAngle(source, 0.4f) * damage) .custom((source, damage) -> getSourceAngle(source, 0.4f) * damage)
.custom((source, damage) -> {
if (source.getDirectEntity() instanceof DroneEntity) {
return 1.5f * damage;
}
return damage;
})
.reduce(8); .reduce(8);
} }

View file

@ -143,6 +143,12 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
.multiply(0.85f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE) .multiply(0.85f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
.multiply(10f, ModDamageTypes.VEHICLE_STRIKE) .multiply(10f, ModDamageTypes.VEHICLE_STRIKE)
.custom((source, damage) -> getSourceAngle(source, 0.25f) * damage) .custom((source, damage) -> getSourceAngle(source, 0.25f) * damage)
.custom((source, damage) -> {
if (source.getDirectEntity() instanceof DroneEntity) {
return 1.5f * damage;
}
return damage;
})
.reduce(7); .reduce(7);
} }

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.C4Entity;
import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity; import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity;
@ -188,6 +189,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
} }
return damage; return damage;
}) })
.custom((source, damage) -> {
if (source.getDirectEntity() instanceof C4Entity || source.getDirectEntity() instanceof DroneEntity) {
return 3f * damage;
}
return damage;
})
.reduce(9); .reduce(9);
} }

View file

@ -423,5 +423,7 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> YX_100_FAR = REGISTRY.register("yx_100_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_far"))); public static final RegistryObject<SoundEvent> YX_100_FAR = REGISTRY.register("yx_100_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_far")));
public static final RegistryObject<SoundEvent> YX_100_VERYFAR = REGISTRY.register("yx_100_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_veryfar"))); public static final RegistryObject<SoundEvent> YX_100_VERYFAR = REGISTRY.register("yx_100_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("yx_100_veryfar")));
public static final RegistryObject<SoundEvent> TURRET_TURN = REGISTRY.register("turret_turn", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("turret_turn"))); public static final RegistryObject<SoundEvent> TURRET_TURN = REGISTRY.register("turret_turn", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("turret_turn")));
public static final RegistryObject<SoundEvent> C4_BEEP = REGISTRY.register("c4_beep", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_beep")));
public static final RegistryObject<SoundEvent> C4_FINAL = REGISTRY.register("c4_final", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_final")));
} }

View file

@ -2915,5 +2915,21 @@
"stream": false "stream": false
} }
] ]
},
"c4_beep": {
"sounds": [
{
"name": "superbwarfare:c4/c4_beep",
"stream": false
}
]
},
"c4_final": {
"sounds": [
{
"name": "superbwarfare:c4/c4_final",
"stream": false
}
]
} }
} }