实现雷达制导功能
This commit is contained in:
parent
20a5ae050c
commit
6403491f59
3 changed files with 33 additions and 16 deletions
|
@ -287,7 +287,8 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
|||
@Override
|
||||
public void onPress() {
|
||||
if (FuMO25Screen.this.menu.getFuncType() == 3 && FuMO25Screen.this.menu.getSlot(0).getItem().isEmpty()) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new RadarSetTargetMessage((byte) 0));
|
||||
if (FuMO25Screen.this.currentTarget == null) return;
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new RadarSetTargetMessage(FuMO25Screen.this.currentTarget.getUUID()));
|
||||
} else {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new RadarSetParametersMessage((byte) 0));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.entity.vehicle;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
|
||||
|
@ -34,6 +35,7 @@ import net.minecraft.world.phys.HitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Math;
|
||||
import software.bernie.geckolib.animatable.GeoEntity;
|
||||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
||||
|
@ -127,11 +129,11 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
}
|
||||
}
|
||||
|
||||
public void setOwnerUUID(@javax.annotation.Nullable UUID pUuid) {
|
||||
public void setOwnerUUID(@Nullable UUID pUuid) {
|
||||
this.entityData.set(OWNER_UUID, Optional.ofNullable(pUuid));
|
||||
}
|
||||
|
||||
@javax.annotation.Nullable
|
||||
@Nullable
|
||||
public UUID getOwnerUUID() {
|
||||
return this.entityData.get(OWNER_UUID).orElse(null);
|
||||
}
|
||||
|
@ -206,7 +208,7 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
} else {
|
||||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0));
|
||||
}
|
||||
autoAim();
|
||||
this.autoAim();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -223,7 +225,6 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
|
||||
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
|
||||
setRot(getYRot(), getXRot());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -249,8 +250,9 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
}
|
||||
|
||||
public void autoAim() {
|
||||
if (this.getEnergy() <= 0 || !entityData.get(ACTIVE) || this.entityData.get(COOL_DOWN) > 30)
|
||||
if (this.getEnergy() <= 0 || !entityData.get(ACTIVE) || this.entityData.get(COOL_DOWN) > 30) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entityData.get(TARGET_UUID).equals("none") && tickCount % 10 == 0) {
|
||||
Entity naerestEntity = seekNearLivingEntity(72);
|
||||
|
@ -263,9 +265,14 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
|
||||
if (target != null) {
|
||||
if (target instanceof LivingEntity living && living.getHealth() <= 0) {
|
||||
entityData.set(TARGET_UUID, "none");
|
||||
this.entityData.set(TARGET_UUID, "none");
|
||||
return;
|
||||
}
|
||||
if (target == this || target instanceof TargetEntity) {
|
||||
this.entityData.set(TARGET_UUID, "none");
|
||||
return;
|
||||
}
|
||||
|
||||
Vec3 barrelRootPos = new Vec3(this.getX(), this.getY() + 1.390625f, this.getZ());
|
||||
Vec3 targetVec = barrelRootPos.vectorTo(target.getEyePosition()).normalize();
|
||||
|
||||
|
@ -285,7 +292,7 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
changeTargetTimer++;
|
||||
}
|
||||
|
||||
if (this.entityData.get(COOL_DOWN) == 0 && VectorTool.calculateAngle(getViewVector(1), targetVec) < 1 && NoClip(target)) {
|
||||
if (this.entityData.get(COOL_DOWN) == 0 && VectorTool.calculateAngle(getViewVector(1), targetVec) < 1 && checkNoClip(target)) {
|
||||
|
||||
this.entityData.set(COOL_DOWN, 40);
|
||||
|
||||
|
@ -323,13 +330,13 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
// TODO 自定义目标列表
|
||||
if (e.distanceTo(this) <= seekRange && ((e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0)
|
||||
)) {
|
||||
return NoClip(e);
|
||||
return checkNoClip(e);
|
||||
}
|
||||
return false;
|
||||
}).min(Comparator.comparingDouble(e -> e.distanceTo(this))).orElse(null);
|
||||
}
|
||||
|
||||
public boolean NoClip(Entity target) {
|
||||
public boolean checkNoClip(Entity target) {
|
||||
return level().clip(new ClipContext(this.getEyePosition(), target.getEyePosition(),
|
||||
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() != HitResult.Type.BLOCK;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
package com.atsuishio.superbwarfare.network.message;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.LaserTowerEntity;
|
||||
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class RadarSetTargetMessage {
|
||||
|
||||
private final byte mode;
|
||||
private final UUID targetUUID;
|
||||
|
||||
public RadarSetTargetMessage(byte mode) {
|
||||
this.mode = mode;
|
||||
public RadarSetTargetMessage(UUID targetUUID) {
|
||||
this.targetUUID = targetUUID;
|
||||
}
|
||||
|
||||
public static void encode(RadarSetTargetMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeByte(message.mode);
|
||||
buffer.writeUUID(message.targetUUID);
|
||||
}
|
||||
|
||||
public static RadarSetTargetMessage decode(FriendlyByteBuf buffer) {
|
||||
return new RadarSetTargetMessage(buffer.readByte());
|
||||
return new RadarSetTargetMessage(buffer.readUUID());
|
||||
}
|
||||
|
||||
public static void handler(RadarSetTargetMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
|
@ -34,7 +38,12 @@ public class RadarSetTargetMessage {
|
|||
if (!player.containerMenu.stillValid(player)) {
|
||||
return;
|
||||
}
|
||||
System.out.println(123);
|
||||
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.targetUUID.toString()));
|
||||
});
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue