优化近战相关代码

This commit is contained in:
Light_Quanta 2025-05-22 15:09:58 +08:00
parent e93114b911
commit 8145f027c5
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 20 additions and 12 deletions

View file

@ -25,8 +25,6 @@ public class DefaultGunData {
public double spread; public double spread;
@SerializedName("Damage") @SerializedName("Damage")
public double damage; public double damage;
@SerializedName("MeleeDamage")
public double meleeDamage;
@SerializedName("Headshot") @SerializedName("Headshot")
public double headshot = 1.5; public double headshot = 1.5;
@SerializedName("Velocity") @SerializedName("Velocity")
@ -34,6 +32,13 @@ public class DefaultGunData {
@SerializedName("Magazine") @SerializedName("Magazine")
public int magazine; public int magazine;
@SerializedName("MeleeDamage")
public double meleeDamage;
@SerializedName("MeleeDuration")
public int meleeDuration = 26;
@SerializedName("MeleeDamageTime")
public int meleeDamageTime = 6;
@SerializedName("Projectile") @SerializedName("Projectile")
public ProjectileInfo projectile = new ProjectileInfo(); public ProjectileInfo projectile = new ProjectileInfo();

View file

@ -164,6 +164,14 @@ public class GunData {
return defaultGunData().meleeDamage; return defaultGunData().meleeDamage;
} }
public int meleeDuration() {
return Math.max(0, defaultGunData().meleeDuration);
}
public int meleeDamageTime() {
return Math.min(meleeDuration(), defaultGunData().meleeDamageTime);
}
public double explosionDamage() { public double explosionDamage() {
return defaultGunData().explosionDamage; return defaultGunData().explosionDamage;
} }

View file

@ -419,11 +419,11 @@ public class ClientEventHandler {
&& !data.reloading() && !data.reloading()
&& !data.charging() && !player.getCooldowns().isOnCooldown(stack.getItem()) && !data.charging() && !player.getCooldowns().isOnCooldown(stack.getItem())
) { ) {
gunMelee = 36; gunMelee = data.meleeDuration();
cantFireTime = 40; cantFireTime = gunMelee + 4;
player.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, 1f, 1);
} }
if (gunMelee == 22) { if (gunMelee == data.meleeDuration() - data.meleeDamageTime()) {
player.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, 1f, 1);
Entity lookingEntity = TraceTool.findMeleeEntity(player, player.entityInteractionRange()); Entity lookingEntity = TraceTool.findMeleeEntity(player, player.entityInteractionRange());
if (lookingEntity != null) { if (lookingEntity != null) {
PacketDistributor.sendToServer(new MeleeAttackMessage(lookingEntity.getUUID())); PacketDistributor.sendToServer(new MeleeAttackMessage(lookingEntity.getUUID()));

View file

@ -312,7 +312,7 @@ public abstract class GunItem extends Item implements CustomRendererItem {
* @param stack 武器物品 * @param stack 武器物品
*/ */
public boolean hasMeleeAttack(ItemStack stack) { public boolean hasMeleeAttack(ItemStack stack) {
return false; return GunData.from(stack).meleeDamage() > 0;
} }
/** /**

View file

@ -179,11 +179,6 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag
return Optional.of(new SecondaryCataclysmImageComponent(pStack)); return Optional.of(new SecondaryCataclysmImageComponent(pStack));
} }
@Override
public boolean hasMeleeAttack(ItemStack stack) {
return true;
}
@Override @Override
public String getAmmoDisplayName(GunData data) { public String getAmmoDisplayName(GunData data) {
return "40mm Grenade"; return "40mm Grenade";