将重生换弹调整至配置文件中

This commit is contained in:
17146 2024-10-10 01:08:25 +08:00
parent 1b7d5d5beb
commit 17296dafc2
5 changed files with 49 additions and 25 deletions

View file

@ -11,6 +11,14 @@ public class GameplayClothConfig {
public static void init(ConfigBuilder root, ConfigEntryBuilder entryBuilder) { public static void init(ConfigBuilder root, ConfigEntryBuilder entryBuilder) {
ConfigCategory category = root.getOrCreateCategory(Component.translatable("config.superbwarfare.common.gameplay")); 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 category.addEntry(entryBuilder
.startBooleanToggle(Component.translatable("config.superbwarfare.common.gameplay.global_indication"), GameplayConfig.GLOBAL_INDICATION.get()) .startBooleanToggle(Component.translatable("config.superbwarfare.common.gameplay.global_indication"), GameplayConfig.GLOBAL_INDICATION.get())
.setDefaultValue(false) .setDefaultValue(false)

View file

@ -4,11 +4,15 @@ import net.minecraftforge.common.ForgeConfigSpec;
public class GameplayConfig { public class GameplayConfig {
public static ForgeConfigSpec.BooleanValue RESPAWN_RELOAD;
public static ForgeConfigSpec.BooleanValue GLOBAL_INDICATION; public static ForgeConfigSpec.BooleanValue GLOBAL_INDICATION;
public static void init(ForgeConfigSpec.Builder builder) { public static void init(ForgeConfigSpec.Builder builder) {
builder.push("gameplay"); 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"); 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); GLOBAL_INDICATION = builder.define("global_indication", true);

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare.event; package net.mcreator.superbwarfare.event;
import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.config.common.GameplayConfig;
import net.mcreator.superbwarfare.init.ModItems; import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.init.ModSounds;
import net.mcreator.superbwarfare.init.ModTags; import net.mcreator.superbwarfare.init.ModTags;
@ -54,31 +55,7 @@ public class PlayerEventHandler {
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);
}); });
for (ItemStack stack : player.getInventory().items) { handleRespawnReload(player);
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 @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 @SubscribeEvent
public static void onAnvilUpdate(AnvilUpdateEvent event) { public static void onAnvilUpdate(AnvilUpdateEvent event) {
ItemStack left = event.getLeft(); ItemStack left = event.getLeft();

View file

@ -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.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": "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": "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", "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",

View file

@ -387,6 +387,8 @@
"config.superbwarfare.client.display.armor_plate_hud.des": "开启时,在屏幕左下角显示当前胸甲装备的防弹插板的耐久", "config.superbwarfare.client.display.armor_plate_hud.des": "开启时,在屏幕左下角显示当前胸甲装备的防弹插板的耐久",
"config.superbwarfare.common.gameplay": "游戏内容配置", "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": "全局伤害提示",
"config.superbwarfare.common.gameplay.global_indication.des": "是否在仅使用本模组的伤害类型击杀生物时,在准星周围显示击杀提示", "config.superbwarfare.common.gameplay.global_indication.des": "是否在仅使用本模组的伤害类型击杀生物时,在准星周围显示击杀提示",