diff options
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 80 |
1 files changed, 44 insertions, 36 deletions
@@ -1,13 +1,5 @@ rgblightstone = {} -if type(minetest.colorize) == "function" then - rgblightstone.colorize = minetest.colorize -else - rgblightstone.colorize = function(color,text) - return text - end -end - function rgblightstone.autofill(pos,player) local name = player:get_player_name() if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, { protection_bypass = true }) then @@ -29,10 +21,19 @@ function rgblightstone.autofill(pos,player) meta:set_string("channel",channel) meta:set_string("addrx",addrx) meta:set_string("addry",addry) - minetest.chat_send_player(player:get_player_name(),rgblightstone.colorize("#55FF55","Success: ").."Auto-filled with channel "..rgblightstone.colorize("#00FFFF",channel)..", X address "..rgblightstone.colorize("#00FFFF",addrx)..", and Y address "..rgblightstone.colorize("#00FFFF",addry)..".") + local message = minetest.colorize("#55FF55","Success: ").. + "Auto-filled with channel ".. + minetest.colorize("#00FFFF",channel).. + ", X address ".. + minetest.colorize("#00FFFF",addrx).. + ", and Y address ".. + minetest.colorize("#00FFFF",addry).. + "." + minetest.chat_send_player(player:get_player_name(),message) meta:set_string("infotext","") else - minetest.chat_send_player(player:get_player_name(),rgblightstone.colorize("#FF0000","ERROR: ").."Node above is not RGB Lightstone or is not configured correctly!") + local message = minetest.colorize("#FF0000","ERROR: ").."Node above is not RGB Lightstone or is not configured correctly!" + minetest.chat_send_player(player:get_player_name(),message) end end end @@ -68,22 +69,16 @@ function rgblightstone.handle_digilines(pos,node,channel,msg,truecolor) return end --Make sure there aren't any invalid chars - local acceptable_chars = {["0"]=true,["1"]=true,["2"]=true,["3"]=true,["4"]=true,["5"]=true,["6"]=true,["7"]=true,["8"]=true,["9"]=true,["A"]=true,["B"]=true,["C"]=true,["D"]=true,["E"]=true,["F"]=true} - for i = 1,6,1 do - if not acceptable_chars[string.sub(msg,i,i)] then - return - else - end - end + if not tonumber(msg,16) then return end --Should be a valid hex color by this point - + meta:set_string("color",msg) - + --Split into three colors local r = tonumber(string.sub(msg,1,2),16) local g = tonumber(string.sub(msg,3,4),16) local b = tonumber(string.sub(msg,5,6),16) - + --Convert RGB to HSV... or at least V, for the light local v = math.max(r,g,b) v = math.floor(v/255*14) @@ -98,7 +93,7 @@ function rgblightstone.handle_digilines(pos,node,channel,msg,truecolor) r = math.floor(r/32) g = math.floor(g/32) b = math.floor(b/64) --Blue has one fewer bit - + local paletteidx = 32*g+4*r+b --Set the color @@ -108,7 +103,7 @@ function rgblightstone.handle_digilines(pos,node,channel,msg,truecolor) end end -function rgblightstone.handle_fields(pos,formname,fields,sender) +function rgblightstone.handle_fields(pos,_,fields,sender) local name = sender:get_player_name() if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, { protection_bypass = true }) then minetest.record_protection_violation(pos, name) @@ -140,15 +135,16 @@ function rgblightstone.update_entity(pos) end minetest.register_entity("rgblightstone:entity",{ - hp_max = 1, - physical = false, - collisionbox = {0,0,0,0,0,0}, - visual_size = {x=1,y=1}, - visual = "cube", - static_save = false, + initial_properties = { + physical = false, + collisionbox = {0,0,0,0,0,0}, + visual_size = {x=1,y=1}, + visual = "cube", + static_save = false, + }, }) -for i=0,14,1 do +for i=0,14,1 do minetest.register_node("rgblightstone:rgblightstone_"..i, { tiles = {"rgblightstone_white.png"}, palette = "rgblightstone_palette.png", @@ -163,15 +159,21 @@ for i=0,14,1 do end, on_construct = function(pos) local meta = minetest.get_meta(pos) - 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]") + local fs = "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("formspec",fs) meta:set_string("infotext","Not configured! Right-click to set up manually, or punch to auto-fill from the node above.") meta:set_string("color","000000") end, - on_punch = function(pos,node,player,pointed_thing) + on_punch = function(pos,_,player) rgblightstone.autofill(pos,player) end, on_receive_fields = rgblightstone.handle_fields, - light_source = 0, digiline = { wire = { rules = { @@ -191,7 +193,7 @@ for i=0,14,1 do } } }) - + minetest.register_node("rgblightstone:rgblightstone_truecolor_"..i, { tiles = {"rgblightstone_white.png^[colorize:#000000:255"}, groups = i == 0 and {cracky = 2,} or {cracky = 2,not_in_creative_inventory = 1,}, @@ -204,12 +206,19 @@ for i=0,14,1 do end, on_construct = function(pos) local meta = minetest.get_meta(pos) - 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]") + local fs = "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("formspec",fs) meta:set_string("infotext","Not configured! Right-click to set up manually, or punch to auto-fill from the node above.") meta:set_string("color","000000") rgblightstone.update_entity(pos) end, - on_punch = function(pos,node,player,pointed_thing) + on_punch = function(pos,_,player) rgblightstone.autofill(pos,player) end, after_destruct = function(pos) @@ -235,7 +244,6 @@ for i=0,14,1 do fixed = {{-0.5,-0.5,-0.5,0.5,0.5,0.5}} }, on_receive_fields = rgblightstone.handle_fields, - light_source = 0, digiline = { wire = { rules = { |