实现多座位载具武器切换适配
This commit is contained in:
parent
759b4f10bd
commit
f81ab2e4eb
10 changed files with 148 additions and 95 deletions
|
@ -154,10 +154,20 @@ public class ClickHandler {
|
|||
|
||||
double scroll = event.getScrollDelta();
|
||||
|
||||
// TODO 实现多座位武器切换适配
|
||||
if (player.getVehicle() instanceof MultiWeaponVehicleEntity && !Screen.hasShiftDown()) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(-scroll));
|
||||
event.setCanceled(true);
|
||||
// 未按下shift时,为载具切换武器
|
||||
if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && !Screen.hasShiftDown()) {
|
||||
if (player.getVehicle() instanceof MultiSeatVehicleEntity multiSeatVehicle) {
|
||||
// 若该载具有多个座位,且该座位存在武器时,取消滚动并发送武器切换请求
|
||||
if (multiWeaponVehicle.hasWeapon(multiSeatVehicle.getSeatIndex(player))) {
|
||||
int index = multiSeatVehicle.getSeatIndex(player);
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(index, -scroll));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
} else {
|
||||
// 若该载具无多座位,直接发送0号位武器切换请求
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(0, -scroll));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) {
|
||||
|
|
|
@ -115,7 +115,7 @@ public class HelicopterHudOverlay {
|
|||
w / 2 - 140, h / 2, 0x66FF00, false);
|
||||
|
||||
if (mobileVehicle instanceof Ah6Entity ah6Entity) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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 {
|
||||
|
@ -183,7 +183,7 @@ public class HelicopterHudOverlay {
|
|||
poseStack.scale(0.75f, 0.75f, 1);
|
||||
|
||||
if (mobileVehicle instanceof Ah6Entity ah6Entity) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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 {
|
||||
|
|
|
@ -105,7 +105,7 @@ public class VehicleHudOverlay {
|
|||
|
||||
if (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))
|
||||
&& !(iVehicle instanceof ICannonEntity
|
||||
|| (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getWeaponType() == 1))
|
||||
|| (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getWeaponType(0) == 1))
|
||||
) {
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
|
@ -157,7 +157,7 @@ public class VehicleHudOverlay {
|
|||
return Component.translatable("des.superbwarfare.tips.ammo_type.cal50").getString();
|
||||
}
|
||||
if (iVehicle instanceof Ah6Entity ah6Entity) {
|
||||
if (ah6Entity.getWeaponType() == 0) {
|
||||
if (ah6Entity.getWeaponType(0) == 0) {
|
||||
return Component.translatable("des.superbwarfare.tips.ammo_type.20mm_cannon").getString();
|
||||
} else {
|
||||
return Component.translatable("des.superbwarfare.tips.ammo_type.rocket").getString();
|
||||
|
@ -218,18 +218,18 @@ public class VehicleHudOverlay {
|
|||
|
||||
// 不同武器种类的准星
|
||||
if (multiWeaponVehicle instanceof Yx100Entity) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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() == 1) {
|
||||
} else if (multiWeaponVehicle.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) {
|
||||
if (multiWeaponVehicle.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() == 1) {
|
||||
} else if (multiWeaponVehicle.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() == 2) {
|
||||
} else if (multiWeaponVehicle.getWeaponType(0) == 2) {
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ public class VehicleHudOverlay {
|
|||
// 武器名称
|
||||
//LAV-150
|
||||
if (player.getVehicle() instanceof Lav150Entity lav) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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 {
|
||||
|
@ -298,10 +298,10 @@ public class VehicleHudOverlay {
|
|||
|
||||
//BMP-2
|
||||
if (player.getVehicle() instanceof Bmp2Entity bmp2) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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() == 1) {
|
||||
} else if (multiWeaponVehicle.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 {
|
||||
|
@ -312,7 +312,7 @@ public class VehicleHudOverlay {
|
|||
|
||||
//YX-100
|
||||
if (player.getVehicle() instanceof Yx100Entity yx100) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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,7 +344,7 @@ public class VehicleHudOverlay {
|
|||
|
||||
//LAV-150
|
||||
if (multiWeaponVehicle instanceof Lav150Entity lav1501) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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,10 +354,10 @@ public class VehicleHudOverlay {
|
|||
}
|
||||
//BMP-2
|
||||
if (multiWeaponVehicle instanceof Bmp2Entity bmp201) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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() == 1) {
|
||||
} else if (multiWeaponVehicle.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,7 +366,7 @@ public class VehicleHudOverlay {
|
|||
}
|
||||
//YX-100
|
||||
if (multiWeaponVehicle instanceof Yx100Entity yx100) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (multiWeaponVehicle.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);
|
||||
|
|
|
@ -226,7 +226,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
|
||||
}
|
||||
|
||||
if (this.getWeaponType() == 0) {
|
||||
if (this.getWeaponType(0) == 0) {
|
||||
this.entityData.set(AMMO, ammoCount);
|
||||
} else {
|
||||
this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET));
|
||||
|
@ -538,7 +538,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
Vector4f worldPositionRight;
|
||||
Vector4f worldPositionLeft;
|
||||
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
if (this.cannotFire) return;
|
||||
|
||||
x = 1.15f;
|
||||
|
@ -615,7 +615,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 7, this.getX(), this.getEyeY(), this.getZ()));
|
||||
}
|
||||
}
|
||||
} else if (getWeaponType() == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) {
|
||||
} else if (getWeaponType(0) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) {
|
||||
x = 1.7f;
|
||||
y = 0.62f - 1.45f;
|
||||
z = 0.8f;
|
||||
|
@ -711,9 +711,9 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
|
||||
@Override
|
||||
public boolean canShoot(Player player) {
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
return this.entityData.get(AMMO) > 0;
|
||||
}
|
||||
return false;
|
||||
|
@ -856,9 +856,11 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
|
||||
|
||||
@Override
|
||||
public void changeWeapon(int scroll) {
|
||||
var type = (getWeaponType() + scroll + 2) % 2;
|
||||
setWeaponType(type);
|
||||
public void changeWeapon(int index, int scroll) {
|
||||
if (index != 0) return;
|
||||
|
||||
var type = (getWeaponType(0) + scroll + 2) % 2;
|
||||
setWeaponType(0, type);
|
||||
|
||||
var sound = switch (type) {
|
||||
case 0 -> ModSounds.INTO_MISSILE.get();
|
||||
|
@ -870,12 +872,13 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getWeaponType() {
|
||||
return entityData.get(WEAPON_TYPE);
|
||||
public int getWeaponType(int index) {
|
||||
if (index == 0) return entityData.get(WEAPON_TYPE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeaponType(int type) {
|
||||
public void setWeaponType(int index, int type) {
|
||||
entityData.set(WEAPON_TYPE, type);
|
||||
}
|
||||
|
||||
|
|
|
@ -287,9 +287,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
this.level().playSound(null, this, ModSounds.BMP_MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
|
||||
}
|
||||
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get()));
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
this.entityData.set(AMMO, ammoCount);
|
||||
} else {
|
||||
this.entityData.set(AMMO, countItem(ModItems.WIRE_GUIDE_MISSILE.get()));
|
||||
|
@ -307,7 +307,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
@Override
|
||||
public void vehicleShoot(Player player) {
|
||||
Matrix4f transform = getBarrelTransform();
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
if (this.cannotFire) return;
|
||||
float x = -0.1125f;
|
||||
float y = 0.174025f;
|
||||
|
@ -348,7 +348,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
this.entityData.set(HEAT, this.entityData.get(HEAT) + 7);
|
||||
this.entityData.set(FIRE_ANIM, 3);
|
||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
if (this.cannotFireCoax) return;
|
||||
float x = 0.1125f;
|
||||
float y = 0.174025f;
|
||||
|
@ -396,7 +396,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
serverPlayer.playSound(ModSounds.M_60_VERYFAR.get(), 12, 1);
|
||||
}
|
||||
}
|
||||
} else if (getWeaponType() == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) {
|
||||
} else if (getWeaponType(0) == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) {
|
||||
Matrix4f transformT = getBarrelTransform();
|
||||
Vector4f worldPosition = transformPosition(transformT, 0, 1, 0);
|
||||
|
||||
|
@ -681,11 +681,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
}
|
||||
|
||||
private PlayState firePredicate(AnimationState<Bmp2Entity> event) {
|
||||
if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType() == 0) {
|
||||
if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType(0) == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire"));
|
||||
}
|
||||
|
||||
if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType() == 1) {
|
||||
if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType(0) == 1) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2"));
|
||||
}
|
||||
|
||||
|
@ -719,9 +719,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
|
||||
@Override
|
||||
public int mainGunRpm() {
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
return 250;
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
return 750;
|
||||
}
|
||||
return 250;
|
||||
|
@ -729,11 +729,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
|
||||
@Override
|
||||
public boolean canShoot(Player player) {
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
|
||||
} else if (getWeaponType() == 2) {
|
||||
} else if (getWeaponType(0) == 2) {
|
||||
return (this.entityData.get(LOADED_MISSILE) > 0);
|
||||
}
|
||||
return false;
|
||||
|
@ -760,9 +760,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeWeapon(int scroll) {
|
||||
var type = (getWeaponType() + scroll + 3) % 3;
|
||||
setWeaponType(type);
|
||||
public void changeWeapon(int index, int scroll) {
|
||||
if (index != 0) return;
|
||||
|
||||
var type = (getWeaponType(0) + scroll + 3) % 3;
|
||||
setWeaponType(0, type);
|
||||
|
||||
var sound = switch (type) {
|
||||
case 0, 2 -> ModSounds.INTO_MISSILE.get();
|
||||
|
@ -774,13 +776,13 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getWeaponType() {
|
||||
return entityData.get(WEAPON_TYPE);
|
||||
public int getWeaponType(int index) {
|
||||
return index == 0 ? entityData.get(WEAPON_TYPE) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeaponType(int type) {
|
||||
entityData.set(WEAPON_TYPE, type);
|
||||
public void setWeaponType(int index, int type) {
|
||||
if (type == 0) entityData.set(WEAPON_TYPE, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -258,9 +258,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
return false;
|
||||
}).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get());
|
||||
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get()));
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
this.entityData.set(AMMO, ammoCount);
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||
|
||||
Matrix4f transform = getBarrelTransform();
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
if (this.cannotFire) return;
|
||||
float x = -0.0234375f;
|
||||
float y = 0f;
|
||||
|
@ -320,7 +320,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
this.entityData.set(FIRE_ANIM, 3);
|
||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
if (this.cannotFireCoax) return;
|
||||
float x = 0.3f;
|
||||
float y = 0.08f;
|
||||
|
@ -627,11 +627,11 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
}
|
||||
|
||||
private PlayState firePredicate(AnimationState<Lav150Entity> event) {
|
||||
if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType() == 0) {
|
||||
if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType(0) == 0) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire"));
|
||||
}
|
||||
|
||||
if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType() == 1) {
|
||||
if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType(0) == 1) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2"));
|
||||
}
|
||||
|
||||
|
@ -665,9 +665,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
|
||||
@Override
|
||||
public int mainGunRpm() {
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
return 300;
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
return 600;
|
||||
}
|
||||
return 300;
|
||||
|
@ -675,9 +675,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
|
||||
@Override
|
||||
public boolean canShoot(Player player) {
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
|
||||
}
|
||||
return false;
|
||||
|
@ -704,9 +704,11 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeWeapon(int scroll) {
|
||||
var type = (getWeaponType() + scroll + 2) % 2;
|
||||
setWeaponType(type);
|
||||
public void changeWeapon(int index, int scroll) {
|
||||
if (index != 0) return;
|
||||
|
||||
var type = (getWeaponType(0) + scroll + 2) % 2;
|
||||
setWeaponType(0, type);
|
||||
|
||||
var sound = switch (type) {
|
||||
case 0 -> ModSounds.INTO_MISSILE.get();
|
||||
|
@ -718,12 +720,13 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getWeaponType() {
|
||||
return entityData.get(WEAPON_TYPE);
|
||||
public int getWeaponType(int index) {
|
||||
return index == 0 ? entityData.get(WEAPON_TYPE) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeaponType(int type) {
|
||||
public void setWeaponType(int index, int type) {
|
||||
if (index != 0) return;
|
||||
entityData.set(WEAPON_TYPE, type);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,40 @@
|
|||
package com.atsuishio.superbwarfare.entity.vehicle;
|
||||
|
||||
public interface MultiWeaponVehicleEntity extends IArmedVehicleEntity {
|
||||
/**
|
||||
* 检测该槽位是否有可用武器
|
||||
*
|
||||
* @param index 武器槽位
|
||||
* @return 武器是否可用
|
||||
*/
|
||||
default boolean hasWeapon(int index) {
|
||||
return getWeaponType(index) != -1;
|
||||
}
|
||||
|
||||
void changeWeapon(int scroll);
|
||||
/**
|
||||
* 切换武器事件
|
||||
*
|
||||
* @param index 武器槽位
|
||||
* @param scroll 滚动值,-1~1之间的整数
|
||||
*/
|
||||
void changeWeapon(int index, int scroll);
|
||||
|
||||
int getWeaponType();
|
||||
/**
|
||||
* 获取该槽位当前的武器类型,返回-1则表示该位置没有可用武器
|
||||
*
|
||||
* @param index 武器槽位
|
||||
* @return 武器类型
|
||||
*/
|
||||
default int getWeaponType(int index) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void setWeaponType(int type);
|
||||
/**
|
||||
* 设置该槽位当前的武器类型
|
||||
*
|
||||
* @param index 武器槽位
|
||||
* @param type 武器类型
|
||||
*/
|
||||
|
||||
void setWeaponType(int index, int type);
|
||||
}
|
||||
|
|
|
@ -116,14 +116,14 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
public void addAdditionalSaveData(CompoundTag compound) {
|
||||
super.addAdditionalSaveData(compound);
|
||||
compound.putInt("LoadedAmmo", this.entityData.get(LOADED_AMMO));
|
||||
compound.putInt("WeaponType", getWeaponType());
|
||||
compound.putInt("WeaponType", getWeaponType(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag compound) {
|
||||
super.readAdditionalSaveData(compound);
|
||||
this.entityData.set(LOADED_AMMO, compound.getInt("LoadedAmmo"));
|
||||
setWeaponType(compound.getInt("WeaponType"));
|
||||
setWeaponType(0, compound.getInt("WeaponType"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -247,10 +247,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
}
|
||||
|
||||
private Item getCurrentAmmoItem() {
|
||||
return switch (getWeaponType()) {
|
||||
return switch (getWeaponType(0)) {
|
||||
case 0 -> ModItems.AP_5_INCHES.get();
|
||||
case 1 -> ModItems.HE_5_INCHES.get();
|
||||
default -> throw new IllegalStateException("Unexpected value: " + getWeaponType());
|
||||
default -> throw new IllegalStateException("Unexpected value: " + getWeaponType(0));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
int fireTime, durability;
|
||||
float v;
|
||||
|
||||
if (getWeaponType() == 0) {
|
||||
if (getWeaponType(0) == 0) {
|
||||
hitDamage = 500;
|
||||
explosionRadius = 4;
|
||||
explosionDamage = 100;
|
||||
|
@ -301,7 +301,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
fireTime = 0;
|
||||
durability = 60;
|
||||
v = 40;
|
||||
} else if (getWeaponType() == 1) {
|
||||
} else if (getWeaponType(0) == 1) {
|
||||
hitDamage = 100;
|
||||
explosionRadius = 10;
|
||||
explosionDamage = 150;
|
||||
|
@ -310,7 +310,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
durability = 1;
|
||||
v = 25;
|
||||
} else {
|
||||
throw new IllegalStateException("Unexpected value: " + getWeaponType());
|
||||
throw new IllegalStateException("Unexpected value: " + getWeaponType(0));
|
||||
}
|
||||
|
||||
Vector4f worldPosition = transformPosition(transform, 0, 0, 0);
|
||||
|
@ -734,7 +734,9 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeWeapon(int scroll) {
|
||||
public void changeWeapon(int index, int scroll) {
|
||||
if (index != 0) return;
|
||||
|
||||
if (entityData.get(LOADED_AMMO) > 0) {
|
||||
if (this.getFirstPassenger() instanceof Player player && !player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
this.insertItem(getCurrentAmmoItem(), 1);
|
||||
|
@ -749,8 +751,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
player.connection.send(clientboundstopsoundpacket);
|
||||
}
|
||||
|
||||
var type = (getWeaponType() + scroll + 2) % 2;
|
||||
setWeaponType(type);
|
||||
var type = (getWeaponType(0) + scroll + 2) % 2;
|
||||
setWeaponType(0, type);
|
||||
|
||||
var sound = switch (type) {
|
||||
case 0 -> ModSounds.INTO_MISSILE.get();
|
||||
|
@ -761,13 +763,13 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getWeaponType() {
|
||||
return entityData.get(WEAPON_TYPE);
|
||||
public int getWeaponType(int index) {
|
||||
return index == 0 ? entityData.get(WEAPON_TYPE) : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeaponType(int type) {
|
||||
entityData.set(WEAPON_TYPE, type);
|
||||
public void setWeaponType(int index, int type) {
|
||||
if (index == 0) entityData.set(WEAPON_TYPE, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -733,36 +733,36 @@ public class ClientEventHandler {
|
|||
player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1);
|
||||
}
|
||||
|
||||
if (iVehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle) {
|
||||
if (iVehicle instanceof MultiWeaponVehicleEntity) {
|
||||
if (iVehicle instanceof Ah6Entity ah6Entity) {
|
||||
float pitch = ah6Entity.heat <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.heat));
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (ah6Entity.getWeaponType(0) == 0) {
|
||||
ah6Entity.heat += 5;
|
||||
player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch);
|
||||
} else if (multiWeaponVehicle.getWeaponType() == 1) {
|
||||
} else if (ah6Entity.getWeaponType(0) == 1) {
|
||||
player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1);
|
||||
}
|
||||
}
|
||||
if (iVehicle instanceof Lav150Entity lav150) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (lav150.getWeaponType(0) == 0) {
|
||||
float pitch = lav150.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(HEAT)));
|
||||
player.playSound(ModSounds.LAV_CANNON_FIRE_1P.get(), 1f, pitch);
|
||||
player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1);
|
||||
} else if (multiWeaponVehicle.getWeaponType() == 1) {
|
||||
} else if (lav150.getWeaponType(0) == 1) {
|
||||
float pitch = lav150.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(COAX_HEAT)));
|
||||
player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch);
|
||||
}
|
||||
|
||||
}
|
||||
if (iVehicle instanceof Bmp2Entity bmp2) {
|
||||
if (multiWeaponVehicle.getWeaponType() == 0) {
|
||||
if (bmp2.getWeaponType(0) == 0) {
|
||||
float pitch = bmp2.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(HEAT)));
|
||||
player.playSound(ModSounds.BMP_CANNON_FIRE_1P.get(), 1f, pitch);
|
||||
player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1);
|
||||
} else if (multiWeaponVehicle.getWeaponType() == 1) {
|
||||
} else if (bmp2.getWeaponType(0) == 1) {
|
||||
float pitch = bmp2.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(COAX_HEAT)));
|
||||
player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch);
|
||||
} else if (multiWeaponVehicle.getWeaponType() == 2) {
|
||||
} else if (bmp2.getWeaponType(0) == 2) {
|
||||
player.playSound(ModSounds.BMP_MISSILE_FIRE_1P.get(), 1f, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,19 +9,22 @@ import net.minecraftforge.network.NetworkEvent;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
public class SwitchVehicleWeaponMessage {
|
||||
private final int index;
|
||||
|
||||
private final double scroll;
|
||||
|
||||
public SwitchVehicleWeaponMessage(double scroll) {
|
||||
public SwitchVehicleWeaponMessage(int index, double scroll) {
|
||||
this.index = index;
|
||||
this.scroll = scroll;
|
||||
}
|
||||
|
||||
public static void encode(SwitchVehicleWeaponMessage message, FriendlyByteBuf byteBuf) {
|
||||
byteBuf.writeDouble(message.index);
|
||||
byteBuf.writeDouble(message.scroll);
|
||||
}
|
||||
|
||||
public static SwitchVehicleWeaponMessage decode(FriendlyByteBuf byteBuf) {
|
||||
return new SwitchVehicleWeaponMessage(byteBuf.readDouble());
|
||||
return new SwitchVehicleWeaponMessage(byteBuf.readInt(), byteBuf.readDouble());
|
||||
}
|
||||
|
||||
public static void handler(SwitchVehicleWeaponMessage message, Supplier<NetworkEvent.Context> context) {
|
||||
|
@ -32,7 +35,7 @@ public class SwitchVehicleWeaponMessage {
|
|||
}
|
||||
|
||||
if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) {
|
||||
multiWeaponVehicle.changeWeapon(Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1));
|
||||
multiWeaponVehicle.changeWeapon(message.index, Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1));
|
||||
}
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue