Liking cljdoc? Tell your friends :D

lambdaisland.witchcraft.cursor

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)
    )
```
raw docstring

?blockclj

(?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")
sourceraw docstring

blockclj

(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.
sourceraw docstring

block-valueclj

(block-value cursor)
source

buildclj

(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.
sourceraw docstring

default-materialclj

source

directionsclj

source

drawclj

(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.
sourceraw docstring

excursionclj

(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.
sourceraw docstring

extrudeclj

(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.
sourceraw docstring

faceclj

(face cursor dir)

Face the cursor in a certain direction

Face the cursor in a certain direction
sourceraw docstring

materialclj

(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.
sourceraw docstring

material->keywordclj

source

moveclj

(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.
sourceraw docstring

move-toclj

(move-to cursor loc)

Move the cursor to the given location, does not draw.

Move the cursor to the given location, does not draw.
sourceraw docstring

movementsclj

source

redo!clj

(redo!)

Redo the last build that was undone with undo!

Redo the last build that was undone with [[undo!]]
sourceraw docstring

redo-historyclj

source

relative-movementsclj

source

resolve-dirclj

(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.
sourceraw docstring

rotateclj

(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.
sourceraw docstring

rotate-dirclj

(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
sourceraw docstring

startclj

(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.
sourceraw docstring

stepclj

(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.
sourceraw docstring

stepsclj

(steps cursor n)
(steps cursor n dir)

Take n steps forward as with step

Take n steps forward as with [[step]]
sourceraw docstring

undo!clj

(undo!)

Undo the last build. Can be repeated to undo multiple builds.

Undo the last build. Can be repeated to undo multiple builds.
sourceraw docstring

undo-historyclj

source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close