无人机应用鼠标操控
This commit is contained in:
parent
cacc1ef879
commit
32d029ca65
6 changed files with 84 additions and 20 deletions
|
@ -87,7 +87,7 @@ public class DroneHudOverlay implements LayeredDraw.Layer {
|
||||||
boolean lookAtEntity = false;
|
boolean lookAtEntity = false;
|
||||||
double distance = player.distanceTo(entity);
|
double distance = player.distanceTo(entity);
|
||||||
|
|
||||||
BlockHitResult result = entity.level().clip(new ClipContext(cameraPos, cameraPos.add(player.getViewVector(1).scale(512)),
|
BlockHitResult result = entity.level().clip(new ClipContext(cameraPos, cameraPos.add(entity.getViewVector(1).scale(512)),
|
||||||
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity));
|
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity));
|
||||||
Vec3 hitPos = result.getLocation();
|
Vec3 hitPos = result.getLocation();
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class DroneHudOverlay implements LayeredDraw.Layer {
|
||||||
|
|
||||||
double entityRange = 0;
|
double entityRange = 0;
|
||||||
|
|
||||||
Entity lookingEntity = TraceTool.camerafFindLookingEntity(player, cameraPos, 512, deltaTracker.getRealtimeDeltaTicks());
|
Entity lookingEntity = TraceTool.droneFindLookingEntity(entity, cameraPos, 512, deltaTracker.getGameTimeDeltaPartialTick(true));
|
||||||
if (lookingEntity != null) {
|
if (lookingEntity != null) {
|
||||||
lookAtEntity = true;
|
lookAtEntity = true;
|
||||||
entityRange = entity.distanceTo(lookingEntity);
|
entityRange = entity.distanceTo(lookingEntity);
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.atsuishio.superbwarfare.client.overlay;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.tools.FormatTool;
|
import com.atsuishio.superbwarfare.tools.FormatTool;
|
||||||
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
import com.atsuishio.superbwarfare.tools.TraceTool;
|
import com.atsuishio.superbwarfare.tools.TraceTool;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
|
@ -14,6 +16,7 @@ import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
@ -37,6 +40,10 @@ public class VehicleTeamOverlay implements LayeredDraw.Layer {
|
||||||
PoseStack poseStack = guiGraphics.pose();
|
PoseStack poseStack = guiGraphics.pose();
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
var tag = NBTTool.getTag(stack);
|
||||||
|
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked")) return;
|
||||||
|
|
||||||
boolean lookAtEntity = false;
|
boolean lookAtEntity = false;
|
||||||
|
|
||||||
double entityRange = 0;
|
double entityRange = 0;
|
||||||
|
|
|
@ -107,6 +107,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
public boolean playHitSoundOnHurt() {
|
public boolean playHitSoundOnHurt() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData(SynchedEntityData.Builder builder) {
|
protected void defineSynchedData(SynchedEntityData.Builder builder) {
|
||||||
super.defineSynchedData(builder);
|
super.defineSynchedData(builder);
|
||||||
|
@ -175,15 +176,12 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||||
|
|
||||||
|
|
||||||
if (!this.onGround()) {
|
if (!this.onGround()) {
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
ItemStack stack = controller.getMainHandItem();
|
ItemStack stack = controller.getMainHandItem();
|
||||||
var tag = NBTTool.getTag(stack);
|
var tag = NBTTool.getTag(stack);
|
||||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using")) {
|
if (!stack.is(ModItems.MONITOR.get()) || !tag.getBoolean("Using")) {
|
||||||
// if (controller.level().isClientSide) {
|
|
||||||
// controller.playSound(ModSounds.DRONE_SOUND.get(), 114, 1);
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
upInputDown = false;
|
upInputDown = false;
|
||||||
downInputDown = false;
|
downInputDown = false;
|
||||||
forwardInputDown = false;
|
forwardInputDown = false;
|
||||||
|
@ -363,8 +361,6 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void travel() {
|
public void travel() {
|
||||||
float diffX;
|
|
||||||
float diffY;
|
|
||||||
if (!this.onGround()) {
|
if (!this.onGround()) {
|
||||||
// left and right
|
// left and right
|
||||||
if (rightInputDown) {
|
if (rightInputDown) {
|
||||||
|
@ -406,7 +402,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
if (up) {
|
if (up) {
|
||||||
holdTickY++;
|
holdTickY++;
|
||||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.02f * Math.min(holdTickY, 5), 0.4f));
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.01f * Math.min(holdTickY, 5), 0.2f));
|
||||||
} else if (down) {
|
} else if (down) {
|
||||||
holdTickY++;
|
holdTickY++;
|
||||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.02f * Math.min(holdTickY, 5), this.onGround() ? 0 : 0.01f));
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.02f * Math.min(holdTickY, 5), this.onGround() ? 0 : 0.01f));
|
||||||
|
@ -418,7 +414,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
if (this.getDeltaMovement().y() < 0) {
|
if (this.getDeltaMovement().y() < 0) {
|
||||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.01f, 0.4f));
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.01f, 0.4f));
|
||||||
} else {
|
} else {
|
||||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.01f, 0f));
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.01f, this.onGround() ? 0 : 0.01f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,11 +436,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
ItemStack stack = controller.getMainHandItem();
|
ItemStack stack = controller.getMainHandItem();
|
||||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using")) {
|
var tag = NBTTool.getTag(stack);
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(controller.getYHeadRot() - this.getYRot()));
|
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using")) {
|
||||||
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(controller.getXRot() - this.getXRot()));
|
this.setYRot(this.getYRot() + 0.5f * entityData.get(MOUSE_SPEED_X));
|
||||||
this.setYRot(this.getYRot() + 0.5f * diffY);
|
this.setXRot(Mth.clamp(this.getXRot() + 0.5f * entityData.get(MOUSE_SPEED_Y), -10, 90));
|
||||||
this.setXRot(Mth.clamp(this.getXRot() + 0.5f * diffX, -10, 90));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,6 +485,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean engineRunning() {
|
||||||
|
return !onGround();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SoundEvent getEngineSound() {
|
public SoundEvent getEngineSound() {
|
||||||
return ModSounds.DRONE_SOUND.get();
|
return ModSounds.DRONE_SOUND.get();
|
||||||
|
@ -497,7 +497,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEngineSoundVolume() {
|
public float getEngineSoundVolume() {
|
||||||
return onGround() ? 0 : 0.1f;
|
return entityData.get(POWER) * 2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,12 +3,14 @@ package com.atsuishio.superbwarfare.event;
|
||||||
import com.atsuishio.superbwarfare.client.MouseMovementHandler;
|
import com.atsuishio.superbwarfare.client.MouseMovementHandler;
|
||||||
import com.atsuishio.superbwarfare.config.client.VehicleControlConfig;
|
import com.atsuishio.superbwarfare.config.client.VehicleControlConfig;
|
||||||
import com.atsuishio.superbwarfare.data.gun.GunData;
|
import com.atsuishio.superbwarfare.data.gun.GunData;
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.AirEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.AirEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.atsuishio.superbwarfare.init.ModMobEffects;
|
import com.atsuishio.superbwarfare.init.ModMobEffects;
|
||||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||||
import com.atsuishio.superbwarfare.network.message.send.MouseMoveMessage;
|
import com.atsuishio.superbwarfare.network.message.send.MouseMoveMessage;
|
||||||
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
import net.minecraft.client.CameraType;
|
import net.minecraft.client.CameraType;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -25,7 +27,6 @@ import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||||
import net.neoforged.neoforge.client.event.ViewportEvent;
|
import net.neoforged.neoforge.client.event.ViewportEvent;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
|
||||||
import static com.atsuishio.superbwarfare.event.ClientEventHandler.droneFovLerp;
|
|
||||||
import static com.atsuishio.superbwarfare.event.ClientEventHandler.isFreeCam;
|
import static com.atsuishio.superbwarfare.event.ClientEventHandler.isFreeCam;
|
||||||
|
|
||||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
|
||||||
|
@ -59,7 +60,24 @@ public class ClientMouseHandler {
|
||||||
posO = posN;
|
posO = posN;
|
||||||
posN = MouseMovementHandler.getMousePos();
|
posN = MouseMovementHandler.getMousePos();
|
||||||
|
|
||||||
if (!notInGame() && player.getVehicle() instanceof VehicleEntity vehicle) {
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
var tag = NBTTool.getTag(stack);
|
||||||
|
|
||||||
|
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked")) {
|
||||||
|
DroneEntity drone = EntityFindUtil.findDrone(player.level(), tag.getString("LinkedDrone"));
|
||||||
|
if (drone != null) {
|
||||||
|
speedX = drone.getMouseSensitivity() * (posN.x - posO.x);
|
||||||
|
speedY = drone.getMouseSensitivity() * (posN.y - posO.y);
|
||||||
|
|
||||||
|
lerpSpeedX = Mth.lerp(drone.getMouseSpeedX(), lerpSpeedX, speedX);
|
||||||
|
lerpSpeedY = Mth.lerp(drone.getMouseSpeedY(), lerpSpeedY, speedY);
|
||||||
|
|
||||||
|
PacketDistributor.sendToServer(new MouseMoveMessage(lerpSpeedX, lerpSpeedY));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!notInGame() && player.getVehicle() instanceof VehicleEntity vehicle && player == vehicle.getFirstPassenger()) {
|
||||||
speedX = vehicle.getMouseSensitivity() * (posN.x - posO.x);
|
speedX = vehicle.getMouseSensitivity() * (posN.x - posO.x);
|
||||||
speedY = vehicle.getMouseSensitivity() * (posN.y - posO.y);
|
speedY = vehicle.getMouseSensitivity() * (posN.y - posO.y);
|
||||||
|
|
||||||
|
@ -164,7 +182,7 @@ public class ClientMouseHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using") && NBTTool.getTag(stack).getBoolean("Linked")) {
|
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using") && NBTTool.getTag(stack).getBoolean("Linked")) {
|
||||||
return 0.33 / (1 + 0.08 * (droneFovLerp - 1));
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFreeCam(player)) {
|
if (isFreeCam(player)) {
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package com.atsuishio.superbwarfare.network.message.send;
|
package com.atsuishio.superbwarfare.network.message.send;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
|
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.network.codec.ByteBufCodecs;
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -27,6 +32,16 @@ public record MouseMoveMessage(double speedX, double speedY) implements CustomPa
|
||||||
if (entity instanceof VehicleEntity vehicle) {
|
if (entity instanceof VehicleEntity vehicle) {
|
||||||
vehicle.mouseInput(message.speedX, message.speedY);
|
vehicle.mouseInput(message.speedX, message.speedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
var tag = NBTTool.getTag(stack);
|
||||||
|
|
||||||
|
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked")) {
|
||||||
|
DroneEntity drone = EntityFindUtil.findDrone(player.level(), tag.getString("LinkedDrone"));
|
||||||
|
if (drone != null) {
|
||||||
|
drone.mouseInput(message.speedX, message.speedY);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -120,6 +120,30 @@ public class TraceTool {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Entity droneFindLookingEntity(Entity entity, Vec3 pos, double entityReach, float ticks) {
|
||||||
|
double distance = entityReach * entityReach;
|
||||||
|
HitResult hitResult = entity.pick(entityReach, 1.0f, false);
|
||||||
|
|
||||||
|
Vec3 viewVec = entity.getViewVector(ticks);
|
||||||
|
Vec3 toVec = pos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach);
|
||||||
|
AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D);
|
||||||
|
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(entity, pos, toVec, aabb, p -> !p.isSpectator()
|
||||||
|
&& p.isAlive()
|
||||||
|
&& !(p instanceof Projectile)
|
||||||
|
&& SeekTool.baseFilter(p)
|
||||||
|
&& !(p instanceof DecoyEntity) && smokeFilter(p)
|
||||||
|
&& p != entity
|
||||||
|
&& p != entity.getVehicle(), distance);
|
||||||
|
if (entityhitresult != null) {
|
||||||
|
hitResult = entityhitresult;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (hitResult.getType() == HitResult.Type.ENTITY) {
|
||||||
|
return ((EntityHitResult) hitResult).getEntity();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Entity camerafFindLookingEntity(Player player, Vec3 pos, double entityReach, float ticks) {
|
public static Entity camerafFindLookingEntity(Player player, Vec3 pos, double entityReach, float ticks) {
|
||||||
double distance = entityReach * entityReach;
|
double distance = entityReach * entityReach;
|
||||||
HitResult hitResult = player.pick(entityReach, 1.0f, false);
|
HitResult hitResult = player.pick(entityReach, 1.0f, false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue