diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a28a34b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "display_api"] + path = display_api + url = https://github.com/pyrollo/display_api.git diff --git a/display_api b/display_api new file mode 160000 index 0000000..246b7f9 --- /dev/null +++ b/display_api @@ -0,0 +1 @@ +Subproject commit 246b7f958863e7f6b7f604b09361696226928a7b diff --git a/display_api/API.md b/display_api/API.md deleted file mode 100644 index 0d52e29..0000000 --- a/display_api/API.md +++ /dev/null @@ -1,94 +0,0 @@ -# Display Lib API -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)** - -This method triggers entities update for the display node at pos. Actual entity update is made by `on_display_update` callback associated to the entity. - -`pos`: Position of the node -### register\_display\_entity -**display\_lib.register\_display\_entity(entity_name)** - -This is a helper to register entities used for display. - -`entity_name`: Name of the entity to register. -## Provided callback implementations -### on_place -**display\_lib.on\_place(itemstack, placer, pointed\_thing)** - -`on_place` node callback implementation. Display nodes should have this callback (avoid placement of horizontal display node). -### on_construct -**display\_lib.on\_construct(pos)** - -`on_construct` node callback implementation. Display nodes should have this callback (creates, places and updates display entities on node construction). -### on_destruct -**display\_lib.on_destruct(pos)** - -`on_destruct` node callback implementation. Display nodes should have this callback (removes display entities on node destruction). -### on_rotate -**display\_lib.on\_rotate(pos, node, user, mode, new_param2)** - -`on_rotate` node callback implementation. Display nodes should have this callback (restricts rotations and rotates display entities associated with node). -### on_activate -**display\_lib.on_activate(entity, staticdata)** - -`On_activate` entity callback implementation for display entities. No need of this method if display entities have been registered using `register_display_entity` (callback is already set). - -## Howto register a display node -* Register display entities with `register_display_entity` - -* Register node with : - - `on_place`, `on_construct`, `on_destruct` and `on_rotate` callbacks using display_api callbacks. -  - - `display_modpack_node` group. This will make this node have their entities updated as soon as the mapblock is loaded (Useful after /clearobjects). -  - - 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 -`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. - -`depth`, `right` and `height` : Entity position regarding to node facedir/wallmounted main axis. -Values for these fields can be any number between -1.5 and 1.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 `right` goes from left (-0.5) to right (0.5). - -In order to avoid flickering text, it's better to have text a little behind node surface. A good spacing value is given by `display_api.entity_spacing` variable. - -### Example - - display_api.register_display_entity("mymod:entity1") - display_api.register_display_entity("mymod:entity2") - - function my_display_update1(pos, objref) - objref:set_properties({ textures= {"mytexture1.png"}, - visual_size = {x=1, y=1} }) - end - - function my_display_update2(pos, objref) - objref:set_properties({ textures= {"mytexture2.png"}, -                         visual_size = {x=1, y=1} }) - end - - minetest.register_node("mymod:test_display_node", { - ... - paramtype2 = "facedir", - ... - groups = { display_modpack_node = 1, ... }, - ... - display_entities = { - ["mymod:entity1"] = { - depth = 0.3, - on_display_update = my_display_update1 }, - ["mymod:entity1"] = { - depth = 0.2, height = 0.1, - on_display_update = my_display_update2 }, - }, - ... - on_place = display_api.on_place, - on_construct = display_api.on_construct, - on_destruct = display_api.on_destruct, - on_rotate = display_api.on_rotate, - ... - }) diff --git a/display_api/LICENSE.txt b/display_api/LICENSE.txt deleted file mode 100644 index 341c30b..0000000 --- a/display_api/LICENSE.txt +++ /dev/null @@ -1,166 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - diff --git a/display_api/README.md b/display_api/README.md deleted file mode 100644 index f51996d..0000000 --- a/display_api/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Display Lib - -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 rotation are limitated to "upside up" positions. - -**Dependancies**:default - -**License**: LPGL - -**API**: See [API.md](https://github.com/pyrollo/display_modpack/blob/master/display_api/API.md) document please. - -For more information, see the [forum topic](https://forum.minetest.net/viewtopic.php?t=19365) at the Minetest forums. - diff --git a/display_api/copyright.txt b/display_api/copyright.txt deleted file mode 100644 index 02b8467..0000000 --- a/display_api/copyright.txt +++ /dev/null @@ -1,6 +0,0 @@ -Code by Pierre-Yves Rollo (pyrollo) -Contributors: -(gpcf): Compatibility with signs lib -(Thomas--S): Fix /clearobjects bug -(12Me21): on_place improvement and code style fixing - diff --git a/display_api/depends.txt b/display_api/depends.txt deleted file mode 100644 index e69de29..0000000 diff --git a/display_api/init.lua b/display_api/init.lua deleted file mode 100644 index ca7b779..0000000 --- a/display_api/init.lua +++ /dev/null @@ -1,269 +0,0 @@ ---[[ - display_api mod for Minetest - Library to add dynamic display - capabilities to nodes - (c) Pierre-Yves Rollo - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . ---]] - -display_api = {} - --- Prefered gap between node and entity --- Entity positionment is up to mods but it is a good practice to use this --- variable as spacing between entity and node -display_api.entity_spacing = 0.002 - --- Miscelaneous values depending on wallmounted param2 -local wallmounted_values = { - [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 - ---- Checks if the object is related to the given position -local function check_entity_pos(pos, objref) - local real_pos = vector.round(objref:get_pos()) - local pos_hash = objref:get_luaentity().pos - if pos_hash == nil then - return vector.equals(real_pos, vector.round(pos)) - else - return vector.equals(minetest.get_position_from_hash(pos_hash), pos) - end -end - ---- Gets the display entities attached with a node. Removes extra ones -local function get_entities(pos) - local objrefs = {} - local ndef = minetest.registered_nodes[minetest.get_node(pos).name] - if ndef and ndef.display_entities then - for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 1.5)) do - local entity = objref:get_luaentity() - if entity and ndef.display_entities[entity.name] and check_entity_pos(pos, objref) then - if objrefs[entity.name] then - objref:remove() - else - objrefs[entity.name] = objref - end - end - end - end - return objrefs -end - -local function clip_pos_prop(posprop) - if posprop then - return math.max(-1.5, math.min(1.5, posprop)) - else - return 0 - end -end - ---- (Create and) place display entities according to the node orientation -local function place_entities(pos) - local node = minetest.get_node(pos) - local ndef = minetest.registered_nodes[node.name] - local values = get_values(node) - local objrefs = get_entities(pos) - - 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 right = clip_pos_prop(props.right) - local top = clip_pos_prop(props.top) - 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.rx * right, - y = pos.y - top, - z = pos.z - values.dz * depth + values.rz * right}) - - objrefs[entity_name]:setyaw(values.yaw) - end - end - return objrefs -end - ---- Call on_display_update callback of a node for one of its display entities -local function call_node_on_display_update(pos, objref) - local ndef = minetest.registered_nodes[minetest.get_node(pos).name] - local entity = objref:get_luaentity() - if ndef and ndef.display_entities and entity and ndef.display_entities[entity.name] then - ndef.display_entities[entity.name].on_display_update(pos, objref) - end -end - ---- Force entity update -function display_api.update_entities(pos) - local objrefs = place_entities(pos) - for _, objref in pairs(objrefs) do - objref:get_luaentity().pos = minetest.hash_node_position(pos) - call_node_on_display_update(pos, objref) - end -end - ---- On_activate callback for display_api entities. Calls on_display_update callbacks ---- of corresponding node for each entity. -function display_api.on_activate(entity, staticdata) - if entity then - if string.sub(staticdata, 1, string.len("return")) == "return" then - local data = core.deserialize(staticdata) - if data and type(data) == "table" then - entity.pos = data.pos - end - end - entity.object:set_armor_groups({immortal=1}) - local pos - if entity.pos then - pos = minetest.get_position_from_hash(entity.pos) - else - pos = entity.object:getpos() - end - display_api.update_entities(pos) - end -end - ---- On_place callback for display_api items. Does nothing more than preventing item ---- from being placed on ceiling or ground -function display_api.on_place(itemstack, placer, pointed_thing) - local ndef = itemstack:get_definition() - local above = pointed_thing.above - local under = pointed_thing.under - local dir = {x = under.x - above.x, - y = 0, - z = under.z - above.z} - - -- If item is not placed on a wall, use the player's view direction instead - if dir.x == 0 and dir.z == 0 then - dir = placer:get_look_dir() - dir.y = 0 - end - - local param2 - if ndef then - if ndef.paramtype2 == "wallmounted" then - param2 = minetest.dir_to_wallmounted(dir) - elseif ndef.paramtype2 == "facedir" then - param2 = minetest.dir_to_facedir(dir) - end - end - return minetest.item_place(itemstack, placer, pointed_thing, param2) -end - ---- On_construct callback for display_api items. Creates entities and update them. -function display_api.on_construct(pos) - display_api.update_entities(pos) -end - ---- On_destruct callback for display_api items. Removes entities. -function display_api.on_destruct(pos) - local objrefs = get_entities(pos) - - for _, objref in pairs(objrefs) do - objref:remove() - end -end - --- On_rotate (screwdriver) callback for display_api items. Prevents axis rotation and reorients entities. -function display_api.on_rotate(pos, node, user, mode, new_param2) - if mode ~= 1 then return false end - - 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 - return false - end -end - ---- Creates display entity with some fields and the on_activate callback -function display_api.register_display_entity(entity_name) - if not minetest.registered_entity then - minetest.register_entity(':'..entity_name, { - collisionbox = { 0, 0, 0, 0, 0, 0 }, - visual = "upright_sprite", - textures = {}, - on_activate = display_api.on_activate, - get_staticdata = function(self) - return minetest.serialize({ - pos = self.pos, - }) - end, - }) - end -end - -minetest.register_lbm({ - label = "Update display_api entities", - name = "display_api:update_entities", - run_at_every_load = true, - nodenames = {"group:display_modpack_node", "group:display_lib_node"}, - action = function(pos, node) display_api.update_entities(pos) end, -}) - --- Compatibility -display_lib = display_api