diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java index 687e2c01b..d90ae8bb0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java @@ -166,6 +166,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti return InteractionResult.sidedSuccess(this.level().isClientSide()); } } + entityData.set(TARGET_UUID, "none"); return super.interact(player, hand); } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/RadarSetTargetMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/RadarSetTargetMessage.java index 8fc6a2eaf..eaaf2d4fd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/RadarSetTargetMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/RadarSetTargetMessage.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.network.message.send; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.entity.vehicle.Hpj11Entity; import com.atsuishio.superbwarfare.entity.vehicle.LaserTowerEntity; import com.atsuishio.superbwarfare.menu.FuMO25Menu; import com.atsuishio.superbwarfare.tools.EntityFindUtil; @@ -9,6 +10,7 @@ import net.minecraft.core.UUIDUtil; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; import net.minecraft.world.inventory.AbstractContainerMenu; import net.neoforged.neoforge.network.handling.IPayloadContext; import org.jetbrains.annotations.NotNull; @@ -33,12 +35,18 @@ public record RadarSetTargetMessage(UUID target) implements CustomPacketPayload if (!player.containerMenu.stillValid(player)) { return; } - fuMO25Menu.getSelfPos().ifPresent(pos -> { - var entities = StreamSupport.stream(EntityFindUtil.getEntities(player.level()).getAll().spliterator(), false) - .filter(e -> e instanceof LaserTowerEntity towerEntity && towerEntity.getOwner() == player && towerEntity.distanceTo(player) <= 16) - .toList(); - entities.forEach(e -> e.getEntityData().set(LaserTowerEntity.TARGET_UUID, message.target.toString())); - }); + fuMO25Menu.getSelfPos().ifPresent(pos -> StreamSupport.stream(EntityFindUtil.getEntities(player.level()).getAll().spliterator(), false) + .filter(e -> (e instanceof LaserTowerEntity towerEntity && towerEntity.getOwner() == player && towerEntity.distanceTo(player) <= 16) + || (e instanceof Hpj11Entity hpj11Entity && hpj11Entity.getOwner() == player && hpj11Entity.distanceTo(player) <= 16)) + .forEach(e -> setTarget(e, message.target.toString()))); + } + } + + public static void setTarget(Entity e, String uuid) { + if (e instanceof LaserTowerEntity laserTower) { + laserTower.getEntityData().set(LaserTowerEntity.TARGET_UUID, uuid); + } else if (e instanceof Hpj11Entity hpj11Entity) { + hpj11Entity.getEntityData().set(Hpj11Entity.TARGET_UUID, uuid); } }