4.2 KiB
4.2 KiB
Blueprints API
![](/luk3yx/blueprints/media/commit/8f163f01a5fe4987e574857fbb2459438afe53f1/blueprint-types.png)
Blueprint rules
Blueprint rules define how nodes can be blueprinted. They are just a table with the following parameters:
allowed
: Specifies whether the item is allowed to be blueprinted (true
,false
or'default'
). If this is'default'
, the item will be blueprinted if it is visible in the creative inventory (does not have thenot_in_creative_inventory
group).param2
: Allows the node's param2 to be saved in the blueprint. Defaults totrue
.meta
: Allows the node's metadata to be copied. Can either betrue
to allow everything to be copied, or a table with a list of metadata strings to copy.pvmeta
: A table containing a list of metadata strings to mark as private when restoring from the blueprint.inv_lists
: A table containing the inventory lists to be copied.item
: A custom blueprint item to give the player when blueprinting the object. Made withblueprints.register_blueprint()
.
All parameters are optional, and will default to the ones specified in
core.lua
.
To modify these rules for your node, you can add a _blueprints
field to your
node's definition with a table containing any of the above parameters. Unknown
rules will be silently ignored.
Functions
The following API functions exist, where the node
parameter is normally a
string
:
Node rules and aliases
blueprints.get_rules(node)
: Gets a rules table for the node specified. You should not modify this table, as you may inadvertently modify the default rules. Theallowed
parameter will always be returned with eithertrue
orfalse
, the value for'default'
will be calculated when this is called.blueprints.register_alias(old_node, new_node)
: This will make blueprints treatold_node
as the same asnew_node
internally. Blueprints made withnew_node
can be applied toold_node
s, and the blueprint rules ofnew_node
will be used forold_node
as well.blueprints.check_alias(node)
: Checks for node aliases, will returnnode
if no alias exists. Nodes registered withmesecon.register_node
will be auto-aliased (_on
to_off
), however this can be overridden by adding a new alias. Aliases are not recursive.
Creating/applying blueprint strings/tables.
blueprints.get_blueprint(pos, raw = false, force = false)
: Returns a blueprint string (or table if raw is true) for the object. If the node cannot be blueprinted, this will returnnil
. Ifforce
istrue
, the rules will be ignored and the entire node will be blueprinted.blueprints.apply_blueprint(pos, blueprint, only_if_exists = false, force = false)
: Applies the blueprintblueprint
atpos
, the blueprint specified may be a string or table. Returnstrue
on success ornil
on faliure. Ifforce
istrue
, the rules will be ignored when applying the blueprint. This must also have beentrue
whenget_blueprint
was called.
Other possibly useful function(s).
blueprints.check_protection(pos, name)
: Checks the protection atpos
forname
, automatically recording a violation if one exists. Returnstrue
and records a violation ifname
has no access topos
, otherwise returnsfalse
.
Registering blueprints.
blueprints.register_blueprint(name, def)
: Registers a non-blank blueprint.def
is optional, and if left out, sensible defaults will be used. Any parameters valid with craftitems should work here, howeveron_use
,on_place
,stack_max
and a few others may be overridden. Ifinventory_image
is not specified, one will be generated based on the node name (for exampleblueprints:test_blueprint
would becomeblueprints_test_blueprint.png
) and are overlayed on top of the empty blueprint texture. If you want to use a custom blank blueprint, you can specify theblank
parameter in the table.bluepritns.register_blank_blueprint(name, def)
: The same asreigster_blueprint
, except for blank blueprints.blank
should not be specified here, and adef
containingdescription
is mandatory.