优化NBT#SoundRadius

This commit is contained in:
17146 2024-12-24 14:04:02 +08:00
parent c95c00457e
commit d26a2b6ee9
3 changed files with 13 additions and 8 deletions

View file

@ -101,19 +101,21 @@ public class GunEventHandler {
);
if (charged.get()) {
float soundRadius = (float) GunsTool.getGunDoubleTag(stack, "SoundRadius");
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_fire_3p"));
if (sound3p != null) {
player.playSound(sound3p, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.4f, 1f);
player.playSound(sound3p, soundRadius * 0.4f, 1f);
}
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_far"));
if (soundFar != null) {
player.playSound(soundFar, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.7f, 1f);
player.playSound(soundFar, soundRadius * 0.7f, 1f);
}
SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_veryfar"));
if (soundVeryFar != null) {
player.playSound(soundVeryFar, (float) stack.getOrCreateTag().getDouble("SoundRadius"), 1f);
player.playSound(soundVeryFar, soundRadius, 1f);
}
return;

View file

@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.core.particles.ParticleTypes;
@ -127,9 +128,11 @@ public class ShootMessage {
float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat")));
if (!player.level().isClientSide() && player instanceof ServerPlayer) {
player.playSound(ModSounds.MINIGUN_FIRE_3P.get(), (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.2f, pitch);
player.playSound(ModSounds.MINIGUN_FAR.get(), (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.5f, pitch);
player.playSound(ModSounds.MINIGUN_VERYFAR.get(), (float) stack.getOrCreateTag().getDouble("SoundRadius"), pitch);
float soundRadius = (float) GunsTool.getGunDoubleTag(stack, "SoundRadius");
player.playSound(ModSounds.MINIGUN_FIRE_3P.get(), soundRadius * 0.2f, pitch);
player.playSound(ModSounds.MINIGUN_FAR.get(), soundRadius * 0.5f, pitch);
player.playSound(ModSounds.MINIGUN_VERYFAR.get(), soundRadius, pitch);
if (perk == ModPerks.BEAST_BULLET.get()) {
player.playSound(ModSounds.HENG.get(), 4f, pitch);

View file

@ -55,7 +55,7 @@ public class GunsTool {
public static void initGun(Level level, ItemStack stack, String location) {
if (level.getServer() == null) return;
gunsData.get(location).forEach((k, v) -> {
if (k.equals("EmptyReloadTime") || k.equals("FireMode") || k.equals("Weight")) {
if (k.equals("EmptyReloadTime") || k.equals("FireMode") || k.equals("Weight") || k.equals("SoundRadius")) {
CompoundTag tag = stack.getOrCreateTag();
CompoundTag data = tag.getCompound("GunData");
data.putDouble(k, v);
@ -69,7 +69,7 @@ public class GunsTool {
public static void initCreativeGun(ItemStack stack, String location) {
if (gunsData != null && gunsData.get(location) != null) {
gunsData.get(location).forEach((k, v) -> {
if (k.equals("EmptyReloadTime") || k.equals("FireMode") || k.equals("Weight")) {
if (k.equals("EmptyReloadTime") || k.equals("FireMode") || k.equals("Weight") || k.equals("SoundRadius")) {
CompoundTag tag = stack.getOrCreateTag();
CompoundTag data = tag.getCompound("GunData");
data.putDouble(k, v);