修复波塞克手部动画和无效发射bug

This commit is contained in:
Atsuishio 2025-04-11 02:31:34 +08:00 committed by Light_Quanta
parent fede5d2a4c
commit 3c13f0753a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 22 additions and 18 deletions

View file

@ -334,6 +334,7 @@ public class ClickHandler {
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
} else { } else {
player.playSound(ModSounds.BOCEK_PULL_1P.get(), 1, 1); player.playSound(ModSounds.BOCEK_PULL_1P.get(), 1, 1);
handTimer = 0;
} }
if (!gunItem.useBackpackAmmo(stack) && data.ammo() <= 0 && data.reload.time() == 0) { if (!gunItem.useBackpackAmmo(stack) && data.ammo() <= 0 && data.reload.time() == 0) {
@ -342,8 +343,12 @@ public class ClickHandler {
ClientEventHandler.burstFireAmount = 0; ClientEventHandler.burstFireAmount = 0;
} }
} else { } else {
PacketDistributor.sendToServer(new FireMessage(0)); PacketDistributor.sendToServer(new FireMessage(0, handTimer, zoom));
if ((!data.reloading() && !data.charging() && !data.bolt.needed()) && drawTime < 0.01) { if ((!data.reloading()
&& !data.charging()
&& !data.bolt.needed())
&& drawTime < 0.01
) {
if (data.fireMode() == 1) { if (data.fireMode() == 1) {
if (ClientEventHandler.burstFireAmount == 0) { if (ClientEventHandler.burstFireAmount == 0) {
ClientEventHandler.burstFireAmount = data.burstAmount(); ClientEventHandler.burstFireAmount = data.burstAmount();
@ -358,7 +363,7 @@ public class ClickHandler {
} }
public static void handleWeaponFireRelease() { public static void handleWeaponFireRelease() {
PacketDistributor.sendToServer(new FireMessage(1)); PacketDistributor.sendToServer(new FireMessage(1, handTimer, zoom));
ClientEventHandler.holdFire = false; ClientEventHandler.holdFire = false;
ClientEventHandler.holdFireVehicle = false; ClientEventHandler.holdFireVehicle = false;
ClientEventHandler.customRpm = 0; ClientEventHandler.customRpm = 0;

View file

@ -1009,7 +1009,7 @@ public class ClientEventHandler {
handleWeaponFire(event, living); handleWeaponFire(event, living);
handleWeaponShell(); handleWeaponShell();
handleGunRecoil(); handleGunRecoil();
handleBowPullAnimation(living); handleBowPullAnimation(living, stack);
handleWeaponDraw(living); handleWeaponDraw(living);
handlePlayerCamera(event); handlePlayerCamera(event);
} }
@ -1420,10 +1420,10 @@ public class ClientEventHandler {
event.setRoll((float) (roll + cameraRot[2] + (DisplayConfig.CAMERA_ROTATE.get() ? 0.35 : 0) * turnRot[2])); event.setRoll((float) (roll + cameraRot[2] + (DisplayConfig.CAMERA_ROTATE.get() ? 0.35 : 0) * turnRot[2]));
} }
private static void handleBowPullAnimation(LivingEntity entity) { private static void handleBowPullAnimation(LivingEntity entity, ItemStack stack) {
float times = 4 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); float times = 4 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
if (holdFire) { if (holdFire && entity instanceof Player player && !player.getCooldowns().isOnCooldown(stack.getItem())) {
pullTimer = Math.min(pullTimer + 0.024 * times, 1.4); pullTimer = Math.min(pullTimer + 0.024 * times, 1.4);
bowTimer = Math.min(bowTimer + 0.018 * times, 1); bowTimer = Math.min(bowTimer + 0.018 * times, 1);
handTimer = Math.min(handTimer + 0.018 * times, 1); handTimer = Math.min(handTimer + 0.018 * times, 1);

View file

@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.network.message.send;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.event.GunEventHandler; import com.atsuishio.superbwarfare.event.GunEventHandler;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
@ -27,21 +26,25 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
public record FireMessage(int msgType) implements CustomPacketPayload { public record FireMessage(int msgType, double power, boolean zoom) implements CustomPacketPayload {
public static final Type<FireMessage> TYPE = new Type<>(Mod.loc("fire")); public static final Type<FireMessage> TYPE = new Type<>(Mod.loc("fire"));
public static final StreamCodec<ByteBuf, FireMessage> STREAM_CODEC = StreamCodec.composite( public static final StreamCodec<ByteBuf, FireMessage> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.INT, ByteBufCodecs.INT,
FireMessage::msgType, FireMessage::msgType,
ByteBufCodecs.DOUBLE,
FireMessage::power,
ByteBufCodecs.BOOL,
FireMessage::zoom,
FireMessage::new FireMessage::new
); );
public static void handler(FireMessage message, final IPayloadContext context) { public static void handler(FireMessage message, final IPayloadContext context) {
pressAction(context.player(), message.msgType); pressAction(context.player(), message.msgType, message.power, message.zoom);
} }
public static void pressAction(Player player, int type) { public static void pressAction(Player player, int type, double power, boolean zoom) {
if (player.isSpectator()) return; if (player.isSpectator()) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return; if (!stack.is(ModTags.Items.GUN)) return;
@ -59,19 +62,15 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
cap.edit = false; cap.edit = false;
// 按下开火 // 按下开火
if (!(stack.getItem() instanceof SpecialFireWeapon specialFireWeapon)) { if (!(stack.getItem() instanceof SpecialFireWeapon specialFireWeapon)) return;
player.setData(ModAttachments.PLAYER_VARIABLE, cap); specialFireWeapon.fireOnPress(player, data, zoom);
cap.sync(player);
return;
}
specialFireWeapon.fireOnPress(player, data, ClientEventHandler.zoom);
} else if (type == 1) { } else if (type == 1) {
// 松开开火 // 松开开火
if (stack.getItem() instanceof SpecialFireWeapon specialFireWeapon) { if (stack.getItem() instanceof SpecialFireWeapon specialFireWeapon) {
if (specialFireWeapon instanceof BocekItem) { if (specialFireWeapon instanceof BocekItem) {
specialFireWeapon.fireOnRelease(player, data, ClientEventHandler.bowTimer, ClientEventHandler.zoom); specialFireWeapon.fireOnRelease(player, data, power, zoom);
} else { } else {
specialFireWeapon.fireOnRelease(player, data, 0, ClientEventHandler.zoom); specialFireWeapon.fireOnRelease(player, data, 0, zoom);
} }
} }
} }