forked from mtcontrib/homedecor_modpack
		
	convert desk lamps to param2 colorization
This commit is contained in:
		@@ -79,6 +79,9 @@ function homedecor.fix_rotation(pos, placer, itemstack, pointed_thing)
 | 
				
			|||||||
	minetest.swap_node(pos, { name = node.name, param2 = fdir })
 | 
						minetest.swap_node(pos, { name = node.name, param2 = fdir })
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- use this when you have a "wallmounted" node that should never be oriented
 | 
				
			||||||
 | 
					-- to floor or ceiling (e.g. a desk lamp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function homedecor.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
 | 
					function homedecor.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
 | 
				
			||||||
	local node = minetest.get_node(pos)
 | 
						local node = minetest.get_node(pos)
 | 
				
			||||||
	local yaw = placer:get_look_yaw()
 | 
						local yaw = placer:get_look_yaw()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -379,6 +379,16 @@ homedecor.register("lattice_lantern_small", {
 | 
				
			|||||||
	on_place = minetest.rotate_node
 | 
						on_place = minetest.rotate_node
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local brightness_tab = {
 | 
				
			||||||
 | 
						0xffd0d0d0,
 | 
				
			||||||
 | 
						0xffd8d8d8,
 | 
				
			||||||
 | 
						0xffe0e0e0,
 | 
				
			||||||
 | 
						0xffe8e8e8,
 | 
				
			||||||
 | 
						0xffffffff,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- table lamps and standing lamps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local repl = {
 | 
					local repl = {
 | 
				
			||||||
	["off"] ="low",
 | 
						["off"] ="low",
 | 
				
			||||||
	["low"] ="med",
 | 
						["low"] ="med",
 | 
				
			||||||
@@ -406,14 +416,6 @@ local slamp_cbox = {
 | 
				
			|||||||
	fixed = { -0.25, -0.5, -0.25, 0.25, 1.5, 0.25 }
 | 
						fixed = { -0.25, -0.5, -0.25, 0.25, 1.5, 0.25 }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local brightness_tab = {
 | 
					 | 
				
			||||||
	0xffd0d0d0,
 | 
					 | 
				
			||||||
	0xffd8d8d8,
 | 
					 | 
				
			||||||
	0xffe0e0e0,
 | 
					 | 
				
			||||||
	0xffe8e8e8,
 | 
					 | 
				
			||||||
	0xffffffff,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
local function reg_lamp(suffix, nxt, light, brightness)
 | 
					local function reg_lamp(suffix, nxt, light, brightness)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local wool_brighten = (light or 0) * 15
 | 
						local wool_brighten = (light or 0) * 15
 | 
				
			||||||
@@ -450,8 +452,6 @@ local function reg_lamp(suffix, nxt, light, brightness)
 | 
				
			|||||||
		end,
 | 
							end,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	-- standing lamps
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	homedecor.register("standing_lamp_"..suffix, {
 | 
						homedecor.register("standing_lamp_"..suffix, {
 | 
				
			||||||
		description = S("Standing Lamp"),
 | 
							description = S("Standing Lamp"),
 | 
				
			||||||
		mesh = "homedecor_standing_lamp.obj",
 | 
							mesh = "homedecor_standing_lamp.obj",
 | 
				
			||||||
@@ -495,29 +495,39 @@ reg_lamp("med", "hi",   7,   3 )
 | 
				
			|||||||
reg_lamp("hi",  "max", 11,   4 )
 | 
					reg_lamp("hi",  "max", 11,   4 )
 | 
				
			||||||
reg_lamp("max", "off", 14,   5 )
 | 
					reg_lamp("max", "off", 14,   5 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- "gooseneck" style desk lamps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local dlamp_cbox = {
 | 
					local dlamp_cbox = {
 | 
				
			||||||
	type = "fixed",
 | 
						type = "wallmounted",
 | 
				
			||||||
	fixed = { -0.2, -0.5, -0.15, 0.32, 0.12, 0.15 },
 | 
						wall_side = { -0.2, -0.5, -0.15, 0.32, 0.12, 0.15 },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local dlamp_colors = { N_("red"), N_("blue"), N_("green"), N_("violet") }
 | 
					homedecor.register("desk_lamp", {
 | 
				
			||||||
 | 
						description = S("Desk Lamp"),
 | 
				
			||||||
 | 
						mesh = "homedecor_desk_lamp.obj",
 | 
				
			||||||
 | 
						tiles = {
 | 
				
			||||||
 | 
							"homedecor_generic_metal.png",
 | 
				
			||||||
 | 
							"homedecor_generic_metal.png",
 | 
				
			||||||
 | 
							{ name = "homedecor_generic_metal.png", color = homedecor.color_med_grey },
 | 
				
			||||||
 | 
							{ name = "homedecor_table_standing_lamp_lightbulb.png", color = brightness_tab[5] },
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						inventory_image = "homedecor_desk_lamp_inv.png",
 | 
				
			||||||
 | 
						paramtype = "light",
 | 
				
			||||||
 | 
						paramtype2 = "colorwallmounted",
 | 
				
			||||||
 | 
						palette = "unifieddyes_palette_colorwallmounted.png",
 | 
				
			||||||
 | 
						selection_box = dlamp_cbox,
 | 
				
			||||||
 | 
						node_box = dlamp_cbox,
 | 
				
			||||||
 | 
						walkable = false,
 | 
				
			||||||
 | 
						groups = {snappy=3},
 | 
				
			||||||
 | 
						after_place_node = homedecor.fix_rotation_nsew,
 | 
				
			||||||
 | 
						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, "homedecor:desk_lamp", "wallmounted")
 | 
				
			||||||
 | 
						end,
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for _, color in ipairs(dlamp_colors) do
 | 
					-- "kitchen"/"dining room" ceiling lamp
 | 
				
			||||||
	homedecor.register("desk_lamp_"..color, {
 | 
					 | 
				
			||||||
		description = S("Desk Lamp (@1)", S(color)),
 | 
					 | 
				
			||||||
		mesh = "homedecor_desk_lamp.obj",
 | 
					 | 
				
			||||||
		tiles = {
 | 
					 | 
				
			||||||
			{ name = "homedecor_table_standing_lamp_lightbulb.png", color = brightness_tab[5] },
 | 
					 | 
				
			||||||
			{ name = "homedecor_generic_metal.png", color = color },
 | 
					 | 
				
			||||||
			{ name = "homedecor_generic_metal.png", color = homedecor.color_med_grey },
 | 
					 | 
				
			||||||
			{ name = "homedecor_generic_metal.png", color = color }
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		inventory_image = "homedecor_desk_lamp_stem_inv.png^(homedecor_desk_lamp_metal_inv.png^[colorize:"..color..":140)",
 | 
					 | 
				
			||||||
		selection_box = dlamp_cbox,
 | 
					 | 
				
			||||||
		walkable = false,
 | 
					 | 
				
			||||||
		groups = {snappy=3},
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
homedecor.register("ceiling_lamp", {
 | 
					homedecor.register("ceiling_lamp", {
 | 
				
			||||||
	description = S("Ceiling Lamp"),
 | 
						description = S("Ceiling Lamp"),
 | 
				
			||||||
@@ -665,3 +675,50 @@ minetest.register_lbm({
 | 
				
			|||||||
		meta:set_string("dye", "unifieddyes:"..color)
 | 
							meta:set_string("dye", "unifieddyes:"..color)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- this one's for the small "gooseneck" desk lamps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					homedecor.old_static_desk_lamps = {
 | 
				
			||||||
 | 
						"homedecor:desk_lamp_red",
 | 
				
			||||||
 | 
						"homedecor:desk_lamp_blue",
 | 
				
			||||||
 | 
						"homedecor:desk_lamp_green",
 | 
				
			||||||
 | 
						"homedecor:desk_lamp_violet",
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					minetest.register_lbm({
 | 
				
			||||||
 | 
						name = "homedecor:convert_lighting",
 | 
				
			||||||
 | 
						label = "Convert homedecor glowlights, table lamps, and standing lamps to use param2 color",
 | 
				
			||||||
 | 
						run_at_every_load = true,
 | 
				
			||||||
 | 
						nodenames = homedecor.old_static_desk_lamps,
 | 
				
			||||||
 | 
						action = function(pos, node)
 | 
				
			||||||
 | 
							local name = node.name
 | 
				
			||||||
 | 
							local newname
 | 
				
			||||||
 | 
							local color = string.sub(name, string.find(name, "_", -8) + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if color == "green" then
 | 
				
			||||||
 | 
								color = "medium_green"
 | 
				
			||||||
 | 
							elseif color == "violet" then
 | 
				
			||||||
 | 
								color = "magenta"
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, "wallmounted")
 | 
				
			||||||
 | 
							local old_fdir = math.floor(node.param2 % 32)
 | 
				
			||||||
 | 
							local new_fdir = 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if old_fdir == 0 then
 | 
				
			||||||
 | 
								new_fdir = 3
 | 
				
			||||||
 | 
							elseif old_fdir == 1 then
 | 
				
			||||||
 | 
								new_fdir = 4
 | 
				
			||||||
 | 
							elseif old_fdir == 2 then
 | 
				
			||||||
 | 
								new_fdir = 2
 | 
				
			||||||
 | 
							elseif old_fdir == 3 then
 | 
				
			||||||
 | 
								new_fdir = 5
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							local param2 = paletteidx + new_fdir
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							minetest.set_node(pos, { name = "homedecor:desk_lamp", param2 = param2 })
 | 
				
			||||||
 | 
							local meta = minetest.get_meta(pos)
 | 
				
			||||||
 | 
							meta:set_string("dye", "unifieddyes:"..color)
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								homedecor/textures/homedecor_desk_lamp_inv.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								homedecor/textures/homedecor_desk_lamp_inv.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.3 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1.4 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1.5 KiB  | 
		Reference in New Issue
	
	Block a user