diff options
-rw-r--r-- | LICENSE.txt | 188 | ||||
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | digilines/internal.lua | 16 | ||||
-rw-r--r-- | digilines/util.lua | 15 | ||||
-rw-r--r-- | digilines/wire_std.lua | 3 | ||||
-rw-r--r-- | digilines/wires_common.lua | 11 | ||||
-rw-r--r-- | digilines_inventory/README | 62 | ||||
-rw-r--r-- | digilines_inventory/depends.txt | 1 | ||||
-rw-r--r-- | digilines_inventory/init.lua | 139 | ||||
-rw-r--r-- | digilines_lcd/characters | 3 | ||||
-rw-r--r-- | digilines_lcd/init.lua | 60 | ||||
-rw-r--r-- | digilines_lcd/textures/_co.png | bin | 0 -> 135 bytes | |||
-rw-r--r-- | digilines_lightsensor/init.lua | 12 | ||||
-rw-r--r-- | digilines_rtc/init.lua | 12 |
14 files changed, 471 insertions, 65 deletions
diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..9569df7 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,188 @@ +The LGPLv3 applies to all code in this project. +The WTFPL applies to textures and any other content in this project which is not source code. + +============================================================= + +GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + 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. + + +============================================================= + + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d57f52 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +Digilines +========== +- The minetest counterpart for bus systems like i2c, SPI, RS232, USB - + + +This mod adds digiline wires, an RTC (Real Time Clock), a light sensor as well as an LCD Screen. +Can be used together with the luacontroller from mesecons. See the luacontroller manual for more information. + +Send "GET" to RTC or light sensor to retrieve Data, send any text to LCD to display it. +Select channel by right-clicking items. + +License: + Code: LGPL + Textures: WTFPL diff --git a/digilines/internal.lua b/digilines/internal.lua index ce4012c..f29cc8d 100644 --- a/digilines/internal.lua +++ b/digilines/internal.lua @@ -14,8 +14,8 @@ function digiline:importrules(spec, node) end function digiline:getAnyInputRules(pos) - local node = minetest.env:get_node(pos) - spec = digiline:getspec(node) + local node = minetest.get_node(pos) + local spec = digiline:getspec(node) if not spec then return end if spec.wire then @@ -29,8 +29,8 @@ function digiline:getAnyInputRules(pos) end function digiline:getAnyOutputRules(pos) - local node = minetest.env:get_node(pos) - spec = digiline:getspec(node) + local node = minetest.get_node(pos) + local spec = digiline:getspec(node) if not spec then return end if spec.wire then @@ -66,12 +66,11 @@ function digiline:rules_link_anydir(output, input) end function digiline:transmit(pos, channel, msg, checked) - checked = checked or {} local checkedid = tostring(pos.x).."_"..tostring(pos.y).."_"..tostring(pos.z) - if checked[checkedid] then return checked end + if checked[checkedid] then return end checked[checkedid] = true - local node = minetest.env:get_node(pos) + local node = minetest.get_node(pos) local spec = digiline:getspec(node) if not spec then return end @@ -86,9 +85,8 @@ function digiline:transmit(pos, channel, msg, checked) local rules = digiline:importrules(spec.wire.rules, node) for _,rule in ipairs(rules) do if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then - checked = digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) + digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) end end end - return checked end diff --git a/digilines/util.lua b/digilines/util.lua index dad6579..9982257 100644 --- a/digilines/util.lua +++ b/digilines/util.lua @@ -50,3 +50,18 @@ function digiline:rotate_rules_up(rules) end return nr end + +function digiline:tablecopy(table) -- deep table copy + if type(table) ~= "table" then return table end -- no need to copy + local newtable = {} + + for idx, item in pairs(table) do + if type(item) == "table" then + newtable[idx] = mesecon:tablecopy(item) + else + newtable[idx] = item + end + end + + return newtable +end diff --git a/digilines/wire_std.lua b/digilines/wire_std.lua index 32645e9..71bbd0f 100644 --- a/digilines/wire_std.lua +++ b/digilines/wire_std.lua @@ -91,7 +91,8 @@ for zmy=0, 1 do { wire = { - basename = "digilines:wire_std_" + basename = "digilines:wire_std_", + use_autoconnect = true } }, selection_box = { diff --git a/digilines/wires_common.lua b/digilines/wires_common.lua index 4370241..44414f2 100644 --- a/digilines/wires_common.lua +++ b/digilines/wires_common.lua @@ -42,9 +42,12 @@ function digiline:update_autoconnect(pos, secondcall) digiline:update_autoconnect(zmympos, true) end - local digilinespec = minetest.registered_nodes[minetest.env:get_node(pos).name].digiline - if not digilinespec then return nil end - if not digilinespec.wire then return nil end + local def = minetest.registered_nodes[minetest.get_node(pos).name] + local digilinespec = def and def.digiline + if not (digilinespec and digilinespec.wire and + digilinespec.wire.use_autoconnect) then + return nil + end local zmg = digiline:rules_link_anydir(pos, zmpos) local zmymg = digiline:rules_link_anydir(pos, zmympos) @@ -80,5 +83,5 @@ function digiline:update_autoconnect(pos, secondcall) tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy) - minetest.env:set_node(pos, {name = digilinespec.wire.basename..nodeid}) + minetest.set_node(pos, {name = digilinespec.wire.basename..nodeid}) end diff --git a/digilines_inventory/README b/digilines_inventory/README new file mode 100644 index 0000000..a88115f --- /dev/null +++ b/digilines_inventory/README @@ -0,0 +1,62 @@ +Basic idea: place this chest down at the end of a pipeline. Feed stuff into it. Attach a luacontroller to it with a digiline in between. Program the luacontroller to turn on a wire to stop the pipeline when the chest is full. Don't put more than one kind of item down the pipeline into the chest, unless you want weird tricksy behavior. + +...[F]===[C]--{L} + |__________| + [B] +F: filter +B: blinky plant +C: digiline chest +L: luacontroller +==: pipe +__: mesecons +--: digiline + +Make sure you use mem in the luacontroller to keep the mesecon wire on indefinitely after the chest signals full. When it signals "take" someone took an item out and you can start the pipeline up again. +This may be a bad idea if they only take half a stack or something. Oh well. + +When you put something in, you get a "put" to indicate it's OK (sort of (still buggy)) and can fit inside the chest. When you get a "lost", that means it won't fit inside the chest, and will bounce, possibly popping out. When you get a "overflow" that means you tried to add something to a chest that just filled up, and the stack will bounce. When you get a "full" that means the chest just filled up. + +"Filled up" for all intents and purposes, means taking the type of whatever just went into the chest, and seeing if at least 1 of that type can be added to the chest. If it cannot, then it's filled up. That means a chest full of stacks of 30 copper and one spot of 98 gold, and you add one gold to that, it will say it's full. Add 30 copper to it, and it won't. + +Generally you'll be working with full stacks in pipeworks. Even the non-mese filters will accumulate items in a chest, and not spread them out into multiple stacks. And generally your destination chests will each have one of any kind of item. So all you have to worry about is when you've got 99 everywhere, and one space possibly free. A mese filter can fail on that in fact, for instance if you have room for 45 gold, and it tries to push a stack of 50 gold. All 50 will bounce! The code for chests isn't smart enough to add the 45 and bounce the leftover 5. So only use mese filters when you're sure a full stack has accumulated for the filter to push, and there are no partial stacks at the destination. + +For some reason when an "overflow" happens, when it checks if the stack can fit inside the chest, the answer is yes it can fit! Then it doesn't. Sort of buggy. + +itemstack - the qualified name, a space, then the amount. If the space and amount are ommitted, that represents just 1. + +examples: "default:chest 33" "default:coal" "default:axe_diamond" + +bounce + - when an item cannot enter the destination container it will travel back up the tube it came from, going along alternate routes if they exist, but otherwise popping out of the tube. + +popping out + - the little thingy travelling through the tube disappears, and an entity of the item appears, as if it was just dropped. This entity can expire, losing your items permanently! + + +The messages are: + + +put <itemstack> + - this means that the inventory claimed it could fit that stack of items inside it. Inventories lie. But with the above caveats this is quite usable. +lost <itemstack> + - the stack couldn't fit in the chest and bounces. +full <itemstack> <count> + - the chest has been filled. The itemstack is what filled it. count is what's leftover. + until chests can suck up part of a stack and not bounce the whole stack, that count will + always be 0 +overflow <itemstack> <count> + - generally this is the same as lost, except that the "put" event happened, meaning that the + itemstack was allowed in the chest. + - this will happen with two stacks in rapid succession, the first filling the chest, and the + second bouncing. the <count> in this case will be the amount of the second. + - overflow can't happen with two different kinds of items, you'll get a put, maybe full, then lost for the second kind + +Tricky situation: +if you have a blank spot and put say 82 torches down your pipeline, followed by 99 coal, the 82 torches will go in the chest, and the chest will see that 1 more torch can fit since that would only go to 83. Since 1 more torch can fit, no "full" message will fire off. Then when the coal hits the chest, the "fail" message will fire and the coal will bounce out. The chest couldn't predict that coal would be coming next, so it couldn't know that the chest is full, for coal, while not full for torches. + +TODO: + - make chest.lua a mixin that gets both default and locked chests + - digiline aware furnaces + - digiline aware technic machines, grinders, alloy furnaces, etc + - the pipes going into the chests don't snap to the pipe holes in the digiline chests. They still act fine as pipeworks destinations though. + - digiline chests seem to be immune to filters. But it's late and I'm shipping this. Someone else can figure out why the chests aren't acting like pipeworks chests, despite cloning the pipeworks chest's object. Oh who am I kidding. I'll do it myself I guess, once I've lost hope of aid again. diff --git a/digilines_inventory/depends.txt b/digilines_inventory/depends.txt new file mode 100644 index 0000000..da1d119 --- /dev/null +++ b/digilines_inventory/depends.txt @@ -0,0 +1 @@ +digilines diff --git a/digilines_inventory/init.lua b/digilines_inventory/init.lua new file mode 100644 index 0000000..4fe9397 --- /dev/null +++ b/digilines_inventory/init.lua @@ -0,0 +1,139 @@ +if not minetest.get_modpath("pipeworks") then + print("[Digilines] Install pipeworks if you want to use the digilines chest") + return +end + +local defaultChest = minetest.registered_nodes['default:chest'] + +local sendMessage = function (pos, msg, channel) + if channel == nil then + channel = minetest.get_meta(pos):get_string("channel") + end + digiline:receptor_send(pos,digiline.rules.default,channel,msg) +end + +tableMerge = function(first_table,second_table) + if second_table == nil then return end + for k,v in pairs(second_table) do first_table[k] = v end +end + +tableMergeImmutable = function(first_table, second_table) + if first_table == nil then return second_table end + if second_table == nil then return first_table end + copy = digiline:tablecopy(first_table) + for k,v in pairs(second_table) do copy[k] = v end + return copy +end + +local mychest = digiline:tablecopy(defaultChest) + +function defer(what,...) + if what then + return what(...) + end +end + +function maybeString(stack) + if type(stack)=='string' then return stack + elseif type(stack)=='table' then return dump(stack) + else return stack:to_string() + end +end + +mychest = tableMergeImmutable(defaultChest,{ + description = "Digiline Chest", + digiline = { + receptor = {}, + effector = { + action = function(pos,node,channel,msg) end + } + }, + on_construct = function(pos) + defaultChest.on_construct(pos) + local meta = minetest.get_meta(pos) + -- we'll sneak into row 4 thanks + meta:set_string("formspec",meta:get_string("formspec").."\nfield[2,4.5;5,1;channel;Channel;${channel}]") + end, + on_receive_fields = function(pos, formname, fields, sender) + if fields.channel ~= nil then + minetest.get_meta(pos):set_string("channel",fields.channel) + return defer(defaultChest.on_receive_fields, pos, formname, fields, sender) + end + end, + tube = tableMergeImmutable(defaultChest.tube, { + -- note: mese filters cannot put part of a stack in the destination. + -- space for 50 coal with 99 added will pop out 99, not 49. + connects = function(i,param2) + return not pipeworks.connects.facingFront(i,param2) + end, + insert_object = function(pos, node, stack, direction) + local leftover = defaultChest.tube.insert_object(pos,node,stack,direction) + local count = leftover:get_count() + if count == 0 then + local derpstack = stack:get_name()..' 1' + if not defaultChest.tube.can_insert(pos, node, derpstack, direction) then + -- when you can't put a single more of whatever you just put, + -- you'll get a put for it, then a full + sendMessage(pos,"full "..maybeString(stack)..' '..tostring(count)) + end + else + -- this happens when the chest has received two stacks in a row and + -- filled up exactly with the first one. + -- You get a put for the first stack, a put for the second + -- and then a overflow with the first in stack and the second in leftover + -- and NO full? + sendMessage(pos,"overflow "..maybeString(stack)..' '..tostring(count)) + end + return leftover + end, + can_insert = function(pos, node, stack, direction) + local can = defaultChest.tube.can_insert(pos, node, stack, direction) + if can then + sendMessage(pos,"put "..maybeString(stack)) + else + -- overflow and lost means that items are gonna be out as entities :/ + sendMessage(pos,"lost "..maybeString(stack)) + end + return can + end, + }), + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not mychest.tube.can_insert(pos,nil,stack,nil) then + sendMessage(pos,"uoverflow "..maybeString(stack)) + end + local ret = defer(defaultChest.allow_metadata_inventory_put, pos, listname, index, stack, player) + if ret then return ret end + return stack:get_count() + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + local channel = minetest.get_meta(pos):get_string("channel") + local send = function(msg) + sendMessage(pos,msg,channel) + end + -- direction is only for furnaces + -- as the item has already been put, can_insert should return false if the chest is now full. + local derpstack = stack:get_name()..' 1' + if mychest.tube.can_insert(pos,nil,derpstack,nil) then + send("uput "..maybeString(stack)) + else + send("ufull "..maybeString(stack)) + end + return defer(defaultChest.on_metadata_inventory_put, pos, listname, index, stack, player) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + sendMessage(pos,"utake "..maybeString(stack)) + return defaultChest.on_metadata_inventory_take(pos, listname, index, stack, player) + end +}) + +if mychest.tube.can_insert == nil then + -- we can use the can_insert function from pipeworks, but will duplicate if not found. + mychest.tube.can_insert = function(pos,node,stack,direction) + local meta=minetest.get_meta(pos) + local inv=meta:get_inventory() + return inv:room_for_item("main",stack) + end +end + +-- minetest.register_node(":default:chest", mychest) +minetest.register_node("digilines_inventory:chest", mychest) diff --git a/digilines_lcd/characters b/digilines_lcd/characters index 83d6505..b36eea4 100644 --- a/digilines_lcd/characters +++ b/digilines_lcd/characters @@ -250,6 +250,9 @@ _eq ; _sm 1 +: +_co +1 , _cm 2 diff --git a/digilines_lcd/init.lua b/digilines_lcd/init.lua index 4fe3151..ed3fbd7 100644 --- a/digilines_lcd/init.lua +++ b/digilines_lcd/init.lua @@ -33,11 +33,11 @@ local lcds = { } local reset_meta = function(pos) - minetest.env:get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]") + minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]") end local clearscreen = function(pos) - local objects = minetest.env:get_objects_inside_radius(pos, 0.5) + local objects = minetest.get_objects_inside_radius(pos, 0.5) for _, o in ipairs(objects) do if o:get_entity_name() == "digilines_lcd:text" then o:remove() @@ -45,30 +45,33 @@ local clearscreen = function(pos) end end -local prepare_writing = function (pos) - lcd_info = lcds[minetest.env:get_node(pos).param2] +local prepare_writing = function(pos) + lcd_info = lcds[minetest.get_node(pos).param2] if lcd_info == nil then return end - local text = minetest.env:add_entity( + local text = minetest.add_entity( {x = pos.x + lcd_info.delta.x, y = pos.y + lcd_info.delta.y, z = pos.z + lcd_info.delta.z}, "digilines_lcd:text") - text:setyaw (lcd_info.yaw or 0) + text:setyaw(lcd_info.yaw or 0) --* text:setpitch(lcd_info.yaw or 0) return text end local on_digiline_receive = function(pos, node, channel, msg) - local setchan = minetest.env:get_meta(pos):get_string("channel") + local meta = minetest.get_meta(pos) + local setchan = meta:get_string("channel") if setchan ~= channel then return end + meta:set_string("text", msg) clearscreen(pos) - local text = prepare_writing (pos) - text:set_properties({textures={generate_texture(create_lines(msg))}}) + if msg ~= "" then + prepare_writing(pos) + end end local lcd_box = { type = "wallmounted", - wall_top = {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16} + wall_top = {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16} } minetest.register_node("digilines_lcd:lcd", { @@ -83,12 +86,12 @@ minetest.register_node("digilines_lcd:lcd", { paramtype2 = "wallmounted", node_box = lcd_box, selection_box = lcd_box, - groups = {choppy = 3, dig_immediate = 2}, + groups = {choppy = 3, dig_immediate = 2}, after_place_node = function (pos, placer, itemstack) - local param2 = minetest.env:get_node(pos).param2 + local param2 = minetest.get_node(pos).param2 if param2 == 0 or param2 == 1 then - minetest.env:add_node(pos, {name = "digilines_lcd:lcd", param2 = 3}) + minetest.add_node(pos, {name = "digilines_lcd:lcd", param2 = 3}) end prepare_writing (pos) end, @@ -102,7 +105,9 @@ minetest.register_node("digilines_lcd:lcd", { end, on_receive_fields = function(pos, formname, fields, sender) - minetest.env:get_meta(pos):set_string("channel", fields.channel) + if (fields.channel) then + minetest.get_meta(pos):set_string("channel", fields.channel) + end end, digiline = @@ -122,7 +127,7 @@ minetest.register_entity("digilines_lcd:text", { textures = {}, on_activate = function(self) - local meta = minetest.env:get_meta(self.object:getpos()) + local meta = minetest.get_meta(self.object:getpos()) local text = meta:get_string("text") self.object:set_properties({textures={generate_texture(create_lines(text))}}) end @@ -138,34 +143,11 @@ local NUMBER_OF_LINES = 5 local LINE_HEIGHT = 14 local CHAR_WIDTH = 5 -string_to_array = function(str) - local tab = {} - for i=1,string.len(str) do - table.insert(tab, string.sub(str, i,i)) - end - return tab -end - -string_to_word_array = function(str) - local tab = {} - local current = 1 - tab[1] = "" - for _,char in ipairs(string_to_array(str)) do - if char ~= " " then - tab[current] = tab[current]..char - else - current = current+1 - tab[current] = "" - end - end - return tab -end - create_lines = function(text) local line = "" local line_num = 1 local tab = {} - for _,word in ipairs(string_to_word_array(text)) do + for word in string.gmatch(text, "%S+") do if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then if line ~= "" then line = line.." "..word diff --git a/digilines_lcd/textures/_co.png b/digilines_lcd/textures/_co.png Binary files differnew file mode 100644 index 0000000..b161819 --- /dev/null +++ b/digilines_lcd/textures/_co.png diff --git a/digilines_lightsensor/init.lua b/digilines_lightsensor/init.lua index 8db748e..7dda1ce 100644 --- a/digilines_lightsensor/init.lua +++ b/digilines_lightsensor/init.lua @@ -22,9 +22,9 @@ local lsensor_selbox = } local on_digiline_receive = function (pos, node, channel, msg) - local setchan = minetest.env:get_meta(pos):get_string("channel") + local setchan = minetest.get_meta(pos):get_string("channel") if channel == setchan and msg == GET_COMMAND then - local lightval = minetest.env:get_node_light(pos) + local lightval = minetest.get_node_light(pos) digiline:receptor_send(pos, digiline.rules.default, channel, lightval) end end @@ -46,12 +46,12 @@ minetest.register_node("digilines_lightsensor:lightsensor", { }, }, on_construct = function(pos) - local meta = minetest.env:get_meta(pos) + local meta = minetest.get_meta(pos) meta:set_string("formspec", "field[channel;Channel;${channel}]") end, on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.env:get_meta(pos) - fields.channel = fields.channel or "" - meta:set_string("channel", fields.channel) + if (fields.channel) then + minetest.get_meta(pos):set_string("channel", fields.channel) + end end, }) diff --git a/digilines_rtc/init.lua b/digilines_rtc/init.lua index b2b21ec..6b7bfaf 100644 --- a/digilines_rtc/init.lua +++ b/digilines_rtc/init.lua @@ -17,9 +17,9 @@ local rtc_selbox = } local on_digiline_receive = function (pos, node, channel, msg) - local setchan = minetest.env:get_meta(pos):get_string("channel") + local setchan = minetest.get_meta(pos):get_string("channel") if channel == setchan and msg == GET_COMMAND then - local timeofday = minetest.env:get_timeofday() + local timeofday = minetest.get_timeofday() digiline:receptor_send(pos, digiline.rules.default, channel, timeofday) end end @@ -42,12 +42,12 @@ minetest.register_node("digilines_rtc:rtc", { }, }, on_construct = function(pos) - local meta = minetest.env:get_meta(pos) + local meta = minetest.get_meta(pos) meta:set_string("formspec", "field[channel;Channel;${channel}]") end, on_receive_fields = function(pos, formname, fields, sender) - local meta = minetest.env:get_meta(pos) - fields.channel = fields.channel or "" - meta:set_string("channel", fields.channel) + if (fields.channel) then + minetest.get_meta(pos):set_string("channel", fields.channel) + end end, }) |