优化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);
|
stack.shrink(1);
|
||||||
|
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
var newAmmoCount = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> switch (this.type) {
|
var newAmmoCount = switch (this.type) {
|
||||||
case HANDGUN -> c.handgunAmmo;
|
case HANDGUN -> capability.handgunAmmo;
|
||||||
case RIFLE -> c.rifleAmmo;
|
case RIFLE -> capability.rifleAmmo;
|
||||||
case SHOTGUN -> c.shotgunAmmo;
|
case SHOTGUN -> capability.shotgunAmmo;
|
||||||
case SNIPER -> c.sniperAmmo;
|
case SNIPER -> capability.sniperAmmo;
|
||||||
}).orElse(0) + ammoToAdd;
|
} + ammoToAdd;
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case HANDGUN -> capability.handgunAmmo = newAmmoCount;
|
case HANDGUN -> capability.handgunAmmo = newAmmoCount;
|
||||||
case RIFLE -> capability.rifleAmmo = newAmmoCount;
|
case RIFLE -> capability.rifleAmmo = newAmmoCount;
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class GunReload {
|
||||||
int mag = tag.getInt("mag");
|
int mag = tag.getInt("mag");
|
||||||
int ammo = tag.getInt("ammo");
|
int ammo = tag.getInt("ammo");
|
||||||
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
|
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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue