Permalink
Browse files

Fix line, event change and is-block?

  • Loading branch information...
CmdrDats committed Dec 29, 2012
1 parent fc7a2c7 commit c338851ebcd9231941acda2afb0d9c2cff7d7248
Showing with 36 additions and 13 deletions.
  1. +6 −0 README.md
  2. +18 −11 src/cljminecraft/blocks.clj
  3. +9 −2 src/cljminecraft/events.clj
  4. +3 −0 src/cljminecraft/items.clj
View
@@ -23,6 +23,12 @@ understand what changes are made and adjust your plugins accordingly.
Changelog:
+29 December 2012:
+ - Now sends a message to the player triggering an event when the event function returns {:msg "..."}
+ - Fix up line function
+ - Add `actions` enum to events.clj
+ - Add `is-block` convenience function to items.clj for checking if a block is a certain material
+
27 December 2012:
- Introduce cut-to-mark, copy-to-mark, pen-from-mark and clear-mark
- Interface of line and empty line-to-mark - have to work out the math involved
@@ -114,7 +114,7 @@
(defaction pen-from-mark
"Restore the pen state from mark"
ctx [mark]
- (assoc :ctx :panting? (get-in ctx [:marks mark :painting?] true)))
+ (assoc :ctx :painting? (get-in ctx [:marks mark :painting?] true)))
(defaction material
"Set the current material to paint with"
@@ -214,7 +214,7 @@
(update-in ctx [:marks mark] {}))
-(defn line
+(defn calcline
"This returns a set of points for a line"
[xt yt zt]
(if (= [xt yt zt] [0 0 0])
@@ -231,14 +231,15 @@
;; to be finished......
(defaction line-to-mark
"Draw a line directly to a given mark from current point"
- {:keys [origin material marks]} [mark]
+ {:keys [origin material marks] :as ctx} [mark]
(let [originblock (.getBlock origin)
mat (i/get-material material)
point (location-to-point origin (:origin (get marks mark)))
- linepoints (apply line point)]
+ linepoints (apply calcline point)]
(doseq [[x y z] linepoints]
(let [block (.getRelative originblock x y z)]
- (.setTypeIdAndData block (.getItemTypeId mat) (.getData mat) false)))))
+ (.setTypeIdAndData block (.getItemTypeId mat) (.getData mat) false)))
+ ctx))
(defn line
"Draw a line, relative to current position and direction"
@@ -249,7 +250,7 @@
(forward fwd)
(left lft)
(up u)
- (pen-from-mark m)
+ (pen :down)
(line-to-mark m)
(clear-mark m)]))
@@ -288,11 +289,17 @@
(forward 10) (right 10) (back 8) (left 2) (back 2) (left 8))
)
- (bk/ui-sync
- @cljminecraft.core/clj-plugin
- #(run-actions ctx (material :air) (mark :start) (left 100) (forward 100) (up 40) (cut-to-mark :start) (clear-mark :start)))
+ (run-actions
+ ctx
+ ;(material :air)
+ (line 10 10 10)
+ (line 1 2 3)
+ (line -5 0 0)
+ (line 0 -5 0)
+ (line 0 0 -5))
-
- )
+ (bk/ui-sync
+ @cljminecraft.core/clj-plugin
+ #(run-actions ctx (material :air) (mark :start) (left 100) (forward 100) (up 40) (cut-to-mark :start) (clear-mark :start))))
@@ -2,10 +2,17 @@
"Event handlers for bukkit"
(:require [cljminecraft.logging :as log]
[cljminecraft.util :as util]
- [cljminecraft.bukkit :as bk]))
+ [cljminecraft.bukkit :as bk]
+ [cljminecraft.player :as plr]))
+(defonce actions (util/map-enums org.bukkit.event.block.Action))
(defonce priorities (util/map-enums org.bukkit.event.EventPriority))
+(defn handle-event [f e]
+ (if-let [response (f e)]
+ (do
+ (if (:msg response) (plr/send-msg e (:msg response))))))
+
(defn register-event [plugin eventname f & [priority-key]]
(let [eventclass (resolve (symbol (util/package-classname "org.bukkit.event" (str eventname "-event"))))]
(log/info "Registering event %s for plugin %s" eventname (.getName plugin))
@@ -15,7 +22,7 @@
(proxy [org.bukkit.event.Listener] [])
(get priorities (or priority-key :normal))
(proxy [org.bukkit.plugin.EventExecutor] []
- (execute [l e] (f e)))
+ (execute [l e] (handle-event f e)))
plugin)))
(defonce registered-events
@@ -22,6 +22,9 @@
(def cocoaplantsizes (util/map-enums org.bukkit.material.CocoaPlant$CocoaPlantSize))
(def coaltypes (util/map-enums org.bukkit.CoalType))
+(defn is-block? [block & material-keys]
+ (contains? (set (map materials material-keys)) (.getType block)))
+
(defmulti get-new-data
"Returns a new MaterialData depending on Material Type"
(fn [t _ _] t))

0 comments on commit c338851

Please sign in to comment.