Add mesecons support for the rest of the other relevant lights

Each light connects only according to what sides make sense.

For example:

* a plasma lamp cube or large lattice lamp will connect from all 6 sides
* a ground lantern will only connect from its NSEW sides, not its top or
  bottom
* a glowlight slab, glowlight cube, or lattice cube uses the same rules as
  mesecons lamps, so its four edges and it back/bottom, whatever its
  orientation, but not its top/front.
* a (kitchen) ceiling lamp, and a (hanging, exterior) ceiling lantern will
  only connect from the top.

Rope lights are defined as a conductor, just like a mesecons wire,
so if mesecons is present, they will default to off unless powered by
a mesecons wire/switch/etc.

You can still right-click-toggle individual segments on/off.

Ceiling rope light connection rules are a little funky, but they work
(I wanted them to only connect from the top, but I couldn't get it
just right).  Floor-orientation connections are straightforward.
This commit is contained in:
Vanessa Dannenberg 2019-05-25 23:52:42 -04:00
parent 07141bff47
commit cacf04e2d1

View File

@ -2,31 +2,79 @@
local S = homedecor.gettext local S = homedecor.gettext
local actions = {
action_off = function(pos, node)
local sep = string.find(node.name, "_o", -5)
local onoff = string.sub(node.name, sep + 1)
if minetest.get_meta(pos):get_int("toggled") > 0 then
minetest.swap_node(pos, {
name = string.sub(node.name, 1, sep - 1).."_off",
param2 = node.param2
})
end
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_int("toggled", 1)
local sep = string.find(node.name, "_o", -5)
local onoff = string.sub(node.name, sep + 1)
minetest.swap_node(pos, {
name = string.sub(node.name, 1, sep - 1).."_on",
param2 = node.param2
})
end
}
local rules_xz = {
{x = -1, y = 0, z = 0}, -- borrowed from extrawires crossing
{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1},
{x = 0, y = 0, z = 1},
}
local rules_alldir = {
{x = 0, y = 0, z = -1}, -- borrowed from lightstones
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 1, y = 1, z = 0},
{x = 1, y = -1, z = 0},
{x = -1, y = 1, z = 0},
{x = -1, y = -1, z = 0},
{x = 0, y = 1, z = 1},
{x = 0, y = -1, z = 1},
{x = 0, y = 1, z = -1},
{x = 0, y = -1, z = -1},
{x = 0, y = -1, z = 0},
}
local rules_toponly = {
{x = 1, y = 1, z = 0},
{x = -1, y = 1, z = 0},
{x = 0, y = 1, z = 1},
{x = 0, y = 1, z = -1},
}
if minetest.get_modpath("mesecons") then if minetest.get_modpath("mesecons") then
homedecor.mesecon_wall_light = { homedecor.mesecon_wall_light = {
effector = { effector = table.copy(actions)
action_off = function(pos, node)
local sep = string.find(node.name, "_o", -5)
local onoff = string.sub(node.name, sep + 1)
if minetest.get_meta(pos):get_int("toggled") > 0 then
minetest.swap_node(pos, {
name = string.sub(node.name, 1, sep - 1).."_off",
param2 = node.param2
})
end
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_int("toggled", 1)
local sep = string.find(node.name, "_o", -5)
local onoff = string.sub(node.name, sep + 1)
minetest.swap_node(pos, {
name = string.sub(node.name, 1, sep - 1).."_on",
param2 = node.param2
})
end,
rules = mesecon.rules.wallmounted_get
}
} }
homedecor.mesecon_wall_light.effector.rules = mesecon.rules.wallmounted_get
homedecor.mesecon_xz_light = {
effector = table.copy(actions)
}
homedecor.mesecon_xz_light.effector.rules = rules_xz
homedecor.mesecon_alldir_light = {
effector = table.copy(actions),
}
homedecor.mesecon_alldir_light.effector.rules = rules_alldir
homedecor.mesecon_toponly_light = {
effector = table.copy(actions)
}
homedecor.mesecon_toponly_light.effector.rules = rules_toponly
end end
local brightness_tab = { local brightness_tab = {
@ -291,7 +339,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:plasma_lamp_on"}}, {items = {"homedecor:plasma_lamp_on"}},
} }
} },
mesecons = homedecor.mesecon_alldir_light
}) })
local lighttex = "homedecor_blanktile.png" local lighttex = "homedecor_blanktile.png"
@ -326,7 +375,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:plasma_ball_on"}}, {items = {"homedecor:plasma_ball_on"}},
} }
} },
mesecons = homedecor.mesecon_xz_light
}) })
local gl_cbox = { local gl_cbox = {
@ -357,7 +407,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:ground_lantern_on"}}, {items = {"homedecor:ground_lantern_on"}},
} }
} },
mesecons = homedecor.mesecon_xz_light
}) })
local hl_cbox = { local hl_cbox = {
@ -381,7 +432,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:hanging_lantern_on"}}, {items = {"homedecor:hanging_lantern_on"}},
} }
} },
mesecons = homedecor.mesecon_alldir_light
}) })
local cl_cbox = { local cl_cbox = {
@ -405,7 +457,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:ceiling_lantern_on"}}, {items = {"homedecor:ceiling_lantern_on"}},
} }
} },
mesecons = homedecor.mesecon_toponly_light
}) })
if minetest.get_modpath("darkage") then if minetest.get_modpath("darkage") then
@ -425,11 +478,12 @@ for _, onoff in ipairs({"on", "off"}) do
light_source = onflag and default.LIGHT_MAX or nil, light_source = onflag and default.LIGHT_MAX or nil,
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
on_rightclick = homedecor.toggle_light, on_rightclick = homedecor.toggle_light,
drop = { drop = {
items = { items = {
{items = {"homedecor:lattice_lantern_large_on"}}, {items = {"homedecor:lattice_lantern_large_on"}},
} }
} },
mesecons = homedecor.mesecon_alldir_light
}) })
end end
@ -468,7 +522,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:lattice_lantern_small_on"}}, {items = {"homedecor:lattice_lantern_small_on"}},
} }
} },
mesecons = homedecor.mesecon_wall_light
}) })
-- "gooseneck" style desk lamps -- "gooseneck" style desk lamps
@ -505,7 +560,8 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:desk_lamp_on"}, inherit_color = true }, {items = {"homedecor:desk_lamp_on"}, inherit_color = true },
} }
} },
mesecons = homedecor.mesecon_xz_light
}) })
-- "kitchen"/"dining room" ceiling lamp -- "kitchen"/"dining room" ceiling lamp
@ -528,9 +584,12 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:ceiling_lamp_on"}}, {items = {"homedecor:ceiling_lamp_on"}},
} }
} },
mesecons = homedecor.mesecon_toponly_light
}) })
-- rope lighting
minetest.register_node(":homedecor:rope_light_on_floor_"..onoff, { minetest.register_node(":homedecor:rope_light_on_floor_"..onoff, {
description = "Rope lighting (on floor)", description = "Rope lighting (on floor)",
inventory_image = "homedecor_rope_light_on_floor.png", inventory_image = "homedecor_rope_light_on_floor.png",
@ -554,7 +613,11 @@ for _, onoff in ipairs({"on", "off"}) do
{ -6/16, -8/16, 4/16, 6/16, -6/16, 6/16 } { -6/16, -8/16, 4/16, 6/16, -6/16, 6/16 }
}, },
}, },
connects_to = { "homedecor:rope_light_on_floor" }, connects_to = {
"homedecor:rope_light_on_floor_on",
"homedecor:rope_light_on_floor_off",
"group:mesecon_conductor_craftable"
},
mesh = "homedecor_chandelier.obj", mesh = "homedecor_chandelier.obj",
groups = {cracky=3, not_in_creative_inventory = nici}, groups = {cracky=3, not_in_creative_inventory = nici},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
@ -563,6 +626,14 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:rope_light_on_floor_on"} }, {items = {"homedecor:rope_light_on_floor_on"} },
} }
},
mesecons = {
conductor = {
state = mesecon and (onflag and mesecon.state.on or mesecon.state.off),
onstate = "homedecor:rope_light_on_floor_on",
offstate = "homedecor:rope_light_on_floor_off",
rules = rules_xz
},
} }
}) })
@ -589,7 +660,11 @@ for _, onoff in ipairs({"on", "off"}) do
{ -6/16, 8/16, 4/16, 6/16, 6/16, 6/16 } { -6/16, 8/16, 4/16, 6/16, 6/16, 6/16 }
}, },
}, },
connects_to = { "homedecor:rope_light_on_ceiling" }, connects_to = {
"homedecor:rope_light_on_ceiling_on",
"homedecor:rope_light_on_ceiling_off",
"group:mesecon_conductor_craftable"
},
mesh = "homedecor_chandelier.obj", mesh = "homedecor_chandelier.obj",
groups = {cracky=3, not_in_creative_inventory = nici}, groups = {cracky=3, not_in_creative_inventory = nici},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
@ -598,6 +673,14 @@ for _, onoff in ipairs({"on", "off"}) do
items = { items = {
{items = {"homedecor:rope_light_on_ceiling_on"}}, {items = {"homedecor:rope_light_on_ceiling_on"}},
} }
},
mesecons = {
conductor = {
state = mesecon and (onflag and mesecon.state.on or mesecon.state.off),
onstate = "homedecor:rope_light_on_ceiling_on",
offstate = "homedecor:rope_light_on_ceiling_off",
rules = rules_alldir
},
} }
}) })
@ -899,8 +982,7 @@ local function reg_lamp(suffix, nxt, light, brightness)
items = { items = {
{items = {"homedecor:table_lamp_hi"}, inherit_color = true }, {items = {"homedecor:table_lamp_hi"}, inherit_color = true },
} }
} },
}) })
homedecor.register("standing_lamp_"..suffix, { homedecor.register("standing_lamp_"..suffix, {