From 72e4b0ac12d89f6afa3f4d0e131034e5e49a4fe7 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Sun, 12 May 2024 17:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A3=85=E5=BC=B9=E5=8F=AA?= =?UTF-8?q?=E6=B6=88=E8=80=97=E7=8B=99=E5=87=BB=E5=BC=B9=E8=8D=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/net/mcreator/target/tools/GunReload.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/mcreator/target/tools/GunReload.java b/src/main/java/net/mcreator/target/tools/GunReload.java index 1c74cb47e..f8b1aeb6b 100644 --- a/src/main/java/net/mcreator/target/tools/GunReload.java +++ b/src/main/java/net/mcreator/target/tools/GunReload.java @@ -27,7 +27,14 @@ public class GunReload { }).orElse(0d); entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { - capability.sniperAmmo = Math.max(0, playerAmmo - ammoToAdd); + var newAmmoCount = Math.max(0, playerAmmo - ammoToAdd); + switch (type) { + case RIFLE -> capability.rifleAmmo = newAmmoCount; + case HANDGUN -> capability.handgunAmmo = newAmmoCount; + case SHOTGUN -> capability.shotgunAmmo = newAmmoCount; + case SNIPER -> capability.sniperAmmo = newAmmoCount; + } + capability.syncPlayerVariables(entity); }); tag.putDouble("ammo", ammo + Math.min(ammoToAdd, playerAmmo));