优化Optional写法

This commit is contained in:
Light_Quanta 2024-05-18 03:24:35 +08:00
parent d9feb95cff
commit 527cd6d22b
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 8 additions and 8 deletions

View file

@ -30,12 +30,12 @@ public abstract class AmmoSupplierItem extends Item {
stack.shrink(1);
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
var newAmmoCount = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> switch (this.type) {
case HANDGUN -> c.handgunAmmo;
case RIFLE -> c.rifleAmmo;
case SHOTGUN -> c.shotgunAmmo;
case SNIPER -> c.sniperAmmo;
}).orElse(0) + ammoToAdd;
var newAmmoCount = switch (this.type) {
case HANDGUN -> capability.handgunAmmo;
case RIFLE -> capability.rifleAmmo;
case SHOTGUN -> capability.shotgunAmmo;
case SNIPER -> capability.sniperAmmo;
} + ammoToAdd;
switch (this.type) {
case HANDGUN -> capability.handgunAmmo = newAmmoCount;
case RIFLE -> capability.rifleAmmo = newAmmoCount;

View file

@ -18,10 +18,10 @@ public class GunReload {
int mag = tag.getInt("mag");
int ammo = tag.getInt("ammo");
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
/**
/*
* 空仓换弹的栓动武器应该在换单后取消待上膛标记
*/
if (ammo ==0 && tag.getDouble("bolt_action_time") > 0) {
if (ammo == 0 && tag.getDouble("bolt_action_time") > 0) {
tag.putDouble("need_bolt_action", 0);
}