3 In this text, common terms such as `pos`, `node`, or `placer`/`digger` will not be explained unless they have a different meaning than what's usually used in Minetest mods. See [minetest/doc/lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt) for details on these and other common terms, if necessary. Similarly, common shorthand such as `int`, `float`, etc. should require no explanation.
7 * `signs_lib.register_sign(nodename, def)`
9 To put it simply, where you'd have used `minetest.register_node()` before, just replace it with this call. The syntax is identical, and in general, all settings/items allowed there are allowed here as well. Anything that `signs_lib` doesn't need to override or alter will be passed straight through to `register_node()`, unchanged (such as `description`, `tiles`, or `inventory_image`).
11 The supplied `nodename` will be prepended with `":"`, so that any mod can register signs under any other mod's namespace, if desired.
13 Many items have default settings applied when omitted, most of which would produce something equivalent to `"default:sign_wall_wood"` if enough other node defintion settings were to be included.
15 * `drawtype = "string"`
21 Default: `"signs_lib_standard_wall_sign.obj"`.
23 * `paramtype = "string"`
27 * `paramtype2 = "string"`
29 As with any other node, this determines how param2 is interpreted. Since these are signs, only two modes make sense: `"wallmounted"` and `"facedir"`. Any other string is the same as `"facedir"`.
31 Default: `"wallmounted"`
33 * `wield_image = "string"`
35 Default: whatever the `inventory_image` is set to (if anything).
39 Sets the sign's groups, as usual. In addition to whatever arbitrary groups you may have in mind, there are two presets available (both of which have `attached_node` removed, and `sign = 1` added):
41 * `signs_lib.standard_wood_groups`, inherited from `"default:sign_wall_wood"`
42 * `signs_lib.standard_steel_groups`, inherited from `"default:sign_wall_steel"`
44 Default: `signs_lib.standard_wood_groups`
46 * `sounds = something`
48 Sets the sign's sound profile, as usual. In addition to whatever sound profile you may have in mind, there are two presets available:
50 * `signs_lib.standard_wood_sign_sounds`, inherited from `"default:sign_wall_wood"`
51 * `signs_lib.standard_steel_sign_sounds`, inherited from `"default:sign_wall_steel"`
53 Default: `signs_lib.standard_wood_sign_sounds`
57 Default: inherited from the `nodename` argument given to `signs_lib.register_sign()`
59 * `after_place_node = function(pos, placer, itemstack, pointed_thing, locked)`
61 See below under "Main functions".
63 Default: `signs_lib.after_place_node`
65 * `on_rightclick = function(pos)`
67 See below under "Main functions".
69 Default: `signs_lib.construct_sign`
71 * `on_construct = function(pos)`
73 See below under "Main functions".
75 Default: `signs_lib.construct_sign`
77 * `on_destruct = function(pos)`
79 See below under "Main functions".
81 Default: `signs_lib.destruct_sign`
83 * `on_receive_fields = function(pos, formname, fields, sender)`
85 See below under "Main functions".
87 Default: `signs_lib.receive_fields`
89 * `on_punch = function(pos)`
91 See below under "Main functions".
93 Default: `signs_lib.update_sign`
95 * `default_color = "string"`
97 Sets the default text color for this sign, in hexadecimal (`0-9`, `a-f`), from the standard Linux/IRC/CGA color palette. Same as the colors shown in the sign's formspec.
99 Default: `"0"` (black)
101 * `number_of_lines = int`
103 Just what it says on the tin. How many lines you can fit will vary with overall sign node size, font size, scaling, line spacing, etc.
107 * `horiz_scaling = float`
109 Scaling factor applied to the entity texture horizontal resolution. Larger values increase the resolution. Since a given sign's entity is always displayed at a fixed visual scale, increasing this setting squeezes more pixels into the same horizontal space, making the text appear narrower.
113 * `vert_scaling = float`
115 Scaling factor applied to the entity texture's vertical resolution. Larger values increase the resolution, making the text appear shorter, and increasing the number of lines the sign can display.
119 * `line_spacing = int`
121 Number of blank pixels to add between lines.
127 Selects which font to use, either 15 or 31 (pixel height). This setting directly affects the sign's vertical resolution.
133 Starting X position in pixels, relative to the text entity UV map left edge.
139 Starting Y position in pixels, relative to the text entity UV map top edge.
143 * `chars_per_line = int`
145 Approximate number of characters that should fit on a line. This, the selected font's average character width, and the `horiz_scaling` together set the horizontal resolution of the text entity's texture.
149 * `entity_info = something`
151 Describes the entity model and yaw table to use. May be one of:
153 * A table specifying the two directly, such as:
157 mesh = "signs_lib_standard_wall_sign_entity.obj",
158 yaw = signs_lib.wallmounted_yaw
161 * `signs_lib.standard_yaw` is also available as a yaw preset, if desired.
163 * `"standard"`: just use the standard wood/steel sign model, in wallmounted mode. Equivalent to the example above.
164 * If this item is `nil`/not set, the sign will not have a formspec, basically all text-related settings will be ignored and/or omitted entirely, and no entity will be spawned for this sign, thus the sign will not be writable. This is the default, and is of course what one would want for any sign that's just an image wrapped around a model, as in most of the signs in [my street signs mod](https://forum.minetest.net/viewtopic.php?t=20866).
166 * `allow_hanging = bool`
168 If `true`, allow the registration function to create a "hanging from the ceiling" version of the initial, base sign node.
172 * `allow_onpole = bool`
174 Allow creation of an on-pole variant of the base sign.
178 * `allow_onpole_horizontal = bool`
180 Allow creation of an on-horizontal-pole variant. This flag is independent of `allow_onpole`; the mod may specify either or both.
184 * `allow_widefont = bool`
186 Just what it says on the tin. If enabled, the formspec will have a little "on/off switch" left of the "Write" button, to select the font width.
192 Sets this sign to be locked/owned, like the original default steel wall sign.
196 ### Example sign definition:
199 signs_lib.register_sign("basic_signs:sign_wall_glass", {
200 description = S("Glass Sign"),
202 { name = "basic_signs_sign_wall_glass.png", backface_culling = true},
203 "basic_signs_sign_wall_glass_edges.png",
205 inventory_image = "basic_signs_sign_wall_glass_inv.png",
208 entity_info = "standard",
209 sounds = default.node_sound_glass_defaults(),
210 groups = {cracky = 3, oddly_breakable_by_hand = 3},
211 allow_hanging = true,
212 allow_widefont = true,
214 allow_onpole_horizontal = true,
215 use_texture_alpha = true,
219 ### Main functions used within a sign definition
221 * `signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locked)`
223 Determines if the `pointed_thing` is a wall, floor, ceiling, or pole/post, and swaps the placed sign for the correct model.
225 * `locked`: if set to true, the sign's meta will be tweaked to indicate its ownership by the `placer`.
227 * `signs_lib.construct_sign(pos)`
229 Sets up the sign's formspec and infotext overlay.
231 * `signs_lib.destruct_sign(pos)`
233 Deletes the sign's entity, if any, when the sign is dug.
235 * `signs_lib.receive_fields(pos, formname, fields, sender)`
237 This handles the text input and wide font on/off switch, logging any actions the user takes. Bails-out silently if the user is not allowed to edit the sign. See the standard Minetest lua_api.txt for details.
239 * `signs_lib.update_sign(pos, fields)`
241 If the sign's writable, this deletes any entities in the sign's node space, spawns a new one, and renders whatever text is in the sign's meta.
243 * `signs_lib.can_modify(pos, player)`
245 Returns `true` if the player is allowed to dig, edit, or change the font width of the sign.
247 * `signs_lib.handle_rotation(pos, node, player, mode)`
249 Just what it says on the tin. Limits the sign's rotation as needed (for example, a sign on a horizontal pole can only flip from one side to the other).
251 * `mode`: the screwdriver's mode, as passed from the screwdriver mod.
253 Returns `false` if the user tried to right-click with the screwdriver, `true` otherwise.
255 * `signs_lib.make_selection_boxes(x_size, y_size, foo, x_offset, y_offset, z_offset, is_facedir)`
257 * `x_size`/`y_size`: dimensions in inches. One node is 39.37 inches on a side. This function uses inches instead of metric because it started out as a selection box maker for MUTCD-compliant signs, which are measured in inches.
258 * `x_offset`/`y_offset`/`z_offset`: shift the selection box (inches, defaults to centered, with the back face flush with the back of the node).
259 * `is_facedir`: if unset, the selection boxes will be created with the assumption that `paramtype2 = "wallmounted"` mode is set. Any other value creates a selection box for "facedir" mode.
260 * `foo` is ignored (leftover from an argument that's long since been rendered obsolete.
262 Returns a table suitable for the `selection_box` node definition entry.
264 #### Helper functions
266 You probably won't need to call any of these directly.
268 * `signs_lib.read_image_size(filename)`
270 Returns width and height of the indicated PNG file (return values will be gibberish if it isn't a PNG).
272 * `signs_lib.split_lines_and_words(text)`
274 Just what it says on the tin.
276 Returns a table of lines, each line entry being a table of words.
278 * `signs_lib.delete_objects(pos)`
280 Deletes all entities within the node space given by `pos`.
282 * `signs_lib.spawn_entity(pos, texture)`
284 Spawns a new text entity at the given position and assigns the supplied `texture` to it, if any.
286 * `signs_lib.check_for_pole(pos, pointed_thing)`
288 Attempts to determine if the `pointed_thing` qualifies as a vertical pole or post of some kind.
290 Returns `true` if a suitable pole/post is found
292 * `signs_lib.check_for_horizontal_pole(pos, pointed_thing)`
294 Same idea, but for horizontal poles/posts.
296 Returns `true` if a suitable pole/post is found.
298 * `signs_lib.check_for_ceiling(pointed_thing)`
300 Returns `true` if the `pointed_thing` appears to be the bottom of a node.
302 * `signs_lib.check_for_floor(pointed_thing)`
304 Returns `true` if the `pointed_thing` appears to be the top of a node.
306 * `signs_lib.set_obj_text(pos, text)`
308 Cooks the supplied `text` as needed and passes it to the entity rendering code. Essentially, this is where rendering text into an image starts.
310 ## Options for pole/post nodes
312 Occasionally, you'll run into a node that either looks like a pole/post, or has one in the middle of its node space (with room to fit a sign in there), but which isn't detected as a pole/post by the standard sign placement code. In these situations, some kind of special check is needed.
314 Supplying one or both of the following in the pole/post node's definition will cause `signs_lib` to skip its usual pole/post detection code, in favor of the supplied function(s).
316 * `check_for_pole = function(pos, node, def, pole_pos, pole_node, pole_def)`
318 If supplied, this function will be run when the mod is looking for a normal vertical pole/post. Useful if the target node's orientation and/or shape determine what sides a sign can attach to. For example, [Pipeworks](https://forum.minetest.net/viewtopic.php?pid=27794) uses this to figure out if a sign can be attached to a tube or pipe, depending on the tube's/pipe's number of junctions, and on its orientation and that of the placed sign.
320 * `def`: the placed sign's node defintion
321 * `pole_pos`: the target node's position
322 * `pole_node`: the target node itself
323 * `pole_def`: its node definition
325 Your code must return `true` if the sign should attach to the target node.
327 If desired, this entry may simply be set to `check_for_pole = true` if a sign can always attach to this node regardless of facing direction (for example, [Home Decor](https://forum.minetest.net/viewtopic.php?pid=26061) has a round brass pole/post, which always stands vertical, and [Cottages](https://forum.minetest.net/viewtopic.php?id=5120) has a simple table that's basically a fencepost with a platform on top).
329 * `check_for_horiz_pole = function(pos, node, def, pole_pos, pole_node, pole_def)`
331 If supplied, this does the same thing for horizontal poles.
333 Your code must return `true` if the sign should attach to the target node.