From 3c7717303e3862a149696f8a20ca58f04437e51e Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Sun, 3 Nov 2024 17:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B9=85=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E6=81=B6=E5=8A=A3=E7=8E=AF=E5=A2=83=E4=B8=8B=E5=B0=84=E5=87=BB?= =?UTF-8?q?=E8=BF=9E=E7=BB=AD=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/model/item/MinigunItemModel.java | 2 +- .../client/model/item/SentinelItemModel.java | 2 +- .../event/ClientEventHandler.java | 140 ++++++++++++++---- .../superbwarfare/event/GunEventHandler.java | 27 +--- .../network/message/ShootMessage.java | 22 +-- 5 files changed, 126 insertions(+), 67 deletions(-) diff --git a/src/main/java/net/mcreator/superbwarfare/client/model/item/MinigunItemModel.java b/src/main/java/net/mcreator/superbwarfare/client/model/item/MinigunItemModel.java index dddb8b069..ca8a7ae54 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/model/item/MinigunItemModel.java +++ b/src/main/java/net/mcreator/superbwarfare/client/model/item/MinigunItemModel.java @@ -61,7 +61,7 @@ public class MinigunItemModel extends GeoModel { heat_barrels.setScaleZ(4 * heat); - gun.setRotZ((float) (gun.getRotZ() + times * -0.008f * stack.getOrCreateTag().getDouble("minigun_rotation"))); + gun.setRotZ((float) (gun.getRotZ() + times * -0.18f * stack.getOrCreateTag().getDouble("minigun_rotation"))); shen.setPosX((float) (0.75f * ClientEventHandler.recoilHorizon * fpz * fp)); shen.setPosY((float) (-0.03f * fp - 0.06f * fr)); diff --git a/src/main/java/net/mcreator/superbwarfare/client/model/item/SentinelItemModel.java b/src/main/java/net/mcreator/superbwarfare/client/model/item/SentinelItemModel.java index 8b1182724..a84980652 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/model/item/SentinelItemModel.java +++ b/src/main/java/net/mcreator/superbwarfare/client/model/item/SentinelItemModel.java @@ -69,7 +69,7 @@ public class SentinelItemModel extends GeoModel { gun.setScaleZ(1f - (0.7f * (float) zp)); scope.setScaleZ(1f - (0.8f * (float) zp)); - cb.setRotZ(cb.getRotZ() + times * 0.03f * (float) (stack.getOrCreateTag().getDouble("chamber_rot"))); + cb.setRotZ(cb.getRotZ() + times * (float) (stack.getOrCreateTag().getDouble("chamber_rot"))); CoreGeoBone holo = getAnimationProcessor().getBone("holo"); holo.setPosY(0.09f); diff --git a/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java index 159f14106..04a9c8e56 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java @@ -4,10 +4,7 @@ import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.config.client.DisplayConfig; import net.mcreator.superbwarfare.entity.DroneEntity; import net.mcreator.superbwarfare.entity.ICannonEntity; -import net.mcreator.superbwarfare.init.ModItems; -import net.mcreator.superbwarfare.init.ModMobEffects; -import net.mcreator.superbwarfare.init.ModPerks; -import net.mcreator.superbwarfare.init.ModTags; +import net.mcreator.superbwarfare.init.*; import net.mcreator.superbwarfare.network.ModVariables; import net.mcreator.superbwarfare.network.message.ShootMessage; import net.mcreator.superbwarfare.perk.AmmoPerk; @@ -21,6 +18,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; @@ -36,14 +35,17 @@ import net.minecraftforge.client.event.RenderGuiOverlayEvent; import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.ViewportEvent; import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.registries.ForgeRegistries; import org.lwjgl.glfw.GLFW; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; import static net.mcreator.superbwarfare.entity.DroneEntity.ROT_X; @@ -205,6 +207,13 @@ public class ClientEventHandler { && drawTime < 0.01 && !notInGame() && !player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit + && ((GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS || stack.getOrCreateTag().getInt("burst_fire") > 0) + && !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) + && !stack.getOrCreateTag().getBoolean("reloading") + && !stack.getOrCreateTag().getBoolean("charging") + && stack.getOrCreateTag().getInt("ammo") > 0 + && !player.getCooldowns().isOnCooldown(stack.getItem()) + && !stack.getOrCreateTag().getBoolean("need_bolt_action")) || (stack.is(ModItems.MINIGUN.get()) && !player.isSprinting() && stack.getOrCreateTag().getDouble("overheat") == 0 && !player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getDouble("minigun_rotation") >= 10 ))) { double customRpm = 0; @@ -239,6 +248,7 @@ public class ClientEventHandler { } if (clientTimer.getProgress() >= cooldown) { + shootClient(player); ModUtils.PACKET_HANDLER.sendToServer(new ShootMessage(spread)); clientTimer.setProgress((long) (clientTimer.getProgress() - cooldown)); } @@ -253,6 +263,106 @@ public class ClientEventHandler { } } + public static void shootClient(Player player) { + ItemStack stack = player.getMainHandItem(); + if (stack.is(ModTags.Items.NORMAL_GUN)) { + + if (stack.getOrCreateTag().getInt("ammo") > 0) { + + playGunClientSounds(player); + handleClientShoot(); + } + } else if (stack.is(ModItems.MINIGUN.get())) { + var tag = stack.getOrCreateTag(); + + + if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 + || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + + var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO); + float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat"))); + + player.playSound(ModSounds.MINIGUN_FIRE_1P.get(), 2f, pitch); + + if (perk == ModPerks.BEAST_BULLET.get()) { + player.playSound(ModSounds.HENG.get(), 4f, 1f); + } + } + + handleClientShoot(); + } + } + + public static void handleClientShoot() { + Player player = Minecraft.getInstance().player; + if (player == null) return; + CompoundTag tag = player.getMainHandItem().getOrCreateTag(); + if (!player.getMainHandItem().is(ModTags.Items.GUN)) return; + + fireRecoilTime = 10; + + float gunRecoilY = (float) tag.getDouble("recoil_y") * 10; + recoilY = (float) (2 * Math.random() - 1) * gunRecoilY; + + } + + public static void playGunClientSounds(Player player) { + ItemStack stack = player.getMainHandItem(); + if (!stack.is(ModTags.Items.GUN)) { + return; + } + + String origin = stack.getItem().getDescriptionId(); + String name = origin.substring(origin.lastIndexOf(".") + 1); + + if (stack.getItem() == ModItems.SENTINEL.get()) { + AtomicBoolean charged = new AtomicBoolean(false); + + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent( + e -> charged.set(e.getEnergyStored() > 0) + ); + + if (charged.get()) { + SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_fire_1p")); + if (sound1p != null) { + player.playSound(sound1p, 2, 1); + } + return; + } + } + + var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO); + + if (perk == ModPerks.BEAST_BULLET.get()) { + player.playSound(ModSounds.HENG.get(), 4f, 1f); + } + + int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); + + SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(ModUtils.loc(name + (barrelType == 2 ? "_fire_1p_s" : "_fire_1p"))); + + if (sound1p != null) { + player.playSound(sound1p, 2, 1); + } + } + + public static void handleFireRecoilTimeMessage(double time, Supplier ctx) { + if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) { + Player player = Minecraft.getInstance().player; + if (player == null) return; + if (!player.getMainHandItem().is(ModTags.Items.GUN)) return; + + +// fireRecoilTime = time; + shellIndex++; + shellIndexTime[shellIndex] = 0.001; + + randomShell[0] = (1 + 0.2 * (Math.random() - 0.5)); + randomShell[1] = (0.2 + (Math.random() - 0.5)); + randomShell[2] = (0.7 + (Math.random() - 0.5)); + } + } + @SubscribeEvent public static void handleWeaponBreathSway(TickEvent.RenderTickEvent event) { Player player = Minecraft.getInstance().player; @@ -486,28 +596,6 @@ public class ClientEventHandler { zoomPosZ = -Math.pow(2 * zoomTime - 1, 2) + 1; } - public static void handleFireRecoilTimeMessage(double time, Supplier ctx) { - if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) { - Player player = Minecraft.getInstance().player; - if (player == null) return; - CompoundTag tag = player.getMainHandItem().getOrCreateTag(); - if (!player.getMainHandItem().is(ModTags.Items.GUN)) return; - - fireRecoilTime = time; - shellIndex++; - - shellIndexTime[shellIndex] = 0.001; - - randomShell[0] = (1 + 0.2 * (Math.random() - 0.5)); - randomShell[1] = (0.2 + (Math.random() - 0.5)); - randomShell[2] = (0.7 + (Math.random() - 0.5)); - - float gunRecoilY = (float) tag.getDouble("recoil_y") * 10; - recoilY = (float) (2 * Math.random() - 1) * gunRecoilY; - - } - } - private static void handleWeaponFire(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) { float times = 2f * Math.min(Minecraft.getInstance().getDeltaFrameTime(), 0.48f); float yaw = event.getYaw(); diff --git a/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java index 2b5a04e23..ce4c5c9bf 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/GunEventHandler.java @@ -18,7 +18,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -116,24 +115,19 @@ public class GunEventHandler { ); if (charged.get()) { - SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_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, "sentinel_charge_fire_3p")); if (sound3p != null) { - player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.4f, 1f); + player.playSound(sound3p, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.4f, 1f); } SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_far")); if (soundFar != null) { - player.level().playSound(null, player.getOnPos(), soundFar, SoundSource.PLAYERS, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.7f, 1f); + player.playSound(soundFar, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.7f, 1f); } SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_veryfar")); if (soundVeryFar != null) { - player.level().playSound(null, player.getOnPos(), soundVeryFar, SoundSource.PLAYERS, (float) stack.getOrCreateTag().getDouble("SoundRadius"), 1f); + player.playSound(soundVeryFar, (float) stack.getOrCreateTag().getDouble("SoundRadius"), 1f); } return; @@ -144,34 +138,25 @@ public class GunEventHandler { if (perk == ModPerks.BEAST_BULLET.get()) { player.playSound(ModSounds.HENG.get(), 4f, 1f); - - if (player instanceof ServerPlayer serverPlayer) { - SoundTool.playLocalSound(serverPlayer, ModSounds.HENG.get(), 4f, 1f); - } } 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 + (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 + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p"))); if (sound3p != null) { - player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, soundRadius * 0.4f, 1f); + player.playSound(sound3p, soundRadius * 0.4f, 1f); } 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.7f, 1f); + player.playSound(soundFar, soundRadius * 0.7f, 1f); } 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); + player.playSound(soundVeryFar, soundRadius, 1f); } } } diff --git a/src/main/java/net/mcreator/superbwarfare/network/message/ShootMessage.java b/src/main/java/net/mcreator/superbwarfare/network/message/ShootMessage.java index 65b806fb1..941c3f39f 100644 --- a/src/main/java/net/mcreator/superbwarfare/network/message/ShootMessage.java +++ b/src/main/java/net/mcreator/superbwarfare/network/message/ShootMessage.java @@ -70,13 +70,7 @@ public class ShootMessage { double mode = stack.getOrCreateTag().getInt("fire_mode"); int projectileAmount = (int) stack.getOrCreateTag().getDouble("projectile_amount"); - if (((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).holdFire || stack.getOrCreateTag().getInt("burst_fire") > 0) - && !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) - && !stack.getOrCreateTag().getBoolean("reloading") - && !stack.getOrCreateTag().getBoolean("charging") - && stack.getOrCreateTag().getInt("ammo") > 0 - && !player.getCooldowns().isOnCooldown(stack.getItem()) - && !stack.getOrCreateTag().getBoolean("need_bolt_action")) { + if (stack.getOrCreateTag().getInt("ammo") > 0) { int singleInterval = 0; int burstCooldown = 0; @@ -171,14 +165,8 @@ public class ShootMessage { int projectileAmount = (int) tag.getDouble("projectile_amount"); - int count = 0; - for (var inv : player.getInventory().items) { - if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) { - count++; - } - } - - if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 || count > 0) { + if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 + || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { tag.putDouble("heat", (tag.getDouble("heat") + 0.5)); if (tag.getDouble("heat") >= 50.5) { tag.putDouble("overheat", 40); @@ -191,14 +179,12 @@ 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 serverPlayer) { - SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_FIRE_1P.get(), 2f, pitch); 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); if (perk == ModPerks.BEAST_BULLET.get()) { player.playSound(ModSounds.HENG.get(), 4f, pitch); - SoundTool.playLocalSound(serverPlayer, ModSounds.HENG.get(), 4f, pitch); } } @@ -206,7 +192,7 @@ public class ShootMessage { gunShoot(player, spared); } - if (count == 0) { + if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.rifleAmmo = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).rifleAmmo - 1; capability.syncPlayerVariables(player);