(-get-or-add-trait _ c)
(-get-traits _)
(-remove-trait _ c)
(make-trait name callbacks)
Create a subclass of npcs.citizensapi.trait.Trait, name
is a simple lowercase
identifier of the trait like "sneak"
or "aggressive"
. callbacks
is a
map from keyword to function (or var, IFn). Callbacks receive this
(the
trait) as first arg. :load
and :save
also receive a DataKey
.
Callbacks: :load
, :save
, :on-attach
, :on-copy
, :on-despawn
,
:on-pre-spawn
, :run
, :save
.
Can be called multiple times, subsequent calls will only replace the
callbacks. Returns the trait subclass java.lang.Class
.
Note that adding a :run
callback for a Trait that is already attached to an
NPC will not cause it to be called. Remove the Trait from the NPC and add it
back.
To give your trait state, provide an :init
key (map or function that returns
a map), this will provide your trait's initial state. You can use the trait
instance itself as an atom, e.g. call @this
or (swap! this ...)
to get/set
values. Any state set this way will automatically be persisted by the default
:load
/:save
implementations, unless the value has a :no-persist
metadata.
To initialize the Trait instance after instantiation, use :post-init
.
Create a subclass of npcs.citizensapi.trait.Trait, `name` is a simple lowercase identifier of the trait like `"sneak"` or `"aggressive"`. `callbacks` is a map from keyword to function (or var, IFn). Callbacks receive `this` (the trait) as first arg. `:load` and `:save` also receive a `DataKey`. Callbacks: `:load`, `:save`, `:on-attach`, `:on-copy`, `:on-despawn`, `:on-pre-spawn`, `:run`, `:save`. Can be called multiple times, subsequent calls will only replace the callbacks. Returns the trait subclass `java.lang.Class`. Note that adding a `:run` callback for a Trait that is already attached to an NPC will not cause it to be called. Remove the Trait from the NPC and add it back. To give your trait state, provide an `:init` key (map or function that returns a map), this will provide your trait's initial state. You can use the trait instance itself as an atom, e.g. call `@this` or `(swap! this ...)` to get/set values. Any state set this way will automatically be persisted by the default `:load`/`:save` implementations, unless the value has a `:no-persist` metadata. To initialize the Trait instance after instantiation, use `:post-init`.
(npc-trait npc trait-name)
Get the trait with the given name for the given NPC, adds it if it hasn't been added to the NPC already, and returns the Trait instance.
Get the trait with the given name for the given NPC, adds it if it hasn't been added to the NPC already, and returns the Trait instance.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close