优化切枪音效取消写法

This commit is contained in:
Light_Quanta 2024-05-15 23:46:44 +08:00
parent c23a46ee00
commit c10572883c
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -138,31 +138,22 @@ public class LivingEntityEventHandler {
ItemStack newStack = event.getTo(); ItemStack newStack = event.getTo();
if (oldStack.getItem() instanceof GunItem oldGun && player.level() instanceof ServerLevel serverLevel) { if (oldStack.getItem() instanceof GunItem oldGun && player.level() instanceof ServerLevel serverLevel) {
if (newStack.getItem() != oldStack.getItem()) { var newTag = newStack.getTag();
var oldTag = oldStack.getTag();
if (newStack.getItem() != oldStack.getItem()
|| newTag == null || oldTag == null
|| !newTag.hasUUID("gun_uuid") || !oldTag.hasUUID("gun_uuid")
|| !newTag.getUUID("gun_uuid").equals(oldTag.getUUID("gun_uuid"))
) {
stopGunReloadSound(serverLevel, oldGun); stopGunReloadSound(serverLevel, oldGun);
if (newStack.getItem() instanceof GunItem) {
newStack.getOrCreateTag().putDouble("draw", 1); newStack.getOrCreateTag().putDouble("draw", 1);
}
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false; capability.zoom = false;
capability.syncPlayerVariables(player);
});
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zooming = false;
capability.syncPlayerVariables(player);
});
player.getPersistentData().putDouble("zoompos", 0);
player.getPersistentData().putDouble("zoom_time", 0);
} else if (!newStack.getOrCreateTag().hasUUID("gun_uuid") || !oldStack.getOrCreateTag().hasUUID("gun_uuid") ||
!newStack.getOrCreateTag().getUUID("gun_uuid").equals(oldStack.getOrCreateTag().getUUID("gun_uuid"))) {
stopGunReloadSound(serverLevel, oldGun);
newStack.getOrCreateTag().putDouble("draw", 1);
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = false;
capability.syncPlayerVariables(player);
});
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zooming = false; capability.zooming = false;
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);
}); });