Clojure API for Minecraft/Bukkit
Clojure API for Minecraft/Bukkit
Server-specific set-block implementation
Server-specific set-block implementation
(add this that)
(add this that & more)
Add multiple vector/location-like things together. Returns a value with the same type of the first argument.
Add multiple vector/location-like things together. Returns a value with the same type of the first argument.
(add-inventory has-inventory item)
(add-inventory has-inventory item n)
Add the named item to the player or entity's inventory, or n copies of it
Add the named item to the player or entity's inventory, or n copies of it
(block block-or-loc)
Get the block at the given location, returns a Clojure map. See get-block
if you need the actual block object.
Get the block at the given location, returns a Clojure map. See [[get-block]] if you need the actual block object.
Map from keyword to block.Action value
Map from keyword to block.Action value
(block-face kw)
Coerce to BlockFace
Use to convert keywords like :east/:west/:self to BlockFace instances. Idempotent.
Coerce to BlockFace Use to convert keywords like :east/:west/:self to BlockFace instances. Idempotent.
Map from BlockFace value to keyword
Map from BlockFace value to keyword
Map from keyword to BlockFace value
Map from keyword to BlockFace value
(block-set coll)
(block-set xform coll)
Create a block set, a set of maps where every :x/:y/:z value can only occur once.
Create a block set, a set of maps where every :x/:y/:z value can only occur once.
(blockv block-or-loc)
Like block
, but return a vector instead of a map. Contains in order:
x,y,z,material, and optionally a direction and/or a block-data map (or
block-data integer pre-flattening). Generally the same structure as can be
passed to set-blocks
.
Like [[block]], but return a vector instead of a map. Contains in order: x,y,z,material, and optionally a direction and/or a block-data map (or block-data integer pre-flattening). Generally the same structure as can be passed to [[set-blocks]].
(break-naturally block-like)
(break-naturally block-like tool-or-effect)
(break-naturally block-like tool effect?)
Breaks the block and spawns items, can optionally take a tool
argument, as if
a player had digged the block with that specific tool (ItemStack
, or
something that can be coerced to an item-stack or material, like a keyword).
Optionally also takes an effect?
boolean, which determines whether to play
the block break particle effect and sound.
effect?
is not supported on all implementations.
Breaks the block and spawns items, can optionally take a `tool` argument, as if a player had digged the block with that specific tool (`ItemStack`, or something that can be coerced to an item-stack or material, like a keyword). Optionally also takes an `effect?` boolean, which determines whether to play the block break particle effect and sound. `effect?` is not supported on all implementations.
Alias for set-blocks
, for symmetry with lambdaisland.witchcraft.cursor/build!
Alias for [[set-blocks]], for symmetry with [[lambdaisland.witchcraft.cursor/build!]]
(-break-naturally-effect _ effect)
(-break-naturally-tool-effect _ tool effect?)
(-render-and-set-display-name _ _)
(clear-weather)
(clear-weather world)
Get clear weather
Get clear weather
(contents o)
Get the contents of the inventory of something as a sequence of maps.
Get the contents of the inventory of something as a sequence of maps.
(create-explosion loc-like)
(create-explosion loc-like strength)
Create an explosion at a certain location, with a given explosion size (default: 5)
Create an explosion at a certain location, with a given explosion size (default: 5)
(create-world name opts)
Create a new world with a given name and options
Create a new world with a given name and options - :seed long - :structures? boolean - :hardcore? boolean
(default-world)
World used for commands when no explicit world is given.
Uses *default-world*
, or the first world on the server.
World used for commands when no explicit world is given. Uses [[*default-world*]], or the first world on the server.
(despawn entity)
Remove an entity from the world
Remove an entity from the world
(difficulty)
(difficulty the-world)
Get the difficulty of the world (keyword, World instance, or anything coercible by world
)
Get the difficulty of the world (keyword, World instance, or anything coercible by [[world]])
Map from keyword to Difficulty
Map from keyword to Difficulty
(direction block-or-loc)
Get the direction of a Block, or of the block at a certain location.
Get the direction of a Block, or of the block at a certain location.
(display-name o)
Get the display-name for an item, itemstack, itemmeta, or nameable block or blockstate.
Get the display-name for an item, itemstack, itemmeta, or nameable block or blockstate.
(distance this that)
Get the euclidian distance between two locations. Can take various bukkit
objects (Location, Block, Vector), as well as Clojure vectors [x y z]
or
maps {:x x :y y :z z}
, and any combination thereof.
Get the euclidian distance between two locations. Can take various bukkit objects (Location, Block, Vector), as well as Clojure vectors `[x y z]` or maps `{:x x :y y :z z}`, and any combination thereof.
(empty-inventory entity)
Clear out the inventory
Clear out the inventory
Make sure there is only one block for each coordinate in the set, and keep them sorted by x/z/y.
Make sure there is only one block for each coordinate in the set, and keep them sorted by x/z/y.
(entity o)
Get an object's entity, or get entity by UUID.
Get an object's entity, or get entity by UUID.
Map from keyword to EntityType value
Map from keyword to EntityType value
(fast-forward time)
(fast-forward world time)
Fast forward the clock, time is given in ticks, with 20 ticks per second, or 24000 ticks in a Minecraft day.
Fast forward the clock, time is given in ticks, with 20 ticks per second, or 24000 ticks in a Minecraft day.
(fly!)
(fly! player)
Set a player as allowing flight and flying. Note: doesn't seem to actually cause flying, but it does make flying possible.
Set a player as allowing flight and flying. Note: doesn't seem to actually cause flying, but it does make flying possible.
(food-level player)
Get the player's food level, a number between 0 and 20
Get the player's food level, a number between 0 and 20
(game-mode)
(game-mode player)
Get the current game mode
Get the current game mode
(get-block loc)
Get the block at a given location. Idempotent.
Get the block at a given location. Idempotent.
(get-inventory o)
Get the org.bukkit.inventory.Inventory for the given object/entity. Works for players, blocks (e.g. chests), itemstacks (e.g. shulker box in inventory), etc.
Get the org.bukkit.inventory.Inventory for the given object/entity. Works for players, blocks (e.g. chests), itemstacks (e.g. shulker box in inventory), etc.
(get-target-block entity)
(get-target-block entity transparent)
(get-target-block entity transparent max-distance)
Get the target block in the line of sight of the entity/player, as org.bukkit.block.Block
Get the target block in the line of sight of the entity/player, as org.bukkit.block.Block
(-get-block-data _)
(-set-block-data _ _)
(-get-custom-name _)
(-set-custom-name _ _)
(-get-difficulty _)
(-set-difficulty _ d)
(-display-name _)
(-set-display-name _ _)
(-location _)
Get the location of the given object
Get the location of the given object
(-world-by-name _ _)
(-world-by-uuid _ _)
(-worlds _)
(health player)
Get the player's health, a number between 0 and 20
Get the player's health, a number between 0 and 20
(highest-block-at loc)
Retrieve the highest block at the given location
Retrieve the highest block at the given location
(in-front-of loc)
(in-front-of loc n)
Get the location n
blocks in front of the given location, based on the
location's direction. Polymorphic, can work with most things that have a
location. Returns plain data.
Get the location `n` blocks in front of the given location, based on the location's direction. Polymorphic, can work with most things that have a location. Returns plain data.
(init-xmaterial!)
We can only access the XMaterial class once a Bukkit server is available
We can only access the XMaterial class once a Bukkit server is available
(into-inventory has-inventory items)
Add multiple items to an inventory at once
Add multiple items to an inventory at once
(inventory i)
Get a Clojure/EDN representation of an inventory (or of something that has an
inventory). Has :type
and :contents
keys, and :size
for chest type
inventories (others have a fixed size).
Get a Clojure/EDN representation of an inventory (or of something that has an inventory). Has `:type` and `:contents` keys, and `:size` for chest type inventories (others have a fixed size).
(inventory-type i)
Get the type of an inventory object, or of something that has an inventory (like a player or chest entity) as a keyword.
Get the type of an inventory object, or of something that has an inventory (like a player or chest entity) as a keyword.
(item-meta o)
Get the ItemMeta for an item or compatible object, this object contains things like the display name of the item, if it has been renamed.
Get the ItemMeta for an item or compatible object, this object contains things like the display name of the item, if it has been renamed.
(item-stack o)
(item-stack material count)
Create (from a material) or get (from something that has an item-stack) an ItemStack object
Create (from a material) or get (from something that has an item-stack) an ItemStack object
(listen! event k f)
Listen for an event
Event is a keyword based on the event type, like :player-interact
or
:item-spawn
, k`` is a key this event is registered under, so you can
unlisten!` with the same key afterwards. Re-registering a listener with the
same event and key will replace the old listener.
See (keys
lambdaisland.witchcraft.events/events
)
for all known
events.
Listen for an event Event is a keyword based on the event type, like `:player-interact` or `:item-spawn`, `k`` is a key this event is registered under, so you can `unlisten!` with the same key afterwards. Re-registering a listener with the same event and key will replace the old listener. See `(keys `[[lambdaisland.witchcraft.events/events]]`)` for all known events.
(loc obj)
Get the location of a thing, as a clojure map. Can take most objects that have some kind of location, e.g. Location, Player, Vector, Block, Entity. Can also take Clojure maps or vectors, so you can use it to coerce input of unknown type.
Get the location of a thing, as a clojure map. Can take most objects that have some kind of location, e.g. Location, Player, Vector, Block, Entity. Can also take Clojure maps or vectors, so you can use it to coerce input of unknown type.
(location o)
Get the location of the given object
Get the location of the given object
(lore o)
Get the lore for an item or compatible object.
Get the lore for an item or compatible object.
(make-inventory {:keys [owner type size title contents] :or {size 27}})
Make a new Bukkit inventory object, with either :type
(keyword) or
:size
(must be multiple of 9), and optional :owner
and/or :title
.
Make a new Bukkit inventory object, with either `:type` (keyword) or `:size` (must be multiple of 9), and optional `:owner` and/or `:title`.
(mat m)
Get the material name of something, as a keyword.
Get the material name of something, as a keyword.
(material m)
Get the org.bukkit.Material
for the given object.
:material
keygetMaterial()
or getType()
, use
the object method to get the materialget-block
to get the
material at that locationGet the `org.bukkit.Material` for the given object. - map: looks for a `:material` key - vector: will look for a keyword in the fourth position (so you can use `[x y z material]``) - keyword: looks up the named material - Objects that implement `getMaterial()` or `getType()`, use the object method to get the material - location-like things: pass on to `get-block` to get the material at that location
(material-name m)
Get the material name of something, as a keyword. Alias for mat
.
Get the material name of something, as a keyword. Alias for [[mat]].
Map from XMaterial value to keyword
Map from XMaterial value to keyword
Map from keyword to XMaterial value
Map from keyword to XMaterial value
(normalize-text txt)
When dealing with text which contains §
-based color and markup codes,
"normalize" it by setting it on an item and reading back the result. This
will cause the server to strip out redundant markup. Useful if you later want
to use equality checks on the name of items.
Can also take hiccup-like markup as per lambdaisland.witchcraft.markup
When dealing with text which contains `§`-based color and markup codes, "normalize" it by setting it on an item and reading back the result. This will cause the server to strip out redundant markup. Useful if you later want to use equality checks on the name of items. Can also take hiccup-like markup as per [[lambdaisland.witchcraft.markup]]
(online-players)
List all online players
List all online players
(open-inventory target)
(open-inventory target inventory)
Open the inventory UI, pass it a player and the inventory to show.
Open the inventory UI, pass it a player and the inventory to show.
(player)
(player name)
Get a player by name, or simply the first player found.
Get a player by name, or simply the first player found.
(player-chunk player)
Return the chunk the player is in
Return the chunk the player is in
For the rare API calls that really want a plugin instance
For the rare API calls that really want a plugin instance
(plugin-manager)
Get the Bukkit plugin manager
Get the Bukkit plugin manager
(-add this that)
Add locations, vectors, etc. That can also be a map of :x
, :y
, :z
Add locations, vectors, etc. That can also be a map of `:x`, `:y`, `:z`
(as-vec _)
Coerce to org.bukkit.util.Vector
Coerce to org.bukkit.util.Vector
(chunk _)
Retrieve the chunk for a location, entity, etc.
Retrieve the chunk for a location, entity, etc.
(direction-vec _)
(entities _)
Get the chunk's entities
Get the chunk's entities
(material-data _)
(with-xyz _ xyz)
Return the same type, but with x/y/z updated
Return the same type, but with x/y/z updated
(redo!)
Redo the last build that was undone with undo!
Redo the last build that was undone with [[undo!]]
(remove-inventory has-inventory item)
(remove-inventory has-inventory item n)
Remove the named items from the player or entity's inventory, or n copies of it
Remove the named items from the player or entity's inventory, or n copies of it
Render hiccup-like markup into a string with color and styling codes that Minecraft understand, see the lambdaisland.witchcraft.markup
namespace for details.
Render hiccup-like markup into a string with color and styling codes that Minecraft understand, see the [[lambdaisland.witchcraft.markup]] namespace for details.
(run-task f)
Schedule a task for the next server tick
Schedule a task for the next server tick
(run-task-later f ticks)
Schedule a task for after n ticks
Schedule a task for after n ticks
(satisfies? protocol x)
Like clojure.core/satisfies?, but cache the result. We make heavy use of satisfies, and this is not very well optimized in core.
Like clojure.core/satisfies?, but cache the result. We make heavy use of satisfies, and this is not very well optimized in core.
(send-message p message)
Send a chat message to a specific player
Takes strings or vectors (markup), e.g.
[:red "hello " [:underline "world"]]
See [[markup/codes]].
Send a chat message to a specific player Takes strings or vectors (markup), e.g. ``` [:red "hello " [:underline "world"]] ``` See [[markup/codes]].
(send-title p title)
(send-title p title subtitle)
Send a title and optionally subtitle to the player
Titles are splashed in big type over the middle of the screen, before they fade out.
Takes strings or vectors (markup), e.g.
[:red "hello " [:underline "world"]]
See [[markup/codes]].
Send a title and optionally subtitle to the player Titles are splashed in big type over the middle of the screen, before they fade out. Takes strings or vectors (markup), e.g. ``` [:red "hello " [:underline "world"]] ``` See [[markup/codes]].
(server)
Get the currently active server.
Get the currently active server.
(set-bed-spawn-location player loc)
(set-bed-spawn-location player loc force?)
Set the location where the player will respawn, set force?
to true to update
the spawn location even if there is no valid bed available.
Set the location where the player will respawn, set `force?` to true to update the spawn location even if there is no valid bed available.
(set-block loc-or-map)
(set-block loc material-or-map)
Set the block at a specific location to a specific material
material
can be a keyword (see materials
), a String like RED_WOOL
or
WOOL:14
, a bukkit Material, a Bukkit ItemStack, or an xseries XMaterial.
Single-arity version takes a map with
:x
/:y
/:z
/:world
/:material
/:material-data
/:block-data
(some
optional)
Two-arity version takes something that is or has a location (can also be a
vector or map), and a material or map with
:material
/:direction
/:block-data
.
Set the block at a specific location to a specific material `material` can be a keyword (see [[materials]]), a String like `RED_WOOL` or `WOOL:14`, a bukkit Material, a Bukkit ItemStack, or an xseries XMaterial. Single-arity version takes a map with `:x`/`:y`/`:z`/`:world`/`:material`/`:material-data`/`:block-data` (some optional) Two-arity version takes something that is or has a location (can also be a vector or map), and a material or map with `:material`/`:direction`/`:block-data`.
(set-block-data block prop-map)
(set-block-data block mat prop-map)
Set BlockData
properties, these are material dependent, e.g. slabs can have
{:type :top}
or {:type :bottom}
.
We need to get a matching Material
object to construct the correct type of
BlockData
, if you already have one handy you should pass it in to prevent an
extra lookup.
Set `BlockData` properties, these are material dependent, e.g. slabs can have `{:type :top}` or `{:type :bottom}`. We need to get a matching `Material` object to construct the correct type of `BlockData`, if you already have one handy you should pass it in to prevent an extra lookup.
(set-blocks blocks)
(set-blocks blocks
{:keys [keep-history? start anchor palette material]
:or {keep-history? true}})
Set blocks in bulk
Takes a sequence of maps with :x
, :y
, :z
, :material
, and optionally
:world
and :data
, or a sequence of [x y z material]
vectors.
Alternatively you can pass a sequence of any object that responds to the x
,
y
, z
, and material-name
methods.
This adds an entry to the undo history, capturing the previous state of the
blocks it is changing, so you can undo!
and then redo!
the result,
unless :keep-history?
is set to false
.
Optionally takes an :start
or :anchor
option, which then offsets the whole
structure by that distance (can be a map, vector, Location
, bukkit Vector
,
etc.), so you can define the structure you are passing in independently of its
position in the world.
Can take a :palette
, which is a map with material name aliases (keyword to
keyword, or keyword to [keyword map] pair, to provide block-data).
Currently only optimized on Glowstone, elsewhere it repeatedly
calls set-block
, so changing really large amounts of blocks at once will
incur significant lag.
Set blocks in bulk Takes a sequence of maps with `:x`, `:y`, `:z`, `:material`, and optionally `:world` and `:data`, or a sequence of `[x y z material]` vectors. Alternatively you can pass a sequence of any object that responds to the `x`, `y`, `z`, and `material-name` methods. This adds an entry to the undo history, capturing the previous state of the blocks it is changing, so you can [[undo!]] and then [[redo!]] the result, unless `:keep-history?` is set to `false`. Optionally takes an `:start` or `:anchor` option, which then offsets the whole structure by that distance (can be a map, vector, `Location`, bukkit `Vector`, etc.), so you can define the structure you are passing in independently of its position in the world. Can take a `:palette`, which is a map with material name aliases (keyword to keyword, or keyword to [keyword map] pair, to provide block-data). Currently only optimized on Glowstone, elsewhere it repeatedly calls [[set-block]], so changing really large amounts of blocks at once will incur significant lag.
(set-contents inv items)
Set inventory contents on an inventory or something that has an inventory.
Set inventory contents on an inventory or something that has an inventory.
(set-difficulty level)
(set-difficulty the-world level)
Set the world's difficulty (keyword)
Set the world's difficulty (keyword)
(set-direction loc dir)
Set the direction of a block, takes a keyword or BlockFace,
see block-faces
Set the direction of a block, takes a keyword or BlockFace, see [[block-faces]]
(set-display-name o name)
Set the display-name on an item, itemstack, itemmeta. Takes a list (sequence)
of strings, or of markup vectors as
per lambdaisland.witchcraft.markup/render
.
Set the display-name on an item, itemstack, itemmeta. Takes a list (sequence) of strings, or of markup vectors as per [[lambdaisland.witchcraft.markup/render]].
(set-food-level player food-level)
Set the player's food level, a number between 0 and 20
Set the player's food level, a number between 0 and 20
(set-game-mode player mode)
Sets the game mode for the player, takes a keyword or a org.bukkit.GameMode
,
see game-modes
Sets the game mode for the player, takes a keyword or a `org.bukkit.GameMode`, see [[game-modes]]
(set-health player health)
Set the player's health, a number between 0 and 20
Set the player's health, a number between 0 and 20
(set-item-meta o im)
Set the ItemMeta for compatible objects, like an ItemStack. Either takes an
actual ItemMeta object, or a map with :name
and/or :lore
keys.
Set the ItemMeta for compatible objects, like an ItemStack. Either takes an actual ItemMeta object, or a map with `:name` and/or `:lore` keys.
(set-lore o lore)
Set the lore on an item, itemstack, itemmeta. Takes a list (sequence) of
strings, or of markup vectors as per lambdaisland.witchcraft.markup/render
.
Set the lore on an item, itemstack, itemmeta. Takes a list (sequence) of strings, or of markup vectors as per [[lambdaisland.witchcraft.markup/render]].
(set-time time)
(set-time world time)
Set the time in a world, or the first world on the current server. Time is given in ticks, with 20 ticks per second, or 24000 ticks in a Minecraft day.
Set the time in a world, or the first world on the current server. Time is given in ticks, with 20 ticks per second, or 24000 ticks in a Minecraft day.
(start-glowstone! & args)
Start an embedded Glowstone server
Optionally provided with a map of config options. See [[lambdaisland.witchcraft.config/key-values]]
Start an embedded Glowstone server Optionally provided with a map of config options. See [[lambdaisland.witchcraft.config/key-values]]
(start-paper! & [gui?])
Start an embedded PaperMC server
Start an embedded PaperMC server
(target-block & args)
Get the target block in the line of sight of the entity/player, as a map
Get the target block in the line of sight of the entity/player, as a map
(teleport loc)
(teleport entity l)
Teleport to a given location
Teleport to a given location
(time)
(time world)
Get the current time in the world in ticks.
Get the current time in the world in ticks.
Map from keyword to TreeSpecies value
Map from keyword to TreeSpecies value
(undo!)
Undo the last build. Can be repeated to undo multiple builds.
Undo the last build. Can be repeated to undo multiple builds.
(unlisten! event k)
Remove an event listener
Remove an event listener
(vec3 x y z)
Create a org.bukkit.util.Vector instance
Create a org.bukkit.util.Vector instance
(world o)
(world o n)
Get the world associated with a given object, or look up a world by string or UUID.
Get the world associated with a given object, or look up a world by string or UUID.
(worlds)
(worlds o)
Get a list of all worlds on the server
Get a list of all worlds on the server
(xmaterial m)
Get an XMaterial instance from a keyword, string, Material, or ItemStack, or
anything else for which the polymorphic material
method is implemented.
This is a shim class which provides version-independent material handling.
Get an XMaterial instance from a keyword, string, Material, or ItemStack, or anything else for which the polymorphic [[material]] method is implemented. This is a shim class which provides version-independent material handling.
(xyz o)
Get the x/y/z values of an object as a vector, can work with maps containing
:x
/:y
/:z
keys, or virtually any Glowstone object that encodes or has a
location.
Get the x/y/z values of an object as a vector, can work with maps containing `:x`/`:y`/`:z` keys, or virtually any Glowstone object that encodes or has a location.
(xyz-round o)
Like xyz
, but returns rounded integers.
Like [[xyz]], but returns rounded integers.
(xyz1 o)
Like xyz
, but add an extra 1
at the end, for affine transformations
Like [[xyz]], but add an extra `1` at the end, for affine transformations
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close