diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index cb39eec81..4c4aa9e07 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -732,7 +732,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity public void changeWeapon(int index, int value, boolean isScroll) { if (index != 0) return; - var type = isScroll ? (value + getWeaponType(0)) % 2 : value; + var type = isScroll ? (value + getWeaponType(0) + 2) % 2 : value; var sound = switch (type) { case 0 -> ModSounds.INTO_MISSILE.get(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 1bab086ea..e696b7820 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -743,7 +743,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit public void changeWeapon(int index, int value, boolean isScroll) { if (index != 0) return; - var type = isScroll ? (value + getWeaponType(0)) % 2 : value; + var type = isScroll ? (value + getWeaponType(0) + 2) % 2 : value; var sound = switch (type) { case 0, 2 -> ModSounds.INTO_MISSILE.get(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index cea4cea4b..6c1e4d4a2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -687,7 +687,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt public void changeWeapon(int index, int value, boolean isScroll) { if (index != 0) return; - int type = isScroll ? (value + getWeaponType(0)) % 2 : value; + int type = isScroll ? (value + getWeaponType(0) + 2) % 2 : value; var sound = switch (type) { case 0 -> ModSounds.INTO_MISSILE.get(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index a4aa64765..06216c8dc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.particles.ParticleTypes; @@ -59,6 +60,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor YAW = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor WEAPON_TYPE = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); + public Mk42Entity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.MK_42.get(), world); } @@ -73,6 +76,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity this.entityData.define(COOL_DOWN, 0); this.entityData.define(PITCH, 0f); this.entityData.define(YAW, 0f); + this.entityData.define(WEAPON_TYPE, 0); } @Override @@ -106,6 +110,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity if (stack.getItem() instanceof CannonShellItem) { if (this.entityData.get(COOL_DOWN) == 0) { + var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1; + setWeaponType(0, weaponType); vehicleShoot(player, 0); } return InteractionResult.SUCCESS; @@ -232,45 +238,43 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity @Override public void vehicleShoot(Player player, int type) { - if (this.entityData.get(COOL_DOWN) > 0) { - return; - } + if (this.entityData.get(COOL_DOWN) > 0) return; Level level = player.level(); if (level instanceof ServerLevel server) { - ItemStack stack = player.getMainHandItem(); + var isCreative = player.isCreative() || InventoryTool.countItem(player.getInventory().items, ModItems.CREATIVE_AMMO_BOX.get()) > 0; - if (!(stack.getItem() instanceof CannonShellItem)) { - return; + if (!isCreative) { + var ammo = getWeaponType(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); + var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo); + + if (ammoCount <= 0) return; + InventoryTool.consumeItem(player.getInventory().items, ammo, 1); } - float hitDamage = 0; - float explosionRadius = 0; - float explosionDamage = 0; - float fireProbability = 0; - int fireTime = 0; - int durability = 0; + float hitDamage; + float explosionRadius; + float explosionDamage; + float fireProbability; + int fireTime; + int durability; - if (stack.is(ModItems.HE_5_INCHES.get())) { - hitDamage = VehicleConfig.MK42_HE_DAMAGE.get(); - explosionRadius = VehicleConfig.MK42_HE_EXPLOSION_RADIUS.get(); - explosionDamage = VehicleConfig.MK42_HE_EXPLOSION_DAMAGE.get(); - fireProbability = 0.18F; - fireTime = 2; - durability = 1; - } - - if (stack.is(ModItems.AP_5_INCHES.get())) { + if (getWeaponType(0) == 0) { + // AP hitDamage = VehicleConfig.MK42_AP_DAMAGE.get(); explosionRadius = VehicleConfig.MK42_AP_EXPLOSION_RADIUS.get(); explosionDamage = VehicleConfig.MK42_AP_EXPLOSION_DAMAGE.get(); fireProbability = 0; fireTime = 0; durability = 60; - } - - if (!player.isCreative()) { - stack.shrink(1); + } else { + // HE + hitDamage = VehicleConfig.MK42_HE_DAMAGE.get(); + explosionRadius = VehicleConfig.MK42_HE_EXPLOSION_RADIUS.get(); + explosionDamage = VehicleConfig.MK42_HE_EXPLOSION_DAMAGE.get(); + fireProbability = 0.18F; + fireTime = 2; + durability = 1; } CannonShellEntity entityToSpawn = new CannonShellEntity(player, level, hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime) @@ -282,7 +286,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity if (player instanceof ServerPlayer serverPlayer) { SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_FIRE_1P.get(), 2, 1); - SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_RELOAD.get(), 2, 1); + SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_RELOAD.get(), 2, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_FIRE_3P.get(), SoundSource.PLAYERS, 6, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_FAR.get(), SoundSource.PLAYERS, 16, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_VERYFAR.get(), SoundSource.PLAYERS, 32, 1); @@ -316,7 +320,6 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ()); for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(20), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { - if (target instanceof ServerPlayer serverPlayer) { ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(15, 15, 45, this.getX(), this.getEyeY(), this.getZ())); } @@ -347,6 +350,32 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity entity.setXRot(entity.getXRot() + f1 - f); } + @Override + public void setWeaponType(int index, int type) { + if (index != 0) return; + entityData.set(WEAPON_TYPE, type); + } + + @Override + public void changeWeapon(int index, int value, boolean isScroll) { + if (index != 0) return; + + int type = isScroll ? (value + getWeaponType(0) + 2) % 2 : value; + var sound = switch (type) { + case 0, 1 -> ModSounds.CANNON_RELOAD.get(); + default -> null; + }; + if (sound == null) return; + + setWeaponType(0, type); + this.level().playSound(null, this, sound, this.getSoundSource(), 1, 1); + } + + @Override + public int getWeaponType(int index) { + return index == 0 ? entityData.get(WEAPON_TYPE) : -1; + } + @Override public void onPassengerTurned(Entity entity) { this.clampRotation(entity); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index aa01e4c1b..c6ccff340 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.particles.ParticleTypes; @@ -61,6 +62,8 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = VehicleConfig.MLE1934_HP.get(); + public static final EntityDataAccessor WEAPON_TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); + public Mle1934Entity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.MLE_1934.get(), world); } @@ -76,6 +79,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt this.entityData.define(TYPE, 0); this.entityData.define(PITCH, 0f); this.entityData.define(YAW, 0f); + this.entityData.define(WEAPON_TYPE, 0); } @Override @@ -111,6 +115,8 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt if (stack.getItem() instanceof CannonShellItem) { if (this.entityData.get(COOL_DOWN) == 0) { + var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1; + setWeaponType(0, weaponType); vehicleShoot(player, 0); } return InteractionResult.SUCCESS; @@ -246,48 +252,46 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt @Override public void vehicleShoot(Player player, int type) { - if (this.entityData.get(COOL_DOWN) > 0) { - return; - } + if (this.entityData.get(COOL_DOWN) > 0) return; Level level = player.level(); if (level instanceof ServerLevel server) { - ItemStack stack = player.getMainHandItem(); + var isCreative = player.isCreative() || InventoryTool.countItem(player.getInventory().items, ModItems.CREATIVE_AMMO_BOX.get()) > 0; - if (!(stack.getItem() instanceof CannonShellItem)) { - return; + int consumed; + if (isCreative) { + consumed = 2; + } else { + var ammo = getWeaponType(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); + var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo); + + // 尝试消耗两发弹药 + if (ammoCount <= 0) return; + consumed = InventoryTool.consumeItem(player.getInventory().items, ammo, 2); } - float hitDamage = 0; - float explosionRadius = 0; - float explosionDamage = 0; - float fireProbability = 0; - int fireTime = 0; - int durability = 0; - boolean salvoShoot = false; + float hitDamage; + float explosionRadius; + float explosionDamage; + float fireProbability; + int fireTime; + int durability; + boolean salvoShoot = consumed == 2; - if (stack.is(ModItems.HE_5_INCHES.get())) { + if (getWeaponType(0) == 0) { hitDamage = VehicleConfig.MLE1934_HE_DAMAGE.get(); explosionRadius = VehicleConfig.MLE1934_HE_EXPLOSION_RADIUS.get(); explosionDamage = VehicleConfig.MLE1934_HE_EXPLOSION_DAMAGE.get(); fireProbability = 0.24F; fireTime = 5; durability = 1; - salvoShoot = stack.getCount() > 1 || player.isCreative(); - } - - if (stack.is(ModItems.AP_5_INCHES.get())) { + } else { hitDamage = VehicleConfig.MLE1934_AP_DAMAGE.get(); explosionRadius = VehicleConfig.MLE1934_AP_EXPLOSION_RADIUS.get(); explosionDamage = VehicleConfig.MLE1934_AP_EXPLOSION_DAMAGE.get(); fireProbability = 0; fireTime = 0; durability = 70; - salvoShoot = stack.getCount() > 1 || player.isCreative(); - } - - if (!player.isCreative()) { - stack.shrink(salvoShoot ? 2 : 1); } float yRot = this.getYRot(); @@ -392,7 +396,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt if (player instanceof ServerPlayer serverPlayer) { SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_FIRE_1P.get(), 2, 1); - ModUtils.queueServerWork(44, () -> SoundTool.playLocalSound(serverPlayer, ModSounds.MK_42_RELOAD.get(), 2, 1)); + ModUtils.queueServerWork(44, () -> SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_RELOAD.get(), 2, 1)); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_FIRE_3P.get(), SoundSource.PLAYERS, 6, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_FAR.get(), SoundSource.PLAYERS, 16, 1); serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MK_42_VERYFAR.get(), SoundSource.PLAYERS, 32, 1); @@ -439,6 +443,32 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt entity.setXRot(entity.getXRot() + f1 - f); } + @Override + public void setWeaponType(int index, int type) { + if (index != 0) return; + entityData.set(WEAPON_TYPE, type); + } + + @Override + public void changeWeapon(int index, int value, boolean isScroll) { + if (index != 0) return; + + int type = isScroll ? (value + getWeaponType(0) + 2) % 2 : value; + var sound = switch (type) { + case 0, 1 -> ModSounds.CANNON_RELOAD.get(); + default -> null; + }; + if (sound == null) return; + + setWeaponType(0, type); + this.level().playSound(null, this, sound, this.getSoundSource(), 1, 1); + } + + @Override + public int getWeaponType(int index) { + return index == 0 ? entityData.get(WEAPON_TYPE) : -1; + } + @Override public void onPassengerTurned(Entity entity) { this.clampRotation(entity); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index 5e373ab97..d1c1e94a6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -915,7 +915,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public void changeWeapon(int index, int value, boolean isScroll) { if (index != 0) return; - var type = isScroll ? (value + getWeaponType(0)) % 2 : value; + var type = isScroll ? (value + getWeaponType(0) + 2) % 2 : value; var sound = switch (type) { case 0 -> ModSounds.INTO_MISSILE.get(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java index bfbe9d359..cb973541f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity.vehicle.base; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.menu.VehicleMenu; +import com.atsuishio.superbwarfare.tools.InventoryTool; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; @@ -139,10 +140,7 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i * @return 物品数量 */ public int countItem(@NotNull Item item) { - return this.getItemStacks().stream() - .filter(stack -> stack.is(item)) - .mapToInt(ItemStack::getCount) - .sum(); + return InventoryTool.countItem(this.getItemStacks(), item); } /** @@ -153,15 +151,7 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i * @return 成功消耗的物品数量 */ public int consumeItem(Item item, int count) { - int initialCount = count; - var items = this.getItemStacks().stream().filter(stack -> stack.is(item)).toList(); - for (var stack : items) { - var countToShrink = Math.min(stack.getCount(), count); - stack.shrink(countToShrink); - count -= countToShrink; - if (count <= 0) break; - } - return initialCount - count; + return InventoryTool.consumeItem(this.getItemStacks(), item, count); } /** @@ -171,27 +161,10 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i * @param count 要插入的数量 */ public void insertItem(Item item, int count) { - var defaultStack = new ItemStack(item); - var maxStackSize = item.getMaxStackSize(defaultStack); + var rest = InventoryTool.insertItem(this.getItemStacks(), item, count); - for (int i = 0; i < this.getItemStacks().size(); i++) { - var stack = this.getItemStacks().get(i); - - if (stack.is(item) && stack.getCount() < maxStackSize) { - var countToAdd = Math.min(maxStackSize - stack.getCount(), count); - stack.grow(countToAdd); - count -= countToAdd; - } else if (stack.isEmpty()) { - var countToAdd = Math.min(maxStackSize, count); - this.getItemStacks().set(i, new ItemStack(item, countToAdd)); - count -= countToAdd; - } - - if (count <= 0) break; - } - - if (count > 0) { - var stackToDrop = new ItemStack(item, count); + if (rest > 0) { + var stackToDrop = new ItemStack(item, rest); this.level().addFreshEntity(new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), stackToDrop)); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java b/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java index bcef56edf..3dc32bf04 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModSounds.java @@ -342,7 +342,7 @@ public class ModSounds { public static final RegistryObject MK_42_FIRE_3P = REGISTRY.register("mk_42_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("mk_42_fire_3p"))); public static final RegistryObject MK_42_FAR = REGISTRY.register("mk_42_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("mk_42_far"))); public static final RegistryObject MK_42_VERYFAR = REGISTRY.register("mk_42_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("mk_42_veryfar"))); - public static final RegistryObject MK_42_RELOAD = REGISTRY.register("mk_42_reload", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("mk_42_reload"))); + public static final RegistryObject CANNON_RELOAD = REGISTRY.register("cannon_reload", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("cannon_reload"))); public static final RegistryObject CANNON_ZOOM_IN = REGISTRY.register("cannon_zoom_in", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("cannon_zoom_in"))); public static final RegistryObject CANNON_ZOOM_OUT = REGISTRY.register("cannon_zoom_out", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("cannon_zoom_out"))); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java new file mode 100644 index 000000000..a41a1a230 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java @@ -0,0 +1,72 @@ +package com.atsuishio.superbwarfare.tools; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.joml.Math; + +public class InventoryTool { + + /** + * 计算物品列表内指定物品的数量 + * + * @param item 物品类型 + * @return 物品数量 + */ + public static int countItem(NonNullList itemList, @NotNull Item item) { + return itemList.stream() + .filter(stack -> stack.is(item)) + .mapToInt(ItemStack::getCount) + .sum(); + } + + /** + * 消耗物品列表内指定物品 + * + * @param item 物品类型 + * @param count 要消耗的数量 + * @return 成功消耗的物品数量 + */ + public static int consumeItem(NonNullList itemList, Item item, int count) { + int initialCount = count; + var items = itemList.stream().filter(stack -> stack.is(item)).toList(); + for (var stack : items) { + var countToShrink = Math.min(stack.getCount(), count); + stack.shrink(countToShrink); + count -= countToShrink; + if (count <= 0) break; + } + return initialCount - count; + } + + /** + * 尝试插入指定物品指定数量 + * + * @param item 物品类型 + * @param count 要插入的数量 + * @return 未能成功插入的物品数量 + */ + public static int insertItem(NonNullList itemList, Item item, int count) { + var defaultStack = new ItemStack(item); + var maxStackSize = item.getMaxStackSize(defaultStack); + + for (int i = 0; i < itemList.size(); i++) { + var stack = itemList.get(i); + + if (stack.is(item) && stack.getCount() < maxStackSize) { + var countToAdd = Math.min(maxStackSize - stack.getCount(), count); + stack.grow(countToAdd); + count -= countToAdd; + } else if (stack.isEmpty()) { + var countToAdd = Math.min(maxStackSize, count); + itemList.set(i, new ItemStack(item, countToAdd)); + count -= countToAdd; + } + + if (count <= 0) break; + } + + return count; + } +} diff --git a/src/main/resources/assets/superbwarfare/sounds.json b/src/main/resources/assets/superbwarfare/sounds.json index 3b3f37699..2113810b6 100644 --- a/src/main/resources/assets/superbwarfare/sounds.json +++ b/src/main/resources/assets/superbwarfare/sounds.json @@ -2135,18 +2135,18 @@ } ] }, - "mk_42_reload": { + "cannon_reload": { "sounds": [ { - "name": "superbwarfare:mk_42/mk_42_reload_01", + "name": "superbwarfare:cannon/cannon_reload_01", "stream": false }, { - "name": "superbwarfare:mk_42/mk_42_reload_02", + "name": "superbwarfare:cannon/cannon_reload_02", "stream": false }, { - "name": "superbwarfare:mk_42/mk_42_reload_03", + "name": "superbwarfare:cannon/cannon_reload_03", "stream": false } ] @@ -2154,7 +2154,7 @@ "cannon_zoom_in": { "sounds": [ { - "name": "superbwarfare:mk_42/cannon_zoom_in", + "name": "superbwarfare:cannon/cannon_zoom_in", "stream": false } ] @@ -2162,7 +2162,7 @@ "cannon_zoom_out": { "sounds": [ { - "name": "superbwarfare:mk_42/cannon_zoom_out", + "name": "superbwarfare:cannon/cannon_zoom_out", "stream": false } ] diff --git a/src/main/resources/assets/superbwarfare/sounds/mk_42/mk_42_reload_01.ogg b/src/main/resources/assets/superbwarfare/sounds/cannon/cannon_reload_01.ogg similarity index 100% rename from src/main/resources/assets/superbwarfare/sounds/mk_42/mk_42_reload_01.ogg rename to src/main/resources/assets/superbwarfare/sounds/cannon/cannon_reload_01.ogg diff --git a/src/main/resources/assets/superbwarfare/sounds/mk_42/mk_42_reload_02.ogg b/src/main/resources/assets/superbwarfare/sounds/cannon/cannon_reload_02.ogg similarity index 100% rename from src/main/resources/assets/superbwarfare/sounds/mk_42/mk_42_reload_02.ogg rename to src/main/resources/assets/superbwarfare/sounds/cannon/cannon_reload_02.ogg diff --git a/src/main/resources/assets/superbwarfare/sounds/mk_42/mk_42_reload_03.ogg b/src/main/resources/assets/superbwarfare/sounds/cannon/cannon_reload_03.ogg similarity index 100% rename from src/main/resources/assets/superbwarfare/sounds/mk_42/mk_42_reload_03.ogg rename to src/main/resources/assets/superbwarfare/sounds/cannon/cannon_reload_03.ogg diff --git a/src/main/resources/assets/superbwarfare/sounds/mk_42/cannon_zoom_in.ogg b/src/main/resources/assets/superbwarfare/sounds/cannon/cannon_zoom_in.ogg similarity index 100% rename from src/main/resources/assets/superbwarfare/sounds/mk_42/cannon_zoom_in.ogg rename to src/main/resources/assets/superbwarfare/sounds/cannon/cannon_zoom_in.ogg diff --git a/src/main/resources/assets/superbwarfare/sounds/mk_42/cannon_zoom_out.ogg b/src/main/resources/assets/superbwarfare/sounds/cannon/cannon_zoom_out.ogg similarity index 100% rename from src/main/resources/assets/superbwarfare/sounds/mk_42/cannon_zoom_out.ogg rename to src/main/resources/assets/superbwarfare/sounds/cannon/cannon_zoom_out.ogg