c559409
Branches > main > c559409 > files
Use tagged identifiers for tags instead of strings
Commit: c559409ae4e8a4123de59d17d06500fd8866a4c5
Parent: b1b0aa7
3 changed files:
src/net/bowmap/server/packet/identifier.clj view file
@@ -61,7 +61,15 @@ {:namespace namespace :name name}))))) (defn tag- "Returns the string tag of an identifier, which is the encoded identifier- preceded by a '#'."+ "Returns a tag reference to the identifier." [identifier]- (apply str "#" (encode-identifier identifier)))+ (tagged-literal `tag identifier))++(defn tag? [x]+ (and (tagged-literal? x)+ (= `tag (:tag x))))++(defn encode-tag+ "Encodes a tag reference as a string: the encoded identifier preceded by '#'."+ [{:keys! [form]}]+ (str "#" (encode-identifier form)))src/net/bowmap/server/packet/nbt.clj view file
@@ -3,7 +3,7 @@ See https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/NBT" (:require [clojure.spec.alpha :as s]- [net.bowmap.server.packet.identifier :refer [identifier?]])+ [net.bowmap.server.packet.identifier :refer [identifier? tag?]]) (:refer-clojure :exclude [type])) (declare type)@@ -91,7 +91,8 @@ (s/def ::byte-array (s/coll-of ::byte)) (s/def ::string (s/or :string string? :keyword simple-keyword?- :identifier identifier?))+ :identifier identifier?+ :tag tag?)) (s/def ::list list-type) (s/def ::compound (s/map-of ::string ::nbt)) (s/def ::int-array (s/coll-of ::int))src/net/bowmap/server/packet/writers.clj view file
@@ -231,17 +231,20 @@ (bit-shift-left (bit-and z 0x3FFFFFF) 12) (bit-and y 0xFFF)))) +(defn- name* [x]+ (cond+ (identifier/identifier? x) (identifier/encode-identifier x)+ (identifier/tag? x) (identifier/encode-tag x)+ :else (name x)))+ (defn nbt-string> "Writes an NBT string to buf. May take a string, keyword, or packet identifier. Strings are prefixed by an unsigned short length, followed by up to 65,535 modified UTF-8 bytes." [buf s]- (let [s (if (identifier/identifier? s)- (identifier/encode-identifier s)- (name s))]- (doto buf- (-> (ByteBufOutputStream.)- (ByteBufOutputStream/.writeUTF s)))))+ (doto buf+ (-> (ByteBufOutputStream.)+ (ByteBufOutputStream/.writeUTF (name* s))))) (declare nbt-writer)