Choose cursor aim with /aero controls instead of a keybind
/aero controls keyboard|cursor_aim is open to every player, stored per player and synced to the client, which switches on automatically when seated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVREx3uo7nz1FEhzveWTUh
This commit is contained in:
10 files changed
+133
-20
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package dev.lumareth.improvedAerodynamics.flight;
|
||||
|
||||
import dev.lumareth.improvedAerodynamics.network.ControlModePacket;
|
||||
import dev.lumareth.improvedAerodynamics.network.Network;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
/**
|
||||
* How a player flies: with the keyboard (Warium's own seat controls) or with cursor aim. Chosen per player with
|
||||
* {@code /aero controls}, kept in the player's persistent data and told to their client, which does the rest.
|
||||
*/
|
||||
public final class ControlMode {
|
||||
private static final String KEY = "improved_aerodynamics_cursor_aim";
|
||||
|
||||
private ControlMode() {
|
||||
}
|
||||
|
||||
public static boolean isCursorAim(ServerPlayer player) {
|
||||
CompoundTag persisted = player.getPersistentData().getCompound(Player.PERSISTED_NBT_TAG);
|
||||
return persisted.getBoolean(KEY);
|
||||
}
|
||||
|
||||
public static void set(ServerPlayer player, boolean cursorAim) {
|
||||
CompoundTag data = player.getPersistentData();
|
||||
CompoundTag persisted = data.getCompound(Player.PERSISTED_NBT_TAG);
|
||||
persisted.putBoolean(KEY, cursorAim);
|
||||
data.put(Player.PERSISTED_NBT_TAG, persisted);
|
||||
sync(player);
|
||||
}
|
||||
|
||||
public static void sync(ServerPlayer player) {
|
||||
Network.CHANNEL.send(PacketDistributor.PLAYER.with(() -> player), new ControlModePacket(isCursorAim(player)));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLogin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (event.getEntity() instanceof ServerPlayer player) {
|
||||
sync(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public final class CursorAimServer {
|
||||
}
|
||||
long nodeKey = basis.nodePos().asLong();
|
||||
double length = Math.sqrt(cf * cf + cr * cr + cu * cu);
|
||||
if (!active || !CursorAimConfig.ENABLED.get() || !(length > 1.0E-6) || !Double.isFinite(length)) {
|
||||
if (!active || !ControlMode.isCursorAim(player) || !CursorAimConfig.ENABLED.get() || !(length > 1.0E-6) || !Double.isFinite(length)) {
|
||||
CursorAimRegistry.clear(nodeKey);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user