From b03efb454dcbed17bd00c048cf478374c1a34edc Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 3 Mar 2025 16:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=91=BD=E5=90=8DGunInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/command/AmmoCommand.java | 14 ++++++------ .../superbwarfare/event/GunEventHandler.java | 22 +++++++++---------- .../event/PlayerEventHandler.java | 12 +++++----- .../superbwarfare/init/ModItems.java | 12 +++++----- .../item/common/ammo/AmmoSupplierItem.java | 6 ++--- .../item/common/ammo/HandgunAmmoBox.java | 4 ++-- .../item/common/ammo/RifleAmmoBox.java | 4 ++-- .../item/common/ammo/ShotgunAmmoBox.java | 4 ++-- .../item/common/ammo/SniperAmmoBox.java | 4 ++-- .../superbwarfare/tools/AmmoType.java | 14 ++++++++++++ .../superbwarfare/tools/GunInfo.java | 16 -------------- .../superbwarfare/tools/GunsTool.java | 4 ++-- 12 files changed, 57 insertions(+), 59 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/tools/AmmoType.java delete mode 100644 src/main/java/com/atsuishio/superbwarfare/tools/GunInfo.java diff --git a/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java b/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java index 68c640978..603054578 100644 --- a/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java +++ b/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java @@ -2,7 +2,7 @@ package com.atsuishio.superbwarfare.command; import com.atsuishio.superbwarfare.network.ModVariables; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.commands.CommandSourceStack; @@ -16,7 +16,7 @@ public class AmmoCommand { public static LiteralArgumentBuilder get() { // mojang你看看你写的是个牛魔Builder😅 return Commands.literal("ammo").requires(s -> s.hasPermission(0)) - .then(Commands.literal("get").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("type", EnumArgument.enumArgument(GunInfo.Type.class)).executes(context -> { + .then(Commands.literal("get").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("type", EnumArgument.enumArgument(AmmoType.class)).executes(context -> { var player = EntityArgument.getPlayer(context, "player"); var source = context.getSource(); @@ -29,7 +29,7 @@ public class AmmoCommand { } } - var type = context.getArgument("type", GunInfo.Type.class); + var type = context.getArgument("type", AmmoType.class); var value = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> switch (type) { @@ -43,9 +43,9 @@ public class AmmoCommand { context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.get", Component.translatable(type.translatableKey), value), true); return 0; })))) - .then(Commands.literal("set").requires(s -> s.hasPermission(2)).then(Commands.argument("players", EntityArgument.players()).then(Commands.argument("type", EnumArgument.enumArgument(GunInfo.Type.class)).then(Commands.argument("value", IntegerArgumentType.integer(0)).executes(context -> { + .then(Commands.literal("set").requires(s -> s.hasPermission(2)).then(Commands.argument("players", EntityArgument.players()).then(Commands.argument("type", EnumArgument.enumArgument(AmmoType.class)).then(Commands.argument("value", IntegerArgumentType.integer(0)).executes(context -> { var players = EntityArgument.getPlayers(context, "players"); - var type = context.getArgument("type", GunInfo.Type.class); + var type = context.getArgument("type", AmmoType.class); var value = IntegerArgumentType.getInteger(context, "value"); for (var player : players) { @@ -64,9 +64,9 @@ public class AmmoCommand { context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.set", Component.translatable(type.translatableKey), value, players.size()), true); return 0; }))))) - .then(Commands.literal("add").requires(s -> s.hasPermission(2)).then(Commands.argument("players", EntityArgument.players()).then(Commands.argument("type", EnumArgument.enumArgument(GunInfo.Type.class)).then(Commands.argument("value", IntegerArgumentType.integer(0)).executes(context -> { + .then(Commands.literal("add").requires(s -> s.hasPermission(2)).then(Commands.argument("players", EntityArgument.players()).then(Commands.argument("type", EnumArgument.enumArgument(AmmoType.class)).then(Commands.argument("value", IntegerArgumentType.integer(0)).executes(context -> { var players = EntityArgument.getPlayers(context, "players"); - var type = context.getArgument("type", GunInfo.Type.class); + var type = context.getArgument("type", AmmoType.class); var value = IntegerArgumentType.getInteger(context, "value"); for (var player : players) { diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index d598b1310..1bff645d6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -13,7 +13,7 @@ import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.nbt.CompoundTag; @@ -420,15 +420,15 @@ public class GunEventHandler { + (gunItem.bulletInBarrel(stack) ? 1 : 0)); } else { if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.SHOTGUN, gunItem.bulletInBarrel(stack)); + GunsTool.reload(player, stack, AmmoType.SHOTGUN, gunItem.bulletInBarrel(stack)); } else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.SNIPER, true); + GunsTool.reload(player, stack, AmmoType.SNIPER, true); } else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.HANDGUN, true); + GunsTool.reload(player, stack, AmmoType.HANDGUN, true); } else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.RIFLE, gunItem.bulletInBarrel(stack)); + GunsTool.reload(player, stack, AmmoType.RIFLE, gunItem.bulletInBarrel(stack)); } else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.HEAVY, gunItem.bulletInBarrel(stack)); + GunsTool.reload(player, stack, AmmoType.HEAVY, gunItem.bulletInBarrel(stack)); } } stack.getOrCreateTag().putBoolean("is_normal_reloading", false); @@ -445,15 +445,15 @@ public class GunEventHandler { + GunsTool.getGunIntTag(stack, "CustomMagazine", 0)); } else { if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.SHOTGUN); + GunsTool.reload(player, stack, AmmoType.SHOTGUN); } else if (stack.is(ModTags.Items.USE_SNIPER_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.SNIPER); + GunsTool.reload(player, stack, AmmoType.SNIPER); } else if (stack.is(ModTags.Items.USE_HANDGUN_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.HANDGUN); + GunsTool.reload(player, stack, AmmoType.HANDGUN); } else if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.RIFLE); + GunsTool.reload(player, stack, AmmoType.RIFLE); } else if (stack.is(ModTags.Items.USE_HEAVY_AMMO)) { - GunsTool.reload(player, stack, GunInfo.Type.HEAVY); + GunsTool.reload(player, stack, AmmoType.HEAVY); } else if (stack.getItem() == ModItems.TASER.get()) { GunsTool.setGunIntTag(stack, "Ammo", 1); player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots()); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java index ae60bf747..f01f95d85 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java @@ -7,7 +7,7 @@ import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.SimulationDistanceMessage; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.server.level.ServerLevel; @@ -291,19 +291,19 @@ public class PlayerEventHandler { var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()); if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && cap.shotgunAmmo > 0) { - GunsTool.reload(player, stack, GunInfo.Type.SHOTGUN); + GunsTool.reload(player, stack, AmmoType.SHOTGUN); } if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && cap.sniperAmmo > 0) { - GunsTool.reload(player, stack, GunInfo.Type.SNIPER); + GunsTool.reload(player, stack, AmmoType.SNIPER); } if (stack.is(ModTags.Items.USE_HANDGUN_AMMO) && cap.handgunAmmo > 0) { - GunsTool.reload(player, stack, GunInfo.Type.HANDGUN); + GunsTool.reload(player, stack, AmmoType.HANDGUN); } if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && cap.rifleAmmo > 0) { - GunsTool.reload(player, stack, GunInfo.Type.RIFLE); + GunsTool.reload(player, stack, AmmoType.RIFLE); } if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && cap.heavyAmmo > 0) { - GunsTool.reload(player, stack, GunInfo.Type.HEAVY); + GunsTool.reload(player, stack, AmmoType.HEAVY); } if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(stack, "MaxAmmo") > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) == 0) { diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java b/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java index c49d1f097..adef5a626 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java @@ -24,7 +24,7 @@ import com.atsuishio.superbwarfare.item.gun.smg.VectorItem; import com.atsuishio.superbwarfare.item.gun.sniper.*; import com.atsuishio.superbwarfare.item.gun.special.BocekItem; import com.atsuishio.superbwarfare.item.gun.special.TaserItem; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.RarityTool; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; @@ -86,11 +86,11 @@ public class ModItems { */ public static final DeferredRegister AMMO = DeferredRegister.create(ForgeRegistries.ITEMS, ModUtils.MODID); - public static final RegistryObject HANDGUN_AMMO = AMMO.register("handgun_ammo", () -> new AmmoSupplierItem(GunInfo.Type.HANDGUN, 1, new Item.Properties())); - public static final RegistryObject RIFLE_AMMO = AMMO.register("rifle_ammo", () -> new AmmoSupplierItem(GunInfo.Type.RIFLE, 1, new Item.Properties())); - public static final RegistryObject SNIPER_AMMO = AMMO.register("sniper_ammo", () -> new AmmoSupplierItem(GunInfo.Type.SNIPER, 1, new Item.Properties())); - public static final RegistryObject SHOTGUN_AMMO = AMMO.register("shotgun_ammo", () -> new AmmoSupplierItem(GunInfo.Type.SHOTGUN, 1, new Item.Properties())); - public static final RegistryObject HEAVY_AMMO = AMMO.register("heavy_ammo", () -> new AmmoSupplierItem(GunInfo.Type.HEAVY, 1, new Item.Properties())); + public static final RegistryObject HANDGUN_AMMO = AMMO.register("handgun_ammo", () -> new AmmoSupplierItem(AmmoType.HANDGUN, 1, new Item.Properties())); + public static final RegistryObject RIFLE_AMMO = AMMO.register("rifle_ammo", () -> new AmmoSupplierItem(AmmoType.RIFLE, 1, new Item.Properties())); + public static final RegistryObject SNIPER_AMMO = AMMO.register("sniper_ammo", () -> new AmmoSupplierItem(AmmoType.SNIPER, 1, new Item.Properties())); + public static final RegistryObject SHOTGUN_AMMO = AMMO.register("shotgun_ammo", () -> new AmmoSupplierItem(AmmoType.SHOTGUN, 1, new Item.Properties())); + public static final RegistryObject HEAVY_AMMO = AMMO.register("heavy_ammo", () -> new AmmoSupplierItem(AmmoType.HEAVY, 1, new Item.Properties())); public static final RegistryObject HANDGUN_AMMO_BOX = AMMO.register("handgun_ammo_box", HandgunAmmoBox::new); public static final RegistryObject RIFLE_AMMO_BOX = AMMO.register("rifle_ammo_box", RifleAmmoBox::new); public static final RegistryObject SNIPER_AMMO_BOX = AMMO.register("sniper_ammo_box", SniperAmmoBox::new); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoSupplierItem.java b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoSupplierItem.java index 51f8c31a9..830ac5255 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoSupplierItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/AmmoSupplierItem.java @@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.item.common.ammo; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.ModVariables; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; @@ -15,10 +15,10 @@ import net.minecraft.world.level.Level; public class AmmoSupplierItem extends Item { - public final GunInfo.Type type; + public final AmmoType type; public final int ammoToAdd; - public AmmoSupplierItem(GunInfo.Type type, int ammoToAdd, Properties properties) { + public AmmoSupplierItem(AmmoType type, int ammoToAdd, Properties properties) { super(properties); this.type = type; this.ammoToAdd = ammoToAdd; diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/HandgunAmmoBox.java b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/HandgunAmmoBox.java index 1b38a3db7..35e28d7c5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/HandgunAmmoBox.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/HandgunAmmoBox.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.item.common.ammo; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; @@ -13,7 +13,7 @@ import java.util.List; public class HandgunAmmoBox extends AmmoSupplierItem { public HandgunAmmoBox() { - super(GunInfo.Type.HANDGUN, 30, new Item.Properties()); + super(AmmoType.HANDGUN, 30, new Item.Properties()); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/RifleAmmoBox.java b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/RifleAmmoBox.java index fc3ce5931..cb359698f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/RifleAmmoBox.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/RifleAmmoBox.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.item.common.ammo; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; @@ -13,7 +13,7 @@ import java.util.List; public class RifleAmmoBox extends AmmoSupplierItem { public RifleAmmoBox() { - super(GunInfo.Type.RIFLE, 30, new Item.Properties()); + super(AmmoType.RIFLE, 30, new Item.Properties()); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/ShotgunAmmoBox.java b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/ShotgunAmmoBox.java index 5a831f285..e492a4eed 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/ShotgunAmmoBox.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/ShotgunAmmoBox.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.item.common.ammo; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; @@ -13,7 +13,7 @@ import java.util.List; public class ShotgunAmmoBox extends AmmoSupplierItem { public ShotgunAmmoBox() { - super(GunInfo.Type.SHOTGUN, 12, new Item.Properties()); + super(AmmoType.SHOTGUN, 12, new Item.Properties()); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/SniperAmmoBox.java b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/SniperAmmoBox.java index 672a700ae..181441b6c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/SniperAmmoBox.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/ammo/SniperAmmoBox.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.item.common.ammo; -import com.atsuishio.superbwarfare.tools.GunInfo; +import com.atsuishio.superbwarfare.tools.AmmoType; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; @@ -13,7 +13,7 @@ import java.util.List; public class SniperAmmoBox extends AmmoSupplierItem { public SniperAmmoBox() { - super(GunInfo.Type.SNIPER, 12, new Item.Properties()); + super(AmmoType.SNIPER, 12, new Item.Properties()); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/AmmoType.java b/src/main/java/com/atsuishio/superbwarfare/tools/AmmoType.java new file mode 100644 index 000000000..81fa7580d --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/tools/AmmoType.java @@ -0,0 +1,14 @@ +package com.atsuishio.superbwarfare.tools; + +public enum AmmoType { + HANDGUN("item.superbwarfare.ammo.handgun"), + RIFLE("item.superbwarfare.ammo.rifle"), + SHOTGUN("item.superbwarfare.ammo.shotgun"), + SNIPER("item.superbwarfare.ammo.sniper"), + HEAVY("item.superbwarfare.ammo.heavy"); + public final String translatableKey; + + AmmoType(String translatableKey) { + this.translatableKey = translatableKey; + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/GunInfo.java b/src/main/java/com/atsuishio/superbwarfare/tools/GunInfo.java deleted file mode 100644 index ed5e87e6c..000000000 --- a/src/main/java/com/atsuishio/superbwarfare/tools/GunInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.atsuishio.superbwarfare.tools; - -public class GunInfo { - public enum Type { - HANDGUN("item.superbwarfare.ammo.handgun"), - RIFLE("item.superbwarfare.ammo.rifle"), - SHOTGUN("item.superbwarfare.ammo.shotgun"), - SNIPER("item.superbwarfare.ammo.sniper"), - HEAVY("item.superbwarfare.ammo.heavy"); - public final String translatableKey; - - Type(String translatableKey) { - this.translatableKey = translatableKey; - } - } -} diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java index 078fd8e59..c96023da0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java @@ -97,11 +97,11 @@ public class GunsTool { initJsonData(event.getServer().getResourceManager()); } - public static void reload(Player player, ItemStack stack, GunInfo.Type type) { + public static void reload(Player player, ItemStack stack, AmmoType type) { reload(player, stack, type, false); } - public static void reload(Player player, ItemStack stack, GunInfo.Type type, boolean extraOne) { + public static void reload(Player player, ItemStack stack, AmmoType type, boolean extraOne) { CompoundTag tag = stack.getOrCreateTag(); if (!(stack.getItem() instanceof GunItem)) return;