规范命名GunInfo
This commit is contained in:
parent
84d93078ad
commit
b03efb454d
12 changed files with 57 additions and 59 deletions
|
@ -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<CommandSourceStack> 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) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<Item> AMMO = DeferredRegister.create(ForgeRegistries.ITEMS, ModUtils.MODID);
|
||||
|
||||
public static final RegistryObject<Item> HANDGUN_AMMO = AMMO.register("handgun_ammo", () -> new AmmoSupplierItem(GunInfo.Type.HANDGUN, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> RIFLE_AMMO = AMMO.register("rifle_ammo", () -> new AmmoSupplierItem(GunInfo.Type.RIFLE, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> SNIPER_AMMO = AMMO.register("sniper_ammo", () -> new AmmoSupplierItem(GunInfo.Type.SNIPER, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> SHOTGUN_AMMO = AMMO.register("shotgun_ammo", () -> new AmmoSupplierItem(GunInfo.Type.SHOTGUN, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> HEAVY_AMMO = AMMO.register("heavy_ammo", () -> new AmmoSupplierItem(GunInfo.Type.HEAVY, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> HANDGUN_AMMO = AMMO.register("handgun_ammo", () -> new AmmoSupplierItem(AmmoType.HANDGUN, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> RIFLE_AMMO = AMMO.register("rifle_ammo", () -> new AmmoSupplierItem(AmmoType.RIFLE, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> SNIPER_AMMO = AMMO.register("sniper_ammo", () -> new AmmoSupplierItem(AmmoType.SNIPER, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> SHOTGUN_AMMO = AMMO.register("shotgun_ammo", () -> new AmmoSupplierItem(AmmoType.SHOTGUN, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> HEAVY_AMMO = AMMO.register("heavy_ammo", () -> new AmmoSupplierItem(AmmoType.HEAVY, 1, new Item.Properties()));
|
||||
public static final RegistryObject<Item> HANDGUN_AMMO_BOX = AMMO.register("handgun_ammo_box", HandgunAmmoBox::new);
|
||||
public static final RegistryObject<Item> RIFLE_AMMO_BOX = AMMO.register("rifle_ammo_box", RifleAmmoBox::new);
|
||||
public static final RegistryObject<Item> SNIPER_AMMO_BOX = AMMO.register("sniper_ammo_box", SniperAmmoBox::new);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue