From b181837dc920778cbb4f97c92cc46eeae96e5117 Mon Sep 17 00:00:00 2001 From: cheapie Date: Mon, 23 Jan 2017 02:02:28 -0600 Subject: Convert to use param2 coloring --- README | 3 +- init.lua | 75 ++++++++++--------------------------- textures/rgblightstone_palette.png | Bin 0 -> 2824 bytes textures/rgblightstone_white.png | Bin 0 -> 98 bytes 4 files changed, 22 insertions(+), 56 deletions(-) create mode 100644 textures/rgblightstone_palette.png create mode 100644 textures/rgblightstone_white.png diff --git a/README b/README index 93b04bc..1b042a0 100644 --- a/README +++ b/README @@ -2,6 +2,7 @@ RGB Lightstones for Minetest License: ---Code: WTFPL +---Textures: "white" image by VanessaE (WTFPL), "palette" image is from here: https://commons.wikimedia.org/wiki/File:256colour.png Depends: mesecons_lightstone, digilines (neither is in depends.txt since the order doesn't matter) @@ -17,7 +18,7 @@ Instructions: * Right-click and set a channel * Send a digilines message to it on that channel with the color you want (choices listed below) -Colors available: Any 6-digit hex color, such as "FF0000", "#c0ffee", "123456"... +Colors available: Any 6-digit hex color, such as "FF0000", "#c0ffee", "123456"... (will be set to the nearest color available) Group addressing mode: diff --git a/init.lua b/init.lua index 14c1c6b..ce49349 100644 --- a/init.lua +++ b/init.lua @@ -32,46 +32,17 @@ function rgblightstone.autofill(pos,player) end end -minetest.register_entity("rgblightstone:entity",{ - hp_max = 1, - physical = false, - collisionbox = {0,0,0,0,0,0}, - visual_size = {x=1.003, y=1.003}, - visual = "cube", - is_visible = true -}) - minetest.register_node("rgblightstone:rgblightstone", { - tiles = {"jeija_lightstone_darkgray_off.png^[colorize:#000000FF"}, + tiles = {"rgblightstone_white.png"}, + palette = "rgblightstone_palette.png", groups = {cracky=2}, - sunlight_propagates = true, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = {{-0.45,-0.45,-0.45,0.45,0.45,0.45}} - }, - paramtype = "light", description = "RGB Lightstone", + paramtype2 = "color", 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]") 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") - - --Create a new entity - local obj = minetest.add_entity(pos,"rgblightstone:entity") - - --Set to the black - local tex = "jeija_lightstone_darkgray_off.png^[colorize:#000000FF" - obj:set_properties({textures = {tex,tex,tex,tex,tex,tex}}) - end, - on_destruct = function(pos) - local objs = minetest.get_objects_inside_radius(pos,0.5) - for _,obj in ipairs(objs) do - if obj:get_luaentity().name == "rgblightstone:entity" then - obj:remove() - end - end end, on_punch = function(pos, node, player, pointed_thing) rgblightstone.autofill(pos,player) @@ -133,30 +104,32 @@ minetest.register_node("rgblightstone:rgblightstone", { end --Should be a valid hex color by this point - --Remove old entity, if present - local objs = minetest.get_objects_inside_radius(pos,0.5) - for _,obj in ipairs(objs) do - if obj:get_luaentity() and obj:get_luaentity().name == "rgblightstone:entity" then - obj:remove() - end - end + --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) - --Create a new entity - local obj = minetest.add_entity(pos,"rgblightstone:entity") + --Round to nearest available values and convert to a pixel count in the palette + r = math.floor(r/32) + g = math.floor(g/32) + b = math.floor(b/64) --Blue has one fewer bit - --Set to the correct color - meta:set_string("color",msg) - local tex = "jeija_lightstone_darkgray_off.png^[colorize:#"..msg.."FF" - obj:set_properties({textures = {tex,tex,tex,tex,tex,tex}}) + local paletteidx = 32*g+4*r+b + + print(msg,r,g,b,paletteidx) + + --Set the color + node.param2 = paletteidx + minetest.swap_node(pos,node) end } } }) minetest.register_lbm({ - name = "rgblightstone:reset_entities", + name = "rgblightstone:remove_entities", nodenames = {"rgblightstone:rgblightstone"}, - run_at_every_load = true, + label = "Remove old rgblightstone entities", action = function(pos) local objs = minetest.get_objects_inside_radius(pos,0.5) for _,obj in ipairs(objs) do @@ -164,14 +137,6 @@ minetest.register_lbm({ obj:remove() end end - local meta = minetest.get_meta(pos) - local color = meta:get_string("color") - if color == "" then - return - end - local tex = "jeija_lightstone_darkgray_off.png^[colorize:#"..color.."FF" - local obj = minetest.add_entity(pos,"rgblightstone:entity") - obj:set_properties({textures = {tex,tex,tex,tex,tex,tex}}) end }) diff --git a/textures/rgblightstone_palette.png b/textures/rgblightstone_palette.png new file mode 100644 index 0000000..6043ff1 Binary files /dev/null and b/textures/rgblightstone_palette.png differ diff --git a/textures/rgblightstone_white.png b/textures/rgblightstone_white.png new file mode 100644 index 0000000..095ca8f Binary files /dev/null and b/textures/rgblightstone_white.png differ -- cgit v1.2.3