修复AK切木仓后持续换弹动画的问题

This commit is contained in:
Atsuihsio 2024-07-06 14:58:46 +08:00
parent 1736dacb98
commit 971a61d264
3 changed files with 23 additions and 24 deletions

View file

@ -353,18 +353,18 @@ public class GunEventHandler {
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
if(tag.getInt("ammo") == 0) {
player.getPersistentData().putInt("gun_reloading_time",(int)tag.getDouble("empty_reload_time"));
player.getPersistentData().putBoolean("is_empty_reloading",true);
stack.getOrCreateTag().putBoolean("is_empty_reloading",true);
playGunEmptyReloadSounds(player);
player.getPersistentData().putBoolean("start_reload",false);
} else {
player.getPersistentData().putInt("gun_reloading_time",(int)tag.getDouble("normal_reload_time"));
player.getPersistentData().putBoolean("is_reloading",true);
stack.getOrCreateTag().putBoolean("is_reloading",true);
playGunNormalReloadSounds(player);
player.getPersistentData().putBoolean("start_reload",false);
}
} else {
player.getPersistentData().putInt("gun_reloading_time",(int)tag.getDouble("normal_reload_time"));
player.getPersistentData().putBoolean("is_reloading",true);
stack.getOrCreateTag().putBoolean("is_reloading",true);
playGunNormalReloadSounds(player);
player.getPersistentData().putBoolean("start_reload",false);
}
@ -374,7 +374,7 @@ public class GunEventHandler {
player.getPersistentData().putInt("gun_reloading_time",player.getPersistentData().getInt("gun_reloading_time") - 1);
}
if (player.getPersistentData().getInt("gun_reloading_time") == 0 && (player.getPersistentData().getBoolean("is_empty_reloading") || player.getPersistentData().getBoolean("is_reloading"))) {
if (player.getPersistentData().getInt("gun_reloading_time") == 0 && (stack.getOrCreateTag().getBoolean("is_empty_reloading") || stack.getOrCreateTag().getBoolean("is_reloading"))) {
if (stack.is(TargetModTags.Items.OPEN_BOLT)) {
if(tag.getInt("ammo") == 0) {
@ -387,7 +387,7 @@ public class GunEventHandler {
} else if (stack.is(TargetModTags.Items.RIFLE)) {
GunsTool.reload(player, GunInfo.Type.RIFLE);
}
player.getPersistentData().putBoolean("is_empty_reloading",false);
stack.getOrCreateTag().putBoolean("is_empty_reloading",false);
} else {
@ -400,7 +400,7 @@ public class GunEventHandler {
} else if (stack.is(TargetModTags.Items.RIFLE)) {
GunsTool.reload(player, GunInfo.Type.RIFLE ,true);
}
player.getPersistentData().putBoolean("is_reloading",false);
stack.getOrCreateTag().putBoolean("is_reloading",false);
}
} else {
@ -414,7 +414,7 @@ public class GunEventHandler {
} else if (stack.is(TargetModTags.Items.RIFLE)) {
GunsTool.reload(player, GunInfo.Type.RIFLE);
}
player.getPersistentData().putBoolean("is_reloading",false);
stack.getOrCreateTag().putBoolean("is_reloading",false);
}
}

View file

@ -163,25 +163,24 @@ public class LivingEventHandler {
if (oldStack.getItem() instanceof GunItem oldGun) {
stopGunReloadSound(serverPlayer, oldGun);
}
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false;
capability.zooming = false;
capability.syncPlayerVariables(player);
});
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false;
capability.zooming = false;
capability.syncPlayerVariables(player);
});
player.getPersistentData().putDouble("zoom_pos", 0);
player.getPersistentData().putDouble("zoom_animation_time", 0);
oldStack.getOrCreateTag().putBoolean("is_reloading",false);
oldStack.getOrCreateTag().putBoolean("is_empty_reloading",false);
player.getPersistentData().putInt("gun_reloading_time",0);
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
}
}
}
}
player.getPersistentData().putDouble("zoom_pos", 0);
player.getPersistentData().putDouble("zoom_animation_time", 0);
player.getPersistentData().putBoolean("is_reloading",false);
player.getPersistentData().putBoolean("is_empty_reloading",false);
player.getPersistentData().putInt("gun_reloading_time",0);
}
}

View file

@ -93,11 +93,11 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.fire"));
}
if (player.getPersistentData().getBoolean("is_empty_reloading") && player.getPersistentData().getInt("gun_reloading_time") > 0) {
if (stack.getOrCreateTag().getBoolean("is_empty_reloading")) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_empty"));
}
if (player.getPersistentData().getBoolean("is_reloading") && player.getPersistentData().getInt("gun_reloading_time") > 0) {
if (stack.getOrCreateTag().getBoolean("is_reloading")) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.reload_normal"));
}