重命名AmmoType

This commit is contained in:
Light_Quanta 2025-04-15 22:23:05 +08:00
parent b372ae9612
commit d3094fa6c6
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
24 changed files with 100 additions and 110 deletions

View file

@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.capability.player;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.network.message.receive.PlayerVariablesSyncMessage; import com.atsuishio.superbwarfare.network.message.receive.PlayerVariablesSyncMessage;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -24,7 +24,7 @@ import java.util.Map;
public class PlayerVariable implements INBTSerializable<CompoundTag> { public class PlayerVariable implements INBTSerializable<CompoundTag> {
private PlayerVariable old = null; private PlayerVariable old = null;
public Map<AmmoType, Integer> ammo = new HashMap<>(); public Map<Ammo, Integer> ammo = new HashMap<>();
public boolean tacticalSprint = false; public boolean tacticalSprint = false;
public boolean edit = false; public boolean edit = false;
@ -54,7 +54,7 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
public CompoundTag writeToNBT() { public CompoundTag writeToNBT() {
CompoundTag nbt = new CompoundTag(); CompoundTag nbt = new CompoundTag();
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
type.set(nbt, type.get(this)); type.set(nbt, type.get(this));
} }
@ -65,7 +65,7 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
} }
public PlayerVariable readFromNBT(CompoundTag tag) { public PlayerVariable readFromNBT(CompoundTag tag) {
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
type.set(this, type.get(tag)); type.set(this, type.get(tag));
} }
@ -78,7 +78,7 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
public PlayerVariable copy() { public PlayerVariable copy() {
var clone = new PlayerVariable(); var clone = new PlayerVariable();
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
type.set(clone, type.get(this)); type.set(clone, type.get(this));
} }
@ -92,7 +92,7 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof PlayerVariable other)) return false; if (!(obj instanceof PlayerVariable other)) return false;
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
if (type.get(this) != type.get(other)) return false; if (type.get(this) != type.get(other)) return false;
} }

View file

