From fcf0ce65b45bee9fb79386356b6e314283ebf762 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Thu, 10 Apr 2025 23:25:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E5=B1=8F=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/client/ClickHandler.java | 13 ++-- .../client/ClientRenderHandler.java | 1 + .../client/overlay/BreathOverlay.java | 59 +++++++++++++++++++ .../event/ClientEventHandler.java | 51 ++++++++++++---- .../item/gun/special/BocekItem.java | 16 ++--- 5 files changed, 112 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/client/overlay/BreathOverlay.java diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index 63113ad85..9ab0a7583 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -274,9 +274,6 @@ public class ClickHandler { } } - if (key == ModKeyMappings.BREATH.getKey().getValue()) { -// PacketDistributor.sendToServer(new BreathMessage(true)); - } } else { if (player.hasEffect(ModMobEffects.SHOCK)) return; @@ -291,10 +288,6 @@ public class ClickHandler { if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue() && !switchZoom) { handleWeaponZoomRelease(); } - - if (event.getAction() == GLFW.GLFW_RELEASE && key == ModKeyMappings.BREATH.getKey().getValue()) { -// PacketDistributor.sendToServer(new BreathMessage(false)); - } } } @@ -328,7 +321,11 @@ public class ClickHandler { && !notInGame() ) { var data = GunData.from(stack); - player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); + if (!stack.is(ModItems.BOCEK.get())) { + player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); + } else { + player.playSound(ModSounds.BOCEK_PULL_1P.get(), 1, 1); + } if (!gunItem.useBackpackAmmo(stack) && data.ammo() <= 0 && data.reload.time() == 0) { if (ReloadConfig.LEFT_CLICK_RELOAD.get()) { diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java index 155228d01..b1720a07b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClientRenderHandler.java @@ -57,6 +57,7 @@ public class ClientRenderHandler { event.registerBelowAll(HandsomeFrameOverlay.ID, new HandsomeFrameOverlay()); event.registerBelowAll(SpyglassRangeOverlay.ID, new SpyglassRangeOverlay()); event.registerBelowAll(HelicopterHudOverlay.ID, new HelicopterHudOverlay()); + event.registerBelowAll(BreathOverlay.ID, new BreathOverlay()); event.registerBelowAll(MortarInfoOverlay.ID, new MortarInfoOverlay()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/BreathOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/BreathOverlay.java new file mode 100644 index 000000000..3b15c9dd0 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/BreathOverlay.java @@ -0,0 +1,59 @@ +package com.atsuishio.superbwarfare.client.overlay; + +import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; +import com.atsuishio.superbwarfare.event.ClientEventHandler; +import com.atsuishio.superbwarfare.init.ModAttachments; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.LayeredDraw; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Player; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; + +import javax.annotation.ParametersAreNonnullByDefault; + +@OnlyIn(Dist.CLIENT) +public class BreathOverlay implements LayeredDraw.Layer { + + public static final ResourceLocation ID = Mod.loc("breath"); + + @Override + @ParametersAreNonnullByDefault + public void render(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + Player player = Minecraft.getInstance().player; + var w = guiGraphics.guiWidth(); + var h = guiGraphics.guiHeight(); + + if (player != null && player.getData(ModAttachments.PLAYER_VARIABLE).edit) + return; + if (player != null && player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) + return; + if (!shouldRenderCrossHair(player)) return; + + guiGraphics.pose().pushPose(); + + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(false); + RenderSystem.enableBlend(); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + RenderSystem.setShaderColor(1, 1, 1, (float) Mth.clamp(ClientEventHandler.breathSwitchTime, 0, 1)); + + guiGraphics.fill(RenderType.guiOverlay(), w / 2 - 64, h / 2 + 100, w / 2 + 64, h / 2 + 101, -90, -16777216); + guiGraphics.fill(RenderType.guiOverlay(), w / 2 - 64, h / 2 + 100, w / 2 + 64 - (int) (1.28 * ClientEventHandler.breathTime), h / 2 + 101, -90, -1); + guiGraphics.pose().popPose(); + } + + private static boolean shouldRenderCrossHair(Player player) { + if (player == null) return false; + return ClientEventHandler.breathSwitchTime > 0; + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index ae54dcb69..1dbf8758b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -95,8 +95,6 @@ public class ClientEventHandler { public static double droneFov = 1; public static double droneFovLerp = 1; - - public static double breathTime = 0; public static double fov = 0; public static double pullTimer = 0; public static double bowTimer = 0; @@ -124,6 +122,9 @@ public class ClientEventHandler { public static boolean zoom = false; public static boolean breath = false; + public static int breathTime = 0; + public static double breathSwitchTime = 0; + public static boolean breathExhaustion = false; public static boolean holdFireVehicle = false; public static boolean zoomVehicle = false; @@ -278,6 +279,39 @@ public class ClientEventHandler { handleVariableDecrease(); aimAtVillager(player); + gunBreath(); + } + + //屏息 + public static void gunBreath() { + if (!breathExhaustion && zoom) { + breath = ModKeyMappings.BREATH.isDown(); + } + + if (breath) { + breathTime++; + } else if (breathTime > 0) { + breathTime--; + } + + if (breathTime >= 100) { + breathExhaustion = true; + breath = false; + } + + if (breathExhaustion && breathTime == 0) { + breathExhaustion = false; + } + + if (ModKeyMappings.BREATH.isDown() && zoom) { + breathSwitchTime = Math.min(breathSwitchTime + 0.5, 5); + } else if (breathSwitchTime > 0 && breathTime == 0) { + breathSwitchTime -= 0.15; + } + + if (!zoom) { + breath = false; + } } private static void handleVariableDecrease() { @@ -913,7 +947,6 @@ public class ClientEventHandler { handleWeaponSway(living); handleWeaponMove(living); handleWeaponZoom(living); - handlePlayerBreath(living); handleWeaponFire(event, living); handleWeaponShell(); handleGunRecoil(); @@ -1265,12 +1298,6 @@ public class ClientEventHandler { if (recoilTime >= 2.5) recoilTime = 0; } - private static void handlePlayerBreath(LivingEntity entity) { - float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); - - breathTime = Mth.lerp(0.2f * times, breathTime, breath ? 1 : 0); - } - private static void handleShockCamera(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) { if (entity.hasEffect(ModMobEffects.SHOCK) && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { event.setYaw(Minecraft.getInstance().gameRenderer.getMainCamera().getYRot() + (float) Mth.nextDouble(RandomSource.create(), -3, 3)); @@ -1386,12 +1413,12 @@ public class ClientEventHandler { var data = GunData.from(stack); - customZoom = Mth.lerp(0.6 * times, customZoom, data.zoom()); + customZoom = Mth.lerp(0.6 * times, customZoom, data.zoom() + (breath ? 0.75 : 0)); if (mc.options.getCameraType().isFirstPerson()) { - event.setFOV(event.getFOV() / (1.0 + p * (customZoom - 1)) * (1 - 0.4 * breathTime)); + event.setFOV(event.getFOV() / (1.0 + p * (customZoom - 1))); } else if (mc.options.getCameraType() == CameraType.THIRD_PERSON_BACK) - event.setFOV(event.getFOV() / (1.0 + p * 0.01) * (1 - 0.4 * breathTime)); + event.setFOV(event.getFOV() / (1.0 + p * 0.01)); fov = event.getFOV(); // 智慧芯片 diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java index 44ac335d2..606037825 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java @@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.data.GunData; +import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.tools.GunsTool; @@ -30,6 +31,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; +import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.NotNull; import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; @@ -168,6 +170,12 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon { public void fireOnRelease(Player player, final GunData data, double power, boolean zoom) { if (player.level().isClientSide()) return; + if (player instanceof ServerPlayer serverPlayer) { + SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS); + SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS); + PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10)); + } + var tag = data.tag(); var stack = data.stack(); var perk = data.perk.get(Perk.Type.AMMO); @@ -203,12 +211,4 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon { } } } - - @Override - public void fireOnPress(Player player, final GunData data, boolean zoom) { - if (player instanceof ServerPlayer serverPlayer) { - SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS); - SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS); - } - } } \ No newline at end of file