提取开火音效播放
This commit is contained in:
parent
c14ab91b83
commit
56818096ec
5 changed files with 76 additions and 76 deletions
|
@ -2,12 +2,13 @@ package com.atsuishio.superbwarfare.event;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.event.events.ReloadEvent;
|
import com.atsuishio.superbwarfare.event.events.ReloadEvent;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.ModAttachments;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.value.AttachmentType;
|
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.value.ReloadState;
|
import com.atsuishio.superbwarfare.item.gun.data.value.ReloadState;
|
||||||
import com.atsuishio.superbwarfare.perk.Perk;
|
|
||||||
import com.atsuishio.superbwarfare.tools.Ammo;
|
import com.atsuishio.superbwarfare.tools.Ammo;
|
||||||
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
import com.atsuishio.superbwarfare.tools.InventoryTool;
|
||||||
import com.atsuishio.superbwarfare.tools.SoundTool;
|
import com.atsuishio.superbwarfare.tools.SoundTool;
|
||||||
|
@ -67,71 +68,6 @@ public class GunEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据武器的注册名来寻找音效并播放
|
|
||||||
*/
|
|
||||||
public static void playGunSounds(Player player, boolean zoom) {
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (!(stack.getItem() instanceof GunItem)) return;
|
|
||||||
var data = GunData.from(stack);
|
|
||||||
|
|
||||||
if (!player.level().isClientSide) {
|
|
||||||
String origin = stack.getItem().getDescriptionId();
|
|
||||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.SENTINEL.get()) {
|
|
||||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
|
||||||
|
|
||||||
if (cap != null && cap.getEnergyStored() > 0) {
|
|
||||||
float soundRadius = (float) data.soundRadius();
|
|
||||||
|
|
||||||
player.playSound(ModSounds.SENTINEL_CHARGE_FAR.get(), soundRadius * 0.7f, 1f);
|
|
||||||
player.playSound(ModSounds.SENTINEL_CHARGE_FIRE_3P.get(), soundRadius * 0.4f, 1f);
|
|
||||||
player.playSound(ModSounds.SENTINEL_CHARGE_VERYFAR.get(), soundRadius, 1f);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get()) {
|
|
||||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
|
||||||
|
|
||||||
if (cap != null && cap.getEnergyStored() > 3000 && zoom) {
|
|
||||||
float soundRadius = (float) data.soundRadius();
|
|
||||||
|
|
||||||
player.playSound(ModSounds.SECONDARY_CATACLYSM_FIRE_3P_CHARGE.get(), soundRadius * 0.4f, 1f);
|
|
||||||
player.playSound(ModSounds.SECONDARY_CATACLYSM_FAR_CHARGE.get(), soundRadius * 0.7f, 1f);
|
|
||||||
player.playSound(ModSounds.SECONDARY_CATACLYSM_VERYFAR_CHARGE.get(), soundRadius, 1f);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var perk = data.perk.get(Perk.Type.AMMO);
|
|
||||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
|
||||||
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float soundRadius = (float) data.soundRadius();
|
|
||||||
int barrelType = data.attachment.get(AttachmentType.BARREL);
|
|
||||||
|
|
||||||
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
|
|
||||||
if (sound3p != null) {
|
|
||||||
player.playSound(sound3p, soundRadius * 0.4f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundEvent soundFar = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_far_s" : "_far")));
|
|
||||||
if (soundFar != null) {
|
|
||||||
player.playSound(soundFar, soundRadius * 0.7f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundEvent soundVeryFar = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_veryfar_s" : "_veryfar")));
|
|
||||||
if (soundVeryFar != null) {
|
|
||||||
player.playSound(soundVeryFar, soundRadius, 1f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void playGunBoltSounds(Player player) {
|
public static void playGunBoltSounds(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
if (!(stack.getItem() instanceof GunItem)) return;
|
if (!(stack.getItem() instanceof GunItem)) return;
|
||||||
|
|
|
@ -4,11 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.client.PoseTool;
|
import com.atsuishio.superbwarfare.client.PoseTool;
|
||||||
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||||
import com.atsuishio.superbwarfare.event.GunEventHandler;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.init.ModAttachments;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
|
||||||
import com.atsuishio.superbwarfare.item.CustomRendererItem;
|
import com.atsuishio.superbwarfare.item.CustomRendererItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.value.AttachmentType;
|
import com.atsuishio.superbwarfare.item.gun.data.value.AttachmentType;
|
||||||
|
@ -19,6 +15,7 @@ import net.minecraft.client.model.HumanoidModel;
|
||||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
@ -536,9 +533,41 @@ public abstract class GunItem extends Item implements CustomRendererItem {
|
||||||
shootBullet(player, data, spread, zoom);
|
shootBullet(player, data, spread, zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 提取对应方法
|
playFireSounds(data, player, zoom);
|
||||||
// 播放音效
|
}
|
||||||
GunEventHandler.playGunSounds(player, zoom);
|
|
||||||
|
/**
|
||||||
|
* 播放开火音效
|
||||||
|
*/
|
||||||
|
public void playFireSounds(GunData data, Player player, boolean zoom) {
|
||||||
|
ItemStack stack = data.stack;
|
||||||
|
if (!(stack.getItem() instanceof GunItem)) return;
|
||||||
|
|
||||||
|
String origin = stack.getItem().getDescriptionId();
|
||||||
|
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||||
|
|
||||||
|
var perk = data.perk.get(Perk.Type.AMMO);
|
||||||
|
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||||
|
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
float soundRadius = (float) data.soundRadius();
|
||||||
|
int barrelType = data.attachment.get(AttachmentType.BARREL);
|
||||||
|
|
||||||
|
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
|
||||||
|
if (sound3p != null) {
|
||||||
|
player.playSound(sound3p, soundRadius * 0.4f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundEvent soundFar = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_far_s" : "_far")));
|
||||||
|
if (soundFar != null) {
|
||||||
|
player.playSound(soundFar, soundRadius * 0.7f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundEvent soundVeryFar = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_veryfar_s" : "_veryfar")));
|
||||||
|
if (soundVeryFar != null) {
|
||||||
|
player.playSound(soundVeryFar, soundRadius, 1f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -268,6 +268,10 @@ public class JavelinItem extends GunItem implements GeoItem {
|
||||||
data.save();
|
data.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShoot(GunData data, Player player, double spread, boolean zoom) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFireKeyRelease(GunData data, Player player, double power, boolean zoom) {
|
public void onFireKeyRelease(GunData data, Player player, double power, boolean zoom) {
|
||||||
super.onFireKeyRelease(data, player, power, zoom);
|
super.onFireKeyRelease(data, player, power, zoom);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||||
import com.atsuishio.superbwarfare.init.ModEnumExtensions;
|
import com.atsuishio.superbwarfare.init.ModEnumExtensions;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||||
|
@ -283,6 +284,21 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playFireSounds(GunData data, Player player, boolean zoom) {
|
||||||
|
var cap = data.stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||||
|
|
||||||
|
if (cap != null && cap.getEnergyStored() > 3000 && zoom) {
|
||||||
|
float soundRadius = (float) data.soundRadius();
|
||||||
|
|
||||||
|
player.playSound(ModSounds.SECONDARY_CATACLYSM_FIRE_3P_CHARGE.get(), soundRadius * 0.4f, 1f);
|
||||||
|
player.playSound(ModSounds.SECONDARY_CATACLYSM_FAR_CHARGE.get(), soundRadius * 0.7f, 1f);
|
||||||
|
player.playSound(ModSounds.SECONDARY_CATACLYSM_VERYFAR_CHARGE.get(), soundRadius, 1f);
|
||||||
|
} else {
|
||||||
|
super.playFireSounds(data, player, zoom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxEnergy() {
|
public int getMaxEnergy() {
|
||||||
return 24000;
|
return 24000;
|
||||||
|
|
|
@ -200,6 +200,21 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playFireSounds(GunData data, Player player, boolean zoom) {
|
||||||
|
var cap = data.stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||||
|
|
||||||
|
if (cap != null && cap.getEnergyStored() > 0) {
|
||||||
|
float soundRadius = (float) data.soundRadius();
|
||||||
|
|
||||||
|
player.playSound(ModSounds.SENTINEL_CHARGE_FAR.get(), soundRadius * 0.7f, 1f);
|
||||||
|
player.playSound(ModSounds.SENTINEL_CHARGE_FIRE_3P.get(), soundRadius * 0.4f, 1f);
|
||||||
|
player.playSound(ModSounds.SENTINEL_CHARGE_VERYFAR.get(), soundRadius, 1f);
|
||||||
|
} else {
|
||||||
|
super.playFireSounds(data, player, zoom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxEnergy() {
|
public int getMaxEnergy() {
|
||||||
return 24000;
|
return 24000;
|
||||||
|
|
Loading…
Add table
Reference in a new issue