火炮无人时不判断玩家背包弹药

This commit is contained in:
Atsuishio 2025-07-09 22:01:33 +08:00 committed by Light_Quanta
parent 926b43f32a
commit f876137e17
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 13 additions and 9 deletions

View file

@ -395,7 +395,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
Level level = player.level();
if (level instanceof ServerLevel server) {
if (!InventoryTool.hasCreativeAmmoBox(player)) {
if (!InventoryTool.hasCreativeAmmoBox(player) && player == getFirstPassenger()) {
var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get();
var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo);

View file

@ -407,15 +407,19 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
Level level = player.level();
if (level instanceof ServerLevel server) {
int consumed;
if (InventoryTool.hasCreativeAmmoBox(player)) {
consumed = 2;
} else {
var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get();
var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo);
if (player == getFirstPassenger()) {
if (InventoryTool.hasCreativeAmmoBox(player)) {
consumed = 2;
} else {
var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get();
var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo);
// 尝试消耗两发弹药
if (ammoCount <= 0) return;
consumed = InventoryTool.consumeItem(player.getInventory().items, ammo, 2);
// 尝试消耗两发弹药
if (ammoCount <= 0) return;
consumed = InventoryTool.consumeItem(player.getInventory().items, ammo, 2);
}
} else {
consumed = stack.getCount();
}
if (getFirstPassenger() != getOwner()) {