085e63240d4f
Bit twiddling.
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Wed, 03 Aug 2011 21:11:51 -0400 |
parents | 3b17a92aa31b |
children | c41de2845803 |
branches/tags | (none) |
files | src/clojurecraft/core.clj src/clojurecraft/in.clj |
Changes
--- a/src/clojurecraft/core.clj Wed Aug 03 20:14:46 2011 -0400 +++ b/src/clojurecraft/core.clj Wed Aug 03 21:11:51 2011 -0400 @@ -116,3 +116,5 @@ (defn disconnect [bot] (dosync (alter (:connection bot) merge {:exit true}))) + +(def minecraft-local {:name "localhost" :port 25565})
--- a/src/clojurecraft/in.clj Wed Aug 03 20:14:46 2011 -0400 +++ b/src/clojurecraft/in.clj Wed Aug 03 21:11:51 2011 -0400 @@ -1,6 +1,7 @@ (ns clojurecraft.in (:use [clojurecraft.util]) (:use [clojurecraft.mappings]) + (:use [clojurecraft.chunks]) (:require [clojurecraft.data]) (:import [clojurecraft.data Location Entity]) (:import (java.util.zip Inflater))) @@ -13,31 +14,33 @@ (reverse s)))) (defn top [b] - (bit-shift-right (bit-and b 0xf0) 4)) + (byte (bit-shift-right (bit-and b 0xf0) 4))) (defn bottom [b] - (bit-and b 0x0f)) + (byte (bit-and b 0x0f))) +(defn to-unsigned [b] + (bit-and b 0xff)) ; Reading Data --------------------------------------------------------------------- (defn- -read-byte [conn] - (io! + (io! (let [b (.readByte (:in @conn))] - b))) + (byte b)))) (defn- -read-bytearray [conn size] - (io! + (io! (let [ba (byte-array size)] (.read (:in @conn) ba 0 size) ba))) (defn- -read-int [conn] - (io! + (io! (let [i (.readInt (:in @conn))] i))) (defn- -read-long [conn] - (io! + (io! (let [i (.readLong (:in @conn))] i))) @@ -76,12 +79,12 @@ s))) (defn- -read-metadata [conn] - (io! + (io! (loop [data []] (let [x (-read-byte conn)] (if (= x 127) data - (case (bit-shift-right x 5) + (case (bit-shift-right (to-unsigned x) 5) 0 (recur (conj data (-read-byte conn))) 1 (recur (conj data (-read-short conn))) 2 (recur (conj data (-read-int conn))) @@ -357,7 +360,7 @@ nibbles [] data data] (if (= i len) - [nibbles data] + [(byte-array nibbles) data] (let [next-byte (get data 0) top-byte (top next-byte) bottom-byte (bottom next-byte)]