674073671e6c

Minor cleanup.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 31 Aug 2011 18:50:37 -0400
parents 19fc4b6444f5
children 336987d72de4
branches/tags (none)
files src/clojurecraft/in.clj src/examples/givebot.clj

Changes

--- a/src/clojurecraft/in.clj	Wed Aug 31 18:50:12 2011 -0400
+++ b/src/clojurecraft/in.clj	Wed Aug 31 18:50:37 2011 -0400
@@ -437,7 +437,7 @@
 
 (defn- -chunk-from-full-data [postdata]
   (let [decompressed-data (-decompress-mapchunk postdata)
-        [types meta light sky] (-decode-mapchunk postdata decompressed-data)] ; Note: These are all byte-array's!
+        [types meta light sky] (-decode-mapchunk postdata decompressed-data)] ; These are all byte-array's!
     (Chunk. types meta light sky)))
 
 (defn- -chunk-from-partial-data [{{chunks :chunks} :world} postdata]
@@ -445,7 +445,7 @@
         y (:y postdata)
         z (:z postdata)
         decompressed-data (-decompress-mapchunk postdata)
-        [types meta light sky] (-decode-mapchunk postdata decompressed-data)  ; Note: These are all byte-array's!
+        [types meta light sky] (-decode-mapchunk postdata decompressed-data)  ; These are all byte-array's!
         chunk-coords (coords-of-chunk-containing x z)
         chunk (force (-get-or-make-chunk chunks chunk-coords))
         start-index (block-index-in-chunk x y z)]
@@ -458,12 +458,12 @@
   (time (let [predata (-read-mapchunk-predata conn)
               postdata (assoc predata :raw-data (-read-bytearray-bare conn (:compressedsize predata)))
               chunk-size (* (:sizex postdata) (:sizey postdata) (:sizez postdata))
-              is-full-chunk (= FULL-CHUNK chunk-size)
               chunk-coords (coords-of-chunk-containing (:x postdata) (:z postdata))]
           (dosync (alter (:chunks (:world bot))
-                         assoc chunk-coords (if is-full-chunk
+                         assoc chunk-coords (if (= FULL-CHUNK chunk-size)
                                               (ref (delay (-chunk-from-full-data postdata)))
-                                              (ref (-chunk-from-partial-data bot postdata))))))))
+                                              (ref (-chunk-from-partial-data bot postdata)))))
+          predata)))
 
 
 
--- a/src/examples/givebot.clj	Wed Aug 31 18:50:12 2011 -0400
+++ b/src/examples/givebot.clj	Wed Aug 31 18:50:37 2011 -0400
@@ -37,7 +37,8 @@
 (defn- give-string [username item number]
   (str "/give " username " " item " " number))
 
-(defn- handle-chat [bot message]
+
+(defn handle-chat [bot message]
   (let [matches (re-find WANT-RE (s/lower-case message))]
     (when matches
       (let [item (item-map (get-item matches))
@@ -52,6 +53,7 @@
 
 (defn make-givebot [server username]
   (let [bot (core/connect server username)]
+    (events/add-handler bot :chat #'handle-chat)
     (events/add-handler bot :dead #'handle-dead)
     bot))