diff options
author | Pierre-Yves Rollo <dev@pyrollo.com> | 2015-11-28 20:44:04 +0100 |
---|---|---|
committer | Pierre-Yves Rollo <dev@pyrollo.com> | 2015-11-28 20:44:04 +0100 |
commit | 1b39bf7ae31f0781c65c0a8f9e1d94a37def5f56 (patch) | |
tree | b1ca35fc4238e17eedf782c3b0f631e81d2f7558 /display_lib | |
parent | 9b4513bf9ded0ec759431140b59382fea0bc6009 (diff) | |
download | display_modpack-1b39bf7ae31f0781c65c0a8f9e1d94a37def5f56.tar.gz display_modpack-1b39bf7ae31f0781c65c0a8f9e1d94a37def5f56.tar.bz2 display_modpack-1b39bf7ae31f0781c65c0a8f9e1d94a37def5f56.zip |
Added facedir node support to display_lib, created font_lib, updated mods accordingly
Diffstat (limited to 'display_lib')
-rw-r--r-- | display_lib/API.md | 14 | ||||
-rw-r--r-- | display_lib/README.md | 4 | ||||
-rw-r--r-- | display_lib/init.lua | 98 |
3 files changed, 88 insertions, 28 deletions
diff --git a/display_lib/API.md b/display_lib/API.md index 7bfaaef..148db60 100644 --- a/display_lib/API.md +++ b/display_lib/API.md @@ -1,5 +1,6 @@ # Display Lib API -This document describes Display Lib API. Display Lib allows to add a dynamic display on a node. Node must be wallmounted and Display Lib limits its rotation to vertical positions. +This document describes Display Lib API. Display Lib allows to add a dynamic display on a node. Display Lib limits node rotations. For wallmounted, only vertical positionning is available, and for facedir, only first four position are availabel (those with default axis). + ## Provided methods ### update\_entities **display\_lib.update\_entities(pos)** @@ -38,7 +39,12 @@ This is a helper to register entities used for display. * Register display entities with **register\_display\_entity** * Register node with : - **on\_place**, **on\_construct**, **on\_destruct** and **on\_rotate** callbacks using **display\_lib** callbacks. - - a **display\_entities** field in node definition containing a entity name indexed table. For each entity, two fields : **depth** indicates the entity position (-0.5 to 0.5) and **on_display_update** is a callback in charge of setting up entity texture. + - a **display\_entities** field in node definition containing a entity name indexed table. See below for description of each display\_entities fields. + +### Display_entities fields +**depth**, **right** and **height** : Entity position regarding to node facedir/wallmounted main axis. Values for these fields can be any number between -0.5 and 0.5 (default value is 0). Position 0,0,0 is the center of the node. **depth** goes from front (-0.5) to rear (0.5), **height** goes from bottom (-0.5) to top (0.5) and **height** goes from left (-0.5) to right (0.5). + +**on_display_update** is a callback in charge of setting up entity texture. If not set, entity will have no texture and will be displayed as unknown item. ### Example @@ -60,9 +66,9 @@ This is a helper to register entities used for display. paramtype2 = "wallmounted", ... display_entities = { - ["mymod:entity1"] = { depth = -0.3, + ["mymod:entity1"] = { depth = 0.3, on_display_update = my_display_update1}, - ["mymod:entity1"] = { depth = -0.2, + ["mymod:entity1"] = { depth = 0.2, height = 0.1, on_display_update = my_display_update2}, }, ... diff --git a/display_lib/README.md b/display_lib/README.md index 7ca97b2..b075954 100644 --- a/display_lib/README.md +++ b/display_lib/README.md @@ -1,8 +1,8 @@ # Dislpay Lib -This library's purpose is to ease creation of wallmounted nodes with a display on front side. For example, signs and clocks. Display can be dynamic and/or different for each node instance. +This library's purpose is to ease creation of nodes with one or more displays on sides. For example, signs and clocks. Display can be dynamic and/or different for each node instance. -**Limitations**: This lib uses entities to draw display. This means display has to be vertical. So display nodes are only wallmounted vertically. +**Limitations**: This lib uses entities to draw display. This means display has to be vertical. So display nodes rotation are limitated to "upside up" positions. **Dependancies**:default diff --git a/display_lib/init.lua b/display_lib/init.lua index eaddfd3..276445d 100644 --- a/display_lib/init.lua +++ b/display_lib/init.lua @@ -6,14 +6,59 @@ display_lib = {} -- Miscelaneous values depending on wallmounted param2 local wallmounted_values = { - [0]={dx=0, dz=0, lx=0, lz=0, yaw=0, rotate=0}, -- Should never be used - {dx=1, dz=0, lx=0, lz=0, yaw=0, rotate=1}, -- Should never be used - {dx=1, dz=0, lx=0, lz=-1, yaw=-math.pi/2, rotate=4}, - {dx=-1, dz=0, lx=0, lz=1, yaw=math.pi/2, rotate=5}, - {dx=0, dz=1, lx=1, lz=0, yaw=0, rotate=3}, - {dx=0, dz=-1, lx=-1, lz=0, yaw=math.pi, rotate=2} + [0]={dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, -- Should never be used + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=1}, -- Should never be used + {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=5}, + {dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=4}, + {dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=2}, + {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3} } +-- Miscelaneous values depending on facedir param2 +local facedir_values = { + [0]={dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=1}, + {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2}, + {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3}, + {dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=0}, + -- Forbiden values : + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + } + +-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity, +-- rotate = next facedir/wallmount on rotate + +local function get_values(node) + local ndef = minetest.registered_nodes[node.name] + + if ndef then + if ndef.paramtype2 == "wallmounted" then + return wallmounted_values[node.param2] + end + if ndef.paramtype2 == "facedir" then + return facedir_values[node.param2] + end + end +end + --- Gets the display entities attached with a node. Removes extra ones local function get_entities(pos) local objrefs = {} @@ -45,23 +90,24 @@ end local function place_entities(pos) local node = minetest.get_node(pos) local ndef = minetest.registered_nodes[node.name] - local values = wallmounted_values[node.param2] + local values = get_values(node) local objrefs = get_entities(pos) - if ndef and ndef.display_entities then + if values and ndef and ndef.display_entities then + for entity_name, props in pairs(ndef.display_entities) do local depth = clip_pos_prop(props.depth) - local top = clip_pos_prop(props.top) - local left = clip_pos_prop(props.left) + local height = clip_pos_prop(props.height) + local right = clip_pos_prop(props.right) if not objrefs[entity_name] then objrefs[entity_name] = minetest.add_entity(pos, entity_name) end objrefs[entity_name]:setpos({ - x = pos.x - values.dx * depth + values.lx * left, - y = pos.y + top, - z = pos.z - values.dz * depth + values.lz * left}) + x = pos.x - values.dx * depth + values.rx * right, + y = pos.y + height, + z = pos.z - values.dz * depth + values.rz * right}) objrefs[entity_name]:setyaw(values.yaw) end @@ -97,19 +143,26 @@ end --- On_place callback for display_lib items. Does nothing more than preventing item --- from being placed on ceiling or ground function display_lib.on_place(itemstack, placer, pointed_thing) + local ndef = minetest.registered_nodes[itemstack.name] local above = pointed_thing.above local under = pointed_thing.under local dir = {x = under.x - above.x, y = under.y - above.y, z = under.z - above.z} - local wdir = minetest.dir_to_wallmounted(dir) - if wdir == 0 or wdir == 1 then - dir = placer:get_look_dir() - dir.y = 0 - wdir = minetest.dir_to_wallmounted(dir) + if ndef and ndef.paramtype2 == "wallmounted" then + local wdir = minetest.dir_to_wallmounted(dir) + + if wdir == 0 or wdir == 1 then + dir = placer:get_look_dir() + dir.y = 0 + wdir = minetest.dir_to_wallmounted(dir) + end + + return minetest.item_place(itemstack, placer, pointed_thing, wdir) + else + return minetest.item_place(itemstack, placer, pointed_thing) end - return minetest.item_place(itemstack, placer, pointed_thing, wdir) end --- On_construct callback for display_lib items. Creates entities and update them. @@ -126,13 +179,14 @@ function display_lib.on_destruct(pos) end end - -- On_rotate (screwdriver) callback for display_lib items. Prevents axis rotation and reorients entities. function display_lib.on_rotate(pos, node, user, mode, new_param2) if mode ~= screwdriver.ROTATE_FACE then return false end - if wallmounted_values[node.param2] then - minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = wallmounted_values[node.param2].rotate}) + local values = get_values(node) + + if values then + minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = values.rotate}) place_entities(pos) return true else |