c97d3bd

Branches > facts > c97d3bd > files / src / net / bowmap / transport

Keep track of player movement

Grahp, 2026-08-22

Commit: c97d3bd3d93f92c7e33ecc11bb4abcef1a716ecd
Parent: 1abc195

3 changed files:

src/net/bowmap/protocol/handle.clj modified (view file)

@@ -166,28 +166,23 @@                          :flags #{}}))      :keep-alive? true})) -(defn handle-player-update-movement-packet [client {:keys [x feet-y z yaw pitch flags]}]-  {:facts [{::fact/id ::fact/updated-player-movement-            ; TODO need the player here!-            ; It's never actually kept track of, I guess because you want to use the UUID-            ::player/uuid (req! client ::player/uuid)-            ::position/x x-            ::position/y feet-y-            ::position/z z-            ::position/yaw yaw-            ::position/pitch pitch-            ; may be ::entity/ characteristics, idk-            :pushing-against-wall? (:pushing-against-wall flags)-            :on-ground? (:on-ground flags)}]})+(defn handle-player-update-movement-packet [{::player/keys! [uuid]}+                                            {:keys [& ::position/x ::position/y ::position/z ::position/yaw ::position/pitch]+                                             :as packet+                                             :select movement}]+  {:facts [(merge {::fact/id ::fact/updated-player-movement+                   ::player/uuid uuid}+                  ; may be ::entity/ characteristics, idk+                  movement (zipmap (:flags packet) (repeat true)))]}) -(defmethod handle-packet ::set-player-rotation [client pk]+(defmethod handle-packet ::serverbound/set-player-rotation [client pk]   (handle-player-update-movement-packet client pk)) -(defmethod handle-packet ::set-player-position-and-rotation [client pk]+(defmethod handle-packet ::serverbound/set-player-position-and-rotation [client pk]   (handle-player-update-movement-packet client pk)) -(defmethod handle-packet ::set-player-position [client pk]+(defmethod handle-packet ::serverbound/set-player-position [client pk]   (handle-player-update-movement-packet client pk)) -(defmethod handle-packet ::set-player-movement-flags [client pk]+(defmethod handle-packet ::serverbound/set-player-movement-flags [client pk]   (handle-player-update-movement-packet client pk))

src/net/bowmap/protocol/packet/serverbound.clj modified (view file)

@@ -3,9 +3,10 @@    [net.bowmap.protocol.packet :as pk]    [net.bowmap.protocol.packet.readers     :refer [->bit-mask ->boolean ->byte ->double ->enum ->float ->identifier-            ->int ->list ->long ->optional ->location ->short ->string ->ubyte+            ->int ->list ->location ->long ->optional ->short ->string ->ubyte             ->uuid ->varint coerce]]-   [net.bowmap.protocol.state :as state]))+   [net.bowmap.protocol.state :as state]+   [net.bowmap.server.position :as position]))  (def packet-order   "Map of connection states to vectors of serverbound packet ids in the order the appear in the protocol."@@ -175,18 +176,18 @@    ::keep-alive [:id ->long]    #_::lock-difficulty -   ::set-player-rotation [:yaw ->float-                          :pitch ->float+   ::set-player-rotation [::position/yaw ->float+                          ::position/pitch ->float                           :flags (->bit-mask ->byte [:on-ground :pushing-against-wall])]-   ::set-player-position-and-rotation [:x ->double-                                       :feet-y ->double-                                       :z ->double-                                       :yaw ->float-                                       :pitch ->float+   ::set-player-position-and-rotation [::position/x ->double+                                       ::position/y ->double+                                       ::position/z ->double+                                       ::position/yaw ->float+                                       ::position/pitch ->float                                        :flags (->bit-mask ->byte [:on-ground :pushing-against-wall])]-   ::set-player-position [:x ->double-                          :feet-y ->double-                          :z ->double+   ::set-player-position [::position/x ->double+                          ::position/y ->double+                          ::position/z ->double                           :flags (->bit-mask ->byte [:on-ground :pushing-against-wall])]     ::set-player-movement-flags [:flags (->bit-mask ->byte [:on-ground :pushing-against-wall])]

src/net/bowmap/server/logic.clj modified (view file)

@@ -1,10 +1,12 @@ (ns net.bowmap.server.logic   (:require-    [net.bowmap.server.player :as player]-    [net.bowmap.server.server :as server]-    [net.bowmap.stormbow.fact :as fact]-    [net.bowmap.stormbow.effect :as effect]))+   [net.bowmap.server.player :as player]+   [net.bowmap.server.position :as position]+   [net.bowmap.server.server :as server]+   [net.bowmap.stormbow.effect :as effect]+   [net.bowmap.stormbow.fact :as fact])) +; TODO should also be able to return new facts :) (defmulti handle-fact   "Returns a sequence of effects from a fact."   (fn [fact]@@ -33,3 +35,12 @@   (dosync     (commute server/players dissoc uuid)     []))++(defmethod handle-fact ::fact/updated-player-movement [{:keys! [::player/uuid] :as fact}]+  (dosync+    (let [player (req! @server/players uuid)]+      (alter player merge (select-keys fact [::position/x ::position/y ::position/z ::position/yaw ::position/pitch])))+    []))++; Called when the player actually moves, not just when a position is sent+(defmethod handle-fact ::fact/player-moved [_ _])