重新设计MultiWeaponVehicleEntity,正确处理瞄准音效播放判定

This commit is contained in:
Light_Quanta 2025-03-05 04:04:04 +08:00
parent 4a07e5eb06
commit 27d59709a5
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
13 changed files with 74 additions and 53 deletions

View file

@ -154,11 +154,11 @@ public class ClickHandler {
double scroll = event.getScrollDelta();
// 未按下shift时为有武器的载具切换武器
// 未按下shift时为有武器的载具切换武器
if (!Screen.hasShiftDown()
&& player.getVehicle() instanceof VehicleEntity vehicle
&& vehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle
&& multiWeaponVehicle.hasWeapon(vehicle.getSeatIndex(player))
&& vehicle instanceof WeaponVehicleEntity weaponVehicle
&& weaponVehicle.hasWeapon(vehicle.getSeatIndex(player))
) {
int index = vehicle.getSeatIndex(player);
ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(index, -scroll));

View file

@ -5,8 +5,8 @@ import com.atsuishio.superbwarfare.client.RenderHelper;
import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity;
import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.network.ModVariables;
@ -62,7 +62,7 @@ public class HelicopterHudOverlay {
if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit)
return;
if (player.getVehicle() instanceof HelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle) {
if (player.getVehicle() instanceof HelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && player.getVehicle() instanceof WeaponVehicleEntity weaponVehicle) {
poseStack.pushPose();
poseStack.translate(-6 * ClientEventHandler.turnRot[1], -6 * ClientEventHandler.turnRot[0], 0);
@ -119,7 +119,7 @@ public class HelicopterHudOverlay {
w / 2 - 140, h / 2, 0x66FF00, false);
if (mobileVehicle instanceof Ah6Entity ah6Entity) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle.getWeaponType(0) == 0) {
double heat = 1 - ah6Entity.heat / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : iHelicopterEntity.getAmmoCount(player))), w / 2 - 160, h / 2 - 60, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
} else {
@ -187,7 +187,7 @@ public class HelicopterHudOverlay {
poseStack.scale(0.75f, 0.75f, 1);
if (mobileVehicle instanceof Ah6Entity ah6Entity) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle.getWeaponType(0) == 0) {
double heat = ah6Entity.heat / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
} else {

View file

@ -187,7 +187,7 @@ public class VehicleHudOverlay {
if (player == null) return;
if (player.getVehicle() instanceof LandArmorEntity iLand && iLand.isDriver(player)
&& iLand instanceof MultiWeaponVehicleEntity multiWeaponVehicle
&& iLand instanceof WeaponVehicleEntity weaponVehicle
&& iLand instanceof MobileVehicleEntity mobileVehicle) {
poseStack.pushPose();
@ -218,19 +218,19 @@ public class VehicleHudOverlay {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2f + 112, h - 71, 0, 0.0F, 1, 16, 1, 16);
// 不同武器种类的准星
if (multiWeaponVehicle instanceof Yx100Entity) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle instanceof Yx100Entity) {
if (weaponVehicle.getWeaponType(0) == 0) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/tank_cannon_cross_ap.png"), k, l, 0, 0.0F, i, j, i, j);
} else if (multiWeaponVehicle.getWeaponType(0) == 1) {
} else if (weaponVehicle.getWeaponType(0) == 1) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/tank_cannon_cross_he.png"), k, l, 0, 0.0F, i, j, i, j);
}
} else {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle.getWeaponType(0) == 0) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cannon_cross.png"), k, l, 0, 0.0F, i, j, i, j);
} else if (multiWeaponVehicle.getWeaponType(0) == 1) {
} else if (weaponVehicle.getWeaponType(0) == 1) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_gun_cross.png"), k, l, 0, 0.0F, i, j, i, j);
} else if (multiWeaponVehicle.getWeaponType(0) == 2) {
} else if (weaponVehicle.getWeaponType(0) == 2) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j);
}
}
@ -288,7 +288,7 @@ public class VehicleHudOverlay {
// 武器名称
//LAV-150
if (player.getVehicle() instanceof Lav150Entity lav) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle.getWeaponType(0) == 0) {
double heat = 1 - lav.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : lav.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
} else {
@ -299,10 +299,10 @@ public class VehicleHudOverlay {
//BMP-2
if (player.getVehicle() instanceof Bmp2Entity bmp2) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle.getWeaponType(0) == 0) {
double heat = 1 - bmp2.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal(" 30MM 2A42 " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
} else if (multiWeaponVehicle.getWeaponType(0) == 1) {
} else if (weaponVehicle.getWeaponType(0) == 1) {
double heat = 1 - bmp2.getEntityData().get(COAX_HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal(" 7.62MM ПКТ " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
} else {
@ -313,7 +313,7 @@ public class VehicleHudOverlay {
//YX-100
if (player.getVehicle() instanceof Yx100Entity yx100) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle.getWeaponType(0) == 0) {
guiGraphics.drawString(mc.font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false);
} else {
guiGraphics.drawString(mc.font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false);
@ -344,8 +344,8 @@ public class VehicleHudOverlay {
poseStack.scale(0.75f, 0.75f, 1);
//LAV-150
if (multiWeaponVehicle instanceof Lav150Entity lav1501) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle instanceof Lav150Entity lav1501) {
if (weaponVehicle.getWeaponType(0) == 0) {
double heat = lav1501.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : lav1501.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
} else {
@ -354,11 +354,11 @@ public class VehicleHudOverlay {
}
}
//BMP-2
if (multiWeaponVehicle instanceof Bmp2Entity bmp201) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle instanceof Bmp2Entity bmp201) {
if (weaponVehicle.getWeaponType(0) == 0) {
double heat = bmp201.getEntityData().get(HEAT) / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("30MM 2A42 " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : bmp201.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false);
} else if (multiWeaponVehicle.getWeaponType(0) == 1) {
} else if (weaponVehicle.getWeaponType(0) == 1) {
double heat2 = bmp201.getEntityData().get(COAX_HEAT) / 100.0F;
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("7.62MM ПКТ " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : bmp201.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false);
} else {
@ -366,8 +366,8 @@ public class VehicleHudOverlay {
}
}
//YX-100
if (multiWeaponVehicle instanceof Yx100Entity yx100) {
if (multiWeaponVehicle.getWeaponType(0) == 0) {
if (weaponVehicle instanceof Yx100Entity yx100) {
if (weaponVehicle.getWeaponType(0) == 0) {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false);
} else {
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false);

View file

@ -8,7 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.HeliRocketEntity;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
@ -60,7 +60,7 @@ import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity, HelicopterEntity, MultiWeaponVehicleEntity {
public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity, HelicopterEntity, WeaponVehicleEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = VehicleConfig.AH_6_HP.get();

View file

@ -8,7 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
import com.atsuishio.superbwarfare.entity.projectile.WgMissileEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
@ -59,7 +59,7 @@ import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, MultiWeaponVehicleEntity {
public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.FLOAT);

View file

@ -7,7 +7,7 @@ import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
@ -61,7 +61,7 @@ import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, MultiWeaponVehicleEntity {
public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.FLOAT);

View file

@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.ModVariables;
@ -51,7 +52,7 @@ import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity {
public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
@ -535,4 +536,9 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
public ResourceLocation getVehicleIcon() {
return ModUtils.loc("textures/vehicle_icon/speedboat_icon.png");
}
@Override
public int getWeaponType(int index) {
return index == 0 ? 0 : -1;
}
}

View file

@ -6,7 +6,7 @@ import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
@ -65,7 +65,7 @@ import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, MultiWeaponVehicleEntity {
public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT);

View file

@ -1,5 +1,4 @@
package com.atsuishio.superbwarfare.entity.vehicle.base;
public interface CannonEntity extends ArmedVehicleEntity {
public interface CannonEntity extends ArmedVehicleEntity, WeaponVehicleEntity {
}

View file

@ -1,6 +1,9 @@
package com.atsuishio.superbwarfare.entity.vehicle.base;
public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity {
/**
* 拥有任意武器的载具
*/
public interface WeaponVehicleEntity extends ArmedVehicleEntity {
/**
* 检测该槽位是否有可用武器
*
@ -17,7 +20,8 @@ public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity {
* @param index 武器槽位
* @param scroll 滚动值-1~1之间的整数
*/
void changeWeapon(int index, int scroll);
default void changeWeapon(int index, int scroll) {
}
/**
* 获取该槽位当前的武器类型返回-1则表示该位置没有可用武器
@ -26,7 +30,8 @@ public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity {
* @return 武器类型
*/
default int getWeaponType(int index) {
return -1;
// 默认认为只有第一个位置拥有一个武器
return index == 0 ? 0 : -1;
}
/**
@ -36,5 +41,6 @@ public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity {
* @param type 武器类型
*/
void setWeaponType(int index, int type);
default void setWeaponType(int index, int type) {
}
}

View file

@ -6,8 +6,8 @@ import com.atsuishio.superbwarfare.config.client.DisplayConfig;
import com.atsuishio.superbwarfare.entity.vehicle.*;
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.network.ModVariables;
@ -737,7 +737,7 @@ public class ClientEventHandler {
player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1);
}
if (iVehicle instanceof MultiWeaponVehicleEntity) {
if (iVehicle instanceof WeaponVehicleEntity) {
if (iVehicle instanceof Ah6Entity ah6Entity) {
float pitch = ah6Entity.heat <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.heat));
if (ah6Entity.getWeaponType(0) == 0) {

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
@ -34,8 +34,8 @@ public class SwitchVehicleWeaponMessage {
return;
}
if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) {
multiWeaponVehicle.changeWeapon(message.index, Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1));
if (player.getVehicle() instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.isDriver(player)) {
weaponVehicle.changeWeapon(message.index, Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1));
}
});
context.get().setPacketHandled(true);

View file

@ -1,8 +1,8 @@
package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.entity.vehicle.WheelChairEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.ModVariables;
@ -38,6 +38,9 @@ public class ZoomMessage {
ServerPlayer player = context.getSender();
if (player == null) return;
var vehicle = player.getVehicle();
// 缩放音效播放条件: 载具是武器载具且该位置有可用武器
if (message.type == 0) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.zoom = true;
@ -45,9 +48,12 @@ public class ZoomMessage {
capability.syncPlayerVariables(player);
});
if (player.isPassenger() && player.getVehicle() instanceof ArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
}
if (player.isPassenger()
&& vehicle instanceof WeaponVehicleEntity weaponEntity
&& vehicle instanceof VehicleEntity vehicleEntity
&& weaponEntity.hasWeapon(vehicleEntity.getSeatIndex(player))
) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
}
if (message.type == 1) {
@ -57,9 +63,12 @@ public class ZoomMessage {
capability.syncPlayerVariables(player);
});
if (player.isPassenger() && player.getVehicle() instanceof ArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1);
}
if (player.isPassenger()
&& vehicle instanceof WeaponVehicleEntity weaponEntity
&& vehicle instanceof VehicleEntity vehicleEntity
&& weaponEntity.hasWeapon(vehicleEntity.getSeatIndex(player))
) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1);
if (player.getMainHandItem().getItem() == ModItems.JAVELIN.get()) {
var handItem = player.getMainHandItem();
@ -74,4 +83,5 @@ public class ZoomMessage {
});
context.setPacketHandled(true);
}
}