summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2015-12-15 18:56:59 -0600
committercheapie <no-email-for-you@example.com>2015-12-15 18:57:22 -0600
commit2a9cafccb59fc9c4ce83070ae5c24c5368cbc0ac (patch)
tree9f0e27809a72bb3498688fc28f2e69ae39b88e90
parent3104d9ed96901a0c0e11dd353fa2624949322a69 (diff)
downloadrgblightstone-2a9cafccb59fc9c4ce83070ae5c24c5368cbc0ac.tar
rgblightstone-2a9cafccb59fc9c4ce83070ae5c24c5368cbc0ac.tar.gz
rgblightstone-2a9cafccb59fc9c4ce83070ae5c24c5368cbc0ac.tar.bz2
rgblightstone-2a9cafccb59fc9c4ce83070ae5c24c5368cbc0ac.tar.xz
rgblightstone-2a9cafccb59fc9c4ce83070ae5c24c5368cbc0ac.zip
Add auto-fill function
-rw-r--r--README3
-rw-r--r--init.lua44
2 files changed, 43 insertions, 4 deletions
diff --git a/README b/README
index 34c03d3..9cb1f1c 100644
--- a/README
+++ b/README
@@ -54,3 +54,6 @@ send this:
{{"red","green"},
{"blue","yellow"}}
+
+Note that if you are using group addressing mode, if there is an already-configured RGB lightstone node directly above the one you are setting up,
+punching the one you are setting up (or right-clicking and selecting the Auto-Fill option) will attempt to auto-fill it (incrementing the Y address) from the one above.
diff --git a/init.lua b/init.lua
index 530089b..325d029 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,29 @@
rgblightstone = {}
rgblightstone.colors = {"off","black","blue","brown","cyan","darkblue","darkcyan","darkgray","darkgreen","darkmagenta","darkred","gray","green","magenta","red","white","yellow"}
+function rgblightstone.autofill(pos,player)
+ local meta = minetest.get_meta(pos)
+ if (not meta:get_string("channel")) or meta:get_string("channel")=="" then
+ local pos_above = {x=pos.x,y=pos.y+1,z=pos.z}
+ local node_above = minetest.get_node(pos_above)
+ local meta_above = minetest.get_meta(pos_above)
+ if string.match(node_above.name,"rgblightstone") and
+ meta_above:get_string("channel") and
+ tonumber(meta_above:get_string("addrx")) and
+ tonumber(meta_above:get_string("addry")) then
+ local channel = meta_above:get_string("channel")
+ local addrx = meta_above:get_string("addrx")
+ local addry = tostring(1+tonumber(meta_above:get_string("addry")))
+ meta:set_string("channel",channel)
+ meta:set_string("addrx",addrx)
+ meta:set_string("addry",addry)
+ minetest.chat_send_player(player:get_player_name(),"Successfully auto-filled with channel "..channel..", X address "..addrx..", and Y address "..addry..".")
+ meta:set_string("infotext","")
+ else
+ minetest.chat_send_player(player:get_player_name(),"Node above is not RGB Lightstone or is not configured correctly!")
+ end
+ end
+end
+
function rgblightstone.add(name)
minetest.register_node("rgblightstone:lightstone_" .. name, {
tiles = name == "off" and {"jeija_lightstone_darkgray_off.png"} or {"rgblightstone_"..name..".png"},
@@ -9,12 +33,24 @@ function rgblightstone.add(name)
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
- meta:set_string("formspec", "size[8,4;]field[1,1;6,2;channel;Channel;${channel}]field[1,2;2,2;addrx;X Address;${addrx}]field[5,2;2,2;addry;Y Address;${addry}]button_exit[2.25,3;3,1;submit;Save]label[3,2;Leave address blank\nfor individual mode]")
+ meta:set_string("formspec", "size[8,5;]field[1,1;6,2;channel;Channel;${channel}]field[1,2;2,2;addrx;X Address;${addrx}]field[5,2;2,2;addry;Y Address;${addry}]button_exit[2.25,3;3,1;submit;Save]button_exit[2.25,4;3,1;autofill;Auto-Fill From Node Above]label[3,2;Leave address blank\nfor individual mode]")
+ meta:set_string("infotext","Not configured! Right-click to set up manually, or punch to auto-fill from the node above.")
+ end,
+ on_punch = function(pos, node, player, pointed_thing)
+ rgblightstone.autofill(pos,player)
end,
on_receive_fields = function(pos, formname, fields, sender)
- if fields.channel then minetest.get_meta(pos):set_string("channel", fields.channel) end
- if fields.addrx then minetest.get_meta(pos):set_string("addrx",fields.addrx) end
- if fields.addry then minetest.get_meta(pos):set_string("addry",fields.addry) end
+ local meta = minetest.get_meta(pos)
+ if fields.autofill then
+ rgblightstone.autofill(pos,sender)
+ else
+ if fields.channel then
+ meta:set_string("channel", fields.channel)
+ meta:set_string("infotext","")
+ end
+ if fields.addrx then meta:set_string("addrx",fields.addrx) end
+ if fields.addry then meta:set_string("addry",fields.addry) end
+ end
end,
light_source = name~= "off" and default.LIGHT_MAX-2 or 0,
digiline = {