--- a/src/clojurecraft/actions.clj Tue Jul 05 19:22:59 2011 -0400
+++ b/src/clojurecraft/actions.clj Tue Jul 05 20:57:11 2011 -0400
@@ -1,3 +1,15 @@
(ns clojurecraft.actions
- (:use [clojurecraft.util])
- )
+ (:use [clojurecraft.util]))
+
+
+(defn move [bot x-change y-change z-change]
+ (let [player (:player bot)]
+ (dosync
+ (let [location (:location @player)
+ new-location (merge location
+ {:x (+ x-change (:x location))
+ :y (+ y-change (:y location))
+ :z (+ z-change (:z location))})]
+ (alter player merge {:location new-location}))))
+ bot)
+
--- a/src/clojurecraft/core.clj Tue Jul 05 19:22:59 2011 -0400
+++ b/src/clojurecraft/core.clj Tue Jul 05 20:57:11 2011 -0400
@@ -4,6 +4,7 @@
(:use [clojurecraft.out])
(:use [clojurecraft.util])
(:use [clojure.contrib.pprint :only (pprint)])
+ (:require [clojurecraft.actions :as act])
(:import (java.net Socket)
(java.io DataOutputStream DataInputStream)
(java.util.concurrent LinkedBlockingQueue)))
@@ -39,8 +40,7 @@
outqueue (:outqueue bot)]
(while (nil? (:exit @conn))
(let [location (:location @(:player bot))]
- (when (not (nil? location))
- (.put outqueue [:playerpositionlook location]))
+ (.put outqueue [:playerpositionlook location])
(Thread/sleep 50)))))
(defn output-handler [bot]
@@ -57,7 +57,8 @@
out (DataOutputStream. (.getOutputStream socket))
conn (ref {:in in :out out})
outqueue (LinkedBlockingQueue.)
- player (ref {:location nil})
+ player (ref {:location {:onground false, :pitch 0.0, :yaw 0.0, :z 240.0,
+ :y 85.0, :stance 60.0, :x -120.0}})
world (ref {})
bot {:connection conn, :outqueue outqueue, :player player, :world world,
:packet-counts-in (atom {}), :packet-counts-out(atom {})}]
@@ -88,8 +89,10 @@
; Scratch --------------------------------------------------------------------------
;(def bot (connect minecraft-local))
-(pprint (:packet-counts-in bot))
-(pprint (:packet-counts-out bot))
+(act/move bot -3 0 -4)
+;(pprint @(:packet-counts-in bot))
+;(pprint @(:packet-counts-out bot))
;(println (:world bot))
+;(println (:location @(:player bot)))
;(disconnect bot)
--- a/src/clojurecraft/in.clj Tue Jul 05 19:22:59 2011 -0400
+++ b/src/clojurecraft/in.clj Tue Jul 05 20:57:11 2011 -0400
@@ -40,7 +40,7 @@
i))
(defn- -read-shortarray [conn size]
- (repeatedly size #(-read-short conn)))
+ (doall (repeatedly size #(-read-short conn))))
(defn- -read-bool [conn]
(let [b (.readBoolean (:in @conn))]
@@ -60,7 +60,7 @@
(defn- -read-string-ucs2 [conn]
(let [str-len (.readShort (:in @conn))
- s (apply str (repeatedly str-len #(.readChar (:in @conn))))]
+ s (doall (apply str (repeatedly str-len #(.readChar (:in @conn)))))]
s))
(defn- -read-metadata [conn]
@@ -590,8 +590,7 @@
(/ 1 0))
(let [payload (do ((packet-type packet-readers) bot conn))]
(do
- (when (#{:mapchunk} packet-type)
- (println (str "--PACKET--> " packet-type))
- (println payload))
+ (when (#{} packet-type)
+ (println (str "--PACKET--> " packet-type)))
payload))))))
--- a/src/clojurecraft/out.clj Tue Jul 05 19:22:59 2011 -0400
+++ b/src/clojurecraft/out.clj Tue Jul 05 20:57:11 2011 -0400
@@ -13,7 +13,7 @@
(defn- -write-short [conn i]
(doto (:out @conn)
- (.writeShort (int i))))
+ (.writeShort (short i))))
(defn- -write-shortarray [conn sa]
(map #(-write-short %) sa))
@@ -24,15 +24,15 @@
(defn- -write-long [conn i]
(doto (:out @conn)
- (.writeLong (int i))))
+ (.writeLong (long i))))
(defn- -write-double [conn i]
(doto (:out @conn)
- (.writeDouble (int i))))
+ (.writeDouble (double i))))
(defn- -write-float [conn i]
(doto (:out @conn)
- (.writeFloat (int i))))
+ (.writeFloat (float i))))
(defn- -write-string-utf8 [conn s]
(doto (:out @conn)