@ -6,7 +6,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem; import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.animation.AnimationCurves; import com.atsuishio.superbwarfare.tools.animation.AnimationCurves;
import com.atsuishio.superbwarfare.tools.animation.AnimationTimer; import com.atsuishio.superbwarfare.tools.animation.AnimationTimer;
import com.atsuishio.superbwarfare.tools.animation.ValueAnimator; import com.atsuishio.superbwarfare.tools.animation.ValueAnimator;
@ -38,10 +38,10 @@ public class AmmoCountOverlay implements LayeredDraw.Layer {
.backwardAnimation(AnimationCurves.EASE_IN_EXPO); .backwardAnimation(AnimationCurves.EASE_IN_EXPO);
private static final ValueAnimator<Integer>[] ammoCountAnimators = ValueAnimator.create( private static final ValueAnimator<Integer>[] ammoCountAnimators = ValueAnimator.create(
AmmoType.values().length, 800, 0 Ammo.values().length, 800, 0
); );
private static final ValueAnimator<Integer>[] ammoBoxAnimators = ValueAnimator.create( private static final ValueAnimator<Integer>[] ammoBoxAnimators = ValueAnimator.create(
AmmoType.values().length, 800, 0 Ammo.values().length, 800, 0
); );
/** /**
@ -86,13 +86,13 @@ public class AmmoCountOverlay implements LayeredDraw.Layer {
var ammoX = ammoInfoTimer.lerp(w + 120, (float) w / 2 + 40, currentTime); var ammoX = ammoInfoTimer.lerp(w + 120, (float) w / 2 + 40, currentTime);
final int fontHeight = 15; final int fontHeight = 15;
var yOffset = (-h - AmmoType.values().length * fontHeight) / 2f; var yOffset = (-h - Ammo.values().length * fontHeight) / 2f;
// 渲染总弹药数量 // 渲染总弹药数量
var cap = player.getData(ModAttachments.PLAYER_VARIABLE); var cap = player.getData(ModAttachments.PLAYER_VARIABLE);
var font = Minecraft.getInstance().font; var font = Minecraft.getInstance().font;
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
var index = type.ordinal(); var index = type.ordinal();
var ammoCount = type.get(cap); var ammoCount = type.get(cap);
var animator = ammoCountAnimators[index]; var animator = ammoCountAnimators[index];

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.command; package com.atsuishio.superbwarfare.command;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
@ -15,7 +15,7 @@ public class AmmoCommand {
public static LiteralArgumentBuilder<CommandSourceStack> get() { public static LiteralArgumentBuilder<CommandSourceStack> get() {
// mojang你看看你写的是个牛魔Builder😅 // mojang你看看你写的是个牛魔Builder😅
return Commands.literal("ammo").requires(s -> s.hasPermission(0)) 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(AmmoType.class)).executes(context -> { .then(Commands.literal("get").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("type", EnumArgument.enumArgument(Ammo.class)).executes(context -> {
var player = EntityArgument.getPlayer(context, "player"); var player = EntityArgument.getPlayer(context, "player");
var source = context.getSource(); var source = context.getSource();
@ -28,15 +28,15 @@ public class AmmoCommand {
} }
} }
var type = context.getArgument("type", AmmoType.class); var type = context.getArgument("type", Ammo.class);
var value = type.get(player); var value = type.get(player);
context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.get", Component.translatable(type.translatableKey), value), true); context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.get", Component.translatable(type.translatableKey), value), true);
return 0; return 0;
})))) }))))
.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 -> { .then(Commands.literal("set").requires(s -> s.hasPermission(2)).then(Commands.argument("players", EntityArgument.players()).then(Commands.argument("type", EnumArgument.enumArgument(Ammo.class)).then(Commands.argument("value", IntegerArgumentType.integer(0)).executes(context -> {
var players = EntityArgument.getPlayers(context, "players"); var players = EntityArgument.getPlayers(context, "players");
var type = context.getArgument("type", AmmoType.class); var type = context.getArgument("type", Ammo.class);
var value = IntegerArgumentType.getInteger(context, "value"); var value = IntegerArgumentType.getInteger(context, "value");
for (var player : players) { for (var player : players) {
@ -46,9 +46,9 @@ public class AmmoCommand {
context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.set", Component.translatable(type.translatableKey), value, players.size()), true); context.getSource().sendSuccess(() -> Component.translatable("commands.ammo.set", Component.translatable(type.translatableKey), value, players.size()), true);
return 0; return 0;
}))))) })))))
.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 -> { .then(Commands.literal("add").requires(s -> s.hasPermission(2)).then(Commands.argument("players", EntityArgument.players()).then(Commands.argument("type", EnumArgument.enumArgument(Ammo.class)).then(Commands.argument("value", IntegerArgumentType.integer(0)).executes(context -> {
var players = EntityArgument.getPlayers(context, "players"); var players = EntityArgument.getPlayers(context, "players");
var type = context.getArgument("type", AmmoType.class); var type = context.getArgument("type", Ammo.class);
var value = IntegerArgumentType.getInteger(context, "value"); var value = IntegerArgumentType.getInteger(context, "value");
for (var player : players) { for (var player : players) {

View file

@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.component;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.FiringParameters; import com.atsuishio.superbwarfare.item.FiringParameters;
import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBoxInfo; import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBoxInfo;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
@ -54,7 +54,7 @@ public class ModDataComponents {
} }
public static void register(IEventBus eventBus) { public static void register(IEventBus eventBus) {
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
type.dataComponent = register("ammo_" + type.name.toLowerCase(), builder -> builder.persistent(Codec.INT)); type.dataComponent = register("ammo_" + type.name.toLowerCase(), builder -> builder.persistent(Codec.INT));
} }

View file

@ -17,7 +17,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -208,10 +208,10 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
int ammoCount = this.getItemStacks().stream().filter(stack -> { int ammoCount = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.HEAVY.get(stack) > 0; return Ammo.HEAVY.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get()); }).mapToInt(Ammo.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get());
if ((hasItem(ModItems.ROCKET_70.get()) || InventoryTool.hasCreativeAmmoBox(player)) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) { if ((hasItem(ModItems.ROCKET_70.get()) || InventoryTool.hasCreativeAmmoBox(player)) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) {
this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1); this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1);
@ -562,13 +562,13 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
if (!hasCreativeAmmo) { if (!hasCreativeAmmo) {
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.HEAVY.get(stack) > 0; return Ammo.HEAVY.get(stack) > 0;
} }
return false; return false;
}).findFirst().orElse(ItemStack.EMPTY); }).findFirst().orElse(ItemStack.EMPTY);
if (!ammoBox.isEmpty()) { if (!ammoBox.isEmpty()) {
AmmoType.HEAVY.add(ammoBox, -1); Ammo.HEAVY.add(ammoBox, -1);
} else { } else {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} }

View file

@ -20,7 +20,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -252,10 +252,10 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
int ammoCount = this.getItemStacks().stream().filter(stack -> { int ammoCount = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.RIFLE.get(stack) > 0; return Ammo.RIFLE.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get()); }).mapToInt(Ammo.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get());
if ((hasItem(ModItems.WIRE_GUIDE_MISSILE.get()) if ((hasItem(ModItems.WIRE_GUIDE_MISSILE.get())
|| InventoryTool.hasCreativeAmmoBox(player)) || InventoryTool.hasCreativeAmmoBox(player))
@ -353,13 +353,13 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
if (!hasCreativeAmmo) { if (!hasCreativeAmmo) {
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.RIFLE.get(stack) > 0; return Ammo.RIFLE.get(stack) > 0;
} }
return false; return false;
}).findFirst().orElse(ItemStack.EMPTY); }).findFirst().orElse(ItemStack.EMPTY);
if (!ammoBox.isEmpty()) { if (!ammoBox.isEmpty()) {
AmmoType.RIFLE.add(ammoBox, -1); Ammo.RIFLE.add(ammoBox, -1);
} else { } else {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} }

View file

@ -19,7 +19,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -206,10 +206,10 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
int ammoCount = this.getItemStacks().stream().filter(stack -> { int ammoCount = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.RIFLE.get(stack) > 0; return Ammo.RIFLE.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get()); }).mapToInt(Ammo.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get());
if (getWeaponIndex(0) == 0) { if (getWeaponIndex(0) == 0) {
this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get())); this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get()));
@ -301,13 +301,13 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
if (!hasCreativeAmmo) { if (!hasCreativeAmmo) {
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.RIFLE.get(stack) > 0; return Ammo.RIFLE.get(stack) > 0;
} }
return false; return false;
}).findFirst().orElse(ItemStack.EMPTY); }).findFirst().orElse(ItemStack.EMPTY);
if (!ammoBox.isEmpty()) { if (!ammoBox.isEmpty()) {
AmmoType.RIFLE.add(ammoBox, -1); Ammo.RIFLE.add(ammoBox, -1);
} else { } else {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} }

View file

@ -13,7 +13,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -179,10 +179,10 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
int ammoCount = this.getItemStacks().stream().filter(stack -> { int ammoCount = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.HEAVY.get(stack) > 0; return Ammo.HEAVY.get(stack) > 0;
} }
return false; return false;
}).mapToInt(AmmoType.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get()); }).mapToInt(Ammo.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get());
this.entityData.set(AMMO, ammoCount); this.entityData.set(AMMO, ammoCount);
@ -247,13 +247,13 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
if (!hasCreativeAmmo) { if (!hasCreativeAmmo) {
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.HEAVY.get(stack) > 0; return Ammo.HEAVY.get(stack) > 0;
} }
return false; return false;
}).findFirst().orElse(ItemStack.EMPTY); }).findFirst().orElse(ItemStack.EMPTY);
if (!ammoBox.isEmpty()) { if (!ammoBox.isEmpty()) {
AmmoType.HEAVY.add(ammoBox, -1); Ammo.HEAVY.add(ammoBox, -1);
} else { } else {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} }

View file

@ -509,13 +509,13 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
if (!hasCreativeAmmo) { if (!hasCreativeAmmo) {
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.HEAVY.get(stack) > 0; return Ammo.HEAVY.get(stack) > 0;
} }
return false; return false;
}).findFirst().orElse(ItemStack.EMPTY); }).findFirst().orElse(ItemStack.EMPTY);
if (!ammoBox.isEmpty()) { if (!ammoBox.isEmpty()) {
AmmoType.HEAVY.add(ammoBox, -1); Ammo.HEAVY.add(ammoBox, -1);
} else { } else {
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
} }
@ -576,13 +576,13 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
if (stack.is(ModItems.AMMO_BOX.get())) { if (stack.is(ModItems.AMMO_BOX.get())) {
return AmmoType.HEAVY.get(stack) > 0; return Ammo.HEAVY.get(stack) > 0;
} }
return false; return false;
}).findFirst().orElse(ItemStack.EMPTY); }).findFirst().orElse(ItemStack.EMPTY);
if (!ammoBox.isEmpty()) { if (!ammoBox.isEmpty()) {
AmmoType.HEAVY.add(ammoBox, -1); Ammo.HEAVY.add(ammoBox, -1);
} else { } else {
consumeItem(getWeapon(1).ammo, 1); consumeItem(getWeapon(1).ammo, 1);
} }

View file

@ -11,7 +11,7 @@ import com.atsuishio.superbwarfare.item.gun.data.value.AttachmentType;
import com.atsuishio.superbwarfare.item.gun.data.value.ReloadState; import com.atsuishio.superbwarfare.item.gun.data.value.ReloadState;
import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.SoundTool; import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
@ -255,15 +255,6 @@ public class GunEventHandler {
} }
} }
public static double perkDamage(ItemStack stack) {
var data = GunData.from(stack);
var perk = data.perk.get(Perk.Type.AMMO);
if (perk instanceof AmmoPerk ammoPerk) {
return ammoPerk.damageRate;
}
return 1;
}
public static double perkSpeed(GunData data) { public static double perkSpeed(GunData data) {
var perk = data.perk.get(Perk.Type.AMMO); var perk = data.perk.get(Perk.Type.AMMO);
if (perk instanceof AmmoPerk ammoPerk) { if (perk instanceof AmmoPerk ammoPerk) {
@ -453,7 +444,7 @@ public class GunEventHandler {
var ammoTypeInfo = data.ammoTypeInfo(); var ammoTypeInfo = data.ammoTypeInfo();
if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) { if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) {
var type = AmmoType.getType(ammoTypeInfo.value()); var type = Ammo.getType(ammoTypeInfo.value());
assert type != null; assert type != null;
if (type.get(capability) == 0) { if (type.get(capability) == 0) {
@ -534,7 +525,7 @@ public class GunEventHandler {
var ammoTypeInfo = data.ammoTypeInfo(); var ammoTypeInfo = data.ammoTypeInfo();
if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) { if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) {
var type = AmmoType.getType(ammoTypeInfo.value()); var type = Ammo.getType(ammoTypeInfo.value());
assert type != null; assert type != null;
if (type.get(capability) == 0) { if (type.get(capability) == 0) {

View file

@ -654,7 +654,7 @@ public class LivingEventHandler {
var ammoTypeInfo = data.ammoTypeInfo(); var ammoTypeInfo = data.ammoTypeInfo();
if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) { if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) {
var type = AmmoType.getType(ammoTypeInfo.value()); var type = Ammo.getType(ammoTypeInfo.value());
assert type != null; assert type != null;
int ammoFinal = Math.min(type.get(cap), ammoNeed); int ammoFinal = Math.min(type.get(cap), ammoNeed);
@ -732,14 +732,14 @@ public class LivingEventHandler {
if (event.getEntity() instanceof Player player && !player.level().getLevelData().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) { if (event.getEntity() instanceof Player player && !player.level().getLevelData().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) {
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
boolean drop = Stream.of(AmmoType.values()) boolean drop = Stream.of(Ammo.values())
.mapToInt(type -> type.get(cap)) .mapToInt(type -> type.get(cap))
.sum() > 0; .sum() > 0;
if (drop) { if (drop) {
var stack = new ItemStack(ModItems.AMMO_BOX.get()); var stack = new ItemStack(ModItems.AMMO_BOX.get());
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
type.set(stack, type.get(cap)); type.set(stack, type.get(cap));
type.set(cap, 0); type.set(cap, 0);
} }

View file

@ -25,7 +25,7 @@ import com.atsuishio.superbwarfare.item.gun.smg.VectorItem;
import com.atsuishio.superbwarfare.item.gun.sniper.*; import com.atsuishio.superbwarfare.item.gun.sniper.*;
import com.atsuishio.superbwarfare.item.gun.special.BocekItem; import com.atsuishio.superbwarfare.item.gun.special.BocekItem;
import com.atsuishio.superbwarfare.item.gun.special.TaserItem; import com.atsuishio.superbwarfare.item.gun.special.TaserItem;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
@ -91,11 +91,11 @@ public class ModItems {
*/ */
public static final DeferredRegister<Item> AMMO = DeferredRegister.create(BuiltInRegistries.ITEM, Mod.MODID); public static final DeferredRegister<Item> AMMO = DeferredRegister.create(BuiltInRegistries.ITEM, Mod.MODID);
public static final DeferredHolder<Item, AmmoSupplierItem> HANDGUN_AMMO = AMMO.register("handgun_ammo", () -> new AmmoSupplierItem(AmmoType.HANDGUN, 1, new Item.Properties())); public static final DeferredHolder<Item, AmmoSupplierItem> HANDGUN_AMMO = AMMO.register("handgun_ammo", () -> new AmmoSupplierItem(Ammo.HANDGUN, 1, new Item.Properties()));
public static final DeferredHolder<Item, AmmoSupplierItem> RIFLE_AMMO = AMMO.register("rifle_ammo", () -> new AmmoSupplierItem(AmmoType.RIFLE, 1, new Item.Properties())); public static final DeferredHolder<Item, AmmoSupplierItem> RIFLE_AMMO = AMMO.register("rifle_ammo", () -> new AmmoSupplierItem(Ammo.RIFLE, 1, new Item.Properties()));
public static final DeferredHolder<Item, AmmoSupplierItem> SNIPER_AMMO = AMMO.register("sniper_ammo", () -> new AmmoSupplierItem(AmmoType.SNIPER, 1, new Item.Properties())); public static final DeferredHolder<Item, AmmoSupplierItem> SNIPER_AMMO = AMMO.register("sniper_ammo", () -> new AmmoSupplierItem(Ammo.SNIPER, 1, new Item.Properties()));
public static final DeferredHolder<Item, AmmoSupplierItem> SHOTGUN_AMMO = AMMO.register("shotgun_ammo", () -> new AmmoSupplierItem(AmmoType.SHOTGUN, 1, new Item.Properties())); public static final DeferredHolder<Item, AmmoSupplierItem> SHOTGUN_AMMO = AMMO.register("shotgun_ammo", () -> new AmmoSupplierItem(Ammo.SHOTGUN, 1, new Item.Properties()));
public static final DeferredHolder<Item, AmmoSupplierItem> HEAVY_AMMO = AMMO.register("heavy_ammo", () -> new AmmoSupplierItem(AmmoType.HEAVY, 1, new Item.Properties())); public static final DeferredHolder<Item, AmmoSupplierItem> HEAVY_AMMO = AMMO.register("heavy_ammo", () -> new AmmoSupplierItem(Ammo.HEAVY, 1, new Item.Properties()));
public static final DeferredHolder<Item, HandgunAmmoBox> HANDGUN_AMMO_BOX = AMMO.register("handgun_ammo_box", HandgunAmmoBox::new); public static final DeferredHolder<Item, HandgunAmmoBox> HANDGUN_AMMO_BOX = AMMO.register("handgun_ammo_box", HandgunAmmoBox::new);
public static final DeferredHolder<Item, RifleAmmoBox> RIFLE_AMMO_BOX = AMMO.register("rifle_ammo_box", RifleAmmoBox::new); public static final DeferredHolder<Item, RifleAmmoBox> RIFLE_AMMO_BOX = AMMO.register("rifle_ammo_box", RifleAmmoBox::new);
public static final DeferredHolder<Item, SniperAmmoBox> SNIPER_AMMO_BOX = AMMO.register("sniper_ammo_box", SniperAmmoBox::new); public static final DeferredHolder<Item, SniperAmmoBox> SNIPER_AMMO_BOX = AMMO.register("sniper_ammo_box", SniperAmmoBox::new);

View file

@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
@ -20,10 +20,10 @@ import java.util.List;
public class AmmoSupplierItem extends Item { public class AmmoSupplierItem extends Item {
public final AmmoType type; public final Ammo type;
public final int ammoToAdd; public final int ammoToAdd;
public AmmoSupplierItem(AmmoType type, int ammoToAdd, Properties properties) { public AmmoSupplierItem(Ammo type, int ammoToAdd, Properties properties) {
super(properties); super(properties);
this.type = type; this.type = type;
this.ammoToAdd = ammoToAdd; this.ammoToAdd = ammoToAdd;

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.item.common.ammo; package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,7 +12,7 @@ import java.util.List;
public class HandgunAmmoBox extends AmmoSupplierItem { public class HandgunAmmoBox extends AmmoSupplierItem {
public HandgunAmmoBox() { public HandgunAmmoBox() {
super(AmmoType.HANDGUN, 30, new Properties()); super(Ammo.HANDGUN, 30, new Properties());
} }

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.item.common.ammo; package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,7 +12,7 @@ import java.util.List;
public class RifleAmmoBox extends AmmoSupplierItem { public class RifleAmmoBox extends AmmoSupplierItem {
public RifleAmmoBox() { public RifleAmmoBox() {
super(AmmoType.RIFLE, 30, new Properties()); super(Ammo.RIFLE, 30, new Properties());
} }
@Override @Override

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.item.common.ammo; package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,7 +12,7 @@ import java.util.List;
public class ShotgunAmmoBox extends AmmoSupplierItem { public class ShotgunAmmoBox extends AmmoSupplierItem {
public ShotgunAmmoBox() { public ShotgunAmmoBox() {
super(AmmoType.SHOTGUN, 12, new Properties()); super(Ammo.SHOTGUN, 12, new Properties());
} }
@Override @Override

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.item.common.ammo; package com.atsuishio.superbwarfare.item.common.ammo;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,7 +12,7 @@ import java.util.List;
public class SniperAmmoBox extends AmmoSupplierItem { public class SniperAmmoBox extends AmmoSupplierItem {
public SniperAmmoBox() { public SniperAmmoBox() {
super(AmmoType.SNIPER, 12, new Properties()); super(Ammo.SNIPER, 12, new Properties());
} }
@Override @Override

View file

@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.item.common.ammo.box;
import com.atsuishio.superbwarfare.component.ModDataComponents; import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.FormatTool;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -43,7 +43,7 @@ public class AmmoBox extends Item {
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
if (!level.isClientSide()) { if (!level.isClientSide()) {
var types = selectedType.equals("All") ? AmmoType.values() : new AmmoType[]{AmmoType.getType(selectedType)}; var types = selectedType.equals("All") ? Ammo.values() : new Ammo[]{Ammo.getType(selectedType)};
for (var type : types) { for (var type : types) {
if (type == null) continue; if (type == null) continue;
@ -76,7 +76,7 @@ public class AmmoBox extends Item {
var list = new ArrayList<String>(); var list = new ArrayList<String>();
list.add("All"); list.add("All");
for (var ammoType : AmmoType.values()) { for (var ammoType : Ammo.values()) {
list.add(ammoType.name); list.add(ammoType.name);
} }
@ -96,7 +96,7 @@ public class AmmoBox extends Item {
stack.set(ModDataComponents.AMMO_BOX_INFO, new AmmoBoxInfo(typeString, info.isDrop())); stack.set(ModDataComponents.AMMO_BOX_INFO, new AmmoBoxInfo(typeString, info.isDrop()));
entity.playSound(ModSounds.FIRE_RATE.get(), 1f, 1f); entity.playSound(ModSounds.FIRE_RATE.get(), 1f, 1f);
var type = AmmoType.getType(typeString); var type = Ammo.getType(typeString);
if (type == null) { if (type == null) {
player.displayClientMessage(Component.translatable("des.superbwarfare.ammo_box.type.all").withStyle(ChatFormatting.WHITE), true); player.displayClientMessage(Component.translatable("des.superbwarfare.ammo_box.type.all").withStyle(ChatFormatting.WHITE), true);
return true; return true;
@ -123,28 +123,28 @@ public class AmmoBox extends Item {
public void appendHoverText(ItemStack stack, @NotNull TooltipContext context, @NotNull List<Component> tooltipComponents, @NotNull TooltipFlag tooltipFlag) { public void appendHoverText(ItemStack stack, @NotNull TooltipContext context, @NotNull List<Component> tooltipComponents, @NotNull TooltipFlag tooltipFlag) {
var info = stack.get(ModDataComponents.AMMO_BOX_INFO); var info = stack.get(ModDataComponents.AMMO_BOX_INFO);
if (info == null) info = new AmmoBoxInfo("All", false); if (info == null) info = new AmmoBoxInfo("All", false);
var type = AmmoType.getType(info.type()); var type = Ammo.getType(info.type());
tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box").withStyle(ChatFormatting.GRAY)); tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box").withStyle(ChatFormatting.GRAY));
tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.handgun").withStyle(ChatFormatting.AQUA) tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.handgun").withStyle(ChatFormatting.AQUA)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format0D(AmmoType.HANDGUN.get(stack)) + ((type != AmmoType.HANDGUN) ? " " : " ←-")).withStyle(ChatFormatting.BOLD))); .append(Component.literal(FormatTool.format0D(Ammo.HANDGUN.get(stack)) + ((type != Ammo.HANDGUN) ? " " : " ←-")).withStyle(ChatFormatting.BOLD)));
tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.rifle").withStyle(ChatFormatting.GREEN) tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.rifle").withStyle(ChatFormatting.GREEN)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format0D(AmmoType.RIFLE.get(stack)) + ((type != AmmoType.RIFLE) ? " " : " ←-")).withStyle(ChatFormatting.BOLD))); .append(Component.literal(FormatTool.format0D(Ammo.RIFLE.get(stack)) + ((type != Ammo.RIFLE) ? " " : " ←-")).withStyle(ChatFormatting.BOLD)));
tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.shotgun").withStyle(ChatFormatting.RED) tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.shotgun").withStyle(ChatFormatting.RED)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format0D(AmmoType.SHOTGUN.get(stack)) + ((type != AmmoType.SHOTGUN) ? " " : " ←-")).withStyle(ChatFormatting.BOLD))); .append(Component.literal(FormatTool.format0D(Ammo.SHOTGUN.get(stack)) + ((type != Ammo.SHOTGUN) ? " " : " ←-")).withStyle(ChatFormatting.BOLD)));
tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.sniper").withStyle(ChatFormatting.GOLD) tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.sniper").withStyle(ChatFormatting.GOLD)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format0D(AmmoType.SNIPER.get(stack)) + ((type != AmmoType.SNIPER) ? " " : " ←-")).withStyle(ChatFormatting.BOLD))); .append(Component.literal(FormatTool.format0D(Ammo.SNIPER.get(stack)) + ((type != Ammo.SNIPER) ? " " : " ←-")).withStyle(ChatFormatting.BOLD)));
tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.heavy").withStyle(ChatFormatting.LIGHT_PURPLE) tooltipComponents.add(Component.translatable("des.superbwarfare.ammo_box.heavy").withStyle(ChatFormatting.LIGHT_PURPLE)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format0D(AmmoType.HEAVY.get(stack)) + ((type != AmmoType.HEAVY) ? " " : " ←-")).withStyle(ChatFormatting.BOLD))); .append(Component.literal(FormatTool.format0D(Ammo.HEAVY.get(stack)) + ((type != Ammo.HEAVY) ? " " : " ←-")).withStyle(ChatFormatting.BOLD)));
} }
} }

