From d889c2ddc14deba7943727a4dc97c9cc2d0be87d Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Tue, 8 Apr 2025 17:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E8=9C=82=E7=BE=A4=E6=97=A0=E4=BA=BA?= =?UTF-8?q?=E6=9C=BA=E7=BB=993=E5=8F=B7=E4=BD=8D=EF=BC=8C=E4=B8=89?= =?UTF-8?q?=E5=8F=B7=E4=BD=8D=E6=BD=9C=E8=A1=8C=E6=97=B6=E8=83=BD=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=87=AA=E5=B7=B1=E7=9A=84=E6=AD=A6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/client/ClickHandler.java | 3 +- .../client/overlay/VehicleHudOverlay.java | 8 +- .../overlay/Yx100SwarmDroneHudOverlay.java | 99 ++++++++ .../entity/vehicle/Yx100Entity.java | 238 ++++++++++-------- .../event/ClientEventHandler.java | 9 +- .../message/send/VehicleMovementMessage.java | 3 +- .../network/message/send/ZoomMessage.java | 11 +- 7 files changed, 245 insertions(+), 126 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index 93f78c2e1..b953fedf5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -151,6 +151,7 @@ public class ClickHandler { && player.getVehicle() instanceof VehicleEntity vehicle && vehicle instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.hasWeapon(vehicle.getSeatIndex(player)) + && weaponVehicle.banHand(player) ) { int index = vehicle.getSeatIndex(player); PacketDistributor.sendToServer(new SwitchVehicleWeaponMessage(index, -scroll, true)); @@ -361,7 +362,7 @@ public class ClickHandler { public static void handleWeaponZoomPress(Player player, ItemStack stack) { PacketDistributor.sendToServer(new ZoomMessage(0)); - if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player))) { + if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player)) && iVehicle.banHand(player)) { ClientEventHandler.zoomVehicle = true; return; } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java index 4edae2331..3743dc2a2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.entity.vehicle.base.*; import com.atsuishio.superbwarfare.entity.vehicle.weapon.HeliRocketWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.LaserWeapon; +import com.atsuishio.superbwarfare.entity.vehicle.weapon.SwarmDroneWeapon; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.tools.FormatTool; @@ -48,7 +49,6 @@ import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*; import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.LOADED_MISSILE; import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.MISSILE_COUNT; -import static com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity.LOADED_DRONE; import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.*; @EventBusSubscriber(value = Dist.CLIENT) @@ -291,8 +291,6 @@ public class VehicleHudOverlay { } else if (weaponVehicle.getWeaponIndex(0) == 2) { double heat = 1 - yx100.getEntityData().get(COAX_HEAT) / 100.0F; guiGraphics.drawString(mc.font, Component.literal(" 12.7MM HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); - } else { - guiGraphics.drawString(mc.font, Component.literal(" SWARM " + yx100.getEntityData().get(LOADED_DRONE) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); } } @@ -349,8 +347,6 @@ public class VehicleHudOverlay { } else if (weaponVehicle.getWeaponIndex(0) == 2) { double heat2 = yx100.getEntityData().get(COAX_HEAT) / 100.0F; guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("12.7MM HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false); - } else { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("SWARM " + yx100.getEntityData().get(LOADED_DRONE) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); } } @@ -543,7 +539,7 @@ public class VehicleHudOverlay { ); preciseBlit(guiGraphics, SELECTED, w - 95, startY, 100, 0, 0, 8, 8, 8, 8); - if (InventoryTool.hasCreativeAmmoBox(player) && !(weapon instanceof LaserWeapon) && !(weapon instanceof HeliRocketWeapon)) { + if (InventoryTool.hasCreativeAmmoBox(player) && !(weapon instanceof LaserWeapon) && !(weapon instanceof HeliRocketWeapon) && !(weapon instanceof SwarmDroneWeapon)) { preciseBlit(guiGraphics, NUMBER, w - 28 + xOffset, h - frameIndex * 18 - 15, 100, 58, 0, 10, 7.5f, 75, 7.5f); } else { renderNumber(guiGraphics, weaponVehicle.getAmmoCount(player), weapon instanceof LaserWeapon, diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java new file mode 100644 index 000000000..0142de67d --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/Yx100SwarmDroneHudOverlay.java @@ -0,0 +1,99 @@ +package com.atsuishio.superbwarfare.client.overlay; + +import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.RenderHelper; +import com.atsuishio.superbwarfare.entity.vehicle.Yx100Entity; +import com.atsuishio.superbwarfare.event.ClientEventHandler; +import com.atsuishio.superbwarfare.tools.SeekTool; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.CameraType; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.Vec3; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.RenderGuiEvent; +import org.joml.Math; + +@EventBusSubscriber(modid = Mod.MODID, value = Dist.CLIENT) +public class Yx100SwarmDroneHudOverlay { + private static final ResourceLocation FRAME = Mod.loc("textures/screens/frame/frame.png"); + private static final ResourceLocation FRAME_LOCK = Mod.loc("textures/screens/frame/frame_lock.png"); + + @SubscribeEvent + public static void eventHandler(RenderGuiEvent.Pre event) { + int w = event.getGuiGraphics().guiWidth(); + int h = event.getGuiGraphics().guiHeight(); + Minecraft mc = Minecraft.getInstance(); + Player player = mc.player; + GuiGraphics guiGraphics = event.getGuiGraphics(); + PoseStack poseStack = guiGraphics.pose(); + + if (!shouldRenderCrossHair(player)) return; + + Entity cannon = player.getVehicle(); + if (cannon == null) return; + + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(false); + RenderSystem.enableBlend(); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + RenderSystem.setShaderColor(1, 1, 1, 1); + + if (player.getVehicle() instanceof Yx100Entity yx100 && yx100.banHand(player)) { + if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { + float fovAdjust = (float) 70 / Minecraft.getInstance().options.fov().get(); + + float f = (float) Math.min(w, h); + float f1 = Math.min((float) w / f, (float) h / f) * fovAdjust; + int i = Mth.floor(f * f1); + int j = Mth.floor(f * f1); + int k = (w - i) / 2; + int l = (h - j) / 2; + RenderHelper.preciseBlit(guiGraphics, Mod.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j); + VehicleHudOverlay.renderKillIndicator(guiGraphics, w, h); + Entity naerestEntity = SeekTool.seekLivingEntity(player, player.level(), 384, 6); + + float fovAdjust2 = (float) (Minecraft.getInstance().options.fov().get() / 30) - 1; + + double zoom = 1; + + if (ClientEventHandler.zoomVehicle) { + zoom = Minecraft.getInstance().options.fov().get() / ClientEventHandler.fov + 0.05 * fovAdjust2; + } + + if (naerestEntity != null) { + Vec3 playerVec = new Vec3(Mth.lerp(event.getPartialTick().getRealtimeDeltaTicks(), player.xo, player.getX()), Mth.lerp(event.getPartialTick().getRealtimeDeltaTicks(), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(event.getPartialTick().getRealtimeDeltaTicks(), player.zo, player.getZ())); + Vec3 pos = new Vec3(Mth.lerp(event.getPartialTick().getRealtimeDeltaTicks(), naerestEntity.xo, naerestEntity.getX()), Mth.lerp(event.getPartialTick().getRealtimeDeltaTicks(), naerestEntity.yo + naerestEntity.getEyeHeight(), naerestEntity.getEyeY()), Mth.lerp(event.getPartialTick().getRealtimeDeltaTicks(), naerestEntity.zo, naerestEntity.getZ())); + Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom)); + + var cPos = playerVec.add(lookAngle); + Vec3 point = RenderHelper.worldToScreen(pos, cPos); + if (point == null) return; + + poseStack.pushPose(); + float x = (float) point.x; + float y = (float) point.y; + + RenderHelper.preciseBlit(guiGraphics, FRAME_LOCK, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + poseStack.popPose(); + } + } + } + } + + private static boolean shouldRenderCrossHair(Player player) { + if (player == null) return false; + return !player.isSpectator() + && player.getVehicle() instanceof Yx100Entity yx100 && yx100.getNthEntity(2) == player; + } +} 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 263f970d5..0cda8fd58 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -120,11 +120,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti .ammo(ModItems.HEAVY_AMMO.get()) .sound(ModSounds.INTO_CANNON.get()) .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")), - // 蜂群无人机 - new SwarmDroneWeapon() - .explosionDamage(125) - .explosionRadius(6) - .sound(ModSounds.INTO_MISSILE.get()), }, new VehicleWeapon[]{ // 机枪 @@ -135,6 +130,13 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti .bypassArmorRate(0.4f) .ammo(ModItems.HEAVY_AMMO.get()) .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")), + }, + new VehicleWeapon[]{ + // 蜂群无人机 + new SwarmDroneWeapon() + .explosionDamage(125) + .explosionRadius(6) + .sound(ModSounds.INTO_MISSILE.get()), } }; } @@ -168,6 +170,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti compound.putInt("LoadedAmmoType", this.entityData.get(LOADED_AMMO_TYPE)); compound.putInt("WeaponType", getWeaponIndex(0)); compound.putInt("PassengerWeaponType", getWeaponIndex(1)); + compound.putInt("ThirdPassengerWeaponType", getWeaponIndex(2)); } @Override @@ -179,6 +182,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.entityData.set(LOADED_AMMO_TYPE, compound.getInt("LoadedAmmoType")); setWeaponIndex(0, compound.getInt("WeaponType")); setWeaponIndex(1, compound.getInt("PassengerWeaponType")); + setWeaponIndex(2, compound.getInt("ThirdPassengerWeaponType")); } @Override @@ -257,9 +261,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti if (this.level() instanceof ServerLevel) { boolean hasCreativeAmmo = false; - - if (this.getFirstPassenger() instanceof Player player) { - hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); + for (int i = 0; i < getMaxPassengers(); i++) { + if (getNthEntity(i) instanceof Player pPlayer && InventoryTool.hasCreativeAmmoBox(pPlayer)) { + hasCreativeAmmo = true; + } } if (reloadCoolDown > 0 && ( @@ -273,6 +278,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti droneReloadCoolDown--; } + if ((hasItem(ModItems.SWARM_DRONE.get()) || hasCreativeAmmo) && droneReloadCoolDown == 0 && this.getEntityData().get(LOADED_DRONE) < 14) { + this.entityData.set(LOADED_DRONE, this.getEntityData().get(LOADED_DRONE) + 1); + droneReloadCoolDown = 20; + if (!hasCreativeAmmo) { + this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SWARM_DRONE.get())).findFirst().ifPresent(stack -> stack.shrink(1)); + } + this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); + } + this.handleAmmo(); } @@ -325,9 +339,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } boolean hasCreativeAmmo = false; - - if (this.getFirstPassenger() instanceof Player player) { - hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); + for (int i = 0; i < getMaxPassengers(); i++) { + if (getNthEntity(i) instanceof Player pPlayer && InventoryTool.hasCreativeAmmoBox(pPlayer)) { + hasCreativeAmmo = true; + } } if (hasCreativeAmmo) { @@ -357,15 +372,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } } } - - if ((hasItem(ModItems.SWARM_DRONE.get()) || hasCreativeAmmo) && droneReloadCoolDown == 0 && this.getEntityData().get(LOADED_DRONE) < 14) { - this.entityData.set(LOADED_DRONE, this.getEntityData().get(LOADED_DRONE) + 1); - droneReloadCoolDown = 20; - if (!hasCreativeAmmo) { - this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SWARM_DRONE.get())).findFirst().ifPresent(stack -> stack.shrink(1)); - } - this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); - } } @Override @@ -514,89 +520,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti serverPlayer.playSound(ModSounds.M_2_VERYFAR.get(), 24, pitch); } } - } else if (getWeaponIndex(0) == 3) { - Matrix4f transformT = getTurretTransform(1); - Vector4f worldPosition = new Vector4f(); - - int ammo = this.getEntityData().get(LOADED_DRONE); - - if (ammo == 1) { - worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -0.25390625f); - } - if (ammo == 2) { - worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -0.25390625f); - } - if (ammo == 3) { - worldPosition = transformPosition(transformT, -2.49105625f, 0.71894375f, -0.4296875f); - } - if (ammo == 4) { - worldPosition = transformPosition(transformT, 2.49105625f, 0.71894375f, -0.4296875f); - } - if (ammo == 5) { - worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -0.60546875f); - } - if (ammo == 6) { - worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -0.60546875f); - } - if (ammo == 7) { - worldPosition = transformPosition(transformT, -2.49105625f, 0.71894375f, -0.78125f); - } - if (ammo == 8) { - worldPosition = transformPosition(transformT, 2.49105625f, 0.71894375f, -0.78125f); - } - if (ammo == 9) { - worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -0.95703125f); - } - if (ammo == 10) { - worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -0.95703125f); - } - if (ammo == 11) { - worldPosition = transformPosition(transformT, -2.49105625f, 0.71894375f, -1.1328125f); - } - if (ammo == 12) { - worldPosition = transformPosition(transformT, 2.49105625f, 0.71894375f, -1.1328125f); - } - if (ammo == 13) { - worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -1.30859375f); - } - if (ammo == 14) { - worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -1.30859375f); - } - - Vec3 lookVec = getBarrelVec(1).normalize(); - Entity lookingEntity = SeekTool.vehicleSeekEntity(this, level(), 512, 4); - - var swarmDroneEntity = ((SwarmDroneWeapon) getWeapon(0)).create(player); - - - Vector4f shootPosition1 = transformPosition(transformT, 0, 0, 0); - Vector4f shootPosition2 = transformPosition(transformT, 0, 1, 0); - Vec3 direct = new Vec3(shootPosition1.x, shootPosition1.y, shootPosition1.z).vectorTo(new Vec3(shootPosition2.x, shootPosition2.y, shootPosition2.z)); - - - swarmDroneEntity.setPos(worldPosition.x, worldPosition.y, worldPosition.z); - swarmDroneEntity.shoot(direct.x, direct.y, direct.z, 1.2f, 10); - - if (lookingEntity != null) { - swarmDroneEntity.setGuideType(0); - swarmDroneEntity.setTargetUuid(lookingEntity.getStringUUID()); - swarmDroneEntity.setTargetVec(lookingEntity.getEyePosition()); - } else { - swarmDroneEntity.setGuideType(1); - BlockHitResult result = level().clip(new ClipContext(getNewEyePos(1), getNewEyePos(1).add(lookVec.scale(512)), - ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); - Vec3 hitPos = result.getLocation(); - swarmDroneEntity.setTargetVec(hitPos); - } - - player.level().addFreshEntity(swarmDroneEntity); - - this.level().playSound(null, BlockPos.containing(new Vec3(worldPosition.x, worldPosition.y, worldPosition.z)), ModSounds.DECOY_FIRE.get(), SoundSource.PLAYERS, 1, random.nextFloat() * 0.05f + 1); - - this.entityData.set(LOADED_DRONE, this.getEntityData().get(LOADED_DRONE) - 1); - droneReloadCoolDown = 100; } - } if (type == 1) { @@ -608,7 +532,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti var projectileEntity = projectile.create(player).setGunItemId(this.getType().getDescriptionId() + ".2"); projectileEntity.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); - projectileEntity.shoot(getGunnerVector(1).x, getGunnerVector(1).y + 0.005f, getGunnerVector(1).z, 20, 0.3f); + projectileEntity.shoot(getGunnerVector(1).x, getGunnerVector(1).y + 0.01f, getGunnerVector(1).z, 20, 0.3f); this.level().addFreshEntity(projectileEntity); @@ -649,6 +573,90 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti consumeItem(getWeapon(1).ammo, 1); } } + + if (type == 2) { + Matrix4f transformT = getTurretTransform(1); + Vector4f worldPosition = new Vector4f(); + + int ammo = this.getEntityData().get(LOADED_DRONE); + + if (ammo == 1) { + worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -0.25390625f); + } + if (ammo == 2) { + worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -0.25390625f); + } + if (ammo == 3) { + worldPosition = transformPosition(transformT, -2.49105625f, 0.71894375f, -0.4296875f); + } + if (ammo == 4) { + worldPosition = transformPosition(transformT, 2.49105625f, 0.71894375f, -0.4296875f); + } + if (ammo == 5) { + worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -0.60546875f); + } + if (ammo == 6) { + worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -0.60546875f); + } + if (ammo == 7) { + worldPosition = transformPosition(transformT, -2.49105625f, 0.71894375f, -0.78125f); + } + if (ammo == 8) { + worldPosition = transformPosition(transformT, 2.49105625f, 0.71894375f, -0.78125f); + } + if (ammo == 9) { + worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -0.95703125f); + } + if (ammo == 10) { + worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -0.95703125f); + } + if (ammo == 11) { + worldPosition = transformPosition(transformT, -2.49105625f, 0.71894375f, -1.1328125f); + } + if (ammo == 12) { + worldPosition = transformPosition(transformT, 2.49105625f, 0.71894375f, -1.1328125f); + } + if (ammo == 13) { + worldPosition = transformPosition(transformT, -2.315275f, 0.71894375f, -1.30859375f); + } + if (ammo == 14) { + worldPosition = transformPosition(transformT, 2.315275f, 0.71894375f, -1.30859375f); + } + + Vec3 lookVec = player.getViewVector(1); + Entity lookingEntity = SeekTool.seekLivingEntity(player, level(), 384, 6); + + var swarmDroneEntity = ((SwarmDroneWeapon) getWeapon(2)).create(player); + + + Vector4f shootPosition1 = transformPosition(transformT, 0, 0, 0); + Vector4f shootPosition2 = transformPosition(transformT, 0, 1, 0); + Vec3 direct = new Vec3(shootPosition1.x, shootPosition1.y, shootPosition1.z).vectorTo(new Vec3(shootPosition2.x, shootPosition2.y, shootPosition2.z)); + + + swarmDroneEntity.setPos(worldPosition.x, worldPosition.y, worldPosition.z); + swarmDroneEntity.shoot(direct.x, direct.y, direct.z, 1.2f, 10); + + if (lookingEntity != null) { + swarmDroneEntity.setGuideType(0); + swarmDroneEntity.setTargetUuid(lookingEntity.getStringUUID()); + swarmDroneEntity.setTargetVec(lookingEntity.getEyePosition()); + } else { + swarmDroneEntity.setGuideType(1); + BlockHitResult result = level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(lookVec.scale(384)), + ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); + Vec3 hitPos = result.getLocation(); + swarmDroneEntity.setTargetVec(hitPos); + } + + player.level().addFreshEntity(swarmDroneEntity); + + this.level().playSound(null, BlockPos.containing(new Vec3(worldPosition.x, worldPosition.y, worldPosition.z)), ModSounds.DECOY_FIRE.get(), SoundSource.PLAYERS, 1, random.nextFloat() * 0.05f + 1); + + this.entityData.set(LOADED_DRONE, this.getEntityData().get(LOADED_DRONE) - 1); + droneReloadCoolDown = 100; + } + } @Override @@ -1028,14 +1036,17 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return 15; } else if (getWeaponIndex(0) == 2) { return 500; - } else if (getWeaponIndex(0) == 3) { - return 600; } } if (player == getNthEntity(1)) { return 500; } + + if (player == getNthEntity(2)) { + return 600; + } + return 15; } @@ -1048,14 +1059,16 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return this.entityData.get(LOADED_HE) > 0 && getEnergy() > VehicleConfig.YX_100_SHOOT_COST.get(); } else if (getWeaponIndex(0) == 2) { return (this.entityData.get(MG_AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFireCoax; - } else if (getWeaponIndex(0) == 3) { - return this.entityData.get(LOADED_DRONE) > 0; } } if (player == getNthEntity(1)) { return (this.entityData.get(MG_AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; } + + if (player == getNthEntity(2)) { + return this.entityData.get(LOADED_DRONE) > 0; + } return false; } @@ -1068,20 +1081,25 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return this.entityData.get(LOADED_HE); } else if (getWeaponIndex(0) == 2) { return this.entityData.get(MG_AMMO); - } else if (getWeaponIndex(0) == 3) { - return this.entityData.get(LOADED_DRONE); } } if (player == getNthEntity(1)) { return this.entityData.get(MG_AMMO); } + + if (player == getNthEntity(2)) { + return this.entityData.get(LOADED_DRONE); + } return 0; } @Override public boolean banHand(Player player) { - return hidePassenger(player); + if (player == getNthEntity(0) || player == getNthEntity(1)) { + return true; + } + return player == getNthEntity(2) && !player.isShiftKeyDown(); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index a9f9b984f..597355cbc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -242,8 +242,8 @@ public class ClientEventHandler { // 正在游戏内控制载具或无人机 if (!notInGame() && (player.getVehicle() instanceof MobileVehicleEntity mobileVehicle - && mobileVehicle.getFirstPassenger() == player - || stack.is(ModItems.MONITOR.get()) + && mobileVehicle.getFirstPassenger() == player) + || (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked")) ) { @@ -796,7 +796,7 @@ public class ClientEventHandler { float pitch = yx100.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(HEAT))); player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else { + } else if (type == 0) { if (yx100.getWeaponIndex(0) == 0 || yx100.getWeaponIndex(0) == 1) { player.playSound(ModSounds.YX_100_FIRE_1P.get(), 1f, 1); } else if (yx100.getWeaponIndex(0) == 2) { @@ -1380,8 +1380,9 @@ public class ClientEventHandler { ItemStack stack = player.getMainHandItem(); final var tag = NBTTool.getTag(stack); - if (player.getVehicle() instanceof WeaponVehicleEntity iVehicle && zoomVehicle) { + if (player.getVehicle() instanceof WeaponVehicleEntity iVehicle && zoomVehicle && iVehicle.banHand(player)) { event.setFOV(event.getFOV() / iVehicle.zoomFov()); + fov = event.getFOV(); return; } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/VehicleMovementMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/VehicleMovementMessage.java index 337c34b07..fe580a593 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/VehicleMovementMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/VehicleMovementMessage.java @@ -32,8 +32,7 @@ public record VehicleMovementMessage(short keys) implements CustomPacketPayload final var tag = NBTTool.getTag(stack); VehicleEntity vehicle = null; - if (entity instanceof MobileVehicleEntity mobileVehicleEntity) { - if (mobileVehicleEntity.getFirstPassenger() != player) return; + if (entity instanceof MobileVehicleEntity mobileVehicleEntity && mobileVehicleEntity.getFirstPassenger() == player) { vehicle = mobileVehicleEntity; } else if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java index 5c3e8ffed..8b8a9844a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java @@ -44,7 +44,10 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload { && vehicle instanceof WeaponVehicleEntity weaponEntity && vehicle instanceof VehicleEntity vehicleEntity && weaponEntity.hasWeapon(vehicleEntity.getSeatIndex(player)) - ) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1); + && weaponEntity.banHand(player) + ) { + SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1); + } } else if (message.msgType == 1) { cap.zoom = false; @@ -56,8 +59,10 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload { && vehicle instanceof WeaponVehicleEntity weaponEntity && vehicle instanceof VehicleEntity vehicleEntity && weaponEntity.hasWeapon(vehicleEntity.getSeatIndex(player)) - ) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1); - + && weaponEntity.banHand(player) + ) { + SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1); + } if (player.getMainHandItem().getItem() == ModItems.JAVELIN.get()) { var handItem = player.getMainHandItem();