Logo-like API for drawing blocks by using a walking metaphor.
This is a functional API, movements simply build up a list of block positions,
call build
at the end to actually make them materialize in the game.
A cursor contains a current location (x/y/z), a directions (:north, :north-east, :east, etc.), and a current building material, e.g :lapis-block (see [[lambdaisland.witchcraft.bukkit/materials]]).
It also contains a drawing flag :draw?
and a list of blocks :blocks
. When
drawing is on, then any step will add a block to the list. build
creates
blocks in the world based on this, and resets the list.
Call start
to get an initial cursor, this will return a cursor that is one
step ahead of the player (so what you draw is in sight), facing away from the
player.
(require '[lambdaisland.witchcraft.cursor :as c])
(-> (c/start)
(c/draw)
(c/material :red-glazed-terracotta)
(c/steps 3)
(c/rotate 2)
(c/material :blue-glazed-terracotta)
(c/steps 3)
(c/rotate 2)
(c/material :green-glazed-terracotta)
(c/steps 3)
(c/rotate 2)
(c/material :yellow-glazed-terracotta)
(c/steps 3)
(c/build)
)
Logo-like API for drawing blocks by using a walking metaphor. This is a functional API, movements simply build up a list of block positions, call [[build]] at the end to actually make them materialize in the game. A cursor contains a current location (x/y/z), a directions (:north, :north-east, :east, etc.), and a current building material, e.g :lapis-block (see [[lambdaisland.witchcraft.bukkit/materials]]). It also contains a drawing flag `:draw?` and a list of blocks `:blocks`. When drawing is on, then any step will add a block to the list. [[build]] creates blocks in the world based on this, and resets the list. Call [[start]] to get an initial cursor, this will return a cursor that is one step ahead of the player (so what you draw is in sight), facing away from the player. ``` (require '[lambdaisland.witchcraft.cursor :as c]) (-> (c/start) (c/draw) (c/material :red-glazed-terracotta) (c/steps 3) (c/rotate 2) (c/material :blue-glazed-terracotta) (c/steps 3) (c/rotate 2) (c/material :green-glazed-terracotta) (c/steps 3) (c/rotate 2) (c/material :yellow-glazed-terracotta) (c/steps 3) (c/build) ) ```
(?block c)
Add a block to the block list based on the current cursor location and material, but only if drawing is enabled. (pronounced "maybe block")
Add a block to the block list based on the current cursor location and material, but only if drawing is enabled. (pronounced "maybe block")
(block cursor)
Add a block to the block list based on the cursor location.
Add a block to the block list based on the cursor location.
(build {:keys [blocks] :as cursor})
Apply the list of blocks in the cursor to the world.
Apply the list of blocks in the cursor to the world.
(draw c)
(draw c draw?)
Enable/disable drawing. Enables by default, pass false to disable.
Enable/disable drawing. Enables by default, pass false to disable.
(excursion cursor f)
Apply a block-drawing function f, then return to the original position.
Apply a block-drawing function f, then return to the original position.
(extrude cursor n)
(extrude cursor n dir)
Take the current block list and extrude it in a given direction, by default up.
Take the current block list and extrude it in a given direction, by default up.
(face cursor dir)
Face the cursor in a certain direction
Face the cursor in a certain direction
(material cursor m)
(material cursor m md)
Set the current cursor material, and optionally material-data, to be used for consecutive blocks.
Set the current cursor material, and optionally material-data, to be used for consecutive blocks.
(move cursor)
(move {:keys [draw? dir] :as cursor} n)
(move {:keys [draw?] :as cursor} n dir)
Move the cursor as with steps, but without drawing.
Move the cursor as with steps, but without drawing.
(move-to cursor loc)
Move the cursor to the given location, does not draw.
Move the cursor to the given location, does not draw.
(redo!)
Redo the last build that was undone with undo!
Redo the last build that was undone with [[undo!]]
(resolve-dir facing asked)
Helper for dealing with forward/left/right type of directions, instead of east/north/west.
Helper for dealing with forward/left/right type of directions, instead of east/north/west.
(rotate {:keys [dir xy-dir] :as cursor} n)
Rotate the cursor clockwise by a number of 1/8 turns clockwise.
Rotate the cursor clockwise by a number of 1/8 turns clockwise.
(rotate-dir dir n)
Given a direction keyword like :north or :south and a number, make that many 1/8 turns clockwise.
(rotate :north 4) ;; => :south
Given a direction keyword like :north or :south and a number, make that many 1/8 turns clockwise. (rotate :north 4) ;; => :south
(start)
(start loc)
Creates a new cursor, starting at the given location, or one step in front of the player's location.
Creates a new cursor, starting at the given location, or one step in front of the player's location.
(step cursor)
(step cursor dir)
Take one step forward in the direction given, or the direction the cursor is facing. If drawing is enabled this will also add a block to the block list corresponding with the new location.
Take one step forward in the direction given, or the direction the cursor is facing. If drawing is enabled this will also add a block to the block list corresponding with the new location.
(steps cursor n)
(steps cursor n dir)
Take n steps forward as with step
Take n steps forward as with [[step]]
(undo!)
Undo the last build. Can be repeated to undo multiple builds.
Undo the last build. Can be repeated to undo multiple builds.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close