1ec79708efe2

Entity packets.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 22 Jul 2011 00:27:51 -0400
parents 32c0894fccce
children cc57efc2896f
branches/tags (none)
files src/clojurecraft/core.clj src/clojurecraft/in.clj

Changes

--- a/src/clojurecraft/core.clj	Fri Jul 22 00:11:47 2011 -0400
+++ b/src/clojurecraft/core.clj	Fri Jul 22 00:27:51 2011 -0400
@@ -120,11 +120,12 @@
 ; Scratch --------------------------------------------------------------------------
 (def minecraft-local {:name "localhost" :port 25565})
 
-(def bot (connect minecraft-local nil))
+;(def bot (connect minecraft-local nil))
 ;(act/move bot -2 0 0)
 ;(pprint @(:packet-counts-in bot))
 ;(pprint @(:packet-counts-out bot))
 ;(pprint (:player bot))
+;(pprint (:world bot))
 ;(println (:loc @(:player bot)))
 ;(disconnect bot)
 
--- a/src/clojurecraft/in.clj	Fri Jul 22 00:11:47 2011 -0400
+++ b/src/clojurecraft/in.clj	Fri Jul 22 00:27:51 2011 -0400
@@ -2,7 +2,7 @@
   (:use [clojurecraft.util])
   (:use [clojurecraft.mappings])
   (:require [clojurecraft.data])
-  (:import [clojurecraft.data Location])
+  (:import [clojurecraft.data Location Entity])
   (:import (java.util.zip Inflater)))
 
 ; Bytes ----------------------------------------------------------------------------
@@ -289,8 +289,15 @@
          :eid (-read-int conn)))
 
 (defn- read-packet-entity [bot conn]
-  (assoc {}
-         :eid (-read-int conn)))
+  (let [payload (assoc {}
+                       :eid (-read-int conn))]
+    (dosync
+      (let [eid (:eid payload)
+            entities (:entities (:world bot))
+            entity (@entities eid)]
+        (when-not entity
+          (alter entities assoc eid (Entity. eid nil false)))))
+    payload))
 
 (defn- read-packet-entityrelativemove [bot conn]
   (assoc {}