修复一处可能导致空tag的问题

This commit is contained in:
17146 2025-01-14 18:58:04 +08:00
parent 7017edf4c1
commit edd15e6a1d

View file

@ -64,7 +64,10 @@ public class FireMessage {
} }
public static void pressAction(Player player, int type) { public static void pressAction(Player player, int type) {
handleGunBolt(player, player.getMainHandItem()); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return;
handleGunBolt(player, stack);
if (type == 0) { if (type == 0) {
handlePlayerShoot(player); handlePlayerShoot(player);
@ -102,9 +105,7 @@ public class FireMessage {
private static void handlePlayerShoot(Player player) { private static void handlePlayerShoot(Player player) {
var stack = player.getMainHandItem(); var stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) { if (!stack.is(ModTags.Items.GUN)) return;
return;
}
var tag = stack.getOrCreateTag(); var tag = stack.getOrCreateTag();
@ -147,6 +148,8 @@ public class FireMessage {
} }
private static void handleGunBolt(Player player, ItemStack stack) { private static void handleGunBolt(Player player, ItemStack stack) {
if (!stack.is(ModTags.Items.GUN)) return;
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0) if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
&& GunsTool.getGunIntTag(stack, "BoltActionTick") == 0 && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) && !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))