优化维持生计弹药消耗

This commit is contained in:
Light_Quanta 2025-04-18 21:31:57 +08:00
parent 532f380612
commit ad2db9c888
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 8 additions and 16 deletions

View file

@ -649,30 +649,22 @@ public class LivingEventHandler {
float rate = level * 0.1f + (stack.is(ModTags.Items.SMG) || stack.is(ModTags.Items.RIFLE) ? 0.07f : 0f);
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
int mag = data.magazine();
int ammo = data.ammo.get();
int ammoReload = (int) Math.min(mag, mag * rate);
int ammoNeed = Math.min(mag - ammo, ammoReload);
boolean flag = InventoryTool.hasCreativeAmmoBox(player);
boolean flag = player.isCreative() || InventoryTool.hasCreativeAmmoBox(player);
var ammoType = data.ammoTypeInfo().playerAmmoType();
if (ammoType != null) {
int ammoFinal = Math.min(ammoType.get(cap), ammoNeed);
int ammoFinal = Math.min(data.countBackupAmmo(player), ammoNeed);
if (flag) {
ammoFinal = ammoNeed;
} else {
ammoType.add(cap, -ammoFinal);
data.consumeBackupAmmo(player, ammoFinal);
}
data.ammo.set(Math.min(mag, ammo + ammoFinal));
}
data.save();
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
cap.sync(player);
}

View file

@ -369,7 +369,7 @@ public class GunData {
* 消耗额外弹药不影响枪内弹药
*/
public void consumeBackupAmmo(Player player, int count) {
if (player.isCreative() || InventoryTool.hasCreativeAmmoBox(player)) return;
if (player.isCreative() || InventoryTool.hasCreativeAmmoBox(player) || count <= 0) return;
var info = ammoTypeInfo();
switch (info.type()) {