优化Optional写法
This commit is contained in:
parent
d9feb95cff
commit
527cd6d22b
2 changed files with 8 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue