给步战车不同的武器添加不同的准星,将切换载具武器种类按键改为鼠标滚轮

This commit is contained in:
Atsuihsio 2025-01-29 21:27:48 +08:00
parent 525b1ac07c
commit a6885e5ba0
14 changed files with 100 additions and 34 deletions

View file

@ -169,6 +169,7 @@ public class ModUtils {
addNetworkMessage(ShowChargingRangeMessage.class, ShowChargingRangeMessage::encode, ShowChargingRangeMessage::decode, ShowChargingRangeMessage::handler); addNetworkMessage(ShowChargingRangeMessage.class, ShowChargingRangeMessage::encode, ShowChargingRangeMessage::decode, ShowChargingRangeMessage::handler);
addNetworkMessage(MeleeAttackMessage.class, MeleeAttackMessage::encode, MeleeAttackMessage::decode, MeleeAttackMessage::handler); addNetworkMessage(MeleeAttackMessage.class, MeleeAttackMessage::encode, MeleeAttackMessage::decode, MeleeAttackMessage::handler);
addNetworkMessage(ResetCameraTypeMessage.class, ResetCameraTypeMessage::encode, ResetCameraTypeMessage::decode, ResetCameraTypeMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); addNetworkMessage(ResetCameraTypeMessage.class, ResetCameraTypeMessage::encode, ResetCameraTypeMessage::decode, ResetCameraTypeMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
addNetworkMessage(SwitchVehicleWeaponMessage.class, SwitchVehicleWeaponMessage::encode, SwitchVehicleWeaponMessage::decode, SwitchVehicleWeaponMessage::handler);
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)), event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get()))); Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));

View file

@ -5,10 +5,7 @@ import com.atsuishio.superbwarfare.compat.CompatHolder;
import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper; import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper;
import com.atsuishio.superbwarfare.config.client.ReloadConfig; import com.atsuishio.superbwarfare.config.client.ReloadConfig;
import com.atsuishio.superbwarfare.entity.MortarEntity; import com.atsuishio.superbwarfare.entity.MortarEntity;
import com.atsuishio.superbwarfare.entity.vehicle.IArmedVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.*;
import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -155,6 +152,11 @@ public class ClickHandler {
double scroll = event.getScrollDelta(); double scroll = event.getScrollDelta();
if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) {
ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(-scroll));
event.setCanceled(true);
}
if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) { if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) {
var tag = stack.getOrCreateTag(); var tag = stack.getOrCreateTag();
if (GunsTool.getGunBooleanTag(stack, "CanSwitchScope", false)) { if (GunsTool.getGunBooleanTag(stack, "CanSwitchScope", false)) {

View file

@ -209,10 +209,19 @@ public class VehicleHudOverlay {
int addW = (w / h) * 48; int addW = (w / h) * 48;
int addH = (w / h) * 27; int addH = (w / h) * 27;
preciseBlit(guiGraphics, FRAME, (float) -addW / 2, (float) -addH / 2, 10, 0, 0.0F, w + addW, h + addH, w + addW, h + addH); preciseBlit(guiGraphics, FRAME, (float) -addW / 2, (float) -addH / 2, 10, 0, 0.0F, w + addW, h + addH, w + addW, h + addH);
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cross.png"), k, l, 0, 0.0F, i, j, i, j);
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 - 64, h - 56, 0, 0.0F, 128, 1, 128, 1); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 - 64, h - 56, 0, 0.0F, 128, 1, 128, 1);
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 + 112, h - 71, 0, 0.0F, 1, 16, 1, 16); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 + 112, h - 71, 0, 0.0F, 1, 16, 1, 16);
//不同武器种类的准星
if (multiWeaponVehicle.getWeaponType() == 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) {
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) {
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j);
}
//指南针 //指南针
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16);
@ -277,7 +286,6 @@ public class VehicleHudOverlay {
double heat = 1 - lav.getEntityData().get(COAX_HEAT) / 100.0F; double heat = 1 - lav.getEntityData().get(COAX_HEAT) / 100.0F;
guiGraphics.drawString(mc.font, Component.literal("7.62MM COAX " + (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); guiGraphics.drawString(mc.font, Component.literal("7.62MM COAX " + (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);
} }
} }
if (player.getVehicle() instanceof Bmp2Entity bmp2) { if (player.getVehicle() instanceof Bmp2Entity bmp2) {

View file

@ -761,15 +761,21 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
} }
@Override @Override
public void changeWeapon() { public void changeWeapon(int scroll) {
// entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + 1); entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll);
if (entityData.get(WEAPON_TYPE) == 0) { if (entityData.get(WEAPON_TYPE) == 0) {
this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1);
entityData.set(WEAPON_TYPE, 1); }
} else if (entityData.get(WEAPON_TYPE) == 1) { if (entityData.get(WEAPON_TYPE) == 1) {
entityData.set(WEAPON_TYPE, 0);
this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1);
} }
if (entityData.get(WEAPON_TYPE) <= -1) {
entityData.set(WEAPON_TYPE, 1);
}
if (entityData.get(WEAPON_TYPE) >= 2) {
entityData.set(WEAPON_TYPE, 0);
}
} }
@Override @Override

View file

@ -812,17 +812,25 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ICha
} }
@Override @Override
public void changeWeapon() { public void changeWeapon(int scroll) {
entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll);
if (entityData.get(WEAPON_TYPE) == 0) { if (entityData.get(WEAPON_TYPE) == 0) {
this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1);
entityData.set(WEAPON_TYPE, 1); }
} else if (entityData.get(WEAPON_TYPE) == 1) { if (entityData.get(WEAPON_TYPE) == 1) {
entityData.set(WEAPON_TYPE, 2);
this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1);
} else if (entityData.get(WEAPON_TYPE) == 2) { }
entityData.set(WEAPON_TYPE, 0); if (entityData.get(WEAPON_TYPE) == 2) {
this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1);
} }
if (entityData.get(WEAPON_TYPE) <= -1) {
entityData.set(WEAPON_TYPE, 2);
}
if (entityData.get(WEAPON_TYPE) >= 3) {
entityData.set(WEAPON_TYPE, 0);
}
} }
@Override @Override

View file

@ -778,14 +778,21 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
} }
@Override @Override
public void changeWeapon() { public void changeWeapon(int scroll) {
entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll);
if (entityData.get(WEAPON_TYPE) == 0) { if (entityData.get(WEAPON_TYPE) == 0) {
this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1);
entityData.set(WEAPON_TYPE, 1); }
} else if (entityData.get(WEAPON_TYPE) == 1) { if (entityData.get(WEAPON_TYPE) == 1) {
entityData.set(WEAPON_TYPE, 0);
this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1);
} }
if (entityData.get(WEAPON_TYPE) <= -1) {
entityData.set(WEAPON_TYPE, 1);
}
if (entityData.get(WEAPON_TYPE) >= 2) {
entityData.set(WEAPON_TYPE, 0);
}
} }
@Override @Override

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.entity.vehicle; package com.atsuishio.superbwarfare.entity.vehicle;
public interface MultiWeaponVehicleEntity { public interface MultiWeaponVehicleEntity extends IArmedVehicleEntity {
void changeWeapon(); void changeWeapon(int scroll);
int getWeaponType(); int getWeaponType();
} }

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
@ -555,7 +556,7 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity,
@Override @Override
public boolean banHand() { public boolean banHand() {
return true; return !(this.getFirstPassenger() instanceof Player player) || !(player.getMainHandItem().getItem() instanceof GunItem);
} }
@Override @Override

View file

@ -339,6 +339,7 @@ public class LivingEventHandler {
player.getCapability(ModCapabilities.LASER_CAPABILITY).ifPresent(LaserCapability.ILaserCapability::stop); player.getCapability(ModCapabilities.LASER_CAPABILITY).ifPresent(LaserCapability.ILaserCapability::stop);
if (player instanceof ServerPlayer serverPlayer) { if (player instanceof ServerPlayer serverPlayer) {
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new DrawClientMessage(true));
if (newStack.getItem() != oldStack.getItem() if (newStack.getItem() != oldStack.getItem()
|| newStack.getTag() == null || oldStack.getTag() == null || newStack.getTag() == null || oldStack.getTag() == null
|| (newStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(newStack).hasUUID("UUID")) || (newStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(newStack).hasUUID("UUID"))
@ -420,10 +421,6 @@ public class LivingEventHandler {
GunsTool.setPerkIntTag(newStack, "KillingTally", 0); GunsTool.setPerkIntTag(newStack, "KillingTally", 0);
} }
if (player.level() instanceof ServerLevel) {
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new DrawClientMessage(true));
}
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.tacticalSprint = false; capability.tacticalSprint = false;
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);

View file

@ -1,7 +1,5 @@
package com.atsuishio.superbwarfare.network.message; package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.entity.vehicle.IArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.MultiWeaponVehicleEntity;
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.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -127,10 +125,6 @@ public class FireModeMessage {
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true); GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true);
} }
} }
return;
}
if (player.getVehicle() instanceof IArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle) {
multiWeaponVehicle.changeWeapon();
} }
} }

View file

@ -0,0 +1,42 @@
package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.entity.vehicle.MultiWeaponVehicleEntity;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class SwitchVehicleWeaponMessage {
private final double scroll;
public SwitchVehicleWeaponMessage(double scroll) {
this.scroll = scroll;
}
public static void encode(SwitchVehicleWeaponMessage message, FriendlyByteBuf byteBuf) {
byteBuf.writeDouble(message.scroll);
}
public static SwitchVehicleWeaponMessage decode(FriendlyByteBuf byteBuf) {
return new SwitchVehicleWeaponMessage(byteBuf.readDouble());
}
public static void handler(SwitchVehicleWeaponMessage message, Supplier<NetworkEvent.Context> context) {
context.get().enqueueWork(() -> {
ServerPlayer player = context.get().getSender();
if (player == null) {
return;
}
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));
}
});
context.get().setPacketHandled(true);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB