From 1548a8e01334544cb1e234f6bb7eba7b39acd9d4 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Mon, 30 Jan 2017 13:28:02 -0500 Subject: [PATCH] convert mod over to dynamic param2 colorization --- depends.txt | 3 +- init.lua | 179 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 118 insertions(+), 64 deletions(-) diff --git a/depends.txt b/depends.txt index b08c42c..fe7e3d9 100644 --- a/depends.txt +++ b/depends.txt @@ -1,4 +1,3 @@ default -dye +unifieddyes intllib? - diff --git a/init.lua b/init.lua index 816e6e0..96f2d3e 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,6 @@ -- Industrial lights mod by DanDuncombe -- License: CC-By-Sa +-- rewritten by VanessaE to use param2 colorization ilights = {} @@ -19,71 +20,125 @@ end ilights.modpath = minetest.get_modpath("ilights") --- The important stuff! +-- Helper function to work around an engine bug -ilights.types = { - {"white", "White", 0xffffffff }, - {"grey", "Grey", 0xffa0a0a0 }, - {"black", "Black", 0xff000000 }, - {"red", "Red", 0xffff0000 }, - {"yellow", "Yellow", 0xffffff00 }, - {"green", "Green", 0xff00ff00 }, - {"cyan", "Cyan", 0xff00ffff }, - {"blue", "Blue", 0xff0000ff }, - {"magenta", "Magenta", 0xffff00ff }, - {"orange", "Orange", 0xffff8000 }, - {"violet", "Violet", 0xff8000ff }, - {"dark_grey", "Dark Grey", 0xff404040 }, - {"dark_green", "Dark Green", 0xff008000 }, - {"pink", "Pink", 0xffffb0ff }, - {"brown", "Brown", 0xff604000 }, -} +function ilights.fix_rotation(pos, placer, itemstack, pointed_thing) + local node = minetest.get_node(pos) + local yaw = placer:get_look_yaw() + local dir = minetest.yaw_to_dir(yaw-1.5) + local pitch = placer:get_look_vertical() -local lamp_cbox = { - type = "fixed", - fixed = { -11/32, -8/16, -11/32, 11/32, 4/16, 11/32 } -} - -for _, row in ipairs(ilights.types) do - local name = row[1] - local desc = row[2] - local colordef = row[3] - - -- Node Definition - - minetest.register_node("ilights:light_"..name, { - description = desc.." Industrial Light", - drawtype = "mesh", - mesh = "ilights_lamp.obj", - tiles = { - "ilights_lamp_base.png", - "ilights_lamp_cage.png", - { name = "ilights_lamp_bulb.png", color = colordef }, - "ilights_lamp_bulb_base.png", - { name = "ilights_lamp_lens.png", color = colordef } - }, - use_texture_alpha = true, - groups = {cracky=3}, - paramtype = "light", - paramtype2 = "facedir", - light_source = 14, - selection_box = lamp_cbox, - collision_box = lamp_cbox, - on_place = minetest.rotate_node - }) - - if name then - - --Choose craft material - minetest.register_craft({ - output = "ilights:light_"..name.." 3", - recipe = { - { "", "default:steel_ingot", "" }, - { "dye:"..name, "default:glass", "dye:"..name }, - { "default:steel_ingot", "default:torch", "default:steel_ingot" } - }, - }) + local fdir = minetest.dir_to_wallmounted(dir) + if pitch < -(math.pi/4) then + fdir = 0 + elseif pitch > math.pi/4 then + fdir = 1 end + minetest.swap_node(pos, { name = node.name, param2 = fdir }) end + +-- The important stuff! + +local lamp_cbox = { + type = "wallmounted", + wall_top = { -11/32, -4/16, -11/32, 11/32, 8/16, 11/32 }, + wall_bottom = { -11/32, -8/16, -11/32, 11/32, 4/16, 11/32 }, + wall_side = { -8/16, -11/32, -11/32, 4/16, 11/32, 11/32 } +} + +minetest.register_node("ilights:light", { + description = "Industrial Light", + drawtype = "mesh", + mesh = "ilights_lamp.obj", + tiles = { + { name = "ilights_lamp_base.png", color = 0xffffffff }, + { name = "ilights_lamp_cage.png", color = 0xffffffff }, + "ilights_lamp_bulb.png", + { name = "ilights_lamp_bulb_base.png", color = 0xffffffff }, + "ilights_lamp_lens.png" + }, + use_texture_alpha = true, + groups = {cracky=3}, + paramtype = "light", + paramtype2 = "colorwallmounted", + palette = "unifieddyes_palette_colorwallmounted.png", + light_source = 14, + selection_box = lamp_cbox, + node_box = lamp_cbox, + after_place_node = ilights.fix_rotation, + after_dig_node = unifieddyes.after_dig_node, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + unifieddyes.on_rightclick(pos, node, clicker, + itemstack, pointed_thing, "ilights:light", "wallmounted") + end, +}) + +minetest.register_craft({ + output = "ilights:light 3", + recipe = { + { "", "default:steel_ingot", "" }, + { "", "default:glass", "" }, + { "default:steel_ingot", "default:torch", "default:steel_ingot" } + }, +}) + +-- convert old static nodes to param2 coloring + +ilights.colors = { + "white", + "grey", + "black", + "red", + "yellow", + "green", + "cyan", + "blue", + "magenta", + "orange", + "violet", + "dark_grey", + "dark_green", + "pink", + "brown" +} + +ilights.old_static_nodes = {} + +for _, i in ipairs (ilights.colors) do + table.insert(ilights.old_static_nodes, "ilights:light_"..i) +end + +minetest.register_lbm({ + name = "ilights:convert", + label = "Convert ilights static nodes to use param2 color", + run_at_every_load = true, + nodenames = ilights.old_static_nodes, + action = function(pos, node) + local name = node.name + local color = string.sub(name, string.find(name, "_") + 1) + local paletteidx = unifieddyes.getpaletteidx("unifieddyes:"..color, "wallmounted") + local old_fdir = math.floor(node.param2 / 4) + local param2 + + if old_fdir == 5 then + new_fdir = 0 + elseif old_fdir == 1 then + new_fdir = 5 + elseif old_fdir == 2 then + new_fdir = 4 + elseif old_fdir == 3 then + new_fdir = 3 + elseif old_fdir == 4 then + new_fdir = 2 + elseif old_fdir == 0 then + new_fdir = 1 + end + param2 = paletteidx + new_fdir + + minetest.set_node(pos, { name = "ilights:light", param2 = param2 }) + local meta = minetest.get_meta(pos) + meta:set_string("dye", "unifieddyes:"..color) + end +})