diff --git a/src/main/java/net/mcreator/superbwarfare/compat/clothconfig/common/GameplayClothConfig.java b/src/main/java/net/mcreator/superbwarfare/compat/clothconfig/common/GameplayClothConfig.java index 355545481..3d313f780 100644 --- a/src/main/java/net/mcreator/superbwarfare/compat/clothconfig/common/GameplayClothConfig.java +++ b/src/main/java/net/mcreator/superbwarfare/compat/clothconfig/common/GameplayClothConfig.java @@ -11,6 +11,14 @@ public class GameplayClothConfig { public static void init(ConfigBuilder root, ConfigEntryBuilder entryBuilder) { ConfigCategory category = root.getOrCreateCategory(Component.translatable("config.superbwarfare.common.gameplay")); + category.addEntry(entryBuilder + .startBooleanToggle(Component.translatable("config.superbwarfare.common.gameplay.respawn_reload"), GameplayConfig.RESPAWN_RELOAD.get()) + .setDefaultValue(true) + .setSaveConsumer(GameplayConfig.RESPAWN_RELOAD::set) + .setTooltip(Component.translatable("config.superbwarfare.common.gameplay.respawn_reload.des")) + .build() + ); + category.addEntry(entryBuilder .startBooleanToggle(Component.translatable("config.superbwarfare.common.gameplay.global_indication"), GameplayConfig.GLOBAL_INDICATION.get()) .setDefaultValue(false) diff --git a/src/main/java/net/mcreator/superbwarfare/config/common/GameplayConfig.java b/src/main/java/net/mcreator/superbwarfare/config/common/GameplayConfig.java index 5e006011c..208c06bbc 100644 --- a/src/main/java/net/mcreator/superbwarfare/config/common/GameplayConfig.java +++ b/src/main/java/net/mcreator/superbwarfare/config/common/GameplayConfig.java @@ -4,11 +4,15 @@ import net.minecraftforge.common.ForgeConfigSpec; public class GameplayConfig { + public static ForgeConfigSpec.BooleanValue RESPAWN_RELOAD; public static ForgeConfigSpec.BooleanValue GLOBAL_INDICATION; public static void init(ForgeConfigSpec.Builder builder) { builder.push("gameplay"); + builder.comment("Set TRUE if you want to reload all your guns when respawn"); + RESPAWN_RELOAD = builder.define("respawn_reload", true); + builder.comment("Set FALSE if you want to show kill indication ONLY while killing an entity with a gun"); GLOBAL_INDICATION = builder.define("global_indication", true); diff --git a/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java index b470f7781..760ffaaed 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java @@ -1,6 +1,7 @@ package net.mcreator.superbwarfare.event; import net.mcreator.superbwarfare.ModUtils; +import net.mcreator.superbwarfare.config.common.GameplayConfig; import net.mcreator.superbwarfare.init.ModItems; import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.init.ModTags; @@ -54,31 +55,7 @@ public class PlayerEventHandler { capability.syncPlayerVariables(player); }); - for (ItemStack stack : player.getInventory().items) { - if (stack.is(ModTags.Items.GUN)) { - if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) { - GunsTool.reload(player, GunInfo.Type.SHOTGUN); - } else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) { - GunsTool.reload(player, GunInfo.Type.SNIPER); - } else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) { - GunsTool.reload(player, GunInfo.Type.HANDGUN); - } else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) { - GunsTool.reload(player, GunInfo.Type.RIFLE); - } else if (stack.getItem() == ModItems.TASER.get()) { - stack.getOrCreateTag().putInt("ammo", 1); - player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots()); - } else if (stack.getItem() == ModItems.M_79.get()) { - stack.getOrCreateTag().putInt("ammo", 1); - player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots()); - } else if (stack.getItem() == ModItems.RPG.get()) { - stack.getOrCreateTag().putInt("ammo", 1); - player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots()); - } else if (stack.getItem() == ModItems.JAVELIN.get()) { - stack.getOrCreateTag().putInt("ammo", 1); - player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots()); - } - } - } + handleRespawnReload(player); } @SubscribeEvent @@ -317,6 +294,37 @@ public class PlayerEventHandler { } } + private static void handleRespawnReload(Player player) { + if (!GameplayConfig.RESPAWN_RELOAD.get()) return; + + for (ItemStack stack : player.getInventory().items) { + if (stack.is(ModTags.Items.GUN)) { + if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) { + GunsTool.reload(player, GunInfo.Type.SHOTGUN); + } else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) { + GunsTool.reload(player, GunInfo.Type.SNIPER); + } else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) { + GunsTool.reload(player, GunInfo.Type.HANDGUN); + } else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) { + GunsTool.reload(player, GunInfo.Type.RIFLE); + } else if (stack.getItem() == ModItems.TASER.get()) { + stack.getOrCreateTag().putInt("ammo", 1); + player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots()); + } else if (stack.getItem() == ModItems.M_79.get()) { + stack.getOrCreateTag().putInt("ammo", 1); + player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots()); + } else if (stack.getItem() == ModItems.RPG.get()) { + stack.getOrCreateTag().putInt("ammo", 1); + player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots()); + } else if (stack.getItem() == ModItems.JAVELIN.get()) { + stack.getOrCreateTag().putInt("ammo", 1); + player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots()); + } + } + } + } + + @SubscribeEvent public static void onAnvilUpdate(AnvilUpdateEvent event) { ItemStack left = event.getLeft(); diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index 97c7811dd..5bef1dbd0 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -387,6 +387,8 @@ "config.superbwarfare.client.display.armor_plate_hud.des": "Display the durability of the bulletproof insert currently equipped on the chest armor in the lower left corner when turned on", "config.superbwarfare.common.gameplay": "Gameplay Config", + "config.superbwarfare.common.gameplay.respawn_reload": "Respawn Reload", + "config.superbwarfare.common.gameplay.respawn_reload.des": "Whether to reload all weapons in the inventory after respawning automatically", "config.superbwarfare.common.gameplay.global_indication": "Global damage indicator", "config.superbwarfare.common.gameplay.global_indication.des": "Whether to show a kill indication around the cross hair when killing a creature with only the damage type of this module", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index bbc00c932..b1dbd8380 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -387,6 +387,8 @@ "config.superbwarfare.client.display.armor_plate_hud.des": "开启时,在屏幕左下角显示当前胸甲装备的防弹插板的耐久", "config.superbwarfare.common.gameplay": "游戏内容配置", + "config.superbwarfare.common.gameplay.respawn_reload": "重生换弹", + "config.superbwarfare.common.gameplay.respawn_reload.des": "开启时,玩家在重生时会自动装填全部武器的弹药", "config.superbwarfare.common.gameplay.global_indication": "全局伤害提示", "config.superbwarfare.common.gameplay.global_indication.des": "是否在仅使用本模组的伤害类型击杀生物时,在准星周围显示击杀提示",