重写屏息

This commit is contained in:
Atsuishio 2025-04-10 23:25:00 +08:00 committed by Light_Quanta
parent e60fca1a88
commit fcf0ce65b4
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 112 additions and 28 deletions

View file

@ -274,9 +274,6 @@ public class ClickHandler {
} }
} }
if (key == ModKeyMappings.BREATH.getKey().getValue()) {
// PacketDistributor.sendToServer(new BreathMessage(true));
}
} else { } else {
if (player.hasEffect(ModMobEffects.SHOCK)) return; if (player.hasEffect(ModMobEffects.SHOCK)) return;
@ -291,10 +288,6 @@ public class ClickHandler {
if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue() && !switchZoom) { if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue() && !switchZoom) {
handleWeaponZoomRelease(); 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() && !notInGame()
) { ) {
var data = GunData.from(stack); 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 (!gunItem.useBackpackAmmo(stack) && data.ammo() <= 0 && data.reload.time() == 0) {
if (ReloadConfig.LEFT_CLICK_RELOAD.get()) { if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {

View file

@ -57,6 +57,7 @@ public class ClientRenderHandler {
event.registerBelowAll(HandsomeFrameOverlay.ID, new HandsomeFrameOverlay()); event.registerBelowAll(HandsomeFrameOverlay.ID, new HandsomeFrameOverlay());
event.registerBelowAll(SpyglassRangeOverlay.ID, new SpyglassRangeOverlay()); event.registerBelowAll(SpyglassRangeOverlay.ID, new SpyglassRangeOverlay());
event.registerBelowAll(HelicopterHudOverlay.ID, new HelicopterHudOverlay()); event.registerBelowAll(HelicopterHudOverlay.ID, new HelicopterHudOverlay());
event.registerBelowAll(BreathOverlay.ID, new BreathOverlay());
event.registerBelowAll(MortarInfoOverlay.ID, new MortarInfoOverlay()); event.registerBelowAll(MortarInfoOverlay.ID, new MortarInfoOverlay());
} }

View file

@ -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;
}
}

View file

@ -95,8 +95,6 @@ public class ClientEventHandler {
public static double droneFov = 1; public static double droneFov = 1;
public static double droneFovLerp = 1; public static double droneFovLerp = 1;
public static double breathTime = 0;
public static double fov = 0; public static double fov = 0;
public static double pullTimer = 0; public static double pullTimer = 0;
public static double bowTimer = 0; public static double bowTimer = 0;
@ -124,6 +122,9 @@ public class ClientEventHandler {
public static boolean zoom = false; public static boolean zoom = false;
public static boolean breath = 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 holdFireVehicle = false;
public static boolean zoomVehicle = false; public static boolean zoomVehicle = false;
@ -278,6 +279,39 @@ public class ClientEventHandler {
handleVariableDecrease(); handleVariableDecrease();
aimAtVillager(player); 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() { private static void handleVariableDecrease() {
@ -913,7 +947,6 @@ public class ClientEventHandler {
handleWeaponSway(living); handleWeaponSway(living);
handleWeaponMove(living); handleWeaponMove(living);
handleWeaponZoom(living); handleWeaponZoom(living);
handlePlayerBreath(living);
handleWeaponFire(event, living); handleWeaponFire(event, living);
handleWeaponShell(); handleWeaponShell();
handleGunRecoil(); handleGunRecoil();
@ -1265,12 +1298,6 @@ public class ClientEventHandler {
if (recoilTime >= 2.5) recoilTime = 0; 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) { private static void handleShockCamera(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
if (entity.hasEffect(ModMobEffects.SHOCK) && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { 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)); 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); 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()) { 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) } 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(); fov = event.getFOV();
// 智慧芯片 // 智慧芯片

View file

@ -11,6 +11,7 @@ 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.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
import com.atsuishio.superbwarfare.item.gun.data.GunData; 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.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.GunsTool; 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.Items;
import net.minecraft.world.item.Rarity; import net.minecraft.world.item.Rarity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; 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) { public void fireOnRelease(Player player, final GunData data, double power, boolean zoom) {
if (player.level().isClientSide()) return; 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 tag = data.tag();
var stack = data.stack(); var stack = data.stack();
var perk = data.perk.get(Perk.Type.AMMO); 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);
}
}
} }