2013-12-18 21:14:03 +01:00
|
|
|
local vertical_box = {
|
2012-12-13 18:42:45 +01:00
|
|
|
type = "fixed",
|
2013-12-18 21:14:03 +01:00
|
|
|
fixed = {-1/16, -8/16, -1/16, 1/16, 8/16, 1/16}
|
2012-12-13 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 21:14:03 +01:00
|
|
|
local top_box = {
|
2012-12-13 18:42:45 +01:00
|
|
|
type = "fixed",
|
2013-12-18 21:14:03 +01:00
|
|
|
fixed = {{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}}
|
2012-12-13 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 21:14:03 +01:00
|
|
|
local bottom_box = {
|
2012-12-13 18:42:45 +01:00
|
|
|
type = "fixed",
|
2013-12-18 21:14:03 +01:00
|
|
|
fixed = {
|
|
|
|
{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16},
|
|
|
|
{-1/16, -7/16, -1/16, 1/16, 8/16, 1/16},
|
|
|
|
}
|
2012-12-13 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 21:14:03 +01:00
|
|
|
local vertical_rules = {
|
|
|
|
{x=0, y=1, z=0},
|
2014-11-22 12:28:45 +01:00
|
|
|
{x=0, y=-1, z=0}
|
2013-12-18 21:14:03 +01:00
|
|
|
}
|
2012-12-13 18:42:45 +01:00
|
|
|
|
2013-12-18 21:14:03 +01:00
|
|
|
local top_rules = {
|
|
|
|
{x=1,y=0, z=0},
|
|
|
|
{x=-1,y=0, z=0},
|
|
|
|
{x=0,y=0, z=1},
|
|
|
|
{x=0,y=0, z=-1},
|
2014-11-22 12:28:45 +01:00
|
|
|
{x=0,y=-1, z=0}
|
2013-12-18 21:14:03 +01:00
|
|
|
}
|
2012-12-13 18:42:45 +01:00
|
|
|
|
2013-12-18 21:14:03 +01:00
|
|
|
local bottom_rules = {
|
|
|
|
{x=1, y=0, z=0},
|
|
|
|
{x=-1, y=0, z=0},
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=1, z=0},
|
2014-11-22 12:28:45 +01:00
|
|
|
{x=0, y=2, z=0} -- receive power from pressure plate / detector / ... 2 nodes above
|
2013-12-18 21:14:03 +01:00
|
|
|
}
|
2012-12-13 18:42:45 +01:00
|
|
|
|
2019-09-18 15:46:49 +02:00
|
|
|
local static_middle_rules = {}
|
|
|
|
do
|
|
|
|
-- not rotated, plate can connect to normal wire
|
|
|
|
static_middle_rules[1] = {
|
|
|
|
{x=1, y=0, z=0},
|
|
|
|
{x=-1, y=0, z=0},
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=1, z=0},
|
|
|
|
{x=0, y=2, z=0}, -- receive power from pressure plate / detector / ... 2 nodes above
|
|
|
|
{x=0, y=-1, z=0},
|
|
|
|
}
|
|
|
|
|
|
|
|
-- otherwise rotate these rules
|
|
|
|
local r = mesecon.rotate_rules_up({
|
|
|
|
{x=0, y=1, z=0},
|
|
|
|
{x=0, y=2, z=0}, -- receive power from pressure plate / detector / ... 2 nodes above
|
|
|
|
{x=0, y=-1, z=0},
|
|
|
|
})
|
|
|
|
static_middle_rules[0] = mesecon.rotate_rules_up(r)
|
|
|
|
static_middle_rules[2] = mesecon.rotate_rules_left(mesecon.rotate_rules_left(r))
|
|
|
|
static_middle_rules[3] = r
|
|
|
|
static_middle_rules[4] = mesecon.rotate_rules_left(r)
|
|
|
|
static_middle_rules[5] = mesecon.rotate_rules_right(r)
|
|
|
|
end
|
|
|
|
local function static_middle_rules_get(node)
|
|
|
|
return static_middle_rules[node.param2] or {}
|
2019-09-18 01:13:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function is_dynamic_vertical_wire(node)
|
|
|
|
local nodedef = minetest.registered_nodes[node.name]
|
|
|
|
return nodedef and nodedef.is_vertical_conductor
|
|
|
|
end
|
|
|
|
|
|
|
|
local function is_vertical_conductor(node)
|
|
|
|
if node.name ~= "mesecons_extrawires:vertical_static_middle_off" and
|
|
|
|
node.name ~= "mesecons_extrawires:vertical_static_middle_on" then
|
|
|
|
return is_dynamic_vertical_wire(node)
|
|
|
|
end
|
|
|
|
return node.param2 == 1 or node.param2 == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function vertical_updatepos(pos)
|
2013-12-01 02:43:30 +01:00
|
|
|
local node = minetest.get_node(pos)
|
2019-09-18 01:13:20 +02:00
|
|
|
if not is_dynamic_vertical_wire(node) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local node_above = minetest.get_node(vector.add(pos, vertical_rules[1]))
|
|
|
|
local node_below = minetest.get_node(vector.add(pos, vertical_rules[2]))
|
2016-02-15 22:52:56 +01:00
|
|
|
|
2019-09-18 01:13:20 +02:00
|
|
|
local above = is_vertical_conductor(node_above)
|
|
|
|
local below = is_vertical_conductor(node_below)
|
|
|
|
|
|
|
|
mesecon.on_dignode(pos, node)
|
|
|
|
|
|
|
|
-- Always place offstate conductor and let mesecon.on_placenode take care
|
|
|
|
local newname = "mesecons_extrawires:vertical_"
|
|
|
|
if above and below then -- above and below: vertical mesecon
|
|
|
|
newname = newname .. "off"
|
|
|
|
elseif above and not below then -- above only: bottom
|
|
|
|
newname = newname .. "bottom_off"
|
|
|
|
elseif not above and below then -- below only: top
|
|
|
|
newname = newname .. "top_off"
|
|
|
|
else -- no vertical wire above, no vertical wire below: use bottom
|
|
|
|
newname = newname .. "bottom_off"
|
2012-12-13 18:42:45 +01:00
|
|
|
end
|
2019-09-18 01:13:20 +02:00
|
|
|
|
|
|
|
minetest.set_node(pos, {name = newname})
|
|
|
|
mesecon.on_placenode(pos, {name = newname})
|
2012-12-13 18:42:45 +01:00
|
|
|
end
|
|
|
|
|
2019-09-18 01:13:20 +02:00
|
|
|
local function vertical_update(pos)
|
2012-12-13 18:42:45 +01:00
|
|
|
vertical_updatepos(pos) -- this one
|
2016-02-14 20:55:50 +01:00
|
|
|
vertical_updatepos(vector.add(pos, vertical_rules[1])) -- above
|
|
|
|
vertical_updatepos(vector.add(pos, vertical_rules[2])) -- below
|
2012-12-13 18:42:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Vertical wire
|
2014-11-22 12:28:45 +01:00
|
|
|
mesecon.register_node("mesecons_extrawires:vertical", {
|
2017-02-15 19:52:29 +01:00
|
|
|
description = "Vertical Mesecon",
|
2012-12-13 18:42:45 +01:00
|
|
|
drawtype = "nodebox",
|
|
|
|
walkable = false,
|
|
|
|
paramtype = "light",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-13 18:42:45 +01:00
|
|
|
sunlight_propagates = true,
|
2013-12-18 21:14:03 +01:00
|
|
|
selection_box = vertical_box,
|
|
|
|
node_box = vertical_box,
|
2012-12-13 18:42:45 +01:00
|
|
|
is_vertical_conductor = true,
|
2013-12-01 02:43:30 +01:00
|
|
|
drop = "mesecons_extrawires:vertical_off",
|
2013-12-18 21:14:03 +01:00
|
|
|
after_place_node = vertical_update,
|
2018-01-28 20:56:42 +01:00
|
|
|
after_dig_node = vertical_update,
|
|
|
|
sounds = default.node_sound_defaults(),
|
2019-09-18 01:13:20 +02:00
|
|
|
}, {
|
2014-11-22 11:37:47 +01:00
|
|
|
tiles = {"mesecons_wire_off.png"},
|
2019-09-18 01:13:20 +02:00
|
|
|
groups = {dig_immediate = 3},
|
2012-12-13 18:42:45 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
onstate = "mesecons_extrawires:vertical_on",
|
2013-12-18 21:14:03 +01:00
|
|
|
rules = vertical_rules,
|
2014-11-22 12:28:45 +01:00
|
|
|
}}
|
2019-09-18 01:13:20 +02:00
|
|
|
}, {
|
2014-11-22 11:37:47 +01:00
|
|
|
tiles = {"mesecons_wire_on.png"},
|
2019-09-18 01:13:20 +02:00
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
2012-12-13 18:42:45 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
2014-11-22 12:28:45 +01:00
|
|
|
offstate = "mesecons_extrawires:vertical_off",
|
|
|
|
rules = vertical_rules,
|
|
|
|
}}
|
2012-12-13 18:42:45 +01:00
|
|
|
})
|
|
|
|
|
2014-11-22 12:28:45 +01:00
|
|
|
-- Vertical wire top
|
|
|
|
mesecon.register_node("mesecons_extrawires:vertical_top", {
|
2012-12-13 18:42:45 +01:00
|
|
|
description = "Vertical mesecon",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
walkable = false,
|
|
|
|
paramtype = "light",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-13 18:42:45 +01:00
|
|
|
sunlight_propagates = true,
|
2019-09-18 01:13:20 +02:00
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
2013-12-18 21:14:03 +01:00
|
|
|
selection_box = top_box,
|
|
|
|
node_box = top_box,
|
2012-12-13 18:42:45 +01:00
|
|
|
is_vertical_conductor = true,
|
2014-11-22 12:28:45 +01:00
|
|
|
drop = "mesecons_extrawires:vertical_off",
|
|
|
|
after_place_node = vertical_update,
|
2018-01-28 20:56:42 +01:00
|
|
|
after_dig_node = vertical_update,
|
|
|
|
sounds = default.node_sound_defaults(),
|
2019-09-18 01:13:20 +02:00
|
|
|
}, {
|
2014-11-22 12:28:45 +01:00
|
|
|
tiles = {"mesecons_wire_off.png"},
|
2012-12-13 18:42:45 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
onstate = "mesecons_extrawires:vertical_top_on",
|
2013-12-18 21:14:03 +01:00
|
|
|
rules = top_rules,
|
2014-11-22 12:28:45 +01:00
|
|
|
}}
|
2019-09-18 01:13:20 +02:00
|
|
|
}, {
|
2014-11-22 11:37:47 +01:00
|
|
|
tiles = {"mesecons_wire_on.png"},
|
2012-12-13 18:42:45 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
2014-11-22 12:28:45 +01:00
|
|
|
offstate = "mesecons_extrawires:vertical_top_off",
|
|
|
|
rules = top_rules,
|
|
|
|
}}
|
2012-12-13 18:42:45 +01:00
|
|
|
})
|
|
|
|
|
2014-11-22 12:28:45 +01:00
|
|
|
-- Vertical wire bottom
|
|
|
|
mesecon.register_node("mesecons_extrawires:vertical_bottom", {
|
2012-12-13 18:42:45 +01:00
|
|
|
description = "Vertical mesecon",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
walkable = false,
|
|
|
|
paramtype = "light",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-12-13 18:42:45 +01:00
|
|
|
sunlight_propagates = true,
|
2012-12-15 18:45:51 +01:00
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
2013-12-18 21:14:03 +01:00
|
|
|
selection_box = bottom_box,
|
|
|
|
node_box = bottom_box,
|
2012-12-13 18:42:45 +01:00
|
|
|
is_vertical_conductor = true,
|
2014-11-22 12:28:45 +01:00
|
|
|
drop = "mesecons_extrawires:vertical_off",
|
|
|
|
after_place_node = vertical_update,
|
2018-01-28 20:56:42 +01:00
|
|
|
after_dig_node = vertical_update,
|
|
|
|
sounds = default.node_sound_defaults(),
|
2019-09-18 01:13:20 +02:00
|
|
|
}, {
|
|
|
|
tiles = {"mesecons_wire_off.png", "jeija_insulated_wire_sides_off.png",
|
|
|
|
"mesecons_wire_off.png"},
|
2012-12-13 18:42:45 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
onstate = "mesecons_extrawires:vertical_bottom_on",
|
2013-12-18 21:14:03 +01:00
|
|
|
rules = bottom_rules,
|
2014-11-22 12:28:45 +01:00
|
|
|
}}
|
2019-09-18 01:13:20 +02:00
|
|
|
}, {
|
|
|
|
tiles = {"mesecons_wire_on.png", "jeija_insulated_wire_sides_on.png",
|
|
|
|
"mesecons_wire_on.png"},
|
2014-11-22 12:28:45 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
|
|
|
offstate = "mesecons_extrawires:vertical_bottom_off",
|
|
|
|
rules = bottom_rules,
|
|
|
|
}}
|
2012-12-13 18:42:45 +01:00
|
|
|
})
|
2013-02-22 19:37:05 +01:00
|
|
|
|
2019-09-18 01:13:20 +02:00
|
|
|
-- Static vertical wire middle
|
|
|
|
mesecon.register_node("mesecons_extrawires:vertical_static_middle", {
|
|
|
|
description = "Static middle vertical mesecon",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
walkable = false,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted", -- yes, rotatable
|
|
|
|
place_param2 = 1, -- but no automatic rotation
|
|
|
|
node_placement_prediction = "", -- also no client-side automatic rotation
|
|
|
|
is_ground_content = false,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
selection_box = bottom_box,
|
|
|
|
node_box = bottom_box,
|
|
|
|
after_place_node = vertical_update,
|
|
|
|
after_dig_node = vertical_update,
|
|
|
|
sounds = default.node_sound_defaults(),
|
|
|
|
on_rotate = minetest.global_exists("screwdriver") and function(pos, node, _, mode, _)
|
|
|
|
if mode == screwdriver.ROTATE_FACE then -- left click
|
|
|
|
node.param2 = node.param2 + 1
|
|
|
|
else -- right click
|
|
|
|
node.param2 = node.param2 - 1
|
|
|
|
end
|
|
|
|
node.param2 = node.param2 % 6
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
vertical_update(pos)
|
2019-09-18 15:51:08 +02:00
|
|
|
mesecon.on_placenode(pos, node)
|
2019-09-18 01:13:20 +02:00
|
|
|
return true
|
|
|
|
end,
|
|
|
|
}, {
|
|
|
|
groups = {dig_immediate = 3},
|
|
|
|
tiles = {"mesecons_wire_off.png"},
|
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
onstate = "mesecons_extrawires:vertical_static_middle_on",
|
2019-09-18 15:46:49 +02:00
|
|
|
rules = static_middle_rules_get,
|
2019-09-18 01:13:20 +02:00
|
|
|
}}
|
|
|
|
}, {
|
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
|
|
|
tiles = {"mesecons_wire_on.png"},
|
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
|
|
|
offstate = "mesecons_extrawires:vertical_static_middle_off",
|
2019-09-18 15:46:49 +02:00
|
|
|
rules = static_middle_rules_get,
|
2019-09-18 01:13:20 +02:00
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- crafting
|
2013-02-22 19:37:05 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "mesecons_extrawires:vertical_off 3",
|
|
|
|
recipe = {
|
|
|
|
{"mesecons:wire_00000000_off"},
|
|
|
|
{"mesecons:wire_00000000_off"},
|
|
|
|
{"mesecons:wire_00000000_off"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "mesecons:wire_00000000_off",
|
|
|
|
recipe = {{"mesecons_extrawires:vertical_off"}}
|
|
|
|
})
|
2019-09-18 01:13:20 +02:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "mesecons_extrawires:vertical_static_middle_off 5",
|
|
|
|
recipe = {
|
|
|
|
{"", "mesecons_extrawires:vertical_off", ""},
|
|
|
|
{"", "mesecons_extrawires:vertical_off", ""},
|
|
|
|
{"mesecons_extrawires:vertical_off", "mesecons_extrawires:vertical_off", "mesecons_extrawires:vertical_off"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "mesecons_extrawires:vertical_off",
|
|
|
|
recipe = {{"mesecons_extrawires:vertical_static_middle_off"}}
|
|
|
|
})
|