From 72cab16f45a4f046a7db46d6347f17b9be2632b4 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Mon, 21 Oct 2024 02:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=A8=E6=B2=A1=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E4=BB=B6=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/event/ClientEventHandler.java | 17 +++++++---------- .../superbwarfare/event/GunEventHandler.java | 9 +++++---- .../superbwarfare/item/gun/rifle/AK12Item.java | 14 ++++++-------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java index a4c422f4c..cfaada219 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java @@ -13,6 +13,7 @@ import net.mcreator.superbwarfare.network.message.ShootMessage; import net.mcreator.superbwarfare.perk.AmmoPerk; import net.mcreator.superbwarfare.perk.Perk; import net.mcreator.superbwarfare.perk.PerkHelper; +import net.mcreator.superbwarfare.tools.GunsTool; import net.mcreator.superbwarfare.tools.MillisTimer; import net.mcreator.superbwarfare.tools.SeekTool; import net.minecraft.client.CameraType; @@ -613,21 +614,17 @@ public class ClientEventHandler { CompoundTag tag = player.getMainHandItem().getOrCreateTag(); float times = (float) Math.min(Minecraft.getInstance().getDeltaFrameTime(), 1.6); - int barrelType = tag.getInt("barrel_type"); + int barrelType = GunsTool.getAttachmentType(player.getMainHandItem(), GunsTool.AttachmentType.BARREL); - double recoil = 1.8; - - if (barrelType == 1) { - recoil = 0.7; - } else if (barrelType == 2) { - recoil = 1; - } + double recoil = switch (barrelType) { + case 1 -> 0.7; + case 2 -> 1; + default -> 1.8; + }; float gunRecoilX = (float) tag.getDouble("recoil_x") * 60; - - if (recoilHorizon > 0) { recoilHorizon = recoilHorizon - Math.min(Math.pow(recoilHorizon, 2), 6) * times + recoilY; } else { diff --git a/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java index b53b62c84..bf62238c7 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java @@ -152,23 +152,24 @@ public class GunEventHandler { float soundRadius = (float) (stack.getOrCreateTag().getDouble("SoundRadius") * stack.getOrCreateTag().getDouble("CustomSoundRadius")); + int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); - SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (stack.getOrCreateTag().getInt("barrel_type") == 2 ? "_fire_1p_s" : "_fire_1p"))); + SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_fire_1p_s" : "_fire_1p"))); if (sound1p != null && player instanceof ServerPlayer serverPlayer) { SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f); } - SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (stack.getOrCreateTag().getInt("barrel_type") == 2 ? "_fire_3p_s" : "_fire_3p"))); + SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p"))); if (sound3p != null) { player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, soundRadius * 0.2f, 1f); } - SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (stack.getOrCreateTag().getInt("barrel_type") == 2 ? "_far_s" : "_far"))); + SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_far_s" : "_far"))); if (soundFar != null) { player.level().playSound(null, player.getOnPos(), soundFar, SoundSource.PLAYERS, soundRadius * 0.5f, 1f); } - SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (stack.getOrCreateTag().getInt("barrel_type") == 2 ? "_veryfar_s" : "_veryfar"))); + SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_veryfar_s" : "_veryfar"))); if (soundVeryFar != null) { player.level().playSound(null, player.getOnPos(), soundVeryFar, SoundSource.PLAYERS, soundRadius, 1f); } diff --git a/src/main/java/net/mcreator/superbwarfare/item/gun/rifle/AK12Item.java b/src/main/java/net/mcreator/superbwarfare/item/gun/rifle/AK12Item.java index 792550e86..61828ef6d 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/gun/rifle/AK12Item.java +++ b/src/main/java/net/mcreator/superbwarfare/item/gun/rifle/AK12Item.java @@ -135,16 +135,14 @@ public class AK12Item extends GunItem implements GeoItem, AnimatedItem { int scopeType = stack.getOrCreateTag().getInt("scope_type"); int barrelType = stack.getOrCreateTag().getInt("barrel_type"); - int magType = stack.getOrCreateTag().getInt("magazine_type"); + int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); int stockType = stack.getOrCreateTag().getInt("stock_type"); - int customMag = 0; - - if (magType == 1) { - customMag = 15; - } else if (magType == 2) { - customMag = 45; - } + int customMag = switch (magType) { + case 1 -> 15; + case 2 -> 45; + default -> 0; + }; // if (scopeType == 1) { //