View file

@ -10,7 +10,7 @@ import com.atsuishio.superbwarfare.item.CustomRendererItem;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.item.gun.data.value.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.value.AttachmentType;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -81,7 +81,7 @@ public abstract class GunItem extends Item implements CustomRendererItem {
var ammoTypeInfo = data.ammoTypeInfo(); var ammoTypeInfo = data.ammoTypeInfo();
if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) { if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) {
var type = AmmoType.getType(ammoTypeInfo.value()); var type = Ammo.getType(ammoTypeInfo.value());
assert type != null; assert type != null;
type.add(capability, count); type.add(capability, count);
@ -461,7 +461,7 @@ public abstract class GunItem extends Item implements CustomRendererItem {
public String getAmmoDisplayName(GunData data) { public String getAmmoDisplayName(GunData data) {
var ammoTypeInfo = data.ammoTypeInfo(); var ammoTypeInfo = data.ammoTypeInfo();
if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) { if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) {
var type = AmmoType.getType(ammoTypeInfo.value()); var type = Ammo.getType(ammoTypeInfo.value());
assert type != null; assert type != null;
return switch (type) { return switch (type) {

View file

@ -6,7 +6,7 @@ import com.atsuishio.superbwarfare.item.gun.data.subdata.*;
import com.atsuishio.superbwarfare.item.gun.data.value.*; import com.atsuishio.superbwarfare.item.gun.data.value.*;
import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
@ -279,7 +279,7 @@ public class GunData {
// 玩家弹药 // 玩家弹药
if (ammoType.startsWith("@")) { if (ammoType.startsWith("@")) {
if (AmmoType.getType(ammoType.substring(1)) == null) { if (Ammo.getType(ammoType.substring(1)) == null) {
return new AmmoTypeInfo(AmmoConsumeType.INVALID, ammoType.substring(1)); return new AmmoTypeInfo(AmmoConsumeType.INVALID, ammoType.substring(1));
} }
return new AmmoTypeInfo(AmmoConsumeType.PLAYER_AMMO, ammoType.substring(1)); return new AmmoTypeInfo(AmmoConsumeType.PLAYER_AMMO, ammoType.substring(1));
@ -310,7 +310,7 @@ public class GunData {
var info = ammoTypeInfo(); var info = ammoTypeInfo();
return switch (info.type()) { return switch (info.type()) {
case PLAYER_AMMO -> { case PLAYER_AMMO -> {
var type = AmmoType.getType(info.value()); var type = Ammo.getType(info.value());
assert type != null; assert type != null;
yield type.get(player); yield type.get(player);
@ -335,7 +335,7 @@ public class GunData {
var info = ammoTypeInfo(); var info = ammoTypeInfo();
switch (info.type()) { switch (info.type()) {
case PLAYER_AMMO -> { case PLAYER_AMMO -> {
var type = AmmoType.getType(info.value()); var type = Ammo.getType(info.value());
assert type != null; assert type != null;
type.set(player, type.get(player) - count); type.set(player, type.get(player) - count);

View file

@ -5,7 +5,7 @@ import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.codec.StreamCodec;
@ -57,7 +57,7 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
var ammoTypeInfo = data.ammoTypeInfo(); var ammoTypeInfo = data.ammoTypeInfo();
if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) { if (ammoTypeInfo.type() == GunData.AmmoConsumeType.PLAYER_AMMO) {
var ammoType = AmmoType.getType(ammoTypeInfo.value()); var ammoType = Ammo.getType(ammoTypeInfo.value());
assert ammoType != null; assert ammoType != null;
if (ammoType.get(cap) == 0) return; if (ammoType.get(cap) == 0) return;

View file

@ -3,7 +3,7 @@ package com.atsuishio.superbwarfare.recipe;
import com.atsuishio.superbwarfare.init.ModRecipes; import com.atsuishio.superbwarfare.init.ModRecipes;
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem; import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBox; import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBox;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingBookCategory; import net.minecraft.world.item.crafting.CraftingBookCategory;
@ -42,14 +42,14 @@ public class AmmoBoxAddAmmoRecipe extends CustomRecipe {
} }
private void addAmmo(HashMap<AmmoType, Integer> map, AmmoType type, int count) { private void addAmmo(HashMap<Ammo, Integer> map, Ammo type, int count) {
map.put(type, map.getOrDefault(type, 0) + count); map.put(type, map.getOrDefault(type, 0) + count);
} }
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public @NotNull ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) { public @NotNull ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
var map = new HashMap<AmmoType, Integer>(); var map = new HashMap<Ammo, Integer>();
var ammoBox = ItemStack.EMPTY; var ammoBox = ItemStack.EMPTY;
for (var item : input.items()) { for (var item : input.items()) {
@ -57,13 +57,13 @@ public class AmmoBoxAddAmmoRecipe extends CustomRecipe {
addAmmo(map, ammoSupplier.type, ammoSupplier.ammoToAdd); addAmmo(map, ammoSupplier.type, ammoSupplier.ammoToAdd);
} else if (item.getItem() instanceof AmmoBox) { } else if (item.getItem() instanceof AmmoBox) {
ammoBox = item.copy(); ammoBox = item.copy();
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
addAmmo(map, type, type.get(item)); addAmmo(map, type, type.get(item));
} }
} }
} }
for (var type : AmmoType.values()) { for (var type : Ammo.values()) {
type.set(ammoBox, map.getOrDefault(type, 0)); type.set(ammoBox, map.getOrDefault(type, 0));
} }

View file

@ -4,7 +4,7 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModRecipes; import com.atsuishio.superbwarfare.init.ModRecipes;
import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBox; import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBox;
import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.Ammo;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -43,7 +43,7 @@ public class AmmoBoxExtractAmmoRecipe extends CustomRecipe {
if (data == null) return false; if (data == null) return false;
var typeString = data.type(); var typeString = data.type();
var type = AmmoType.getType(typeString); var type = Ammo.getType(typeString);
if (type == null) return false; if (type == null) return false;
return type.get(ammoBoxItem) > 0; return type.get(ammoBoxItem) > 0;
@ -52,13 +52,13 @@ public class AmmoBoxExtractAmmoRecipe extends CustomRecipe {
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public @NotNull ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) { public @NotNull ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
AmmoType type = null; Ammo type = null;
for (var item : input.items()) { for (var item : input.items()) {
if (item.getItem() instanceof AmmoBox) { if (item.getItem() instanceof AmmoBox) {
var data = item.get(ModDataComponents.AMMO_BOX_INFO); var data = item.get(ModDataComponents.AMMO_BOX_INFO);
assert data != null; assert data != null;
type = AmmoType.getType(data.type()); type = Ammo.getType(data.type());
break; break;
} }
} }
@ -72,7 +72,6 @@ public class AmmoBoxExtractAmmoRecipe extends CustomRecipe {
case SHOTGUN -> new ItemStack(ModItems.SHOTGUN_AMMO.get()); case SHOTGUN -> new ItemStack(ModItems.SHOTGUN_AMMO.get());
case SNIPER -> new ItemStack(ModItems.SNIPER_AMMO.get()); case SNIPER -> new ItemStack(ModItems.SNIPER_AMMO.get());
case HEAVY -> new ItemStack(ModItems.HEAVY_AMMO.get()); case HEAVY -> new ItemStack(ModItems.HEAVY_AMMO.get());
default -> throw new IllegalStateException("Unexpected value: " + type);
}; };
} }
@ -87,7 +86,7 @@ public class AmmoBoxExtractAmmoRecipe extends CustomRecipe {
var data = ammoBox.get(ModDataComponents.AMMO_BOX_INFO); var data = ammoBox.get(ModDataComponents.AMMO_BOX_INFO);
assert data != null; assert data != null;
AmmoType type = AmmoType.getType(data.type()); Ammo type = Ammo.getType(data.type());
assert type != null; assert type != null;
type.add(ammoBox, -1); type.add(ammoBox, -1);

View file

@ -8,7 +8,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredHolder;
public enum AmmoType { public enum Ammo {
HANDGUN("item.superbwarfare.ammo.handgun", "HandgunAmmo"), HANDGUN("item.superbwarfare.ammo.handgun", "HandgunAmmo"),
RIFLE("item.superbwarfare.ammo.rifle", "RifleAmmo"), RIFLE("item.superbwarfare.ammo.rifle", "RifleAmmo"),
SHOTGUN("item.superbwarfare.ammo.shotgun", "ShotgunAmmo"), SHOTGUN("item.superbwarfare.ammo.shotgun", "ShotgunAmmo"),
@ -18,13 +18,13 @@ public enum AmmoType {
public final String name; public final String name;
public DeferredHolder<DataComponentType<?>, DataComponentType<Integer>> dataComponent; public DeferredHolder<DataComponentType<?>, DataComponentType<Integer>> dataComponent;
AmmoType(String translatableKey, String name) { Ammo(String translatableKey, String name) {
this.translatableKey = translatableKey; this.translatableKey = translatableKey;
this.name = name; this.name = name;
} }
public static AmmoType getType(String name) { public static Ammo getType(String name) {
for (AmmoType type : values()) { for (Ammo type : values()) {
if (type.name.equals(name)) { if (type.name.equals(name)) {
return type; return type;
} }