9fe9231
Branches > refactor/use-spec-1 > 9fe9231 > files
Add some new shit yeah
Commit: 9fe9231ff22e44316e62989b2c5b0c9badc0812c
Parent: 5cf4061
6 changed files:
src/dev/grahp/error.clj view file
@@ -87,13 +87,13 @@ k# ~k] (if (contains? m# k#) (get m# k#)- (raise ~msg {:map m# :key k#}))))+ (raise ~msg {:form '~&form :map m# :key k#})))) ([m k msg data-map] `(let [m# ~m k# ~k] (if (contains? m# k#) (get m# k#)- (raise ~msg (merge {:map m# :key k#} ~data-map))))))+ (raise ~msg (merge {:form '~&form :map m# :key k#} ~data-map)))))) (defmacro defn! {:clj-kondo/lint-as 'clojure.core/defn}src/net/bowmap/minecraft_server.clj view file
@@ -31,6 +31,7 @@ (defn handle-process! [process client messages-out process-chan] (run-effects! messages-out process-chan (a/apply-process process client))) +; TODO I don't really like all these channels... (defn handle-packets-and-messages! [client packets-in messages-out packets-out process-chan] (alt!! process-chan ([process]src/net/bowmap/network/message/client.clj view file
@@ -223,16 +223,16 @@ ::pong-response [:timestamp "The same timestamp as serverbound ::ping-request" long->] ::login-success [:uuid uuid-> :username string->- :properties (list-> (table-> [:name string->- :value string->- :signature (optional-> string->)]))]- ::known-packs [:known-packs (list-> (table-> [:namespace string->- :id string->- :version string->]))]+ :properties (list-> [:name string->+ :value string->+ :signature (optional-> string->)])]+ ::known-packs [:known-packs (list-> [:namespace string->+ :id string->+ :version string->])] ::registry-data [::reg/id identifier->- ::reg/entries (list-> (table-> [::reg/entry-id identifier->- ::reg/entry-data (optional-> nbt->)]))]+ ::reg/entries (list-> [::reg/entry-id identifier->+ ::reg/entry-data (optional-> nbt->)])] ::keep-alive [:id long->] ::finish-config [] ::login [:entity-id int->src/net/bowmap/network/message/server.clj view file
@@ -6,8 +6,9 @@ [net.bowmap.network.message :as msg] [net.bowmap.network.packet :as pk] [net.bowmap.network.packet.read :refer [->bit-mask ->byte ->double ->enum- ->float ->long ->short ->string- ->table ->ubyte ->uuid ->varint]]+ ->float ->long ->position ->short+ ->string ->table ->ubyte ->uuid+ ->varint]] [net.bowmap.network.state :as state]) (:import [io.netty.buffer ByteBuf]))@@ -157,6 +158,23 @@ :z ->double :flags ->byte] ::set-player-movement-flags [:flags (->bit-mask ->byte [:on-ground :pushing-against-wall])]+ ::player-action [:status (->enum ->varint {0 :started-digging+ 1 :canceled-digging+ 2 :finished-digging+ 3 :drop-item-stack+ 4 :drop-item+ 5 :update-item-state+ 6 :swap-item-in-hand})+ ; TODO aren't positions and locations different things?+ :location ->position+ ; TODO block face might be something logical+ :face (->enum ->byte {0 :bottom+ 1 :top+ 2 :north+ 3 :south+ 4 :west+ 5 :east})+ :sequence ->varint] ::player-command [:entity-id ->varint :action-id (->enum ->varint {0 :leave-bed 1 :start-sprintingsrc/net/bowmap/network/packet/read.clj view file
@@ -88,3 +88,10 @@ (let [mask (t/mapize-vector-or-something mask)] (fn [buf] (read-bit-mask! buf reader mask))))++(defn ->position [buf]+ (let [v (ByteBuf/.readLong buf)+ x (bit-shift-right v 38)+ y (bit-shift-right (bit-shift-left v 52) 52)+ z (bit-shift-right (bit-shift-left v 26) 38)]+ {:x x :y y :z z}))src/net/bowmap/network/packet/write.clj view file
@@ -44,18 +44,6 @@ (defn json-> [buf s] (string-> buf (json/write-str s))) -(defn array-> [writer]- (fn [buf xs]- (reduce (fn [acc x]- (writer acc x))- buf xs)))--(defn list-> [writer]- (let [writer (array-> writer)]- (fn [buf xs]- (-> (varint-> buf (count xs))- (writer xs)))))- (defn uuid-> [buf uuid] (-> buf (ByteBuf/.writeLong (UUID/.getMostSignificantBits uuid))@@ -80,6 +68,33 @@ (writer buf x) buf))) +; Want to conform the given map to the table, and error if any non-optional keys are missing?+(defn table-> [t]+ (let [table (S/ensure-conform ::t/table t)]+ (fn [buf m]+ (write-table! buf table m))))++(defn coerce+ "If writer is an actual writer, returns it. If writer is a vector, turnes it into a table writer."+ [writer]+ (if (vector? writer)+ (table-> writer)+ writer))++; Only coerces these for now idk+(defn array-> [writer]+ (let [writer (coerce writer)]+ (fn [buf xs]+ (reduce (fn [acc x]+ (writer acc x))+ buf xs))))++(defn list-> [writer]+ (let [writer (array-> writer)]+ (fn [buf xs]+ (-> (varint-> buf (count xs))+ (writer xs)))))+ ;;; NBT (defn write-modified-utf8! [buf s]@@ -228,12 +243,6 @@ (boolean-> buf x) (writer buf x)))) -; Want to conform the given map to the table, and error if any non-optional keys are missing?-(defn table-> [t]- (let [table (S/ensure-conform ::t/table t)]- (fn [buf m]- (write-table! buf table m))))- ; Chunks ; TODO eventually encode pallates and the different values